~ubuntu-branches/ubuntu/feisty/muse/feisty

« back to all changes in this revision

Viewing changes to waveedit/waveedit.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Kobras
  • Date: 2002-04-23 17:28:23 UTC
  • Revision ID: james.westby@ubuntu.com-20020423172823-w8yplzr81a759xa3
Tags: upstream-0.5.2
ImportĀ upstreamĀ versionĀ 0.5.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//=========================================================
 
2
//  MusE
 
3
//  Linux Music Editor
 
4
//    $Id: waveedit.cpp,v 1.1 2002/01/30 14:10:09 muse Exp $
 
5
//  (C) Copyright 2000 Werner Schweer (ws@seh.de)
 
6
//=========================================================
 
7
 
 
8
#include "xml.h"
 
9
#include "waveedit.h"
 
10
#include "mtscale.h"
 
11
#include "scrollscale.h"
 
12
#include "intlabel.h"
 
13
#include "seq.h"
 
14
#include "waveview.h"
 
15
#include "ttoolbar.h"
 
16
#include "globals.h"
 
17
#include "waveview.h"
 
18
#include "utils.h"
 
19
#include "song.h"
 
20
#include "poslabel.h"
 
21
 
 
22
#include <qtoolbar.h>
 
23
#include <qtoolbutton.h>
 
24
#include <qaccel.h>
 
25
#include <qlayout.h>
 
26
#include <qhbox.h>
 
27
#include <qsizegrip.h>
 
28
#include <qscrollbar.h>
 
29
#include <qlabel.h>
 
30
#include <qpushbutton.h>
 
31
#include <qradiobutton.h>
 
32
#include <qbuttongroup.h>
 
33
#include <qlistbox.h>
 
34
#include <qcombobox.h>
 
35
#include <qheader.h>
 
36
#include <qpopupmenu.h>
 
37
#include <qmenubar.h>
 
38
 
 
39
extern QColor readColor(Xml& xml);
 
40
 
 
41
QColor WaveEdit::bg = QColor(0xff,0xff,0xff);
 
42
 
 
43
//---------------------------------------------------------
 
44
//   setBg
 
45
//---------------------------------------------------------
 
46
 
 
47
void WaveEdit::setBg(QColor _bg)
 
48
      {
 
49
      bg = _bg;
 
50
      view->setBg(bg);
 
51
      }
 
52
 
 
53
//---------------------------------------------------------
 
54
//   closeEvent
 
55
//---------------------------------------------------------
 
56
 
 
57
void WaveEdit::closeEvent(QCloseEvent* e)
 
58
      {
 
59
      emit deleted((int)this);
 
60
      e->accept();
 
61
      }
 
62
 
 
63
//---------------------------------------------------------
 
64
//   WaveEdit
 
65
//---------------------------------------------------------
 
66
 
 
67
WaveEdit::WaveEdit(PartList* pl)
 
68
   : MidiEditor(1, 1, pl)
 
69
      {
 
70
      parts = pl;
 
71
      WavePart* part = (WavePart*)(pl->begin()->second);
 
72
      partSn = part->sn();
 
73
 
 
74
      //---------Pulldown Menu----------------------------
 
75
      QPopupMenu* menuFile = new QPopupMenu(this);
 
76
      menuBar()->insertItem("&File", menuFile);
 
77
      QPopupMenu* menuFunctions = new QPopupMenu(this);
 
78
      menuBar()->insertItem("Functions", menuFunctions);
 
79
      menuFunctions->insertItem(tr("Normalize"), 1);
 
80
 
 
81
      connect(menuFunctions, SIGNAL(activated(int)), SLOT(cmd(int)));
 
82
      connect(menuFile, SIGNAL(activated(int)), SLOT(cmd(int)));
 
83
 
 
84
      //---------ToolBar----------------------------------
 
85
      tools = new QToolBar(this, "waveedit-tools");
 
86
      undoRedo->addTo(tools);
 
87
 
 
88
      //--------------------------------------------------
 
89
      //    Transport Bar
 
90
      new TransportToolbar(this, "pr-tr-tools");
 
91
 
 
92
      //--------------------------------------------------
 
93
      //    ToolBar:   Solo  Cursor1 Cursor2
 
94
 
 
95
      tb1 = new QToolBar(this, "pianoroll-tools");
 
96
//      tb1->setHorizontalStretchable(true);
 
97
 
 
98
      tb1->setLabel(tr("weTools"));
 
99
      solo = new QToolButton(tb1);
 
100
      solo->setText(tr("Solo"));
 
101
      solo->setToggleButton(true);
 
102
 
 
103
      QLabel* label = new QLabel(tr("Cursor"), tb1, "Cursor");
 
104
      label->setAlignment(AlignRight|AlignVCenter);
 
105
      label->setIndent(3);
 
106
      pos1 = new PosLabel(tb1);
 
107
      pos2 = new PosLabel(tb1);
 
108
      pos2->setSmpte(true);
 
109
 
 
110
      //---------------------------------------------------
 
111
      //    Rest
 
112
      //---------------------------------------------------
 
113
 
 
114
      int yscale = 256;
 
115
      int xscale = -8000;
 
116
 
 
117
      view                 = new WaveView(this, mainw, xscale, yscale);
 
118
      wview                = view;   // HACK!
 
119
      view->setBg(bg);
 
120
 
 
121
      QSizeGrip* corner    = new QSizeGrip(mainw);
 
122
      ymag                 = new QSlider(1, 256, 256, yscale, Vertical, mainw);
 
123
//      time                 = new WTScale(&_raster, mainw, xscale);
 
124
      time                 = new MTScale(&_raster, mainw, xscale, true);
 
125
      ymag->setFixedWidth(16);
 
126
      connect(ymag, SIGNAL(valueChanged(int)), view, SLOT(setYScale(int)));
 
127
 
 
128
      hscroll = new ScrollScale(1, -32768, xscale, 10000, Horizontal, mainw, 0, true, 10000.0);
 
129
      hscroll->setPos(0);
 
130
 
 
131
      int s, e;
 
132
      view->range(&s, &e);
 
133
      hscroll->setRange(s, e);
 
134
 
 
135
      mainGrid->setRowStretch(0, 100);
 
136
      mainGrid->setColStretch(0, 100);
 
137
 
 
138
      mainGrid->addMultiCellWidget(time,   0, 0, 0, 1);
 
139
      mainGrid->addMultiCellWidget(hLine(mainw),    1, 1, 0, 1);
 
140
      mainGrid->addWidget(view,    2, 0);
 
141
      mainGrid->addWidget(ymag,    2, 1);
 
142
      mainGrid->addWidget(hscroll, 3, 0);
 
143
      mainGrid->addWidget(corner,  3, 1, AlignBottom | AlignRight);
 
144
 
 
145
      connect(hscroll, SIGNAL(scrollChanged(int)), view, SLOT(setXPos(int)));
 
146
      connect(hscroll, SIGNAL(scaleChanged(int)),  view, SLOT(setXMag(int)));
 
147
      setCaption(view->getCaption());
 
148
      connect(view, SIGNAL(followEvent(int)), hscroll, SLOT(setOffset(int)));
 
149
 
 
150
      connect(hscroll, SIGNAL(scrollChanged(int)), time,  SLOT(setXPos(int)));
 
151
      connect(hscroll, SIGNAL(scaleChanged(int)),  time,  SLOT(setXMag(int)));
 
152
      connect(time,    SIGNAL(timeChanged(int)),  SLOT(setTime(int)));
 
153
      connect(view,    SIGNAL(timeChanged(int)),  SLOT(setTime(int)));
 
154
      connect(song,    SIGNAL(songChanged(int)), SLOT(songChanged(int)));
 
155
      }
 
156
 
 
157
//---------------------------------------------------------
 
158
//   setTime
 
159
//---------------------------------------------------------
 
160
 
 
161
void WaveEdit::setTime(int samplepos)
 
162
      {
 
163
      int tick = tempomap.samples2tick(samplepos);
 
164
      pos1->setValue(tick);
 
165
      pos2->setValue(tick);
 
166
      time->setPos(3, tick, false);
 
167
      }
 
168
 
 
169
//---------------------------------------------------------
 
170
//   ~WaveEdit
 
171
//---------------------------------------------------------
 
172
 
 
173
WaveEdit::~WaveEdit()
 
174
      {
 
175
      undoRedo->removeFrom(tools);
 
176
      }
 
177
 
 
178
//---------------------------------------------------------
 
179
//   cmd
 
180
//---------------------------------------------------------
 
181
 
 
182
void WaveEdit::cmd(int n)
 
183
      {
 
184
      switch(n) {
 
185
            case 1: printf("normalize: not implemented\n"); break;
 
186
            default:
 
187
                  break;
 
188
            }
 
189
      }
 
190
 
 
191
//---------------------------------------------------------
 
192
//   loadConfiguration
 
193
//---------------------------------------------------------
 
194
 
 
195
void WaveEdit::readConfiguration(Xml& xml)
 
196
      {
 
197
      for (;;) {
 
198
            Xml::Token token = xml.parse();
 
199
            const QString& tag = xml.s1();
 
200
            switch (token) {
 
201
                  case Xml::TagStart:
 
202
                        if (tag == "bgcolor")
 
203
                              bg = readColor(xml);
 
204
                        else
 
205
                              xml.unknown("WaveEdit");
 
206
                        break;
 
207
                  case Xml::TagEnd:
 
208
                        if (tag == "waveedit")
 
209
                              return;
 
210
                  default:
 
211
                        break;
 
212
                  case Xml::Error:
 
213
                  case Xml::End:
 
214
                        return;
 
215
                  }
 
216
            }
 
217
      }
 
218
 
 
219
//---------------------------------------------------------
 
220
//   saveConfiguration
 
221
//---------------------------------------------------------
 
222
 
 
223
void WaveEdit::writeConfiguration(int level, Xml& xml)
 
224
      {
 
225
      xml.tag(level++, "waveedit");
 
226
      xml.put(level, "<bgcolor r=\"%d\" g=\"%d\" b=\"%d\"></bgcolor>",
 
227
         bg.red(), bg.green(), bg.blue());
 
228
      xml.tag(level, "/waveedit");
 
229
      }
 
230
 
 
231
//---------------------------------------------------------
 
232
//   writeStatus
 
233
//---------------------------------------------------------
 
234
 
 
235
void WaveEdit::writeStatus(int level, Xml& xml) const
 
236
      {
 
237
      writePartList(level, xml);
 
238
      xml.tag(level++, "waveedit");
 
239
      MidiEditor::writeStatus(level, xml);
 
240
      xml.intTag(level, "xpos", hscroll->pos());
 
241
      xml.intTag(level, "xmag", hscroll->mag());
 
242
      xml.intTag(level, "ymag", ymag->value());
 
243
      xml.tag(level, "/waveedit");
 
244
      }
 
245
 
 
246
//---------------------------------------------------------
 
247
//   readStatus
 
248
//---------------------------------------------------------
 
249
 
 
250
void WaveEdit::readStatus(Xml& xml)
 
251
      {
 
252
      for (;;) {
 
253
            Xml::Token token = xml.parse();
 
254
            if (token == Xml::Error || token == Xml::End)
 
255
                  break;
 
256
            QString tag = xml.s1();
 
257
            switch (token) {
 
258
                  case Xml::TagStart:
 
259
                        if (tag == "midieditor")
 
260
                              MidiEditor::readStatus(xml);
 
261
                        else if (tag == "xmag")
 
262
                              hscroll->setMag(xml.parseInt());
 
263
                        else if (tag == "ymag")
 
264
                              ymag->setValue(xml.parseInt());
 
265
                        else if (tag == "xpos")
 
266
                              hscroll->setPos(xml.parseInt());
 
267
                        else
 
268
                              xml.unknown("WaveEdit");
 
269
                        break;
 
270
                  case Xml::TagEnd:
 
271
                        if (tag == "waveedit")
 
272
                              return;
 
273
                  default:
 
274
                        break;
 
275
                  }
 
276
            }
 
277
      }
 
278
 
 
279