summaryrefslogtreecommitdiff
path: root/muse2/muse/cliplist/cliplist.cpp
blob: 9200203280c9e6917ee3f59c902c025b8593f7b8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
//=========================================================
//  MusE
//  Linux Music Editor
//  $Id: cliplist.cpp,v 1.6.2.3 2008/08/18 00:15:24 terminator356 Exp $
//
//  (C) Copyright 2000 Werner Schweer (ws@seh.de)
//=========================================================

#include "cliplist.h"
#include "song.h"
#include "globals.h"
#include "wave.h"
#include "xml.h"
#include "posedit.h"
#include "cliplisteditorbase.h"

#include <q3listview.h>
#include <qlayout.h>
#include <q3groupbox.h>
#include <qlabel.h>
#include <qstyle.h>
//Added by qt3to4:
#include <QCloseEvent>

extern int mtcType;
enum { COL_NAME=0, COL_REFS, COL_POS, COL_LEN };

//---------------------------------------------------------
//   ClipItem
//---------------------------------------------------------

class ClipItem : public Q3ListViewItem {
      SndFileR _wf;

      virtual QString text(int) const;

   public:
      ClipItem(Q3ListView*, const SndFileR&);
      SndFileR* wf() { return &_wf; }
      };

ClipItem::ClipItem(Q3ListView* parent, const SndFileR& w)
   : Q3ListViewItem(parent), _wf(w)
      {
      }

//---------------------------------------------------------
//   samples2smpte
//---------------------------------------------------------

#if 0
static QString samples2smpte(int samples)
      {
      double time = double(samples) / double(sampleRate);
      int min  = int(time) / 60;
      int sec  = int(time) % 60;
      double rest = time - (min * 60 + sec);
      switch(mtcType) {
            case 0:     // 24 frames sec
                  rest *= 24;
                  break;
            case 1:     // 25
                  rest *= 25;
                  break;
            case 2:     // 30 drop frame
                  rest *= 30;
                  break;
            case 3:     // 30 non drop frame
                  rest *= 30;
                  break;
                  }
      int frame = int(rest);
      int subframe = int((rest-frame)*100);
      QString s;
      s.sprintf("%03d:%02d:%02d:%02d", min, sec, frame, subframe);
      return s;
      }
#endif

//---------------------------------------------------------
//   text
//---------------------------------------------------------

QString ClipItem::text(int col) const
      {
      QString s("");
      switch(col) {
            case COL_NAME:
                  s = _wf.name();
                  break;
            case COL_POS:
            case COL_LEN:
                  break;
            case COL_REFS:
                  s.setNum(_wf.getRefCount());
                  break;
            }
      return s;
      }

//---------------------------------------------------------
//   ClipListEdit
//---------------------------------------------------------

ClipListEdit::ClipListEdit()
   : TopWin(0, "cliplist", Qt::WType_TopLevel /*|WDestructiveClose*/)
      {
      setCaption(tr("MusE: Clip List Editor"));

      editor = new ClipListEditorBase(this, "edit");
      setCentralWidget(editor);

      editor->view->setColumnAlignment(COL_REFS, Qt::AlignRight);

      QFontMetrics fm(editor->view->font());
      int fw = style()->pixelMetric(QStyle::PM_DefaultFrameWidth,0, this); // ddskrjo 0
      int w  = 2 + fm.width('9') * 9 + fm.width(':') * 3 + fw * 4;
      editor->view->setColumnAlignment(COL_POS, Qt::AlignRight);
      editor->view->setColumnWidth(COL_POS, w);
      editor->view->setColumnAlignment(COL_LEN, Qt::AlignRight);
      editor->view->setColumnWidth(COL_LEN, w);

      connect(editor->view, SIGNAL(selectionChanged()), SLOT(clipSelectionChanged()));
      connect(editor->view, SIGNAL(clicked(Q3ListViewItem*)), SLOT(clicked(Q3ListViewItem*)));

      connect(song, SIGNAL(songChanged(int)), SLOT(songChanged(int)));
      connect(editor->start, SIGNAL(valueChanged(const Pos&)), SLOT(startChanged(const Pos&)));
      connect(editor->len, SIGNAL(valueChanged(const Pos&)), SLOT(lenChanged(const Pos&)));

      updateList();
      }

//---------------------------------------------------------
//   updateList
//---------------------------------------------------------

void ClipListEdit::updateList()
      {
      editor->view->clear();
      for (iSndFile f = SndFile::sndFiles.begin(); f != SndFile::sndFiles.end(); ++f) {
            new ClipItem(editor->view, *f);
            }
      clipSelectionChanged();
      }

//---------------------------------------------------------
//   closeEvent
//---------------------------------------------------------

void ClipListEdit::closeEvent(QCloseEvent* e)
      {
      emit deleted((unsigned long)this);
      e->accept();
      }

//---------------------------------------------------------
//   songChanged
//---------------------------------------------------------

void ClipListEdit::songChanged(int type)
      {
      // Is it simply a midi controller value adjustment? Forget it.
      if(type == SC_MIDI_CONTROLLER)
        return;
    
      updateList();
      }

//---------------------------------------------------------
//   readStatus
//---------------------------------------------------------

void ClipListEdit::readStatus(Xml& xml)
      {
      for (;;) {
            Xml::Token token = xml.parse();
            const QString& tag = xml.s1();
            if (token == Xml::Error || token == Xml::End)
                  break;
            switch (token) {
                  case Xml::TagStart:
                        if (tag == "topwin")
                              TopWin::readStatus(xml);
                        else
                              xml.unknown("CliplistEdit");
                        break;
                  case Xml::TagEnd:
                        if (tag == "cliplist")
                              return;
                  default:
                        break;
                  }
            }
      }

//---------------------------------------------------------
//   writeStatus
//---------------------------------------------------------

void ClipListEdit::writeStatus(int level, Xml& xml) const
      {
      xml.tag(level++, "cliplist");
      TopWin::writeStatus(level, xml);
      xml.etag(level, "cliplist");
      }

//---------------------------------------------------------
//   startChanged
//---------------------------------------------------------

void ClipListEdit::startChanged(const Pos& /*pos*/)//prevent compiler warning: unsused parameter
      {
//      editor->view->triggerUpdate();
      }

//---------------------------------------------------------
//   lenChanged
//---------------------------------------------------------

void ClipListEdit::lenChanged(const Pos& /*pos*/) //prevent compiler warning: unsused parameter
      {
//      curClip.setLenFrame(pos.frame());
//      editor->view->triggerUpdate();
      }

//---------------------------------------------------------
//   clipSelectionChanged
//---------------------------------------------------------

void ClipListEdit::clipSelectionChanged()
      {
//      ClipItem* item = (ClipItem*)(editor->view->selectedItem());

//      if (item == 0) {
            editor->start->setEnabled(false);
            editor->len->setEnabled(false);
            return;
#if 0
            }
      editor->start->setEnabled(true);
      editor->len->setEnabled(true);
      Pos pos, len;
      pos.setType(Pos::FRAMES);
      len.setType(Pos::FRAMES);
      pos.setFrame(curClip.spos());
      len.setFrame(curClip.lenFrame());
      editor->start->setValue(pos);
      editor->len->setValue(len);
#endif
      }

//---------------------------------------------------------
//   clicked
//---------------------------------------------------------

void ClipListEdit::clicked(Q3ListViewItem*)
      {
//      printf("clicked\n");
      }