Chris@0
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@0
|
2
|
Chris@0
|
3 /*
|
Chris@0
|
4 Sonic Visualiser
|
Chris@0
|
5 An audio file viewer and annotation editor.
|
Chris@0
|
6 Centre for Digital Music, Queen Mary, University of London.
|
Chris@77
|
7 This file copyright 2006 Chris Cannam and QMUL.
|
Chris@0
|
8
|
Chris@0
|
9 This program is free software; you can redistribute it and/or
|
Chris@0
|
10 modify it under the terms of the GNU General Public License as
|
Chris@0
|
11 published by the Free Software Foundation; either version 2 of the
|
Chris@0
|
12 License, or (at your option) any later version. See the file
|
Chris@0
|
13 COPYING included with this distribution for more information.
|
Chris@0
|
14 */
|
Chris@0
|
15
|
Chris@1
|
16 #include "version.h"
|
Chris@0
|
17
|
Chris@0
|
18 #include "MainWindow.h"
|
Chris@1
|
19 #include "document/Document.h"
|
Chris@0
|
20 #include "PreferencesDialog.h"
|
Chris@0
|
21
|
Chris@1
|
22 #include "view/Pane.h"
|
Chris@1
|
23 #include "view/PaneStack.h"
|
Chris@1
|
24 #include "data/model/WaveFileModel.h"
|
Chris@1
|
25 #include "data/model/SparseOneDimensionalModel.h"
|
Chris@1
|
26 #include "view/ViewManager.h"
|
Chris@0
|
27 #include "base/Preferences.h"
|
Chris@0
|
28 #include "layer/WaveformLayer.h"
|
Chris@0
|
29 #include "layer/TimeRulerLayer.h"
|
Chris@0
|
30 #include "layer/TimeInstantLayer.h"
|
Chris@0
|
31 #include "layer/TimeValueLayer.h"
|
Chris@0
|
32 #include "layer/Colour3DPlotLayer.h"
|
Chris@0
|
33 #include "widgets/Fader.h"
|
Chris@65
|
34 #include "view/Overview.h"
|
Chris@0
|
35 #include "widgets/PropertyBox.h"
|
Chris@0
|
36 #include "widgets/PropertyStack.h"
|
Chris@0
|
37 #include "widgets/AudioDial.h"
|
Chris@0
|
38 #include "widgets/LayerTree.h"
|
Chris@0
|
39 #include "widgets/ListInputDialog.h"
|
Chris@36
|
40 #include "widgets/SubdividingMenu.h"
|
Chris@90
|
41 #include "widgets/NotifyingPushButton.h"
|
Chris@0
|
42 #include "audioio/AudioCallbackPlaySource.h"
|
Chris@0
|
43 #include "audioio/AudioCallbackPlayTarget.h"
|
Chris@0
|
44 #include "audioio/AudioTargetFactory.h"
|
Chris@59
|
45 #include "audioio/PlaySpeedRangeMapper.h"
|
Chris@1
|
46 #include "data/fileio/AudioFileReaderFactory.h"
|
Chris@1
|
47 #include "data/fileio/DataFileReaderFactory.h"
|
Chris@1
|
48 #include "data/fileio/WavFileWriter.h"
|
Chris@1
|
49 #include "data/fileio/CSVFileWriter.h"
|
Chris@1
|
50 #include "data/fileio/BZipFileDevice.h"
|
Chris@85
|
51 #include "data/fileio/RemoteFile.h"
|
Chris@91
|
52 #include "data/fft/FFTDataServer.h"
|
Chris@1
|
53 #include "base/RecentFiles.h"
|
Chris@0
|
54 #include "transform/TransformFactory.h"
|
Chris@0
|
55 #include "base/PlayParameterRepository.h"
|
Chris@0
|
56 #include "base/XmlExportable.h"
|
Chris@0
|
57 #include "base/CommandHistory.h"
|
Chris@0
|
58 #include "base/Profiler.h"
|
Chris@0
|
59 #include "base/Clipboard.h"
|
Chris@69
|
60 #include "osc/OSCQueue.h"
|
Chris@0
|
61
|
Chris@0
|
62 // For version information
|
Chris@0
|
63 #include "vamp/vamp.h"
|
Chris@0
|
64 #include "vamp-sdk/PluginBase.h"
|
Chris@0
|
65 #include "plugin/api/ladspa.h"
|
Chris@0
|
66 #include "plugin/api/dssi.h"
|
Chris@0
|
67
|
Chris@0
|
68 #include <QApplication>
|
Chris@0
|
69 #include <QMessageBox>
|
Chris@0
|
70 #include <QGridLayout>
|
Chris@0
|
71 #include <QLabel>
|
Chris@0
|
72 #include <QAction>
|
Chris@0
|
73 #include <QMenuBar>
|
Chris@0
|
74 #include <QToolBar>
|
Chris@0
|
75 #include <QInputDialog>
|
Chris@0
|
76 #include <QStatusBar>
|
Chris@0
|
77 #include <QTreeView>
|
Chris@0
|
78 #include <QFile>
|
Chris@88
|
79 #include <QFileInfo>
|
Chris@88
|
80 #include <QDir>
|
Chris@0
|
81 #include <QTextStream>
|
Chris@0
|
82 #include <QProcess>
|
Chris@7
|
83 #include <QShortcut>
|
Chris@5
|
84 #include <QSettings>
|
Chris@11
|
85 #include <QDateTime>
|
Chris@11
|
86 #include <QProcess>
|
Chris@16
|
87 #include <QCheckBox>
|
Chris@55
|
88 #include <QRegExp>
|
Chris@0
|
89
|
Chris@0
|
90 #include <iostream>
|
Chris@0
|
91 #include <cstdio>
|
Chris@0
|
92 #include <errno.h>
|
Chris@0
|
93
|
Chris@0
|
94 using std::cerr;
|
Chris@0
|
95 using std::endl;
|
Chris@0
|
96
|
Chris@33
|
97 using std::vector;
|
Chris@33
|
98 using std::map;
|
Chris@33
|
99 using std::set;
|
Chris@33
|
100
|
Chris@0
|
101
|
Chris@70
|
102 MainWindow::MainWindow(bool withAudioOutput, bool withOSCSupport) :
|
Chris@0
|
103 m_document(0),
|
Chris@0
|
104 m_paneStack(0),
|
Chris@0
|
105 m_viewManager(0),
|
Chris@65
|
106 m_overview(0),
|
Chris@0
|
107 m_timeRulerLayer(0),
|
Chris@46
|
108 m_audioOutput(withAudioOutput),
|
Chris@0
|
109 m_playSource(0),
|
Chris@0
|
110 m_playTarget(0),
|
Chris@70
|
111 m_oscQueue(withOSCSupport ? new OSCQueue() : 0),
|
Chris@81
|
112 m_recentFiles("RecentFiles", 20),
|
Chris@49
|
113 m_recentTransforms("RecentTransforms", 20),
|
Chris@0
|
114 m_mainMenusCreated(false),
|
Chris@0
|
115 m_paneMenu(0),
|
Chris@0
|
116 m_layerMenu(0),
|
Chris@34
|
117 m_transformsMenu(0),
|
Chris@0
|
118 m_existingLayersMenu(0),
|
Chris@34
|
119 m_recentFilesMenu(0),
|
Chris@34
|
120 m_recentTransformsMenu(0),
|
Chris@0
|
121 m_rightButtonMenu(0),
|
Chris@0
|
122 m_rightButtonLayerMenu(0),
|
Chris@34
|
123 m_rightButtonTransformsMenu(0),
|
Chris@0
|
124 m_documentModified(false),
|
Chris@70
|
125 m_openingAudioFile(false),
|
Chris@70
|
126 m_abandoning(false),
|
Chris@0
|
127 m_preferencesDialog(0)
|
Chris@0
|
128 {
|
Chris@0
|
129 setWindowTitle(tr("Sonic Visualiser"));
|
Chris@0
|
130
|
Chris@0
|
131 UnitDatabase::getInstance()->registerUnit("Hz");
|
Chris@0
|
132 UnitDatabase::getInstance()->registerUnit("dB");
|
Chris@0
|
133
|
Chris@0
|
134 connect(CommandHistory::getInstance(), SIGNAL(commandExecuted()),
|
Chris@0
|
135 this, SLOT(documentModified()));
|
Chris@0
|
136 connect(CommandHistory::getInstance(), SIGNAL(documentRestored()),
|
Chris@0
|
137 this, SLOT(documentRestored()));
|
Chris@0
|
138
|
Chris@0
|
139 QFrame *frame = new QFrame;
|
Chris@0
|
140 setCentralWidget(frame);
|
Chris@0
|
141
|
Chris@0
|
142 QGridLayout *layout = new QGridLayout;
|
Chris@0
|
143
|
Chris@0
|
144 m_viewManager = new ViewManager();
|
Chris@0
|
145 connect(m_viewManager, SIGNAL(selectionChanged()),
|
Chris@0
|
146 this, SLOT(updateMenuStates()));
|
Chris@0
|
147
|
Chris@0
|
148 m_descriptionLabel = new QLabel;
|
Chris@0
|
149
|
Chris@0
|
150 m_paneStack = new PaneStack(frame, m_viewManager);
|
Chris@0
|
151 connect(m_paneStack, SIGNAL(currentPaneChanged(Pane *)),
|
Chris@0
|
152 this, SLOT(currentPaneChanged(Pane *)));
|
Chris@0
|
153 connect(m_paneStack, SIGNAL(currentLayerChanged(Pane *, Layer *)),
|
Chris@0
|
154 this, SLOT(currentLayerChanged(Pane *, Layer *)));
|
Chris@0
|
155 connect(m_paneStack, SIGNAL(rightButtonMenuRequested(Pane *, QPoint)),
|
Chris@0
|
156 this, SLOT(rightButtonMenuRequested(Pane *, QPoint)));
|
Chris@73
|
157 connect(m_paneStack, SIGNAL(propertyStacksResized()),
|
Chris@73
|
158 this, SLOT(propertyStacksResized()));
|
Chris@90
|
159 connect(m_paneStack, SIGNAL(contextHelpChanged(const QString &)),
|
Chris@90
|
160 statusBar(), SLOT(showMessage(const QString &)));
|
Chris@0
|
161
|
Chris@65
|
162 m_overview = new Overview(frame);
|
Chris@65
|
163 m_overview->setViewManager(m_viewManager);
|
Chris@65
|
164 m_overview->setFixedHeight(40);
|
Chris@90
|
165 connect(m_overview, SIGNAL(contextHelpChanged(const QString &)),
|
Chris@90
|
166 statusBar(), SLOT(showMessage(const QString &)));
|
Chris@0
|
167
|
Chris@0
|
168 m_panLayer = new WaveformLayer;
|
Chris@0
|
169 m_panLayer->setChannelMode(WaveformLayer::MergeChannels);
|
Chris@0
|
170 // m_panLayer->setScale(WaveformLayer::MeterScale);
|
Chris@39
|
171 // m_panLayer->setAutoNormalize(true);
|
Chris@0
|
172 m_panLayer->setBaseColour(Qt::darkGreen);
|
Chris@0
|
173 m_panLayer->setAggressiveCacheing(true);
|
Chris@65
|
174 m_overview->addLayer(m_panLayer);
|
Chris@0
|
175
|
Chris@0
|
176 m_playSource = new AudioCallbackPlaySource(m_viewManager);
|
Chris@0
|
177
|
Chris@0
|
178 connect(m_playSource, SIGNAL(sampleRateMismatch(size_t, size_t, bool)),
|
Chris@0
|
179 this, SLOT(sampleRateMismatch(size_t, size_t, bool)));
|
Chris@42
|
180 connect(m_playSource, SIGNAL(audioOverloadPluginDisabled()),
|
Chris@42
|
181 this, SLOT(audioOverloadPluginDisabled()));
|
Chris@0
|
182
|
Chris@0
|
183 m_fader = new Fader(frame, false);
|
Chris@90
|
184 connect(m_fader, SIGNAL(mouseEntered()), this, SLOT(mouseEnteredWidget()));
|
Chris@90
|
185 connect(m_fader, SIGNAL(mouseLeft()), this, SLOT(mouseLeftWidget()));
|
Chris@0
|
186
|
Chris@0
|
187 m_playSpeed = new AudioDial(frame);
|
Chris@12
|
188 m_playSpeed->setMinimum(0);
|
Chris@48
|
189 m_playSpeed->setMaximum(200);
|
Chris@25
|
190 m_playSpeed->setValue(100);
|
Chris@0
|
191 m_playSpeed->setFixedWidth(24);
|
Chris@0
|
192 m_playSpeed->setFixedHeight(24);
|
Chris@0
|
193 m_playSpeed->setNotchesVisible(true);
|
Chris@25
|
194 m_playSpeed->setPageStep(10);
|
Chris@60
|
195 m_playSpeed->setObjectName(tr("Playback Speedup"));
|
Chris@25
|
196 m_playSpeed->setDefaultValue(100);
|
Chris@59
|
197 m_playSpeed->setRangeMapper(new PlaySpeedRangeMapper(0, 200));
|
Chris@60
|
198 m_playSpeed->setShowToolTip(true);
|
Chris@0
|
199 connect(m_playSpeed, SIGNAL(valueChanged(int)),
|
Chris@0
|
200 this, SLOT(playSpeedChanged(int)));
|
Chris@90
|
201 connect(m_playSpeed, SIGNAL(mouseEntered()), this, SLOT(mouseEnteredWidget()));
|
Chris@90
|
202 connect(m_playSpeed, SIGNAL(mouseLeft()), this, SLOT(mouseLeftWidget()));
|
Chris@90
|
203
|
Chris@90
|
204 m_playSharpen = new NotifyingPushButton(frame);
|
Chris@17
|
205 m_playSharpen->setToolTip(tr("Sharpen percussive transients"));
|
Chris@26
|
206 m_playSharpen->setFixedSize(20, 20);
|
Chris@26
|
207 // m_playSharpen->setFlat(true);
|
Chris@16
|
208 m_playSharpen->setEnabled(false);
|
Chris@26
|
209 m_playSharpen->setCheckable(true);
|
Chris@26
|
210 m_playSharpen->setChecked(false);
|
Chris@26
|
211 m_playSharpen->setIcon(QIcon(":icons/sharpen.png"));
|
Chris@26
|
212 connect(m_playSharpen, SIGNAL(clicked()), this, SLOT(playSharpenToggled()));
|
Chris@90
|
213 connect(m_playSharpen, SIGNAL(mouseEntered()), this, SLOT(mouseEnteredWidget()));
|
Chris@90
|
214 connect(m_playSharpen, SIGNAL(mouseLeft()), this, SLOT(mouseLeftWidget()));
|
Chris@90
|
215
|
Chris@90
|
216 m_playMono = new NotifyingPushButton(frame);
|
Chris@26
|
217 m_playMono->setToolTip(tr("Run time stretcher in mono only"));
|
Chris@26
|
218 m_playMono->setFixedSize(20, 20);
|
Chris@26
|
219 // m_playMono->setFlat(true);
|
Chris@26
|
220 m_playMono->setEnabled(false);
|
Chris@26
|
221 m_playMono->setCheckable(true);
|
Chris@26
|
222 m_playMono->setChecked(false);
|
Chris@26
|
223 m_playMono->setIcon(QIcon(":icons/mono.png"));
|
Chris@26
|
224 connect(m_playMono, SIGNAL(clicked()), this, SLOT(playMonoToggled()));
|
Chris@90
|
225 connect(m_playMono, SIGNAL(mouseEntered()), this, SLOT(mouseEnteredWidget()));
|
Chris@90
|
226 connect(m_playMono, SIGNAL(mouseLeft()), this, SLOT(mouseLeftWidget()));
|
Chris@21
|
227
|
Chris@21
|
228 QSettings settings;
|
Chris@21
|
229 settings.beginGroup("MainWindow");
|
Chris@24
|
230 m_playSharpen->setChecked(settings.value("playsharpen", true).toBool());
|
Chris@26
|
231 m_playMono->setChecked(settings.value("playmono", false).toBool());
|
Chris@21
|
232 settings.endGroup();
|
Chris@21
|
233
|
Chris@26
|
234 layout->addWidget(m_paneStack, 0, 0, 1, 5);
|
Chris@65
|
235 layout->addWidget(m_overview, 1, 0);
|
Chris@0
|
236 layout->addWidget(m_fader, 1, 1);
|
Chris@0
|
237 layout->addWidget(m_playSpeed, 1, 2);
|
Chris@16
|
238 layout->addWidget(m_playSharpen, 1, 3);
|
Chris@26
|
239 layout->addWidget(m_playMono, 1, 4);
|
Chris@16
|
240
|
Chris@16
|
241 layout->setColumnStretch(0, 10);
|
Chris@16
|
242
|
Chris@0
|
243 frame->setLayout(layout);
|
Chris@0
|
244
|
Chris@0
|
245 connect(m_viewManager, SIGNAL(outputLevelsChanged(float, float)),
|
Chris@0
|
246 this, SLOT(outputLevelsChanged(float, float)));
|
Chris@0
|
247
|
Chris@0
|
248 connect(Preferences::getInstance(),
|
Chris@0
|
249 SIGNAL(propertyChanged(PropertyContainer::PropertyName)),
|
Chris@0
|
250 this,
|
Chris@0
|
251 SLOT(preferenceChanged(PropertyContainer::PropertyName)));
|
Chris@0
|
252
|
Chris@70
|
253 if (m_oscQueue && m_oscQueue->isOK()) {
|
Chris@69
|
254 connect(m_oscQueue, SIGNAL(messagesAvailable()), this, SLOT(pollOSC()));
|
Chris@69
|
255 QTimer *oscTimer = new QTimer(this);
|
Chris@69
|
256 connect(oscTimer, SIGNAL(timeout()), this, SLOT(pollOSC()));
|
Chris@69
|
257 oscTimer->start(1000);
|
Chris@69
|
258 }
|
Chris@69
|
259
|
Chris@0
|
260 setupMenus();
|
Chris@0
|
261 setupToolbars();
|
Chris@0
|
262
|
Chris@90
|
263 statusBar();
|
Chris@0
|
264
|
Chris@0
|
265 newSession();
|
Chris@0
|
266 }
|
Chris@0
|
267
|
Chris@0
|
268 MainWindow::~MainWindow()
|
Chris@0
|
269 {
|
Chris@70
|
270 if (!m_abandoning) {
|
Chris@70
|
271 closeSession();
|
Chris@70
|
272 }
|
Chris@0
|
273 delete m_playTarget;
|
Chris@0
|
274 delete m_playSource;
|
Chris@0
|
275 delete m_viewManager;
|
Chris@69
|
276 delete m_oscQueue;
|
Chris@0
|
277 Profiles::getInstance()->dump();
|
Chris@0
|
278 }
|
Chris@0
|
279
|
Chris@81
|
280 QString
|
Chris@88
|
281 MainWindow::getOpenFileName(FileFinder::FileType type)
|
Chris@81
|
282 {
|
Chris@88
|
283 FileFinder *ff = FileFinder::getInstance();
|
Chris@81
|
284 switch (type) {
|
Chris@88
|
285 case FileFinder::SessionFile:
|
Chris@88
|
286 return ff->getOpenFileName(type, m_sessionFile);
|
Chris@88
|
287 case FileFinder::AudioFile:
|
Chris@88
|
288 return ff->getOpenFileName(type, m_audioFile);
|
Chris@88
|
289 case FileFinder::LayerFile:
|
Chris@88
|
290 return ff->getOpenFileName(type, m_sessionFile);
|
Chris@88
|
291 case FileFinder::SessionOrAudioFile:
|
Chris@88
|
292 return ff->getOpenFileName(type, m_sessionFile);
|
Chris@88
|
293 case FileFinder::AnyFile:
|
Chris@88
|
294 if (getMainModel() != 0 &&
|
Chris@88
|
295 m_paneStack != 0 &&
|
Chris@88
|
296 m_paneStack->getCurrentPane() != 0) { // can import a layer
|
Chris@88
|
297 return ff->getOpenFileName(FileFinder::AnyFile, m_sessionFile);
|
Chris@81
|
298 } else {
|
Chris@88
|
299 return ff->getOpenFileName(FileFinder::SessionOrAudioFile,
|
Chris@88
|
300 m_sessionFile);
|
Chris@81
|
301 }
|
Chris@81
|
302 }
|
Chris@88
|
303 return "";
|
Chris@88
|
304 }
|
Chris@88
|
305
|
Chris@88
|
306 QString
|
Chris@88
|
307 MainWindow::getSaveFileName(FileFinder::FileType type)
|
Chris@88
|
308 {
|
Chris@88
|
309 FileFinder *ff = FileFinder::getInstance();
|
Chris@88
|
310 switch (type) {
|
Chris@88
|
311 case FileFinder::SessionFile:
|
Chris@88
|
312 return ff->getSaveFileName(type, m_sessionFile);
|
Chris@88
|
313 case FileFinder::AudioFile:
|
Chris@88
|
314 return ff->getSaveFileName(type, m_audioFile);
|
Chris@88
|
315 case FileFinder::LayerFile:
|
Chris@88
|
316 return ff->getSaveFileName(type, m_sessionFile);
|
Chris@88
|
317 case FileFinder::SessionOrAudioFile:
|
Chris@88
|
318 return ff->getSaveFileName(type, m_sessionFile);
|
Chris@88
|
319 case FileFinder::AnyFile:
|
Chris@88
|
320 return ff->getSaveFileName(type, m_sessionFile);
|
Chris@81
|
321 }
|
Chris@88
|
322 return "";
|
Chris@81
|
323 }
|
Chris@81
|
324
|
Chris@88
|
325 void
|
Chris@88
|
326 MainWindow::registerLastOpenedFilePath(FileFinder::FileType type, QString path)
|
Chris@81
|
327 {
|
Chris@88
|
328 FileFinder *ff = FileFinder::getInstance();
|
Chris@88
|
329 ff->registerLastOpenedFilePath(type, path);
|
Chris@81
|
330 }
|
Chris@81
|
331
|
Chris@81
|
332 void
|
Chris@0
|
333 MainWindow::setupMenus()
|
Chris@0
|
334 {
|
Chris@0
|
335 if (!m_mainMenusCreated) {
|
Chris@0
|
336 m_rightButtonMenu = new QMenu();
|
Chris@0
|
337 }
|
Chris@0
|
338
|
Chris@0
|
339 if (m_rightButtonLayerMenu) {
|
Chris@0
|
340 m_rightButtonLayerMenu->clear();
|
Chris@0
|
341 } else {
|
Chris@0
|
342 m_rightButtonLayerMenu = m_rightButtonMenu->addMenu(tr("&Layer"));
|
Chris@0
|
343 m_rightButtonMenu->addSeparator();
|
Chris@0
|
344 }
|
Chris@0
|
345
|
Chris@34
|
346 if (m_rightButtonTransformsMenu) {
|
Chris@34
|
347 m_rightButtonTransformsMenu->clear();
|
Chris@34
|
348 } else {
|
Chris@34
|
349 m_rightButtonTransformsMenu = m_rightButtonMenu->addMenu(tr("&Transform"));
|
Chris@34
|
350 m_rightButtonMenu->addSeparator();
|
Chris@34
|
351 }
|
Chris@34
|
352
|
Chris@0
|
353 if (!m_mainMenusCreated) {
|
Chris@0
|
354 CommandHistory::getInstance()->registerMenu(m_rightButtonMenu);
|
Chris@0
|
355 m_rightButtonMenu->addSeparator();
|
Chris@66
|
356 }
|
Chris@66
|
357
|
Chris@66
|
358 setupFileMenu();
|
Chris@66
|
359 setupEditMenu();
|
Chris@66
|
360 setupViewMenu();
|
Chris@66
|
361 setupPaneAndLayerMenus();
|
Chris@66
|
362 setupTransformsMenu();
|
Chris@66
|
363 setupHelpMenu();
|
Chris@66
|
364
|
Chris@66
|
365 m_mainMenusCreated = true;
|
Chris@66
|
366 }
|
Chris@66
|
367
|
Chris@66
|
368 void
|
Chris@66
|
369 MainWindow::setupFileMenu()
|
Chris@66
|
370 {
|
Chris@66
|
371 if (m_mainMenusCreated) return;
|
Chris@66
|
372
|
Chris@66
|
373 QMenu *menu = menuBar()->addMenu(tr("&File"));
|
Chris@66
|
374 QToolBar *toolbar = addToolBar(tr("File Toolbar"));
|
Chris@66
|
375
|
Chris@66
|
376 QIcon icon(":icons/filenew.png");
|
Chris@66
|
377 icon.addFile(":icons/filenew-22.png");
|
Chris@66
|
378 QAction *action = new QAction(icon, tr("&New Session"), this);
|
Chris@66
|
379 action->setShortcut(tr("Ctrl+N"));
|
Chris@90
|
380 action->setStatusTip(tr("Abandon the current Sonic Visualiser session and start a new one"));
|
Chris@66
|
381 connect(action, SIGNAL(triggered()), this, SLOT(newSession()));
|
Chris@66
|
382 menu->addAction(action);
|
Chris@66
|
383 toolbar->addAction(action);
|
Chris@0
|
384
|
Chris@66
|
385 icon = QIcon(":icons/fileopen.png");
|
Chris@66
|
386 icon.addFile(":icons/fileopen-22.png");
|
Chris@66
|
387
|
Chris@66
|
388 action = new QAction(icon, tr("&Open Session..."), this);
|
Chris@66
|
389 action->setShortcut(tr("Ctrl+O"));
|
Chris@66
|
390 action->setStatusTip(tr("Open a previously saved Sonic Visualiser session file"));
|
Chris@66
|
391 connect(action, SIGNAL(triggered()), this, SLOT(openSession()));
|
Chris@66
|
392 menu->addAction(action);
|
Chris@66
|
393
|
Chris@66
|
394 action = new QAction(icon, tr("&Open..."), this);
|
Chris@66
|
395 action->setStatusTip(tr("Open a session file, audio file, or layer"));
|
Chris@66
|
396 connect(action, SIGNAL(triggered()), this, SLOT(openSomething()));
|
Chris@66
|
397 toolbar->addAction(action);
|
Chris@66
|
398
|
Chris@66
|
399 icon = QIcon(":icons/filesave.png");
|
Chris@66
|
400 icon.addFile(":icons/filesave-22.png");
|
Chris@66
|
401 action = new QAction(icon, tr("&Save Session"), this);
|
Chris@66
|
402 action->setShortcut(tr("Ctrl+S"));
|
Chris@66
|
403 action->setStatusTip(tr("Save the current session into a Sonic Visualiser session file"));
|
Chris@66
|
404 connect(action, SIGNAL(triggered()), this, SLOT(saveSession()));
|
Chris@66
|
405 connect(this, SIGNAL(canSave(bool)), action, SLOT(setEnabled(bool)));
|
Chris@66
|
406 menu->addAction(action);
|
Chris@66
|
407 toolbar->addAction(action);
|
Chris@0
|
408
|
Chris@66
|
409 icon = QIcon(":icons/filesaveas.png");
|
Chris@66
|
410 icon.addFile(":icons/filesaveas-22.png");
|
Chris@66
|
411 action = new QAction(icon, tr("Save Session &As..."), this);
|
Chris@66
|
412 action->setStatusTip(tr("Save the current session into a new Sonic Visualiser session file"));
|
Chris@66
|
413 connect(action, SIGNAL(triggered()), this, SLOT(saveSessionAs()));
|
Chris@66
|
414 menu->addAction(action);
|
Chris@66
|
415 toolbar->addAction(action);
|
Chris@66
|
416
|
Chris@66
|
417 menu->addSeparator();
|
Chris@66
|
418
|
Chris@66
|
419 action = new QAction(tr("&Import Audio File..."), this);
|
Chris@66
|
420 action->setShortcut(tr("Ctrl+I"));
|
Chris@66
|
421 action->setStatusTip(tr("Import an existing audio file"));
|
Chris@66
|
422 connect(action, SIGNAL(triggered()), this, SLOT(importAudio()));
|
Chris@66
|
423 menu->addAction(action);
|
Chris@66
|
424
|
Chris@66
|
425 action = new QAction(tr("Import Secondary Audio File..."), this);
|
Chris@66
|
426 action->setShortcut(tr("Ctrl+Shift+I"));
|
Chris@66
|
427 action->setStatusTip(tr("Import an extra audio file as a separate layer"));
|
Chris@66
|
428 connect(action, SIGNAL(triggered()), this, SLOT(importMoreAudio()));
|
Chris@66
|
429 connect(this, SIGNAL(canImportMoreAudio(bool)), action, SLOT(setEnabled(bool)));
|
Chris@66
|
430 menu->addAction(action);
|
Chris@66
|
431
|
Chris@66
|
432 action = new QAction(tr("&Export Audio File..."), this);
|
Chris@66
|
433 action->setStatusTip(tr("Export selection as an audio file"));
|
Chris@66
|
434 connect(action, SIGNAL(triggered()), this, SLOT(exportAudio()));
|
Chris@66
|
435 connect(this, SIGNAL(canExportAudio(bool)), action, SLOT(setEnabled(bool)));
|
Chris@66
|
436 menu->addAction(action);
|
Chris@66
|
437
|
Chris@66
|
438 menu->addSeparator();
|
Chris@66
|
439
|
Chris@66
|
440 action = new QAction(tr("Import Annotation &Layer..."), this);
|
Chris@66
|
441 action->setShortcut(tr("Ctrl+L"));
|
Chris@66
|
442 action->setStatusTip(tr("Import layer data from an existing file"));
|
Chris@66
|
443 connect(action, SIGNAL(triggered()), this, SLOT(importLayer()));
|
Chris@66
|
444 connect(this, SIGNAL(canImportLayer(bool)), action, SLOT(setEnabled(bool)));
|
Chris@66
|
445 menu->addAction(action);
|
Chris@66
|
446
|
Chris@66
|
447 action = new QAction(tr("Export Annotation Layer..."), this);
|
Chris@66
|
448 action->setStatusTip(tr("Export layer data to a file"));
|
Chris@66
|
449 connect(action, SIGNAL(triggered()), this, SLOT(exportLayer()));
|
Chris@66
|
450 connect(this, SIGNAL(canExportLayer(bool)), action, SLOT(setEnabled(bool)));
|
Chris@66
|
451 menu->addAction(action);
|
Chris@66
|
452
|
Chris@66
|
453 menu->addSeparator();
|
Chris@86
|
454
|
Chris@86
|
455 action = new QAction(tr("Open Lo&cation..."), this);
|
Chris@86
|
456 action->setShortcut(tr("Ctrl+Shift+O"));
|
Chris@86
|
457 action->setStatusTip(tr("Open or import a file from a remote URL"));
|
Chris@86
|
458 connect(action, SIGNAL(triggered()), this, SLOT(openLocation()));
|
Chris@86
|
459 menu->addAction(action);
|
Chris@86
|
460
|
Chris@86
|
461 menu->addSeparator();
|
Chris@86
|
462
|
Chris@66
|
463 m_recentFilesMenu = menu->addMenu(tr("&Recent Files"));
|
Chris@66
|
464 setupRecentFilesMenu();
|
Chris@66
|
465 connect(&m_recentFiles, SIGNAL(recentChanged()),
|
Chris@66
|
466 this, SLOT(setupRecentFilesMenu()));
|
Chris@66
|
467
|
Chris@66
|
468 menu->addSeparator();
|
Chris@66
|
469 action = new QAction(tr("&Preferences..."), this);
|
Chris@66
|
470 action->setStatusTip(tr("Adjust the application preferences"));
|
Chris@66
|
471 connect(action, SIGNAL(triggered()), this, SLOT(preferences()));
|
Chris@66
|
472 menu->addAction(action);
|
Chris@0
|
473
|
Chris@66
|
474 /*!!!
|
Chris@66
|
475 menu->addSeparator();
|
Chris@0
|
476
|
Chris@66
|
477 action = new QAction(tr("Play / Pause"), this);
|
Chris@66
|
478 action->setShortcut(tr("Space"));
|
Chris@66
|
479 action->setStatusTip(tr("Start or stop playback from the current position"));
|
Chris@66
|
480 connect(action, SIGNAL(triggered()), this, SLOT(play()));
|
Chris@66
|
481 menu->addAction(action);
|
Chris@66
|
482 */
|
Chris@66
|
483
|
Chris@66
|
484 menu->addSeparator();
|
Chris@66
|
485 action = new QAction(QIcon(":/icons/exit.png"),
|
Chris@66
|
486 tr("&Quit"), this);
|
Chris@66
|
487 action->setShortcut(tr("Ctrl+Q"));
|
Chris@90
|
488 action->setStatusTip(tr("Exit Sonic Visualiser"));
|
Chris@66
|
489 connect(action, SIGNAL(triggered()), this, SLOT(close()));
|
Chris@66
|
490 menu->addAction(action);
|
Chris@66
|
491 }
|
Chris@66
|
492
|
Chris@66
|
493 void
|
Chris@66
|
494 MainWindow::setupEditMenu()
|
Chris@66
|
495 {
|
Chris@66
|
496 if (m_mainMenusCreated) return;
|
Chris@66
|
497
|
Chris@66
|
498 QMenu *menu = menuBar()->addMenu(tr("&Edit"));
|
Chris@66
|
499 CommandHistory::getInstance()->registerMenu(menu);
|
Chris@66
|
500
|
Chris@66
|
501 menu->addSeparator();
|
Chris@66
|
502
|
Chris@66
|
503 QAction *action = new QAction(QIcon(":/icons/editcut.png"),
|
Chris@66
|
504 tr("Cu&t"), this);
|
Chris@66
|
505 action->setShortcut(tr("Ctrl+X"));
|
Chris@90
|
506 action->setStatusTip(tr("Cut the selection from the current layer to the clipboard"));
|
Chris@66
|
507 connect(action, SIGNAL(triggered()), this, SLOT(cut()));
|
Chris@66
|
508 connect(this, SIGNAL(canEditSelection(bool)), action, SLOT(setEnabled(bool)));
|
Chris@66
|
509 menu->addAction(action);
|
Chris@66
|
510 m_rightButtonMenu->addAction(action);
|
Chris@66
|
511
|
Chris@66
|
512 action = new QAction(QIcon(":/icons/editcopy.png"),
|
Chris@66
|
513 tr("&Copy"), this);
|
Chris@66
|
514 action->setShortcut(tr("Ctrl+C"));
|
Chris@90
|
515 action->setStatusTip(tr("Copy the selection from the current layer to the clipboard"));
|
Chris@66
|
516 connect(action, SIGNAL(triggered()), this, SLOT(copy()));
|
Chris@66
|
517 connect(this, SIGNAL(canEditSelection(bool)), action, SLOT(setEnabled(bool)));
|
Chris@66
|
518 menu->addAction(action);
|
Chris@66
|
519 m_rightButtonMenu->addAction(action);
|
Chris@66
|
520
|
Chris@66
|
521 action = new QAction(QIcon(":/icons/editpaste.png"),
|
Chris@66
|
522 tr("&Paste"), this);
|
Chris@66
|
523 action->setShortcut(tr("Ctrl+V"));
|
Chris@90
|
524 action->setStatusTip(tr("Paste from the clipboard to the current layer"));
|
Chris@66
|
525 connect(action, SIGNAL(triggered()), this, SLOT(paste()));
|
Chris@66
|
526 connect(this, SIGNAL(canPaste(bool)), action, SLOT(setEnabled(bool)));
|
Chris@66
|
527 menu->addAction(action);
|
Chris@66
|
528 m_rightButtonMenu->addAction(action);
|
Chris@66
|
529
|
Chris@66
|
530 action = new QAction(tr("&Delete Selected Items"), this);
|
Chris@66
|
531 action->setShortcut(tr("Del"));
|
Chris@90
|
532 action->setStatusTip(tr("Delete the selection from the current layer"));
|
Chris@66
|
533 connect(action, SIGNAL(triggered()), this, SLOT(deleteSelected()));
|
Chris@66
|
534 connect(this, SIGNAL(canEditSelection(bool)), action, SLOT(setEnabled(bool)));
|
Chris@66
|
535 menu->addAction(action);
|
Chris@66
|
536 m_rightButtonMenu->addAction(action);
|
Chris@66
|
537
|
Chris@66
|
538 menu->addSeparator();
|
Chris@66
|
539 m_rightButtonMenu->addSeparator();
|
Chris@0
|
540
|
Chris@66
|
541 action = new QAction(tr("Select &All"), this);
|
Chris@66
|
542 action->setShortcut(tr("Ctrl+A"));
|
Chris@90
|
543 action->setStatusTip(tr("Select the whole duration of the current session"));
|
Chris@66
|
544 connect(action, SIGNAL(triggered()), this, SLOT(selectAll()));
|
Chris@66
|
545 connect(this, SIGNAL(canSelect(bool)), action, SLOT(setEnabled(bool)));
|
Chris@66
|
546 menu->addAction(action);
|
Chris@66
|
547 m_rightButtonMenu->addAction(action);
|
Chris@0
|
548
|
Chris@66
|
549 action = new QAction(tr("Select &Visible Range"), this);
|
Chris@66
|
550 action->setShortcut(tr("Ctrl+Shift+A"));
|
Chris@90
|
551 action->setStatusTip(tr("Select the time range corresponding to the current window width"));
|
Chris@66
|
552 connect(action, SIGNAL(triggered()), this, SLOT(selectVisible()));
|
Chris@66
|
553 connect(this, SIGNAL(canSelect(bool)), action, SLOT(setEnabled(bool)));
|
Chris@66
|
554 menu->addAction(action);
|
Chris@0
|
555
|
Chris@66
|
556 action = new QAction(tr("Select to &Start"), this);
|
Chris@66
|
557 action->setShortcut(tr("Shift+Left"));
|
Chris@90
|
558 action->setStatusTip(tr("Select from the start of the session to the current playback position"));
|
Chris@66
|
559 connect(action, SIGNAL(triggered()), this, SLOT(selectToStart()));
|
Chris@66
|
560 connect(this, SIGNAL(canSelect(bool)), action, SLOT(setEnabled(bool)));
|
Chris@66
|
561 menu->addAction(action);
|
Chris@0
|
562
|
Chris@66
|
563 action = new QAction(tr("Select to &End"), this);
|
Chris@66
|
564 action->setShortcut(tr("Shift+Right"));
|
Chris@90
|
565 action->setStatusTip(tr("Select from the current playback position to the end of the session"));
|
Chris@66
|
566 connect(action, SIGNAL(triggered()), this, SLOT(selectToEnd()));
|
Chris@66
|
567 connect(this, SIGNAL(canSelect(bool)), action, SLOT(setEnabled(bool)));
|
Chris@66
|
568 menu->addAction(action);
|
Chris@66
|
569
|
Chris@66
|
570 action = new QAction(tr("C&lear Selection"), this);
|
Chris@66
|
571 action->setShortcut(tr("Esc"));
|
Chris@90
|
572 action->setStatusTip(tr("Clear the selection"));
|
Chris@66
|
573 connect(action, SIGNAL(triggered()), this, SLOT(clearSelection()));
|
Chris@66
|
574 connect(this, SIGNAL(canClearSelection(bool)), action, SLOT(setEnabled(bool)));
|
Chris@66
|
575 menu->addAction(action);
|
Chris@66
|
576 m_rightButtonMenu->addAction(action);
|
Chris@66
|
577
|
Chris@66
|
578 menu->addSeparator();
|
Chris@66
|
579
|
Chris@66
|
580 action = new QAction(tr("&Insert Instant at Playback Position"), this);
|
Chris@66
|
581 action->setShortcut(tr("Enter"));
|
Chris@90
|
582 action->setStatusTip(tr("Insert a new time instant at the current playback position, in a new layer if necessary"));
|
Chris@66
|
583 connect(action, SIGNAL(triggered()), this, SLOT(insertInstant()));
|
Chris@66
|
584 connect(this, SIGNAL(canInsertInstant(bool)), action, SLOT(setEnabled(bool)));
|
Chris@66
|
585 menu->addAction(action);
|
Chris@66
|
586
|
Chris@81
|
587 action = new QAction(tr("Insert Instants at Selection &Boundaries"), this);
|
Chris@81
|
588 action->setShortcut(tr("Shift+Enter"));
|
Chris@90
|
589 action->setStatusTip(tr("Insert new time instants at the start and end of the current selection, in a new layer if necessary"));
|
Chris@81
|
590 connect(action, SIGNAL(triggered()), this, SLOT(insertInstantsAtBoundaries()));
|
Chris@81
|
591 connect(this, SIGNAL(canInsertInstantsAtBoundaries(bool)), action, SLOT(setEnabled(bool)));
|
Chris@81
|
592 menu->addAction(action);
|
Chris@81
|
593
|
Chris@66
|
594 // Laptop shortcut (no keypad Enter key)
|
Chris@66
|
595 connect(new QShortcut(tr(";"), this), SIGNAL(activated()),
|
Chris@66
|
596 this, SLOT(insertInstant()));
|
Chris@66
|
597 }
|
Chris@66
|
598
|
Chris@66
|
599 void
|
Chris@66
|
600 MainWindow::setupViewMenu()
|
Chris@66
|
601 {
|
Chris@66
|
602 if (m_mainMenusCreated) return;
|
Chris@66
|
603
|
Chris@90
|
604 QAction *action = 0;
|
Chris@90
|
605
|
Chris@66
|
606 QMenu *menu = menuBar()->addMenu(tr("&View"));
|
Chris@66
|
607 action = new QAction(tr("Scroll &Left"), this);
|
Chris@66
|
608 action->setShortcut(tr("Left"));
|
Chris@66
|
609 action->setStatusTip(tr("Scroll the current pane to the left"));
|
Chris@66
|
610 connect(action, SIGNAL(triggered()), this, SLOT(scrollLeft()));
|
Chris@66
|
611 connect(this, SIGNAL(canScroll(bool)), action, SLOT(setEnabled(bool)));
|
Chris@66
|
612 menu->addAction(action);
|
Chris@0
|
613
|
Chris@66
|
614 action = new QAction(tr("Scroll &Right"), this);
|
Chris@66
|
615 action->setShortcut(tr("Right"));
|
Chris@66
|
616 action->setStatusTip(tr("Scroll the current pane to the right"));
|
Chris@66
|
617 connect(action, SIGNAL(triggered()), this, SLOT(scrollRight()));
|
Chris@66
|
618 connect(this, SIGNAL(canScroll(bool)), action, SLOT(setEnabled(bool)));
|
Chris@66
|
619 menu->addAction(action);
|
Chris@0
|
620
|
Chris@90
|
621 action = new QAction(tr("&Jump Left"), this);
|
Chris@66
|
622 action->setShortcut(tr("Ctrl+Left"));
|
Chris@66
|
623 action->setStatusTip(tr("Scroll the current pane a big step to the left"));
|
Chris@66
|
624 connect(action, SIGNAL(triggered()), this, SLOT(jumpLeft()));
|
Chris@66
|
625 connect(this, SIGNAL(canScroll(bool)), action, SLOT(setEnabled(bool)));
|
Chris@66
|
626 menu->addAction(action);
|
Chris@0
|
627
|
Chris@90
|
628 action = new QAction(tr("J&ump Right"), this);
|
Chris@66
|
629 action->setShortcut(tr("Ctrl+Right"));
|
Chris@66
|
630 action->setStatusTip(tr("Scroll the current pane a big step to the right"));
|
Chris@66
|
631 connect(action, SIGNAL(triggered()), this, SLOT(jumpRight()));
|
Chris@66
|
632 connect(this, SIGNAL(canScroll(bool)), action, SLOT(setEnabled(bool)));
|
Chris@66
|
633 menu->addAction(action);
|
Chris@66
|
634
|
Chris@66
|
635 menu->addSeparator();
|
Chris@66
|
636
|
Chris@66
|
637 action = new QAction(QIcon(":/icons/zoom-in.png"),
|
Chris@66
|
638 tr("Zoom &In"), this);
|
Chris@66
|
639 action->setShortcut(tr("Up"));
|
Chris@66
|
640 action->setStatusTip(tr("Increase the zoom level"));
|
Chris@66
|
641 connect(action, SIGNAL(triggered()), this, SLOT(zoomIn()));
|
Chris@66
|
642 connect(this, SIGNAL(canZoom(bool)), action, SLOT(setEnabled(bool)));
|
Chris@66
|
643 menu->addAction(action);
|
Chris@0
|
644
|
Chris@66
|
645 action = new QAction(QIcon(":/icons/zoom-out.png"),
|
Chris@66
|
646 tr("Zoom &Out"), this);
|
Chris@66
|
647 action->setShortcut(tr("Down"));
|
Chris@66
|
648 action->setStatusTip(tr("Decrease the zoom level"));
|
Chris@66
|
649 connect(action, SIGNAL(triggered()), this, SLOT(zoomOut()));
|
Chris@66
|
650 connect(this, SIGNAL(canZoom(bool)), action, SLOT(setEnabled(bool)));
|
Chris@66
|
651 menu->addAction(action);
|
Chris@0
|
652
|
Chris@66
|
653 action = new QAction(tr("Restore &Default Zoom"), this);
|
Chris@90
|
654 action->setStatusTip(tr("Restore the zoom level to the default"));
|
Chris@66
|
655 connect(action, SIGNAL(triggered()), this, SLOT(zoomDefault()));
|
Chris@66
|
656 connect(this, SIGNAL(canZoom(bool)), action, SLOT(setEnabled(bool)));
|
Chris@66
|
657 menu->addAction(action);
|
Chris@66
|
658
|
Chris@66
|
659 action = new QAction(tr("Zoom to &Fit"), this);
|
Chris@66
|
660 action->setStatusTip(tr("Zoom to show the whole file"));
|
Chris@66
|
661 connect(action, SIGNAL(triggered()), this, SLOT(zoomToFit()));
|
Chris@66
|
662 connect(this, SIGNAL(canZoom(bool)), action, SLOT(setEnabled(bool)));
|
Chris@66
|
663 menu->addAction(action);
|
Chris@90
|
664
|
Chris@90
|
665 menu->addSeparator();
|
Chris@90
|
666
|
Chris@90
|
667 QActionGroup *overlayGroup = new QActionGroup(this);
|
Chris@90
|
668
|
Chris@90
|
669 action = new QAction(tr("Show &No Overlays"), this);
|
Chris@90
|
670 action->setShortcut(tr("0"));
|
Chris@90
|
671 action->setStatusTip(tr("Hide centre indicator, frame times, layer names and scale"));
|
Chris@90
|
672 connect(action, SIGNAL(triggered()), this, SLOT(showNoOverlays()));
|
Chris@90
|
673 action->setCheckable(true);
|
Chris@90
|
674 action->setChecked(false);
|
Chris@90
|
675 overlayGroup->addAction(action);
|
Chris@90
|
676 menu->addAction(action);
|
Chris@90
|
677
|
Chris@90
|
678 action = new QAction(tr("Show &Minimal Overlays"), this);
|
Chris@90
|
679 action->setShortcut(tr("9"));
|
Chris@90
|
680 action->setStatusTip(tr("Show centre indicator only"));
|
Chris@90
|
681 connect(action, SIGNAL(triggered()), this, SLOT(showMinimalOverlays()));
|
Chris@90
|
682 action->setCheckable(true);
|
Chris@90
|
683 action->setChecked(false);
|
Chris@90
|
684 overlayGroup->addAction(action);
|
Chris@90
|
685 menu->addAction(action);
|
Chris@90
|
686
|
Chris@90
|
687 action = new QAction(tr("Show &Standard Overlays"), this);
|
Chris@90
|
688 action->setShortcut(tr("8"));
|
Chris@90
|
689 action->setStatusTip(tr("Show centre indicator, frame times and scale"));
|
Chris@90
|
690 connect(action, SIGNAL(triggered()), this, SLOT(showStandardOverlays()));
|
Chris@90
|
691 action->setCheckable(true);
|
Chris@90
|
692 action->setChecked(true);
|
Chris@90
|
693 overlayGroup->addAction(action);
|
Chris@90
|
694 menu->addAction(action);
|
Chris@90
|
695
|
Chris@90
|
696 action = new QAction(tr("Show &All Overlays"), this);
|
Chris@90
|
697 action->setShortcut(tr("7"));
|
Chris@90
|
698 action->setStatusTip(tr("Show all texts and scale"));
|
Chris@90
|
699 connect(action, SIGNAL(triggered()), this, SLOT(showAllOverlays()));
|
Chris@90
|
700 action->setCheckable(true);
|
Chris@90
|
701 action->setChecked(false);
|
Chris@90
|
702 overlayGroup->addAction(action);
|
Chris@90
|
703 menu->addAction(action);
|
Chris@7
|
704
|
Chris@72
|
705 menu->addSeparator();
|
Chris@72
|
706
|
Chris@66
|
707 action = new QAction(tr("Show &Zoom Wheels"), this);
|
Chris@66
|
708 action->setShortcut(tr("Z"));
|
Chris@66
|
709 action->setStatusTip(tr("Show thumbwheels for zooming horizontally and vertically"));
|
Chris@66
|
710 connect(action, SIGNAL(triggered()), this, SLOT(toggleZoomWheels()));
|
Chris@66
|
711 action->setCheckable(true);
|
Chris@66
|
712 action->setChecked(m_viewManager->getZoomWheelsEnabled());
|
Chris@66
|
713 menu->addAction(action);
|
Chris@72
|
714
|
Chris@72
|
715 action = new QAction(tr("Show Property Bo&xes"), this);
|
Chris@72
|
716 action->setShortcut(tr("X"));
|
Chris@72
|
717 action->setStatusTip(tr("Show the layer property boxes at the side of the main window"));
|
Chris@72
|
718 connect(action, SIGNAL(triggered()), this, SLOT(togglePropertyBoxes()));
|
Chris@72
|
719 action->setCheckable(true);
|
Chris@72
|
720 action->setChecked(true);
|
Chris@72
|
721 menu->addAction(action);
|
Chris@0
|
722
|
Chris@90
|
723 action = new QAction(tr("Show Status &Bar"), this);
|
Chris@90
|
724 action->setStatusTip(tr("Show context help information in the status bar at the bottom of the window"));
|
Chris@90
|
725 connect(action, SIGNAL(triggered()), this, SLOT(toggleStatusBar()));
|
Chris@90
|
726 action->setCheckable(true);
|
Chris@90
|
727 action->setChecked(true);
|
Chris@90
|
728 menu->addAction(action);
|
Chris@90
|
729
|
Chris@90
|
730 QSettings settings;
|
Chris@90
|
731 settings.beginGroup("MainWindow");
|
Chris@90
|
732 bool sb = settings.value("showstatusbar", true).toBool();
|
Chris@90
|
733 if (!sb) {
|
Chris@90
|
734 action->setChecked(false);
|
Chris@90
|
735 statusBar()->hide();
|
Chris@90
|
736 }
|
Chris@90
|
737 settings.endGroup();
|
Chris@90
|
738
|
Chris@0
|
739 /*!!! This one doesn't work properly yet
|
Chris@90
|
740
|
Chris@66
|
741 menu->addSeparator();
|
Chris@66
|
742
|
Chris@90
|
743 action = new QAction(tr("Show La&yer Hierarchy"), this);
|
Chris@66
|
744 action->setShortcut(tr("Alt+L"));
|
Chris@90
|
745 action->setStatusTip(tr("Open a window displaying the hierarchy of panes and layers in this session"));
|
Chris@66
|
746 connect(action, SIGNAL(triggered()), this, SLOT(showLayerTree()));
|
Chris@66
|
747 menu->addAction(action);
|
Chris@90
|
748 */
|
Chris@66
|
749 }
|
Chris@66
|
750
|
Chris@66
|
751 void
|
Chris@66
|
752 MainWindow::setupPaneAndLayerMenus()
|
Chris@66
|
753 {
|
Chris@0
|
754 if (m_paneMenu) {
|
Chris@0
|
755 m_paneActions.clear();
|
Chris@0
|
756 m_paneMenu->clear();
|
Chris@0
|
757 } else {
|
Chris@0
|
758 m_paneMenu = menuBar()->addMenu(tr("&Pane"));
|
Chris@0
|
759 }
|
Chris@0
|
760
|
Chris@0
|
761 if (m_layerMenu) {
|
Chris@0
|
762 m_layerActions.clear();
|
Chris@0
|
763 m_layerMenu->clear();
|
Chris@0
|
764 } else {
|
Chris@0
|
765 m_layerMenu = menuBar()->addMenu(tr("&Layer"));
|
Chris@0
|
766 }
|
Chris@0
|
767
|
Chris@66
|
768 QMenu *menu = m_paneMenu;
|
Chris@66
|
769
|
Chris@66
|
770 QAction *action = new QAction(QIcon(":/icons/pane.png"), tr("Add &New Pane"), this);
|
Chris@66
|
771 action->setShortcut(tr("Alt+N"));
|
Chris@66
|
772 action->setStatusTip(tr("Add a new pane containing only a time ruler"));
|
Chris@66
|
773 connect(action, SIGNAL(triggered()), this, SLOT(addPane()));
|
Chris@66
|
774 connect(this, SIGNAL(canAddPane(bool)), action, SLOT(setEnabled(bool)));
|
Chris@66
|
775 m_paneActions[action] = PaneConfiguration(LayerFactory::TimeRuler);
|
Chris@66
|
776 menu->addAction(action);
|
Chris@66
|
777
|
Chris@66
|
778 menu->addSeparator();
|
Chris@66
|
779
|
Chris@66
|
780 menu = m_layerMenu;
|
Chris@66
|
781
|
Chris@66
|
782 // menu->addSeparator();
|
Chris@66
|
783
|
Chris@66
|
784 LayerFactory::LayerTypeSet emptyLayerTypes =
|
Chris@66
|
785 LayerFactory::getInstance()->getValidEmptyLayerTypes();
|
Chris@66
|
786
|
Chris@66
|
787 for (LayerFactory::LayerTypeSet::iterator i = emptyLayerTypes.begin();
|
Chris@66
|
788 i != emptyLayerTypes.end(); ++i) {
|
Chris@66
|
789
|
Chris@66
|
790 QIcon icon;
|
Chris@66
|
791 QString mainText, tipText, channelText;
|
Chris@66
|
792 LayerFactory::LayerType type = *i;
|
Chris@66
|
793 QString name = LayerFactory::getInstance()->getLayerPresentationName(type);
|
Chris@66
|
794
|
Chris@66
|
795 icon = QIcon(QString(":/icons/%1.png")
|
Chris@66
|
796 .arg(LayerFactory::getInstance()->getLayerIconName(type)));
|
Chris@66
|
797
|
Chris@66
|
798 mainText = tr("Add New %1 Layer").arg(name);
|
Chris@66
|
799 tipText = tr("Add a new empty layer of type %1").arg(name);
|
Chris@66
|
800
|
Chris@66
|
801 action = new QAction(icon, mainText, this);
|
Chris@66
|
802 action->setStatusTip(tipText);
|
Chris@66
|
803
|
Chris@66
|
804 if (type == LayerFactory::Text) {
|
Chris@66
|
805 action->setShortcut(tr("Alt+T"));
|
Chris@66
|
806 }
|
Chris@66
|
807
|
Chris@66
|
808 connect(action, SIGNAL(triggered()), this, SLOT(addLayer()));
|
Chris@66
|
809 connect(this, SIGNAL(canAddLayer(bool)), action, SLOT(setEnabled(bool)));
|
Chris@66
|
810 m_layerActions[action] = type;
|
Chris@66
|
811 menu->addAction(action);
|
Chris@66
|
812 m_rightButtonLayerMenu->addAction(action);
|
Chris@66
|
813 }
|
Chris@66
|
814
|
Chris@66
|
815 m_rightButtonLayerMenu->addSeparator();
|
Chris@66
|
816 menu->addSeparator();
|
Chris@66
|
817
|
Chris@66
|
818 LayerFactory::LayerType backgroundTypes[] = {
|
Chris@66
|
819 LayerFactory::Waveform,
|
Chris@66
|
820 LayerFactory::Spectrogram,
|
Chris@66
|
821 LayerFactory::MelodicRangeSpectrogram,
|
Chris@66
|
822 LayerFactory::PeakFrequencySpectrogram,
|
Chris@66
|
823 LayerFactory::Spectrum
|
Chris@66
|
824 };
|
Chris@66
|
825
|
Chris@66
|
826 std::vector<Model *> models;
|
Chris@66
|
827 if (m_document) models = m_document->getTransformInputModels(); //!!! not well named for this!
|
Chris@66
|
828 bool plural = (models.size() > 1);
|
Chris@66
|
829 if (models.empty()) {
|
Chris@67
|
830 models.push_back(getMainModel()); // probably 0
|
Chris@66
|
831 }
|
Chris@66
|
832
|
Chris@66
|
833 for (unsigned int i = 0;
|
Chris@66
|
834 i < sizeof(backgroundTypes)/sizeof(backgroundTypes[0]); ++i) {
|
Chris@66
|
835
|
Chris@66
|
836 for (int menuType = 0; menuType <= 1; ++menuType) { // pane, layer
|
Chris@66
|
837
|
Chris@66
|
838 if (menuType == 0) menu = m_paneMenu;
|
Chris@66
|
839 else menu = m_layerMenu;
|
Chris@66
|
840
|
Chris@66
|
841 QMenu *submenu = 0;
|
Chris@66
|
842
|
Chris@66
|
843 QIcon icon;
|
Chris@66
|
844 QString mainText, shortcutText, tipText, channelText;
|
Chris@66
|
845 LayerFactory::LayerType type = backgroundTypes[i];
|
Chris@66
|
846 bool mono = true;
|
Chris@66
|
847
|
Chris@66
|
848 switch (type) {
|
Chris@66
|
849
|
Chris@66
|
850 case LayerFactory::Waveform:
|
Chris@66
|
851 icon = QIcon(":/icons/waveform.png");
|
Chris@66
|
852 mainText = tr("Add &Waveform");
|
Chris@66
|
853 if (menuType == 0) {
|
Chris@66
|
854 shortcutText = tr("Alt+W");
|
Chris@66
|
855 tipText = tr("Add a new pane showing a waveform view");
|
Chris@66
|
856 } else {
|
Chris@66
|
857 tipText = tr("Add a new layer showing a waveform view");
|
Chris@66
|
858 }
|
Chris@66
|
859 mono = false;
|
Chris@66
|
860 break;
|
Chris@66
|
861
|
Chris@66
|
862 case LayerFactory::Spectrogram:
|
Chris@67
|
863 icon = QIcon(":/icons/spectrogram.png");
|
Chris@66
|
864 mainText = tr("Add &Spectrogram");
|
Chris@66
|
865 if (menuType == 0) {
|
Chris@66
|
866 shortcutText = tr("Alt+S");
|
Chris@90
|
867 tipText = tr("Add a new pane showing a spectrogram");
|
Chris@66
|
868 } else {
|
Chris@90
|
869 tipText = tr("Add a new layer showing a spectrogram");
|
Chris@66
|
870 }
|
Chris@66
|
871 break;
|
Chris@66
|
872
|
Chris@66
|
873 case LayerFactory::MelodicRangeSpectrogram:
|
Chris@67
|
874 icon = QIcon(":/icons/spectrogram.png");
|
Chris@66
|
875 mainText = tr("Add &Melodic Range Spectrogram");
|
Chris@66
|
876 if (menuType == 0) {
|
Chris@66
|
877 shortcutText = tr("Alt+M");
|
Chris@90
|
878 tipText = tr("Add a new pane showing a spectrogram set up for an overview of note pitches");
|
Chris@66
|
879 } else {
|
Chris@90
|
880 tipText = tr("Add a new layer showing a spectrogram set up for an overview of note pitches");
|
Chris@66
|
881 }
|
Chris@66
|
882 break;
|
Chris@66
|
883
|
Chris@66
|
884 case LayerFactory::PeakFrequencySpectrogram:
|
Chris@67
|
885 icon = QIcon(":/icons/spectrogram.png");
|
Chris@66
|
886 mainText = tr("Add &Peak Frequency Spectrogram");
|
Chris@66
|
887 if (menuType == 0) {
|
Chris@66
|
888 shortcutText = tr("Alt+P");
|
Chris@66
|
889 tipText = tr("Add a new pane showing a spectrogram set up for tracking frequencies");
|
Chris@66
|
890 } else {
|
Chris@66
|
891 tipText = tr("Add a new layer showing a spectrogram set up for tracking frequencies");
|
Chris@66
|
892 }
|
Chris@66
|
893 break;
|
Chris@66
|
894
|
Chris@66
|
895 case LayerFactory::Spectrum:
|
Chris@67
|
896 icon = QIcon(":/icons/spectrum.png");
|
Chris@66
|
897 mainText = tr("Add Spectr&um");
|
Chris@66
|
898 if (menuType == 0) {
|
Chris@66
|
899 shortcutText = tr("Alt+U");
|
Chris@66
|
900 tipText = tr("Add a new pane showing a frequency spectrum");
|
Chris@66
|
901 } else {
|
Chris@66
|
902 tipText = tr("Add a new layer showing a frequency spectrum");
|
Chris@66
|
903 }
|
Chris@66
|
904 break;
|
Chris@66
|
905
|
Chris@66
|
906 default: break;
|
Chris@66
|
907 }
|
Chris@66
|
908
|
Chris@66
|
909 std::vector<Model *> candidateModels;
|
Chris@66
|
910 if (menuType == 0) {
|
Chris@66
|
911 candidateModels = models;
|
Chris@66
|
912 } else {
|
Chris@66
|
913 candidateModels.push_back(0);
|
Chris@66
|
914 }
|
Chris@66
|
915
|
Chris@66
|
916 for (std::vector<Model *>::iterator mi =
|
Chris@66
|
917 candidateModels.begin();
|
Chris@66
|
918 mi != candidateModels.end(); ++mi) {
|
Chris@66
|
919
|
Chris@66
|
920 Model *model = *mi;
|
Chris@66
|
921
|
Chris@66
|
922 int channels = 0;
|
Chris@66
|
923 if (model) {
|
Chris@66
|
924 DenseTimeValueModel *dtvm =
|
Chris@66
|
925 dynamic_cast<DenseTimeValueModel *>(model);
|
Chris@66
|
926 if (dtvm) channels = dtvm->getChannelCount();
|
Chris@66
|
927 }
|
Chris@66
|
928 if (channels < 1 && getMainModel()) {
|
Chris@66
|
929 channels = getMainModel()->getChannelCount();
|
Chris@66
|
930 }
|
Chris@66
|
931 if (channels < 1) channels = 1;
|
Chris@66
|
932
|
Chris@66
|
933 for (int c = 0; c <= channels; ++c) {
|
Chris@66
|
934
|
Chris@66
|
935 if (c == 1 && channels == 1) continue;
|
Chris@66
|
936 bool isDefault = (c == 0);
|
Chris@66
|
937 bool isOnly = (isDefault && (channels == 1));
|
Chris@66
|
938
|
Chris@66
|
939 if (menuType == 1) {
|
Chris@66
|
940 if (isDefault) isOnly = true;
|
Chris@66
|
941 else continue;
|
Chris@66
|
942 }
|
Chris@66
|
943
|
Chris@66
|
944 if (isOnly && (!plural || menuType == 1)) {
|
Chris@66
|
945
|
Chris@67
|
946 if (type != LayerFactory::Waveform) {
|
Chris@67
|
947 action = new QAction(mainText, this);
|
Chris@67
|
948 } else {
|
Chris@67
|
949 action = new QAction(icon, mainText, this);
|
Chris@67
|
950 }
|
Chris@67
|
951
|
Chris@66
|
952 action->setShortcut(shortcutText);
|
Chris@66
|
953 action->setStatusTip(tipText);
|
Chris@66
|
954 if (menuType == 0) {
|
Chris@66
|
955 connect(action, SIGNAL(triggered()),
|
Chris@66
|
956 this, SLOT(addPane()));
|
Chris@66
|
957 connect(this, SIGNAL(canAddPane(bool)),
|
Chris@66
|
958 action, SLOT(setEnabled(bool)));
|
Chris@66
|
959 m_paneActions[action] = PaneConfiguration(type);
|
Chris@66
|
960 } else {
|
Chris@66
|
961 connect(action, SIGNAL(triggered()),
|
Chris@66
|
962 this, SLOT(addLayer()));
|
Chris@66
|
963 connect(this, SIGNAL(canAddLayer(bool)),
|
Chris@66
|
964 action, SLOT(setEnabled(bool)));
|
Chris@66
|
965 m_layerActions[action] = type;
|
Chris@66
|
966 }
|
Chris@66
|
967 menu->addAction(action);
|
Chris@66
|
968
|
Chris@66
|
969 } else {
|
Chris@66
|
970
|
Chris@66
|
971 if (!submenu) {
|
Chris@66
|
972 submenu = menu->addMenu(mainText);
|
Chris@67
|
973 } else if (isDefault) {
|
Chris@67
|
974 submenu->addSeparator();
|
Chris@66
|
975 }
|
Chris@66
|
976
|
Chris@66
|
977 QString actionText;
|
Chris@66
|
978 if (c == 0) {
|
Chris@66
|
979 if (mono) {
|
Chris@66
|
980 actionText = tr("&All Channels Mixed");
|
Chris@66
|
981 } else {
|
Chris@66
|
982 actionText = tr("&All Channels");
|
Chris@66
|
983 }
|
Chris@66
|
984 } else {
|
Chris@66
|
985 actionText = tr("Channel &%1").arg(c);
|
Chris@66
|
986 }
|
Chris@66
|
987
|
Chris@66
|
988 if (model) {
|
Chris@66
|
989 actionText = tr("%1: %2")
|
Chris@66
|
990 .arg(model->objectName())
|
Chris@66
|
991 .arg(actionText);
|
Chris@66
|
992 }
|
Chris@67
|
993
|
Chris@67
|
994 if (isDefault) {
|
Chris@67
|
995 action = new QAction(icon, actionText, this);
|
Chris@67
|
996 if (!model || model == getMainModel()) {
|
Chris@67
|
997 action->setShortcut(shortcutText);
|
Chris@67
|
998 }
|
Chris@67
|
999 } else {
|
Chris@67
|
1000 action = new QAction(actionText, this);
|
Chris@67
|
1001 }
|
Chris@67
|
1002
|
Chris@66
|
1003 action->setStatusTip(tipText);
|
Chris@66
|
1004
|
Chris@66
|
1005 if (menuType == 0) {
|
Chris@66
|
1006 connect(action, SIGNAL(triggered()),
|
Chris@66
|
1007 this, SLOT(addPane()));
|
Chris@66
|
1008 connect(this, SIGNAL(canAddPane(bool)),
|
Chris@66
|
1009 action, SLOT(setEnabled(bool)));
|
Chris@66
|
1010 m_paneActions[action] =
|
Chris@66
|
1011 PaneConfiguration(type, model, c - 1);
|
Chris@66
|
1012 } else {
|
Chris@66
|
1013 connect(action, SIGNAL(triggered()),
|
Chris@66
|
1014 this, SLOT(addLayer()));
|
Chris@66
|
1015 connect(this, SIGNAL(canAddLayer(bool)),
|
Chris@66
|
1016 action, SLOT(setEnabled(bool)));
|
Chris@66
|
1017 m_layerActions[action] = type;
|
Chris@66
|
1018 }
|
Chris@66
|
1019
|
Chris@66
|
1020 submenu->addAction(action);
|
Chris@66
|
1021 }
|
Chris@66
|
1022 }
|
Chris@66
|
1023 }
|
Chris@66
|
1024 }
|
Chris@66
|
1025 }
|
Chris@66
|
1026
|
Chris@66
|
1027 menu = m_paneMenu;
|
Chris@66
|
1028
|
Chris@66
|
1029 menu->addSeparator();
|
Chris@66
|
1030
|
Chris@66
|
1031 action = new QAction(QIcon(":/icons/editdelete.png"), tr("&Delete Pane"), this);
|
Chris@66
|
1032 action->setShortcut(tr("Alt+D"));
|
Chris@90
|
1033 action->setStatusTip(tr("Delete the currently active pane"));
|
Chris@66
|
1034 connect(action, SIGNAL(triggered()), this, SLOT(deleteCurrentPane()));
|
Chris@66
|
1035 connect(this, SIGNAL(canDeleteCurrentPane(bool)), action, SLOT(setEnabled(bool)));
|
Chris@66
|
1036 menu->addAction(action);
|
Chris@66
|
1037
|
Chris@66
|
1038 menu = m_layerMenu;
|
Chris@66
|
1039
|
Chris@66
|
1040 action = new QAction(QIcon(":/icons/timeruler.png"), tr("Add &Time Ruler"), this);
|
Chris@66
|
1041 action->setStatusTip(tr("Add a new layer showing a time ruler"));
|
Chris@66
|
1042 connect(action, SIGNAL(triggered()), this, SLOT(addLayer()));
|
Chris@66
|
1043 connect(this, SIGNAL(canAddLayer(bool)), action, SLOT(setEnabled(bool)));
|
Chris@66
|
1044 m_layerActions[action] = LayerFactory::TimeRuler;
|
Chris@66
|
1045 menu->addAction(action);
|
Chris@66
|
1046
|
Chris@66
|
1047 menu->addSeparator();
|
Chris@66
|
1048
|
Chris@66
|
1049 m_existingLayersMenu = menu->addMenu(tr("Add &Existing Layer"));
|
Chris@66
|
1050 m_rightButtonLayerMenu->addMenu(m_existingLayersMenu);
|
Chris@66
|
1051 setupExistingLayersMenu();
|
Chris@66
|
1052
|
Chris@66
|
1053 m_rightButtonLayerMenu->addSeparator();
|
Chris@66
|
1054 menu->addSeparator();
|
Chris@66
|
1055
|
Chris@66
|
1056 action = new QAction(tr("&Rename Layer..."), this);
|
Chris@66
|
1057 action->setShortcut(tr("Alt+R"));
|
Chris@66
|
1058 action->setStatusTip(tr("Rename the currently active layer"));
|
Chris@66
|
1059 connect(action, SIGNAL(triggered()), this, SLOT(renameCurrentLayer()));
|
Chris@66
|
1060 connect(this, SIGNAL(canRenameLayer(bool)), action, SLOT(setEnabled(bool)));
|
Chris@66
|
1061 menu->addAction(action);
|
Chris@66
|
1062 m_rightButtonLayerMenu->addAction(action);
|
Chris@66
|
1063
|
Chris@66
|
1064 action = new QAction(QIcon(":/icons/editdelete.png"), tr("&Delete Layer"), this);
|
Chris@66
|
1065 action->setShortcut(tr("Alt+Shift+D"));
|
Chris@66
|
1066 action->setStatusTip(tr("Delete the currently active layer"));
|
Chris@66
|
1067 connect(action, SIGNAL(triggered()), this, SLOT(deleteCurrentLayer()));
|
Chris@66
|
1068 connect(this, SIGNAL(canDeleteCurrentLayer(bool)), action, SLOT(setEnabled(bool)));
|
Chris@66
|
1069 menu->addAction(action);
|
Chris@66
|
1070 m_rightButtonLayerMenu->addAction(action);
|
Chris@66
|
1071 }
|
Chris@66
|
1072
|
Chris@66
|
1073 void
|
Chris@66
|
1074 MainWindow::setupTransformsMenu()
|
Chris@66
|
1075 {
|
Chris@34
|
1076 if (m_transformsMenu) {
|
Chris@34
|
1077 m_transformActions.clear();
|
Chris@34
|
1078 m_transformActionsReverse.clear();
|
Chris@34
|
1079 m_transformsMenu->clear();
|
Chris@34
|
1080 } else {
|
Chris@34
|
1081 m_transformsMenu = menuBar()->addMenu(tr("&Transform"));
|
Chris@34
|
1082 }
|
Chris@34
|
1083
|
Chris@0
|
1084 TransformFactory::TransformList transforms =
|
Chris@0
|
1085 TransformFactory::getInstance()->getAllTransforms();
|
Chris@0
|
1086
|
Chris@33
|
1087 vector<QString> types =
|
Chris@0
|
1088 TransformFactory::getInstance()->getAllTransformTypes();
|
Chris@0
|
1089
|
Chris@37
|
1090 map<QString, map<QString, SubdividingMenu *> > categoryMenus;
|
Chris@37
|
1091 map<QString, map<QString, SubdividingMenu *> > makerMenus;
|
Chris@33
|
1092
|
Chris@36
|
1093 map<QString, SubdividingMenu *> byPluginNameMenus;
|
Chris@33
|
1094 map<QString, map<QString, QMenu *> > pluginNameMenus;
|
Chris@33
|
1095
|
Chris@37
|
1096 set<SubdividingMenu *> pendingMenus;
|
Chris@37
|
1097
|
Chris@34
|
1098 m_recentTransformsMenu = m_transformsMenu->addMenu(tr("&Recent Transforms"));
|
Chris@34
|
1099 m_rightButtonTransformsMenu->addMenu(m_recentTransformsMenu);
|
Chris@34
|
1100 connect(&m_recentTransforms, SIGNAL(recentChanged()),
|
Chris@34
|
1101 this, SLOT(setupRecentTransformsMenu()));
|
Chris@34
|
1102
|
Chris@34
|
1103 m_transformsMenu->addSeparator();
|
Chris@34
|
1104 m_rightButtonTransformsMenu->addSeparator();
|
Chris@34
|
1105
|
Chris@33
|
1106 for (vector<QString>::iterator i = types.begin(); i != types.end(); ++i) {
|
Chris@33
|
1107
|
Chris@33
|
1108 if (i != types.begin()) {
|
Chris@34
|
1109 m_transformsMenu->addSeparator();
|
Chris@34
|
1110 m_rightButtonTransformsMenu->addSeparator();
|
Chris@33
|
1111 }
|
Chris@33
|
1112
|
Chris@33
|
1113 QString byCategoryLabel = tr("%1 by Category").arg(*i);
|
Chris@37
|
1114 SubdividingMenu *byCategoryMenu = new SubdividingMenu(byCategoryLabel,
|
Chris@37
|
1115 20, 40);
|
Chris@37
|
1116 m_transformsMenu->addMenu(byCategoryMenu);
|
Chris@34
|
1117 m_rightButtonTransformsMenu->addMenu(byCategoryMenu);
|
Chris@37
|
1118 pendingMenus.insert(byCategoryMenu);
|
Chris@33
|
1119
|
Chris@33
|
1120 vector<QString> categories =
|
Chris@33
|
1121 TransformFactory::getInstance()->getTransformCategories(*i);
|
Chris@33
|
1122
|
Chris@33
|
1123 for (vector<QString>::iterator j = categories.begin();
|
Chris@33
|
1124 j != categories.end(); ++j) {
|
Chris@33
|
1125
|
Chris@33
|
1126 QString category = *j;
|
Chris@33
|
1127 if (category == "") category = tr("Unclassified");
|
Chris@33
|
1128
|
Chris@33
|
1129 if (categories.size() < 2) {
|
Chris@33
|
1130 categoryMenus[*i][category] = byCategoryMenu;
|
Chris@33
|
1131 continue;
|
Chris@33
|
1132 }
|
Chris@33
|
1133
|
Chris@33
|
1134 QStringList components = category.split(" > ");
|
Chris@33
|
1135 QString key;
|
Chris@33
|
1136
|
Chris@33
|
1137 for (QStringList::iterator k = components.begin();
|
Chris@33
|
1138 k != components.end(); ++k) {
|
Chris@33
|
1139
|
Chris@33
|
1140 QString parentKey = key;
|
Chris@33
|
1141 if (key != "") key += " > ";
|
Chris@33
|
1142 key += *k;
|
Chris@33
|
1143
|
Chris@33
|
1144 if (categoryMenus[*i].find(key) == categoryMenus[*i].end()) {
|
Chris@37
|
1145 SubdividingMenu *m = new SubdividingMenu(*k, 20, 40);
|
Chris@37
|
1146 pendingMenus.insert(m);
|
Chris@37
|
1147 categoryMenus[*i][key] = m;
|
Chris@33
|
1148 if (parentKey == "") {
|
Chris@37
|
1149 byCategoryMenu->addMenu(m);
|
Chris@33
|
1150 } else {
|
Chris@37
|
1151 categoryMenus[*i][parentKey]->addMenu(m);
|
Chris@33
|
1152 }
|
Chris@33
|
1153 }
|
Chris@33
|
1154 }
|
Chris@33
|
1155 }
|
Chris@33
|
1156
|
Chris@34
|
1157 QString byPluginNameLabel = tr("%1 by Plugin Name").arg(*i);
|
Chris@36
|
1158 byPluginNameMenus[*i] = new SubdividingMenu(byPluginNameLabel);
|
Chris@36
|
1159 m_transformsMenu->addMenu(byPluginNameMenus[*i]);
|
Chris@34
|
1160 m_rightButtonTransformsMenu->addMenu(byPluginNameMenus[*i]);
|
Chris@37
|
1161 pendingMenus.insert(byPluginNameMenus[*i]);
|
Chris@34
|
1162
|
Chris@33
|
1163 QString byMakerLabel = tr("%1 by Maker").arg(*i);
|
Chris@37
|
1164 SubdividingMenu *byMakerMenu = new SubdividingMenu(byMakerLabel, 20, 40);
|
Chris@37
|
1165 m_transformsMenu->addMenu(byMakerMenu);
|
Chris@34
|
1166 m_rightButtonTransformsMenu->addMenu(byMakerMenu);
|
Chris@37
|
1167 pendingMenus.insert(byMakerMenu);
|
Chris@33
|
1168
|
Chris@33
|
1169 vector<QString> makers =
|
Chris@33
|
1170 TransformFactory::getInstance()->getTransformMakers(*i);
|
Chris@37
|
1171
|
Chris@33
|
1172 for (vector<QString>::iterator j = makers.begin();
|
Chris@33
|
1173 j != makers.end(); ++j) {
|
Chris@33
|
1174
|
Chris@33
|
1175 QString maker = *j;
|
Chris@33
|
1176 if (maker == "") maker = tr("Unknown");
|
Chris@55
|
1177 maker.replace(QRegExp(tr(" [\\(<].*$")), "");
|
Chris@55
|
1178
|
Chris@37
|
1179 makerMenus[*i][maker] = new SubdividingMenu(maker, 30, 40);
|
Chris@37
|
1180 byMakerMenu->addMenu(makerMenus[*i][maker]);
|
Chris@37
|
1181 pendingMenus.insert(makerMenus[*i][maker]);
|
Chris@33
|
1182 }
|
Chris@0
|
1183 }
|
Chris@0
|
1184
|
Chris@0
|
1185 for (unsigned int i = 0; i < transforms.size(); ++i) {
|
Chris@0
|
1186
|
Chris@0
|
1187 QString description = transforms[i].description;
|
Chris@0
|
1188 if (description == "") description = transforms[i].name;
|
Chris@0
|
1189
|
Chris@80
|
1190 // std::cerr << "Plugin Description: " << description.toStdString() << std::endl;
|
Chris@80
|
1191
|
Chris@33
|
1192 QString type = transforms[i].type;
|
Chris@33
|
1193
|
Chris@33
|
1194 QString category = transforms[i].category;
|
Chris@33
|
1195 if (category == "") category = tr("Unclassified");
|
Chris@33
|
1196
|
Chris@33
|
1197 QString maker = transforms[i].maker;
|
Chris@33
|
1198 if (maker == "") maker = tr("Unknown");
|
Chris@55
|
1199 maker.replace(QRegExp(tr(" [\\(<].*$")), "");
|
Chris@33
|
1200
|
Chris@33
|
1201 QString pluginName = description.section(": ", 0, 0);
|
Chris@33
|
1202 QString output = description.section(": ", 1);
|
Chris@33
|
1203
|
Chris@66
|
1204 QAction *action = new QAction(tr("%1...").arg(description), this);
|
Chris@0
|
1205 connect(action, SIGNAL(triggered()), this, SLOT(addLayer()));
|
Chris@34
|
1206 m_transformActions[action] = transforms[i].name;
|
Chris@34
|
1207 m_transformActionsReverse[transforms[i].name] = action;
|
Chris@0
|
1208 connect(this, SIGNAL(canAddLayer(bool)), action, SLOT(setEnabled(bool)));
|
Chris@33
|
1209
|
Chris@90
|
1210 QString tip;
|
Chris@90
|
1211 if (output == "") {
|
Chris@90
|
1212 tip = tr("Transform with \"%1\" plugin (from %3)")
|
Chris@90
|
1213 .arg(pluginName).arg(maker);
|
Chris@90
|
1214 } else {
|
Chris@90
|
1215 tip = tr("Transform with \"%1\" output of \"%2\" plugin (from %3)")
|
Chris@90
|
1216 .arg(output).arg(pluginName).arg(maker);
|
Chris@90
|
1217 }
|
Chris@90
|
1218 action->setStatusTip(tip);
|
Chris@90
|
1219
|
Chris@33
|
1220 if (categoryMenus[type].find(category) == categoryMenus[type].end()) {
|
Chris@33
|
1221 std::cerr << "WARNING: MainWindow::setupMenus: Internal error: "
|
Chris@33
|
1222 << "No category menu for transform \""
|
Chris@33
|
1223 << description.toStdString() << "\" (category = \""
|
Chris@33
|
1224 << category.toStdString() << "\")" << std::endl;
|
Chris@33
|
1225 } else {
|
Chris@33
|
1226 categoryMenus[type][category]->addAction(action);
|
Chris@33
|
1227 }
|
Chris@33
|
1228
|
Chris@33
|
1229 if (makerMenus[type].find(maker) == makerMenus[type].end()) {
|
Chris@33
|
1230 std::cerr << "WARNING: MainWindow::setupMenus: Internal error: "
|
Chris@33
|
1231 << "No maker menu for transform \""
|
Chris@33
|
1232 << description.toStdString() << "\" (maker = \""
|
Chris@33
|
1233 << maker.toStdString() << "\")" << std::endl;
|
Chris@33
|
1234 } else {
|
Chris@80
|
1235 makerMenus[type][maker]->addAction(action);
|
Chris@33
|
1236 }
|
Chris@33
|
1237
|
Chris@33
|
1238 action = new QAction(tr("%1...").arg(output == "" ? pluginName : output), this);
|
Chris@33
|
1239 connect(action, SIGNAL(triggered()), this, SLOT(addLayer()));
|
Chris@34
|
1240 m_transformActions[action] = transforms[i].name;
|
Chris@33
|
1241 connect(this, SIGNAL(canAddLayer(bool)), action, SLOT(setEnabled(bool)));
|
Chris@90
|
1242 action->setStatusTip(tip);
|
Chris@33
|
1243
|
Chris@34
|
1244 // cerr << "Transform: \"" << name.toStdString() << "\": plugin name \"" << pluginName.toStdString() << "\"" << endl;
|
Chris@34
|
1245
|
Chris@33
|
1246 if (pluginNameMenus[type].find(pluginName) ==
|
Chris@33
|
1247 pluginNameMenus[type].end()) {
|
Chris@33
|
1248
|
Chris@36
|
1249 SubdividingMenu *parentMenu = byPluginNameMenus[type];
|
Chris@34
|
1250
|
Chris@33
|
1251 if (output == "") {
|
Chris@36
|
1252 parentMenu->addAction(pluginName, action);
|
Chris@33
|
1253 } else {
|
Chris@34
|
1254 pluginNameMenus[type][pluginName] =
|
Chris@34
|
1255 parentMenu->addMenu(pluginName);
|
Chris@33
|
1256 connect(this, SIGNAL(canAddLayer(bool)),
|
Chris@33
|
1257 pluginNameMenus[type][pluginName],
|
Chris@33
|
1258 SLOT(setEnabled(bool)));
|
Chris@33
|
1259 }
|
Chris@33
|
1260 }
|
Chris@33
|
1261
|
Chris@33
|
1262 if (pluginNameMenus[type].find(pluginName) !=
|
Chris@33
|
1263 pluginNameMenus[type].end()) {
|
Chris@33
|
1264 pluginNameMenus[type][pluginName]->addAction(action);
|
Chris@33
|
1265 }
|
Chris@0
|
1266 }
|
Chris@0
|
1267
|
Chris@37
|
1268 for (set<SubdividingMenu *>::iterator i = pendingMenus.begin();
|
Chris@37
|
1269 i != pendingMenus.end(); ++i) {
|
Chris@37
|
1270 (*i)->entriesAdded();
|
Chris@37
|
1271 }
|
Chris@37
|
1272
|
Chris@34
|
1273 setupRecentTransformsMenu();
|
Chris@66
|
1274 }
|
Chris@66
|
1275
|
Chris@66
|
1276 void
|
Chris@66
|
1277 MainWindow::setupHelpMenu()
|
Chris@66
|
1278 {
|
Chris@66
|
1279 if (m_mainMenusCreated) return;
|
Chris@66
|
1280
|
Chris@66
|
1281 QMenu *menu = menuBar()->addMenu(tr("&Help"));
|
Chris@66
|
1282
|
Chris@66
|
1283 QAction *action = new QAction(tr("&Help Reference"), this);
|
Chris@66
|
1284 action->setStatusTip(tr("Open the Sonic Visualiser reference manual"));
|
Chris@66
|
1285 connect(action, SIGNAL(triggered()), this, SLOT(help()));
|
Chris@0
|
1286 menu->addAction(action);
|
Chris@0
|
1287
|
Chris@66
|
1288 action = new QAction(tr("Sonic Visualiser on the &Web"), this);
|
Chris@66
|
1289 action->setStatusTip(tr("Open the Sonic Visualiser website"));
|
Chris@66
|
1290 connect(action, SIGNAL(triggered()), this, SLOT(website()));
|
Chris@0
|
1291 menu->addAction(action);
|
Chris@66
|
1292
|
Chris@66
|
1293 action = new QAction(tr("&About Sonic Visualiser"), this);
|
Chris@66
|
1294 action->setStatusTip(tr("Show information about Sonic Visualiser"));
|
Chris@66
|
1295 connect(action, SIGNAL(triggered()), this, SLOT(about()));
|
Chris@0
|
1296 menu->addAction(action);
|
Chris@0
|
1297 }
|
Chris@0
|
1298
|
Chris@0
|
1299 void
|
Chris@0
|
1300 MainWindow::setupRecentFilesMenu()
|
Chris@0
|
1301 {
|
Chris@0
|
1302 m_recentFilesMenu->clear();
|
Chris@34
|
1303 vector<QString> files = m_recentFiles.getRecent();
|
Chris@0
|
1304 for (size_t i = 0; i < files.size(); ++i) {
|
Chris@0
|
1305 QAction *action = new QAction(files[i], this);
|
Chris@0
|
1306 connect(action, SIGNAL(triggered()), this, SLOT(openRecentFile()));
|
Chris@0
|
1307 m_recentFilesMenu->addAction(action);
|
Chris@0
|
1308 }
|
Chris@0
|
1309 }
|
Chris@0
|
1310
|
Chris@0
|
1311 void
|
Chris@34
|
1312 MainWindow::setupRecentTransformsMenu()
|
Chris@34
|
1313 {
|
Chris@34
|
1314 m_recentTransformsMenu->clear();
|
Chris@34
|
1315 vector<QString> transforms = m_recentTransforms.getRecent();
|
Chris@34
|
1316 for (size_t i = 0; i < transforms.size(); ++i) {
|
Chris@34
|
1317 TransformActionReverseMap::iterator ti =
|
Chris@34
|
1318 m_transformActionsReverse.find(transforms[i]);
|
Chris@34
|
1319 if (ti == m_transformActionsReverse.end()) {
|
Chris@34
|
1320 std::cerr << "WARNING: MainWindow::setupRecentTransformsMenu: "
|
Chris@34
|
1321 << "Unknown transform \"" << transforms[i].toStdString()
|
Chris@34
|
1322 << "\" in recent transforms list" << std::endl;
|
Chris@34
|
1323 continue;
|
Chris@34
|
1324 }
|
Chris@34
|
1325 m_recentTransformsMenu->addAction(ti->second);
|
Chris@34
|
1326 }
|
Chris@34
|
1327 }
|
Chris@34
|
1328
|
Chris@34
|
1329 void
|
Chris@0
|
1330 MainWindow::setupExistingLayersMenu()
|
Chris@0
|
1331 {
|
Chris@0
|
1332 if (!m_existingLayersMenu) return; // should have been created by setupMenus
|
Chris@0
|
1333
|
Chris@0
|
1334 // std::cerr << "MainWindow::setupExistingLayersMenu" << std::endl;
|
Chris@0
|
1335
|
Chris@0
|
1336 m_existingLayersMenu->clear();
|
Chris@0
|
1337 m_existingLayerActions.clear();
|
Chris@0
|
1338
|
Chris@33
|
1339 vector<Layer *> orderedLayers;
|
Chris@33
|
1340 set<Layer *> observedLayers;
|
Chris@0
|
1341
|
Chris@0
|
1342 for (int i = 0; i < m_paneStack->getPaneCount(); ++i) {
|
Chris@0
|
1343
|
Chris@0
|
1344 Pane *pane = m_paneStack->getPane(i);
|
Chris@0
|
1345 if (!pane) continue;
|
Chris@0
|
1346
|
Chris@0
|
1347 for (int j = 0; j < pane->getLayerCount(); ++j) {
|
Chris@0
|
1348
|
Chris@0
|
1349 Layer *layer = pane->getLayer(j);
|
Chris@0
|
1350 if (!layer) continue;
|
Chris@0
|
1351 if (observedLayers.find(layer) != observedLayers.end()) {
|
Chris@0
|
1352 std::cerr << "found duplicate layer " << layer << std::endl;
|
Chris@0
|
1353 continue;
|
Chris@0
|
1354 }
|
Chris@0
|
1355
|
Chris@0
|
1356 // std::cerr << "found new layer " << layer << " (name = "
|
Chris@0
|
1357 // << layer->getLayerPresentationName().toStdString() << ")" << std::endl;
|
Chris@0
|
1358
|
Chris@0
|
1359 orderedLayers.push_back(layer);
|
Chris@0
|
1360 observedLayers.insert(layer);
|
Chris@0
|
1361 }
|
Chris@0
|
1362 }
|
Chris@0
|
1363
|
Chris@33
|
1364 map<QString, int> observedNames;
|
Chris@0
|
1365
|
Chris@0
|
1366 for (int i = 0; i < orderedLayers.size(); ++i) {
|
Chris@0
|
1367
|
Chris@0
|
1368 QString name = orderedLayers[i]->getLayerPresentationName();
|
Chris@0
|
1369 int n = ++observedNames[name];
|
Chris@0
|
1370 if (n > 1) name = QString("%1 <%2>").arg(name).arg(n);
|
Chris@0
|
1371
|
Chris@0
|
1372 QAction *action = new QAction(name, this);
|
Chris@0
|
1373 connect(action, SIGNAL(triggered()), this, SLOT(addLayer()));
|
Chris@0
|
1374 connect(this, SIGNAL(canAddLayer(bool)), action, SLOT(setEnabled(bool)));
|
Chris@0
|
1375 m_existingLayerActions[action] = orderedLayers[i];
|
Chris@0
|
1376
|
Chris@0
|
1377 m_existingLayersMenu->addAction(action);
|
Chris@0
|
1378 }
|
Chris@0
|
1379 }
|
Chris@0
|
1380
|
Chris@0
|
1381 void
|
Chris@0
|
1382 MainWindow::setupToolbars()
|
Chris@0
|
1383 {
|
Chris@0
|
1384 QToolBar *toolbar = addToolBar(tr("Transport Toolbar"));
|
Chris@0
|
1385
|
Chris@0
|
1386 QAction *action = toolbar->addAction(QIcon(":/icons/rewind-start.png"),
|
Chris@0
|
1387 tr("Rewind to Start"));
|
Chris@0
|
1388 action->setShortcut(tr("Home"));
|
Chris@0
|
1389 action->setStatusTip(tr("Rewind to the start"));
|
Chris@0
|
1390 connect(action, SIGNAL(triggered()), this, SLOT(rewindStart()));
|
Chris@0
|
1391 connect(this, SIGNAL(canPlay(bool)), action, SLOT(setEnabled(bool)));
|
Chris@0
|
1392
|
Chris@0
|
1393 action = toolbar->addAction(QIcon(":/icons/rewind.png"),
|
Chris@0
|
1394 tr("Rewind"));
|
Chris@0
|
1395 action->setShortcut(tr("PageUp"));
|
Chris@0
|
1396 action->setStatusTip(tr("Rewind to the previous time instant in the current layer"));
|
Chris@0
|
1397 connect(action, SIGNAL(triggered()), this, SLOT(rewind()));
|
Chris@0
|
1398 connect(this, SIGNAL(canRewind(bool)), action, SLOT(setEnabled(bool)));
|
Chris@0
|
1399
|
Chris@0
|
1400 action = toolbar->addAction(QIcon(":/icons/playpause.png"),
|
Chris@0
|
1401 tr("Play / Pause"));
|
Chris@0
|
1402 action->setCheckable(true);
|
Chris@0
|
1403 action->setShortcut(tr("Space"));
|
Chris@0
|
1404 action->setStatusTip(tr("Start or stop playback from the current position"));
|
Chris@0
|
1405 connect(action, SIGNAL(triggered()), this, SLOT(play()));
|
Chris@0
|
1406 connect(m_playSource, SIGNAL(playStatusChanged(bool)),
|
Chris@0
|
1407 action, SLOT(setChecked(bool)));
|
Chris@0
|
1408 connect(this, SIGNAL(canPlay(bool)), action, SLOT(setEnabled(bool)));
|
Chris@0
|
1409
|
Chris@0
|
1410 action = toolbar->addAction(QIcon(":/icons/ffwd.png"),
|
Chris@0
|
1411 tr("Fast Forward"));
|
Chris@0
|
1412 action->setShortcut(tr("PageDown"));
|
Chris@0
|
1413 action->setStatusTip(tr("Fast forward to the next time instant in the current layer"));
|
Chris@0
|
1414 connect(action, SIGNAL(triggered()), this, SLOT(ffwd()));
|
Chris@0
|
1415 connect(this, SIGNAL(canFfwd(bool)), action, SLOT(setEnabled(bool)));
|
Chris@0
|
1416
|
Chris@0
|
1417 action = toolbar->addAction(QIcon(":/icons/ffwd-end.png"),
|
Chris@0
|
1418 tr("Fast Forward to End"));
|
Chris@0
|
1419 action->setShortcut(tr("End"));
|
Chris@0
|
1420 action->setStatusTip(tr("Fast-forward to the end"));
|
Chris@0
|
1421 connect(action, SIGNAL(triggered()), this, SLOT(ffwdEnd()));
|
Chris@0
|
1422 connect(this, SIGNAL(canPlay(bool)), action, SLOT(setEnabled(bool)));
|
Chris@0
|
1423
|
Chris@0
|
1424 toolbar = addToolBar(tr("Play Mode Toolbar"));
|
Chris@0
|
1425
|
Chris@0
|
1426 action = toolbar->addAction(QIcon(":/icons/playselection.png"),
|
Chris@0
|
1427 tr("Constrain Playback to Selection"));
|
Chris@0
|
1428 action->setCheckable(true);
|
Chris@0
|
1429 action->setChecked(m_viewManager->getPlaySelectionMode());
|
Chris@0
|
1430 action->setShortcut(tr("s"));
|
Chris@0
|
1431 action->setStatusTip(tr("Constrain playback to the selected area"));
|
Chris@69
|
1432 connect(m_viewManager, SIGNAL(playSelectionModeChanged(bool)),
|
Chris@69
|
1433 action, SLOT(setChecked(bool)));
|
Chris@0
|
1434 connect(action, SIGNAL(triggered()), this, SLOT(playSelectionToggled()));
|
Chris@0
|
1435 connect(this, SIGNAL(canPlaySelection(bool)), action, SLOT(setEnabled(bool)));
|
Chris@0
|
1436
|
Chris@0
|
1437 action = toolbar->addAction(QIcon(":/icons/playloop.png"),
|
Chris@0
|
1438 tr("Loop Playback"));
|
Chris@0
|
1439 action->setCheckable(true);
|
Chris@0
|
1440 action->setChecked(m_viewManager->getPlayLoopMode());
|
Chris@0
|
1441 action->setShortcut(tr("l"));
|
Chris@0
|
1442 action->setStatusTip(tr("Loop playback"));
|
Chris@69
|
1443 connect(m_viewManager, SIGNAL(playLoopModeChanged(bool)),
|
Chris@69
|
1444 action, SLOT(setChecked(bool)));
|
Chris@0
|
1445 connect(action, SIGNAL(triggered()), this, SLOT(playLoopToggled()));
|
Chris@0
|
1446 connect(this, SIGNAL(canPlay(bool)), action, SLOT(setEnabled(bool)));
|
Chris@0
|
1447
|
Chris@0
|
1448 toolbar = addToolBar(tr("Edit Toolbar"));
|
Chris@0
|
1449 CommandHistory::getInstance()->registerToolbar(toolbar);
|
Chris@0
|
1450
|
Chris@0
|
1451 toolbar = addToolBar(tr("Tools Toolbar"));
|
Chris@0
|
1452 QActionGroup *group = new QActionGroup(this);
|
Chris@0
|
1453
|
Chris@0
|
1454 action = toolbar->addAction(QIcon(":/icons/navigate.png"),
|
Chris@0
|
1455 tr("Navigate"));
|
Chris@0
|
1456 action->setCheckable(true);
|
Chris@0
|
1457 action->setChecked(true);
|
Chris@0
|
1458 action->setShortcut(tr("1"));
|
Chris@90
|
1459 action->setStatusTip(tr("Navigate"));
|
Chris@0
|
1460 connect(action, SIGNAL(triggered()), this, SLOT(toolNavigateSelected()));
|
Chris@0
|
1461 group->addAction(action);
|
Chris@0
|
1462 m_toolActions[ViewManager::NavigateMode] = action;
|
Chris@0
|
1463
|
Chris@0
|
1464 action = toolbar->addAction(QIcon(":/icons/select.png"),
|
Chris@0
|
1465 tr("Select"));
|
Chris@0
|
1466 action->setCheckable(true);
|
Chris@0
|
1467 action->setShortcut(tr("2"));
|
Chris@90
|
1468 action->setStatusTip(tr("Select ranges"));
|
Chris@0
|
1469 connect(action, SIGNAL(triggered()), this, SLOT(toolSelectSelected()));
|
Chris@0
|
1470 group->addAction(action);
|
Chris@0
|
1471 m_toolActions[ViewManager::SelectMode] = action;
|
Chris@0
|
1472
|
Chris@0
|
1473 action = toolbar->addAction(QIcon(":/icons/move.png"),
|
Chris@0
|
1474 tr("Edit"));
|
Chris@0
|
1475 action->setCheckable(true);
|
Chris@0
|
1476 action->setShortcut(tr("3"));
|
Chris@90
|
1477 action->setStatusTip(tr("Edit items in layer"));
|
Chris@0
|
1478 connect(action, SIGNAL(triggered()), this, SLOT(toolEditSelected()));
|
Chris@0
|
1479 connect(this, SIGNAL(canEditLayer(bool)), action, SLOT(setEnabled(bool)));
|
Chris@0
|
1480 group->addAction(action);
|
Chris@0
|
1481 m_toolActions[ViewManager::EditMode] = action;
|
Chris@0
|
1482
|
Chris@0
|
1483 action = toolbar->addAction(QIcon(":/icons/draw.png"),
|
Chris@0
|
1484 tr("Draw"));
|
Chris@0
|
1485 action->setCheckable(true);
|
Chris@0
|
1486 action->setShortcut(tr("4"));
|
Chris@90
|
1487 action->setStatusTip(tr("Draw new items in layer"));
|
Chris@0
|
1488 connect(action, SIGNAL(triggered()), this, SLOT(toolDrawSelected()));
|
Chris@0
|
1489 connect(this, SIGNAL(canEditLayer(bool)), action, SLOT(setEnabled(bool)));
|
Chris@0
|
1490 group->addAction(action);
|
Chris@0
|
1491 m_toolActions[ViewManager::DrawMode] = action;
|
Chris@0
|
1492
|
Chris@0
|
1493 // action = toolbar->addAction(QIcon(":/icons/text.png"),
|
Chris@0
|
1494 // tr("Text"));
|
Chris@0
|
1495 // action->setCheckable(true);
|
Chris@0
|
1496 // action->setShortcut(tr("5"));
|
Chris@0
|
1497 // connect(action, SIGNAL(triggered()), this, SLOT(toolTextSelected()));
|
Chris@0
|
1498 // group->addAction(action);
|
Chris@0
|
1499 // m_toolActions[ViewManager::TextMode] = action;
|
Chris@0
|
1500
|
Chris@0
|
1501 toolNavigateSelected();
|
Chris@0
|
1502 }
|
Chris@0
|
1503
|
Chris@0
|
1504 void
|
Chris@0
|
1505 MainWindow::updateMenuStates()
|
Chris@0
|
1506 {
|
Chris@0
|
1507 bool haveCurrentPane =
|
Chris@0
|
1508 (m_paneStack &&
|
Chris@0
|
1509 (m_paneStack->getCurrentPane() != 0));
|
Chris@0
|
1510 bool haveCurrentLayer =
|
Chris@0
|
1511 (haveCurrentPane &&
|
Chris@0
|
1512 (m_paneStack->getCurrentPane()->getSelectedLayer()));
|
Chris@0
|
1513 bool haveMainModel =
|
Chris@0
|
1514 (getMainModel() != 0);
|
Chris@0
|
1515 bool havePlayTarget =
|
Chris@0
|
1516 (m_playTarget != 0);
|
Chris@0
|
1517 bool haveSelection =
|
Chris@0
|
1518 (m_viewManager &&
|
Chris@0
|
1519 !m_viewManager->getSelections().empty());
|
Chris@0
|
1520 bool haveCurrentEditableLayer =
|
Chris@0
|
1521 (haveCurrentLayer &&
|
Chris@0
|
1522 m_paneStack->getCurrentPane()->getSelectedLayer()->
|
Chris@0
|
1523 isLayerEditable());
|
Chris@0
|
1524 bool haveCurrentTimeInstantsLayer =
|
Chris@0
|
1525 (haveCurrentLayer &&
|
Chris@0
|
1526 dynamic_cast<TimeInstantLayer *>
|
Chris@0
|
1527 (m_paneStack->getCurrentPane()->getSelectedLayer()));
|
Chris@0
|
1528 bool haveCurrentTimeValueLayer =
|
Chris@0
|
1529 (haveCurrentLayer &&
|
Chris@0
|
1530 dynamic_cast<TimeValueLayer *>
|
Chris@0
|
1531 (m_paneStack->getCurrentPane()->getSelectedLayer()));
|
Chris@0
|
1532 bool haveCurrentColour3DPlot =
|
Chris@0
|
1533 (haveCurrentLayer &&
|
Chris@0
|
1534 dynamic_cast<Colour3DPlotLayer *>
|
Chris@0
|
1535 (m_paneStack->getCurrentPane()->getSelectedLayer()));
|
Chris@0
|
1536 bool haveClipboardContents =
|
Chris@0
|
1537 (m_viewManager &&
|
Chris@0
|
1538 !m_viewManager->getClipboard().empty());
|
Chris@0
|
1539
|
Chris@0
|
1540 emit canAddPane(haveMainModel);
|
Chris@0
|
1541 emit canDeleteCurrentPane(haveCurrentPane);
|
Chris@0
|
1542 emit canZoom(haveMainModel && haveCurrentPane);
|
Chris@0
|
1543 emit canScroll(haveMainModel && haveCurrentPane);
|
Chris@0
|
1544 emit canAddLayer(haveMainModel && haveCurrentPane);
|
Chris@0
|
1545 emit canImportMoreAudio(haveMainModel);
|
Chris@0
|
1546 emit canImportLayer(haveMainModel && haveCurrentPane);
|
Chris@0
|
1547 emit canExportAudio(haveMainModel);
|
Chris@0
|
1548 emit canExportLayer(haveMainModel &&
|
Chris@0
|
1549 (haveCurrentEditableLayer || haveCurrentColour3DPlot));
|
Chris@0
|
1550 emit canDeleteCurrentLayer(haveCurrentLayer);
|
Chris@0
|
1551 emit canRenameLayer(haveCurrentLayer);
|
Chris@0
|
1552 emit canEditLayer(haveCurrentEditableLayer);
|
Chris@0
|
1553 emit canSelect(haveMainModel && haveCurrentPane);
|
Chris@0
|
1554 emit canPlay(/*!!! haveMainModel && */ havePlayTarget);
|
Chris@0
|
1555 emit canFfwd(haveCurrentTimeInstantsLayer || haveCurrentTimeValueLayer);
|
Chris@0
|
1556 emit canRewind(haveCurrentTimeInstantsLayer || haveCurrentTimeValueLayer);
|
Chris@0
|
1557 emit canPaste(haveCurrentEditableLayer && haveClipboardContents);
|
Chris@0
|
1558 emit canInsertInstant(haveCurrentPane);
|
Chris@81
|
1559 emit canInsertInstantsAtBoundaries(haveCurrentPane && haveSelection);
|
Chris@0
|
1560 emit canPlaySelection(haveMainModel && havePlayTarget && haveSelection);
|
Chris@0
|
1561 emit canClearSelection(haveSelection);
|
Chris@0
|
1562 emit canEditSelection(haveSelection && haveCurrentEditableLayer);
|
Chris@0
|
1563 emit canSave(m_sessionFile != "" && m_documentModified);
|
Chris@0
|
1564 }
|
Chris@0
|
1565
|
Chris@0
|
1566 void
|
Chris@0
|
1567 MainWindow::updateDescriptionLabel()
|
Chris@0
|
1568 {
|
Chris@0
|
1569 if (!getMainModel()) {
|
Chris@0
|
1570 m_descriptionLabel->setText(tr("No audio file loaded."));
|
Chris@0
|
1571 return;
|
Chris@0
|
1572 }
|
Chris@0
|
1573
|
Chris@0
|
1574 QString description;
|
Chris@0
|
1575
|
Chris@0
|
1576 size_t ssr = getMainModel()->getSampleRate();
|
Chris@0
|
1577 size_t tsr = ssr;
|
Chris@0
|
1578 if (m_playSource) tsr = m_playSource->getTargetSampleRate();
|
Chris@0
|
1579
|
Chris@0
|
1580 if (ssr != tsr) {
|
Chris@0
|
1581 description = tr("%1Hz (resampling to %2Hz)").arg(ssr).arg(tsr);
|
Chris@0
|
1582 } else {
|
Chris@0
|
1583 description = QString("%1Hz").arg(ssr);
|
Chris@0
|
1584 }
|
Chris@0
|
1585
|
Chris@0
|
1586 description = QString("%1 - %2")
|
Chris@0
|
1587 .arg(RealTime::frame2RealTime(getMainModel()->getEndFrame(), ssr)
|
Chris@0
|
1588 .toText(false).c_str())
|
Chris@0
|
1589 .arg(description);
|
Chris@0
|
1590
|
Chris@0
|
1591 m_descriptionLabel->setText(description);
|
Chris@0
|
1592 }
|
Chris@0
|
1593
|
Chris@0
|
1594 void
|
Chris@0
|
1595 MainWindow::documentModified()
|
Chris@0
|
1596 {
|
Chris@0
|
1597 // std::cerr << "MainWindow::documentModified" << std::endl;
|
Chris@0
|
1598
|
Chris@0
|
1599 if (!m_documentModified) {
|
Chris@0
|
1600 setWindowTitle(tr("%1 (modified)").arg(windowTitle()));
|
Chris@0
|
1601 }
|
Chris@0
|
1602
|
Chris@0
|
1603 m_documentModified = true;
|
Chris@0
|
1604 updateMenuStates();
|
Chris@0
|
1605 }
|
Chris@0
|
1606
|
Chris@0
|
1607 void
|
Chris@0
|
1608 MainWindow::documentRestored()
|
Chris@0
|
1609 {
|
Chris@0
|
1610 // std::cerr << "MainWindow::documentRestored" << std::endl;
|
Chris@0
|
1611
|
Chris@0
|
1612 if (m_documentModified) {
|
Chris@0
|
1613 QString wt(windowTitle());
|
Chris@0
|
1614 wt.replace(tr(" (modified)"), "");
|
Chris@0
|
1615 setWindowTitle(wt);
|
Chris@0
|
1616 }
|
Chris@0
|
1617
|
Chris@0
|
1618 m_documentModified = false;
|
Chris@0
|
1619 updateMenuStates();
|
Chris@0
|
1620 }
|
Chris@0
|
1621
|
Chris@0
|
1622 void
|
Chris@0
|
1623 MainWindow::playLoopToggled()
|
Chris@0
|
1624 {
|
Chris@0
|
1625 QAction *action = dynamic_cast<QAction *>(sender());
|
Chris@0
|
1626
|
Chris@0
|
1627 if (action) {
|
Chris@0
|
1628 m_viewManager->setPlayLoopMode(action->isChecked());
|
Chris@0
|
1629 } else {
|
Chris@0
|
1630 m_viewManager->setPlayLoopMode(!m_viewManager->getPlayLoopMode());
|
Chris@0
|
1631 }
|
Chris@0
|
1632 }
|
Chris@0
|
1633
|
Chris@0
|
1634 void
|
Chris@0
|
1635 MainWindow::playSelectionToggled()
|
Chris@0
|
1636 {
|
Chris@0
|
1637 QAction *action = dynamic_cast<QAction *>(sender());
|
Chris@0
|
1638
|
Chris@0
|
1639 if (action) {
|
Chris@0
|
1640 m_viewManager->setPlaySelectionMode(action->isChecked());
|
Chris@0
|
1641 } else {
|
Chris@0
|
1642 m_viewManager->setPlaySelectionMode(!m_viewManager->getPlaySelectionMode());
|
Chris@0
|
1643 }
|
Chris@0
|
1644 }
|
Chris@0
|
1645
|
Chris@0
|
1646 void
|
Chris@0
|
1647 MainWindow::currentPaneChanged(Pane *)
|
Chris@0
|
1648 {
|
Chris@0
|
1649 updateMenuStates();
|
Chris@0
|
1650 }
|
Chris@0
|
1651
|
Chris@0
|
1652 void
|
Chris@0
|
1653 MainWindow::currentLayerChanged(Pane *, Layer *)
|
Chris@0
|
1654 {
|
Chris@0
|
1655 updateMenuStates();
|
Chris@0
|
1656 }
|
Chris@0
|
1657
|
Chris@0
|
1658 void
|
Chris@0
|
1659 MainWindow::toolNavigateSelected()
|
Chris@0
|
1660 {
|
Chris@0
|
1661 m_viewManager->setToolMode(ViewManager::NavigateMode);
|
Chris@0
|
1662 }
|
Chris@0
|
1663
|
Chris@0
|
1664 void
|
Chris@0
|
1665 MainWindow::toolSelectSelected()
|
Chris@0
|
1666 {
|
Chris@0
|
1667 m_viewManager->setToolMode(ViewManager::SelectMode);
|
Chris@0
|
1668 }
|
Chris@0
|
1669
|
Chris@0
|
1670 void
|
Chris@0
|
1671 MainWindow::toolEditSelected()
|
Chris@0
|
1672 {
|
Chris@0
|
1673 m_viewManager->setToolMode(ViewManager::EditMode);
|
Chris@0
|
1674 }
|
Chris@0
|
1675
|
Chris@0
|
1676 void
|
Chris@0
|
1677 MainWindow::toolDrawSelected()
|
Chris@0
|
1678 {
|
Chris@0
|
1679 m_viewManager->setToolMode(ViewManager::DrawMode);
|
Chris@0
|
1680 }
|
Chris@0
|
1681
|
Chris@0
|
1682 //void
|
Chris@0
|
1683 //MainWindow::toolTextSelected()
|
Chris@0
|
1684 //{
|
Chris@0
|
1685 // m_viewManager->setToolMode(ViewManager::TextMode);
|
Chris@0
|
1686 //}
|
Chris@0
|
1687
|
Chris@0
|
1688 void
|
Chris@0
|
1689 MainWindow::selectAll()
|
Chris@0
|
1690 {
|
Chris@0
|
1691 if (!getMainModel()) return;
|
Chris@0
|
1692 m_viewManager->setSelection(Selection(getMainModel()->getStartFrame(),
|
Chris@0
|
1693 getMainModel()->getEndFrame()));
|
Chris@0
|
1694 }
|
Chris@0
|
1695
|
Chris@0
|
1696 void
|
Chris@0
|
1697 MainWindow::selectToStart()
|
Chris@0
|
1698 {
|
Chris@0
|
1699 if (!getMainModel()) return;
|
Chris@0
|
1700 m_viewManager->setSelection(Selection(getMainModel()->getStartFrame(),
|
Chris@0
|
1701 m_viewManager->getGlobalCentreFrame()));
|
Chris@0
|
1702 }
|
Chris@0
|
1703
|
Chris@0
|
1704 void
|
Chris@0
|
1705 MainWindow::selectToEnd()
|
Chris@0
|
1706 {
|
Chris@0
|
1707 if (!getMainModel()) return;
|
Chris@0
|
1708 m_viewManager->setSelection(Selection(m_viewManager->getGlobalCentreFrame(),
|
Chris@0
|
1709 getMainModel()->getEndFrame()));
|
Chris@0
|
1710 }
|
Chris@0
|
1711
|
Chris@0
|
1712 void
|
Chris@0
|
1713 MainWindow::selectVisible()
|
Chris@0
|
1714 {
|
Chris@0
|
1715 Model *model = getMainModel();
|
Chris@0
|
1716 if (!model) return;
|
Chris@0
|
1717
|
Chris@0
|
1718 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@0
|
1719 if (!currentPane) return;
|
Chris@0
|
1720
|
Chris@0
|
1721 size_t startFrame, endFrame;
|
Chris@0
|
1722
|
Chris@0
|
1723 if (currentPane->getStartFrame() < 0) startFrame = 0;
|
Chris@0
|
1724 else startFrame = currentPane->getStartFrame();
|
Chris@0
|
1725
|
Chris@0
|
1726 if (currentPane->getEndFrame() > model->getEndFrame()) endFrame = model->getEndFrame();
|
Chris@0
|
1727 else endFrame = currentPane->getEndFrame();
|
Chris@0
|
1728
|
Chris@0
|
1729 m_viewManager->setSelection(Selection(startFrame, endFrame));
|
Chris@0
|
1730 }
|
Chris@0
|
1731
|
Chris@0
|
1732 void
|
Chris@0
|
1733 MainWindow::clearSelection()
|
Chris@0
|
1734 {
|
Chris@0
|
1735 m_viewManager->clearSelections();
|
Chris@0
|
1736 }
|
Chris@0
|
1737
|
Chris@0
|
1738 void
|
Chris@0
|
1739 MainWindow::cut()
|
Chris@0
|
1740 {
|
Chris@0
|
1741 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@0
|
1742 if (!currentPane) return;
|
Chris@0
|
1743
|
Chris@0
|
1744 Layer *layer = currentPane->getSelectedLayer();
|
Chris@0
|
1745 if (!layer) return;
|
Chris@0
|
1746
|
Chris@0
|
1747 Clipboard &clipboard = m_viewManager->getClipboard();
|
Chris@0
|
1748 clipboard.clear();
|
Chris@0
|
1749
|
Chris@0
|
1750 MultiSelection::SelectionList selections = m_viewManager->getSelections();
|
Chris@0
|
1751
|
Chris@0
|
1752 CommandHistory::getInstance()->startCompoundOperation(tr("Cut"), true);
|
Chris@0
|
1753
|
Chris@0
|
1754 for (MultiSelection::SelectionList::iterator i = selections.begin();
|
Chris@0
|
1755 i != selections.end(); ++i) {
|
Chris@0
|
1756 layer->copy(*i, clipboard);
|
Chris@0
|
1757 layer->deleteSelection(*i);
|
Chris@0
|
1758 }
|
Chris@0
|
1759
|
Chris@0
|
1760 CommandHistory::getInstance()->endCompoundOperation();
|
Chris@0
|
1761 }
|
Chris@0
|
1762
|
Chris@0
|
1763 void
|
Chris@0
|
1764 MainWindow::copy()
|
Chris@0
|
1765 {
|
Chris@0
|
1766 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@0
|
1767 if (!currentPane) return;
|
Chris@0
|
1768
|
Chris@0
|
1769 Layer *layer = currentPane->getSelectedLayer();
|
Chris@0
|
1770 if (!layer) return;
|
Chris@0
|
1771
|
Chris@0
|
1772 Clipboard &clipboard = m_viewManager->getClipboard();
|
Chris@0
|
1773 clipboard.clear();
|
Chris@0
|
1774
|
Chris@0
|
1775 MultiSelection::SelectionList selections = m_viewManager->getSelections();
|
Chris@0
|
1776
|
Chris@0
|
1777 for (MultiSelection::SelectionList::iterator i = selections.begin();
|
Chris@0
|
1778 i != selections.end(); ++i) {
|
Chris@0
|
1779 layer->copy(*i, clipboard);
|
Chris@0
|
1780 }
|
Chris@0
|
1781 }
|
Chris@0
|
1782
|
Chris@0
|
1783 void
|
Chris@0
|
1784 MainWindow::paste()
|
Chris@0
|
1785 {
|
Chris@0
|
1786 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@0
|
1787 if (!currentPane) return;
|
Chris@0
|
1788
|
Chris@0
|
1789 //!!! if we have no current layer, we should create one of the most
|
Chris@0
|
1790 // appropriate type
|
Chris@0
|
1791
|
Chris@0
|
1792 Layer *layer = currentPane->getSelectedLayer();
|
Chris@0
|
1793 if (!layer) return;
|
Chris@0
|
1794
|
Chris@0
|
1795 Clipboard &clipboard = m_viewManager->getClipboard();
|
Chris@0
|
1796 Clipboard::PointList contents = clipboard.getPoints();
|
Chris@0
|
1797 /*
|
Chris@0
|
1798 long minFrame = 0;
|
Chris@0
|
1799 bool have = false;
|
Chris@0
|
1800 for (int i = 0; i < contents.size(); ++i) {
|
Chris@0
|
1801 if (!contents[i].haveFrame()) continue;
|
Chris@0
|
1802 if (!have || contents[i].getFrame() < minFrame) {
|
Chris@0
|
1803 minFrame = contents[i].getFrame();
|
Chris@0
|
1804 have = true;
|
Chris@0
|
1805 }
|
Chris@0
|
1806 }
|
Chris@0
|
1807
|
Chris@0
|
1808 long frameOffset = long(m_viewManager->getGlobalCentreFrame()) - minFrame;
|
Chris@0
|
1809
|
Chris@0
|
1810 layer->paste(clipboard, frameOffset);
|
Chris@0
|
1811 */
|
Chris@0
|
1812 layer->paste(clipboard, 0, true);
|
Chris@0
|
1813 }
|
Chris@0
|
1814
|
Chris@0
|
1815 void
|
Chris@0
|
1816 MainWindow::deleteSelected()
|
Chris@0
|
1817 {
|
Chris@0
|
1818 if (m_paneStack->getCurrentPane() &&
|
Chris@0
|
1819 m_paneStack->getCurrentPane()->getSelectedLayer()) {
|
Chris@0
|
1820
|
Chris@0
|
1821 MultiSelection::SelectionList selections =
|
Chris@0
|
1822 m_viewManager->getSelections();
|
Chris@0
|
1823
|
Chris@0
|
1824 for (MultiSelection::SelectionList::iterator i = selections.begin();
|
Chris@0
|
1825 i != selections.end(); ++i) {
|
Chris@0
|
1826
|
Chris@0
|
1827 m_paneStack->getCurrentPane()->getSelectedLayer()->deleteSelection(*i);
|
Chris@0
|
1828 }
|
Chris@0
|
1829 }
|
Chris@0
|
1830 }
|
Chris@0
|
1831
|
Chris@0
|
1832 void
|
Chris@0
|
1833 MainWindow::insertInstant()
|
Chris@0
|
1834 {
|
Chris@0
|
1835 int frame = m_viewManager->getPlaybackFrame();
|
Chris@81
|
1836 insertInstantAt(frame);
|
Chris@81
|
1837 }
|
Chris@81
|
1838
|
Chris@81
|
1839 void
|
Chris@81
|
1840 MainWindow::insertInstantsAtBoundaries()
|
Chris@81
|
1841 {
|
Chris@81
|
1842 MultiSelection::SelectionList selections = m_viewManager->getSelections();
|
Chris@81
|
1843 for (MultiSelection::SelectionList::iterator i = selections.begin();
|
Chris@81
|
1844 i != selections.end(); ++i) {
|
Chris@81
|
1845 size_t start = i->getStartFrame();
|
Chris@81
|
1846 size_t end = i->getEndFrame();
|
Chris@81
|
1847 if (start != end) {
|
Chris@81
|
1848 insertInstantAt(i->getStartFrame());
|
Chris@81
|
1849 insertInstantAt(i->getEndFrame());
|
Chris@81
|
1850 }
|
Chris@81
|
1851 }
|
Chris@81
|
1852 }
|
Chris@81
|
1853
|
Chris@81
|
1854 void
|
Chris@81
|
1855 MainWindow::insertInstantAt(size_t frame)
|
Chris@81
|
1856 {
|
Chris@0
|
1857 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@0
|
1858 if (!pane) {
|
Chris@0
|
1859 return;
|
Chris@0
|
1860 }
|
Chris@0
|
1861
|
Chris@0
|
1862 Layer *layer = dynamic_cast<TimeInstantLayer *>
|
Chris@0
|
1863 (pane->getSelectedLayer());
|
Chris@0
|
1864
|
Chris@0
|
1865 if (!layer) {
|
Chris@0
|
1866 for (int i = pane->getLayerCount(); i > 0; --i) {
|
Chris@0
|
1867 layer = dynamic_cast<TimeInstantLayer *>(pane->getLayer(i - 1));
|
Chris@0
|
1868 if (layer) break;
|
Chris@0
|
1869 }
|
Chris@0
|
1870
|
Chris@0
|
1871 if (!layer) {
|
Chris@0
|
1872 CommandHistory::getInstance()->startCompoundOperation
|
Chris@0
|
1873 (tr("Add Point"), true);
|
Chris@0
|
1874 layer = m_document->createEmptyLayer(LayerFactory::TimeInstants);
|
Chris@0
|
1875 if (layer) {
|
Chris@0
|
1876 m_document->addLayerToView(pane, layer);
|
Chris@0
|
1877 m_paneStack->setCurrentLayer(pane, layer);
|
Chris@0
|
1878 }
|
Chris@0
|
1879 CommandHistory::getInstance()->endCompoundOperation();
|
Chris@0
|
1880 }
|
Chris@0
|
1881 }
|
Chris@0
|
1882
|
Chris@0
|
1883 if (layer) {
|
Chris@0
|
1884
|
Chris@0
|
1885 Model *model = layer->getModel();
|
Chris@0
|
1886 SparseOneDimensionalModel *sodm = dynamic_cast<SparseOneDimensionalModel *>
|
Chris@0
|
1887 (model);
|
Chris@0
|
1888
|
Chris@0
|
1889 if (sodm) {
|
Chris@0
|
1890 SparseOneDimensionalModel::Point point
|
Chris@0
|
1891 (frame, QString("%1").arg(sodm->getPointCount() + 1));
|
Chris@0
|
1892 CommandHistory::getInstance()->addCommand
|
Chris@0
|
1893 (new SparseOneDimensionalModel::AddPointCommand(sodm, point,
|
Chris@0
|
1894 tr("Add Points")),
|
Chris@0
|
1895 true, true); // bundled
|
Chris@0
|
1896 }
|
Chris@0
|
1897 }
|
Chris@0
|
1898 }
|
Chris@0
|
1899
|
Chris@0
|
1900 void
|
Chris@0
|
1901 MainWindow::importAudio()
|
Chris@0
|
1902 {
|
Chris@88
|
1903 QString path = getOpenFileName(FileFinder::AudioFile);
|
Chris@0
|
1904
|
Chris@0
|
1905 if (path != "") {
|
Chris@82
|
1906 if (openAudioFile(path, ReplaceMainModel) == FileOpenFailed) {
|
Chris@0
|
1907 QMessageBox::critical(this, tr("Failed to open file"),
|
Chris@0
|
1908 tr("Audio file \"%1\" could not be opened").arg(path));
|
Chris@0
|
1909 }
|
Chris@0
|
1910 }
|
Chris@0
|
1911 }
|
Chris@0
|
1912
|
Chris@0
|
1913 void
|
Chris@0
|
1914 MainWindow::importMoreAudio()
|
Chris@0
|
1915 {
|
Chris@88
|
1916 QString path = getOpenFileName(FileFinder::AudioFile);
|
Chris@0
|
1917
|
Chris@0
|
1918 if (path != "") {
|
Chris@82
|
1919 if (openAudioFile(path, CreateAdditionalModel) == FileOpenFailed) {
|
Chris@0
|
1920 QMessageBox::critical(this, tr("Failed to open file"),
|
Chris@0
|
1921 tr("Audio file \"%1\" could not be opened").arg(path));
|
Chris@0
|
1922 }
|
Chris@0
|
1923 }
|
Chris@0
|
1924 }
|
Chris@0
|
1925
|
Chris@0
|
1926 void
|
Chris@0
|
1927 MainWindow::exportAudio()
|
Chris@0
|
1928 {
|
Chris@0
|
1929 if (!getMainModel()) return;
|
Chris@0
|
1930
|
Chris@88
|
1931 QString path = getSaveFileName(FileFinder::AudioFile);
|
Chris@0
|
1932
|
Chris@0
|
1933 if (path == "") return;
|
Chris@0
|
1934
|
Chris@0
|
1935 bool ok = false;
|
Chris@0
|
1936 QString error;
|
Chris@0
|
1937
|
Chris@0
|
1938 MultiSelection ms = m_viewManager->getSelection();
|
Chris@0
|
1939 MultiSelection::SelectionList selections = m_viewManager->getSelections();
|
Chris@0
|
1940
|
Chris@0
|
1941 bool multiple = false;
|
Chris@0
|
1942
|
Chris@38
|
1943 MultiSelection *selectionToWrite = 0;
|
Chris@38
|
1944
|
Chris@38
|
1945 if (selections.size() == 1) {
|
Chris@0
|
1946
|
Chris@0
|
1947 QStringList items;
|
Chris@0
|
1948 items << tr("Export the selected region only")
|
Chris@0
|
1949 << tr("Export the whole audio file");
|
Chris@0
|
1950
|
Chris@0
|
1951 bool ok = false;
|
Chris@0
|
1952 QString item = ListInputDialog::getItem
|
Chris@0
|
1953 (this, tr("Select region to export"),
|
Chris@0
|
1954 tr("Which region from the original audio file do you want to export?"),
|
Chris@0
|
1955 items, 0, &ok);
|
Chris@0
|
1956
|
Chris@0
|
1957 if (!ok || item.isEmpty()) return;
|
Chris@0
|
1958
|
Chris@38
|
1959 if (item == items[0]) selectionToWrite = &ms;
|
Chris@38
|
1960
|
Chris@38
|
1961 } else if (selections.size() > 1) {
|
Chris@0
|
1962
|
Chris@0
|
1963 QStringList items;
|
Chris@0
|
1964 items << tr("Export the selected regions into a single audio file")
|
Chris@0
|
1965 << tr("Export the selected regions into separate files")
|
Chris@0
|
1966 << tr("Export the whole audio file");
|
Chris@0
|
1967
|
Chris@0
|
1968 QString item = ListInputDialog::getItem
|
Chris@0
|
1969 (this, tr("Select region to export"),
|
Chris@0
|
1970 tr("Multiple regions of the original audio file are selected.\nWhat do you want to export?"),
|
Chris@0
|
1971 items, 0, &ok);
|
Chris@0
|
1972
|
Chris@0
|
1973 if (!ok || item.isEmpty()) return;
|
Chris@0
|
1974
|
Chris@0
|
1975 if (item == items[0]) {
|
Chris@0
|
1976
|
Chris@38
|
1977 selectionToWrite = &ms;
|
Chris@38
|
1978
|
Chris@38
|
1979 } else if (item == items[1]) {
|
Chris@0
|
1980
|
Chris@0
|
1981 multiple = true;
|
Chris@0
|
1982
|
Chris@0
|
1983 int n = 1;
|
Chris@0
|
1984 QString base = path;
|
Chris@0
|
1985 base.replace(".wav", "");
|
Chris@0
|
1986
|
Chris@0
|
1987 for (MultiSelection::SelectionList::iterator i = selections.begin();
|
Chris@0
|
1988 i != selections.end(); ++i) {
|
Chris@0
|
1989
|
Chris@0
|
1990 MultiSelection subms;
|
Chris@0
|
1991 subms.setSelection(*i);
|
Chris@0
|
1992
|
Chris@0
|
1993 QString subpath = QString("%1.%2.wav").arg(base).arg(n);
|
Chris@0
|
1994 ++n;
|
Chris@0
|
1995
|
Chris@0
|
1996 if (QFileInfo(subpath).exists()) {
|
Chris@0
|
1997 error = tr("Fragment file %1 already exists, aborting").arg(subpath);
|
Chris@0
|
1998 break;
|
Chris@0
|
1999 }
|
Chris@0
|
2000
|
Chris@38
|
2001 WavFileWriter subwriter(subpath,
|
Chris@38
|
2002 getMainModel()->getSampleRate(),
|
Chris@38
|
2003 getMainModel()->getChannelCount());
|
Chris@38
|
2004 subwriter.writeModel(getMainModel(), &subms);
|
Chris@0
|
2005 ok = subwriter.isOK();
|
Chris@0
|
2006
|
Chris@0
|
2007 if (!ok) {
|
Chris@0
|
2008 error = subwriter.getError();
|
Chris@0
|
2009 break;
|
Chris@0
|
2010 }
|
Chris@0
|
2011 }
|
Chris@0
|
2012 }
|
Chris@0
|
2013 }
|
Chris@0
|
2014
|
Chris@38
|
2015 if (!multiple) {
|
Chris@38
|
2016 WavFileWriter writer(path,
|
Chris@38
|
2017 getMainModel()->getSampleRate(),
|
Chris@38
|
2018 getMainModel()->getChannelCount());
|
Chris@38
|
2019 writer.writeModel(getMainModel(), selectionToWrite);
|
Chris@38
|
2020 ok = writer.isOK();
|
Chris@38
|
2021 error = writer.getError();
|
Chris@0
|
2022 }
|
Chris@0
|
2023
|
Chris@0
|
2024 if (ok) {
|
Chris@0
|
2025 if (!multiple) {
|
Chris@34
|
2026 m_recentFiles.addFile(path);
|
Chris@0
|
2027 }
|
Chris@0
|
2028 } else {
|
Chris@0
|
2029 QMessageBox::critical(this, tr("Failed to write file"), error);
|
Chris@0
|
2030 }
|
Chris@0
|
2031 }
|
Chris@0
|
2032
|
Chris@0
|
2033 void
|
Chris@0
|
2034 MainWindow::importLayer()
|
Chris@0
|
2035 {
|
Chris@0
|
2036 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@0
|
2037
|
Chris@0
|
2038 if (!pane) {
|
Chris@0
|
2039 // shouldn't happen, as the menu action should have been disabled
|
Chris@0
|
2040 std::cerr << "WARNING: MainWindow::importLayer: no current pane" << std::endl;
|
Chris@0
|
2041 return;
|
Chris@0
|
2042 }
|
Chris@0
|
2043
|
Chris@0
|
2044 if (!getMainModel()) {
|
Chris@0
|
2045 // shouldn't happen, as the menu action should have been disabled
|
Chris@0
|
2046 std::cerr << "WARNING: MainWindow::importLayer: No main model -- hence no default sample rate available" << std::endl;
|
Chris@0
|
2047 return;
|
Chris@0
|
2048 }
|
Chris@0
|
2049
|
Chris@88
|
2050 QString path = getOpenFileName(FileFinder::LayerFile);
|
Chris@0
|
2051
|
Chris@0
|
2052 if (path != "") {
|
Chris@0
|
2053
|
Chris@82
|
2054 if (openLayerFile(path) == FileOpenFailed) {
|
Chris@0
|
2055 QMessageBox::critical(this, tr("Failed to open file"),
|
Chris@0
|
2056 tr("File %1 could not be opened.").arg(path));
|
Chris@0
|
2057 return;
|
Chris@0
|
2058 }
|
Chris@0
|
2059 }
|
Chris@0
|
2060 }
|
Chris@0
|
2061
|
Chris@82
|
2062 MainWindow::FileOpenStatus
|
Chris@0
|
2063 MainWindow::openLayerFile(QString path)
|
Chris@0
|
2064 {
|
Chris@86
|
2065 return openLayerFile(path, path);
|
Chris@86
|
2066 }
|
Chris@86
|
2067
|
Chris@86
|
2068 MainWindow::FileOpenStatus
|
Chris@86
|
2069 MainWindow::openLayerFile(QString path, QString location)
|
Chris@86
|
2070 {
|
Chris@0
|
2071 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@0
|
2072
|
Chris@0
|
2073 if (!pane) {
|
Chris@0
|
2074 // shouldn't happen, as the menu action should have been disabled
|
Chris@0
|
2075 std::cerr << "WARNING: MainWindow::openLayerFile: no current pane" << std::endl;
|
Chris@82
|
2076 return FileOpenFailed;
|
Chris@0
|
2077 }
|
Chris@0
|
2078
|
Chris@0
|
2079 if (!getMainModel()) {
|
Chris@0
|
2080 // shouldn't happen, as the menu action should have been disabled
|
Chris@0
|
2081 std::cerr << "WARNING: MainWindow::openLayerFile: No main model -- hence no default sample rate available" << std::endl;
|
Chris@82
|
2082 return FileOpenFailed;
|
Chris@0
|
2083 }
|
Chris@0
|
2084
|
Chris@86
|
2085 bool realFile = (location == path);
|
Chris@86
|
2086
|
Chris@0
|
2087 if (path.endsWith(".svl") || path.endsWith(".xml")) {
|
Chris@0
|
2088
|
Chris@0
|
2089 PaneCallback callback(this);
|
Chris@0
|
2090 QFile file(path);
|
Chris@0
|
2091
|
Chris@0
|
2092 if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
Chris@0
|
2093 std::cerr << "ERROR: MainWindow::openLayerFile("
|
Chris@86
|
2094 << location.toStdString()
|
Chris@0
|
2095 << "): Failed to open file for reading" << std::endl;
|
Chris@82
|
2096 return FileOpenFailed;
|
Chris@0
|
2097 }
|
Chris@0
|
2098
|
Chris@87
|
2099 SVFileReader reader(m_document, callback, location);
|
Chris@0
|
2100 reader.setCurrentPane(pane);
|
Chris@0
|
2101
|
Chris@0
|
2102 QXmlInputSource inputSource(&file);
|
Chris@0
|
2103 reader.parse(inputSource);
|
Chris@0
|
2104
|
Chris@0
|
2105 if (!reader.isOK()) {
|
Chris@0
|
2106 std::cerr << "ERROR: MainWindow::openLayerFile("
|
Chris@86
|
2107 << location.toStdString()
|
Chris@0
|
2108 << "): Failed to read XML file: "
|
Chris@0
|
2109 << reader.getErrorString().toStdString() << std::endl;
|
Chris@82
|
2110 return FileOpenFailed;
|
Chris@0
|
2111 }
|
Chris@0
|
2112
|
Chris@86
|
2113 m_recentFiles.addFile(location);
|
Chris@86
|
2114
|
Chris@86
|
2115 if (realFile) {
|
Chris@88
|
2116 registerLastOpenedFilePath(FileFinder::LayerFile, path); // for file dialog
|
Chris@86
|
2117 }
|
Chris@86
|
2118
|
Chris@82
|
2119 return FileOpenSucceeded;
|
Chris@0
|
2120
|
Chris@0
|
2121 } else {
|
Chris@0
|
2122
|
Chris@0
|
2123 Model *model = DataFileReaderFactory::load(path, getMainModel()->getSampleRate());
|
Chris@0
|
2124
|
Chris@0
|
2125 if (model) {
|
Chris@86
|
2126
|
Chris@0
|
2127 Layer *newLayer = m_document->createImportedLayer(model);
|
Chris@86
|
2128
|
Chris@0
|
2129 if (newLayer) {
|
Chris@86
|
2130
|
Chris@0
|
2131 m_document->addLayerToView(pane, newLayer);
|
Chris@86
|
2132 m_recentFiles.addFile(location);
|
Chris@86
|
2133
|
Chris@86
|
2134 if (realFile) {
|
Chris@88
|
2135 registerLastOpenedFilePath(FileFinder::LayerFile, path); // for file dialog
|
Chris@86
|
2136 }
|
Chris@86
|
2137
|
Chris@82
|
2138 return FileOpenSucceeded;
|
Chris@0
|
2139 }
|
Chris@0
|
2140 }
|
Chris@0
|
2141 }
|
Chris@0
|
2142
|
Chris@82
|
2143 return FileOpenFailed;
|
Chris@0
|
2144 }
|
Chris@0
|
2145
|
Chris@0
|
2146 void
|
Chris@0
|
2147 MainWindow::exportLayer()
|
Chris@0
|
2148 {
|
Chris@0
|
2149 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@0
|
2150 if (!pane) return;
|
Chris@0
|
2151
|
Chris@0
|
2152 Layer *layer = pane->getSelectedLayer();
|
Chris@0
|
2153 if (!layer) return;
|
Chris@0
|
2154
|
Chris@0
|
2155 Model *model = layer->getModel();
|
Chris@0
|
2156 if (!model) return;
|
Chris@0
|
2157
|
Chris@88
|
2158 QString path = getSaveFileName(FileFinder::LayerFile);
|
Chris@0
|
2159
|
Chris@0
|
2160 if (path == "") return;
|
Chris@0
|
2161
|
Chris@0
|
2162 if (QFileInfo(path).suffix() == "") path += ".svl";
|
Chris@0
|
2163
|
Chris@0
|
2164 QString error;
|
Chris@0
|
2165
|
Chris@0
|
2166 if (path.endsWith(".xml") || path.endsWith(".svl")) {
|
Chris@0
|
2167
|
Chris@0
|
2168 QFile file(path);
|
Chris@0
|
2169 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
Chris@0
|
2170 error = tr("Failed to open file %1 for writing").arg(path);
|
Chris@0
|
2171 } else {
|
Chris@0
|
2172 QTextStream out(&file);
|
Chris@0
|
2173 out << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
|
Chris@0
|
2174 << "<!DOCTYPE sonic-visualiser>\n"
|
Chris@0
|
2175 << "<sv>\n"
|
Chris@0
|
2176 << " <data>\n";
|
Chris@0
|
2177
|
Chris@0
|
2178 model->toXml(out, " ");
|
Chris@0
|
2179
|
Chris@0
|
2180 out << " </data>\n"
|
Chris@0
|
2181 << " <display>\n";
|
Chris@0
|
2182
|
Chris@0
|
2183 layer->toXml(out, " ");
|
Chris@0
|
2184
|
Chris@0
|
2185 out << " </display>\n"
|
Chris@0
|
2186 << "</sv>\n";
|
Chris@0
|
2187 }
|
Chris@0
|
2188
|
Chris@0
|
2189 } else {
|
Chris@0
|
2190
|
Chris@0
|
2191 CSVFileWriter writer(path, model,
|
Chris@0
|
2192 (path.endsWith(".csv") ? "," : "\t"));
|
Chris@0
|
2193 writer.write();
|
Chris@0
|
2194
|
Chris@0
|
2195 if (!writer.isOK()) {
|
Chris@0
|
2196 error = writer.getError();
|
Chris@0
|
2197 }
|
Chris@0
|
2198 }
|
Chris@0
|
2199
|
Chris@0
|
2200 if (error != "") {
|
Chris@0
|
2201 QMessageBox::critical(this, tr("Failed to write file"), error);
|
Chris@0
|
2202 } else {
|
Chris@34
|
2203 m_recentFiles.addFile(path);
|
Chris@0
|
2204 }
|
Chris@0
|
2205 }
|
Chris@0
|
2206
|
Chris@82
|
2207 MainWindow::FileOpenStatus
|
Chris@0
|
2208 MainWindow::openAudioFile(QString path, AudioFileOpenMode mode)
|
Chris@0
|
2209 {
|
Chris@86
|
2210 return openAudioFile(path, path, mode);
|
Chris@86
|
2211 }
|
Chris@86
|
2212
|
Chris@86
|
2213 MainWindow::FileOpenStatus
|
Chris@86
|
2214 MainWindow::openAudioFile(QString path, QString location, AudioFileOpenMode mode)
|
Chris@86
|
2215 {
|
Chris@0
|
2216 if (!(QFileInfo(path).exists() &&
|
Chris@0
|
2217 QFileInfo(path).isFile() &&
|
Chris@0
|
2218 QFileInfo(path).isReadable())) {
|
Chris@82
|
2219 return FileOpenFailed;
|
Chris@0
|
2220 }
|
Chris@0
|
2221
|
Chris@70
|
2222 m_openingAudioFile = true;
|
Chris@70
|
2223
|
Chris@88
|
2224 WaveFileModel *newModel = new WaveFileModel(path, location);
|
Chris@0
|
2225
|
Chris@0
|
2226 if (!newModel->isOK()) {
|
Chris@0
|
2227 delete newModel;
|
Chris@70
|
2228 m_openingAudioFile = false;
|
Chris@82
|
2229 return FileOpenFailed;
|
Chris@0
|
2230 }
|
Chris@0
|
2231
|
Chris@0
|
2232 bool setAsMain = true;
|
Chris@0
|
2233 static bool prevSetAsMain = true;
|
Chris@0
|
2234
|
Chris@86
|
2235 bool realFile = (location == path);
|
Chris@86
|
2236
|
Chris@0
|
2237 if (mode == CreateAdditionalModel) setAsMain = false;
|
Chris@0
|
2238 else if (mode == AskUser) {
|
Chris@0
|
2239 if (m_document->getMainModel()) {
|
Chris@0
|
2240
|
Chris@0
|
2241 QStringList items;
|
Chris@0
|
2242 items << tr("Replace the existing main waveform")
|
Chris@0
|
2243 << tr("Load this file into a new waveform pane");
|
Chris@0
|
2244
|
Chris@0
|
2245 bool ok = false;
|
Chris@0
|
2246 QString item = ListInputDialog::getItem
|
Chris@0
|
2247 (this, tr("Select target for import"),
|
Chris@0
|
2248 tr("You already have an audio waveform loaded.\nWhat would you like to do with the new audio file?"),
|
Chris@0
|
2249 items, prevSetAsMain ? 0 : 1, &ok);
|
Chris@0
|
2250
|
Chris@0
|
2251 if (!ok || item.isEmpty()) {
|
Chris@0
|
2252 delete newModel;
|
Chris@70
|
2253 m_openingAudioFile = false;
|
Chris@82
|
2254 return FileOpenCancelled;
|
Chris@0
|
2255 }
|
Chris@0
|
2256
|
Chris@0
|
2257 setAsMain = (item == items[0]);
|
Chris@0
|
2258 prevSetAsMain = setAsMain;
|
Chris@0
|
2259 }
|
Chris@0
|
2260 }
|
Chris@0
|
2261
|
Chris@0
|
2262 if (setAsMain) {
|
Chris@0
|
2263
|
Chris@0
|
2264 Model *prevMain = getMainModel();
|
Chris@0
|
2265 if (prevMain) m_playSource->removeModel(prevMain);
|
Chris@0
|
2266
|
Chris@0
|
2267 PlayParameterRepository::getInstance()->clear();
|
Chris@0
|
2268
|
Chris@0
|
2269 // The clear() call will have removed the parameters for the
|
Chris@0
|
2270 // main model. Re-add them with the new one.
|
Chris@0
|
2271 PlayParameterRepository::getInstance()->addModel(newModel);
|
Chris@0
|
2272
|
Chris@0
|
2273 m_document->setMainModel(newModel);
|
Chris@0
|
2274 setupMenus();
|
Chris@0
|
2275
|
Chris@0
|
2276 if (m_sessionFile == "") {
|
Chris@0
|
2277 setWindowTitle(tr("Sonic Visualiser: %1")
|
Chris@86
|
2278 .arg(QFileInfo(location).fileName()));
|
Chris@0
|
2279 CommandHistory::getInstance()->clear();
|
Chris@0
|
2280 CommandHistory::getInstance()->documentSaved();
|
Chris@0
|
2281 m_documentModified = false;
|
Chris@0
|
2282 } else {
|
Chris@0
|
2283 setWindowTitle(tr("Sonic Visualiser: %1 [%2]")
|
Chris@0
|
2284 .arg(QFileInfo(m_sessionFile).fileName())
|
Chris@86
|
2285 .arg(QFileInfo(location).fileName()));
|
Chris@0
|
2286 if (m_documentModified) {
|
Chris@0
|
2287 m_documentModified = false;
|
Chris@0
|
2288 documentModified(); // so as to restore "(modified)" window title
|
Chris@0
|
2289 }
|
Chris@0
|
2290 }
|
Chris@0
|
2291
|
Chris@86
|
2292 if (realFile) m_audioFile = path;
|
Chris@0
|
2293
|
Chris@0
|
2294 } else { // !setAsMain
|
Chris@0
|
2295
|
Chris@0
|
2296 CommandHistory::getInstance()->startCompoundOperation
|
Chris@86
|
2297 (tr("Import \"%1\"").arg(QFileInfo(location).fileName()), true);
|
Chris@0
|
2298
|
Chris@0
|
2299 m_document->addImportedModel(newModel);
|
Chris@0
|
2300
|
Chris@0
|
2301 AddPaneCommand *command = new AddPaneCommand(this);
|
Chris@0
|
2302 CommandHistory::getInstance()->addCommand(command);
|
Chris@0
|
2303
|
Chris@0
|
2304 Pane *pane = command->getPane();
|
Chris@0
|
2305
|
Chris@0
|
2306 if (!m_timeRulerLayer) {
|
Chris@0
|
2307 m_timeRulerLayer = m_document->createMainModelLayer
|
Chris@0
|
2308 (LayerFactory::TimeRuler);
|
Chris@0
|
2309 }
|
Chris@0
|
2310
|
Chris@0
|
2311 m_document->addLayerToView(pane, m_timeRulerLayer);
|
Chris@0
|
2312
|
Chris@0
|
2313 Layer *newLayer = m_document->createImportedLayer(newModel);
|
Chris@0
|
2314
|
Chris@0
|
2315 if (newLayer) {
|
Chris@0
|
2316 m_document->addLayerToView(pane, newLayer);
|
Chris@0
|
2317 }
|
Chris@0
|
2318
|
Chris@0
|
2319 CommandHistory::getInstance()->endCompoundOperation();
|
Chris@0
|
2320 }
|
Chris@0
|
2321
|
Chris@0
|
2322 updateMenuStates();
|
Chris@86
|
2323 m_recentFiles.addFile(location);
|
Chris@86
|
2324 if (realFile) {
|
Chris@88
|
2325 registerLastOpenedFilePath(FileFinder::AudioFile, path); // for file dialog
|
Chris@86
|
2326 }
|
Chris@70
|
2327 m_openingAudioFile = false;
|
Chris@0
|
2328
|
Chris@82
|
2329 return FileOpenSucceeded;
|
Chris@0
|
2330 }
|
Chris@0
|
2331
|
Chris@0
|
2332 void
|
Chris@0
|
2333 MainWindow::createPlayTarget()
|
Chris@0
|
2334 {
|
Chris@0
|
2335 if (m_playTarget) return;
|
Chris@0
|
2336
|
Chris@0
|
2337 m_playTarget = AudioTargetFactory::createCallbackTarget(m_playSource);
|
Chris@0
|
2338 if (!m_playTarget) {
|
Chris@0
|
2339 QMessageBox::warning
|
Chris@0
|
2340 (this, tr("Couldn't open audio device"),
|
Chris@0
|
2341 tr("Could not open an audio device for playback.\nAudio playback will not be available during this session.\n"),
|
Chris@0
|
2342 QMessageBox::Ok, 0);
|
Chris@0
|
2343 }
|
Chris@0
|
2344 connect(m_fader, SIGNAL(valueChanged(float)),
|
Chris@0
|
2345 m_playTarget, SLOT(setOutputGain(float)));
|
Chris@0
|
2346 }
|
Chris@0
|
2347
|
Chris@0
|
2348 WaveFileModel *
|
Chris@0
|
2349 MainWindow::getMainModel()
|
Chris@0
|
2350 {
|
Chris@0
|
2351 if (!m_document) return 0;
|
Chris@0
|
2352 return m_document->getMainModel();
|
Chris@0
|
2353 }
|
Chris@0
|
2354
|
Chris@0
|
2355 void
|
Chris@0
|
2356 MainWindow::newSession()
|
Chris@0
|
2357 {
|
Chris@0
|
2358 if (!checkSaveModified()) return;
|
Chris@0
|
2359
|
Chris@0
|
2360 closeSession();
|
Chris@0
|
2361 createDocument();
|
Chris@0
|
2362
|
Chris@0
|
2363 Pane *pane = m_paneStack->addPane();
|
Chris@0
|
2364
|
Chris@90
|
2365 connect(pane, SIGNAL(contextHelpChanged(const QString &)),
|
Chris@90
|
2366 statusBar(), SLOT(showMessage(const QString &)));
|
Chris@90
|
2367
|
Chris@0
|
2368 if (!m_timeRulerLayer) {
|
Chris@0
|
2369 m_timeRulerLayer = m_document->createMainModelLayer
|
Chris@0
|
2370 (LayerFactory::TimeRuler);
|
Chris@0
|
2371 }
|
Chris@0
|
2372
|
Chris@0
|
2373 m_document->addLayerToView(pane, m_timeRulerLayer);
|
Chris@0
|
2374
|
Chris@0
|
2375 Layer *waveform = m_document->createMainModelLayer(LayerFactory::Waveform);
|
Chris@0
|
2376 m_document->addLayerToView(pane, waveform);
|
Chris@0
|
2377
|
Chris@65
|
2378 m_overview->registerView(pane);
|
Chris@0
|
2379
|
Chris@0
|
2380 CommandHistory::getInstance()->clear();
|
Chris@0
|
2381 CommandHistory::getInstance()->documentSaved();
|
Chris@0
|
2382 documentRestored();
|
Chris@0
|
2383 updateMenuStates();
|
Chris@0
|
2384 }
|
Chris@0
|
2385
|
Chris@0
|
2386 void
|
Chris@0
|
2387 MainWindow::createDocument()
|
Chris@0
|
2388 {
|
Chris@0
|
2389 m_document = new Document;
|
Chris@0
|
2390
|
Chris@0
|
2391 connect(m_document, SIGNAL(layerAdded(Layer *)),
|
Chris@0
|
2392 this, SLOT(layerAdded(Layer *)));
|
Chris@0
|
2393 connect(m_document, SIGNAL(layerRemoved(Layer *)),
|
Chris@0
|
2394 this, SLOT(layerRemoved(Layer *)));
|
Chris@0
|
2395 connect(m_document, SIGNAL(layerAboutToBeDeleted(Layer *)),
|
Chris@0
|
2396 this, SLOT(layerAboutToBeDeleted(Layer *)));
|
Chris@0
|
2397 connect(m_document, SIGNAL(layerInAView(Layer *, bool)),
|
Chris@0
|
2398 this, SLOT(layerInAView(Layer *, bool)));
|
Chris@0
|
2399
|
Chris@0
|
2400 connect(m_document, SIGNAL(modelAdded(Model *)),
|
Chris@0
|
2401 this, SLOT(modelAdded(Model *)));
|
Chris@0
|
2402 connect(m_document, SIGNAL(mainModelChanged(WaveFileModel *)),
|
Chris@0
|
2403 this, SLOT(mainModelChanged(WaveFileModel *)));
|
Chris@0
|
2404 connect(m_document, SIGNAL(modelAboutToBeDeleted(Model *)),
|
Chris@0
|
2405 this, SLOT(modelAboutToBeDeleted(Model *)));
|
Chris@0
|
2406
|
Chris@0
|
2407 connect(m_document, SIGNAL(modelGenerationFailed(QString)),
|
Chris@0
|
2408 this, SLOT(modelGenerationFailed(QString)));
|
Chris@63
|
2409 connect(m_document, SIGNAL(modelRegenerationFailed(QString, QString)),
|
Chris@63
|
2410 this, SLOT(modelRegenerationFailed(QString, QString)));
|
Chris@0
|
2411 }
|
Chris@0
|
2412
|
Chris@0
|
2413 void
|
Chris@0
|
2414 MainWindow::closeSession()
|
Chris@0
|
2415 {
|
Chris@0
|
2416 if (!checkSaveModified()) return;
|
Chris@0
|
2417
|
Chris@0
|
2418 while (m_paneStack->getPaneCount() > 0) {
|
Chris@0
|
2419
|
Chris@0
|
2420 Pane *pane = m_paneStack->getPane(m_paneStack->getPaneCount() - 1);
|
Chris@0
|
2421
|
Chris@0
|
2422 while (pane->getLayerCount() > 0) {
|
Chris@0
|
2423 m_document->removeLayerFromView
|
Chris@0
|
2424 (pane, pane->getLayer(pane->getLayerCount() - 1));
|
Chris@0
|
2425 }
|
Chris@0
|
2426
|
Chris@65
|
2427 m_overview->unregisterView(pane);
|
Chris@0
|
2428 m_paneStack->deletePane(pane);
|
Chris@0
|
2429 }
|
Chris@0
|
2430
|
Chris@0
|
2431 while (m_paneStack->getHiddenPaneCount() > 0) {
|
Chris@0
|
2432
|
Chris@0
|
2433 Pane *pane = m_paneStack->getHiddenPane
|
Chris@0
|
2434 (m_paneStack->getHiddenPaneCount() - 1);
|
Chris@0
|
2435
|
Chris@0
|
2436 while (pane->getLayerCount() > 0) {
|
Chris@0
|
2437 m_document->removeLayerFromView
|
Chris@0
|
2438 (pane, pane->getLayer(pane->getLayerCount() - 1));
|
Chris@0
|
2439 }
|
Chris@0
|
2440
|
Chris@65
|
2441 m_overview->unregisterView(pane);
|
Chris@0
|
2442 m_paneStack->deletePane(pane);
|
Chris@0
|
2443 }
|
Chris@0
|
2444
|
Chris@0
|
2445 delete m_document;
|
Chris@0
|
2446 m_document = 0;
|
Chris@0
|
2447 m_viewManager->clearSelections();
|
Chris@0
|
2448 m_timeRulerLayer = 0; // document owned this
|
Chris@0
|
2449
|
Chris@0
|
2450 m_sessionFile = "";
|
Chris@0
|
2451 setWindowTitle(tr("Sonic Visualiser"));
|
Chris@0
|
2452
|
Chris@0
|
2453 CommandHistory::getInstance()->clear();
|
Chris@0
|
2454 CommandHistory::getInstance()->documentSaved();
|
Chris@0
|
2455 documentRestored();
|
Chris@0
|
2456 }
|
Chris@0
|
2457
|
Chris@0
|
2458 void
|
Chris@0
|
2459 MainWindow::openSession()
|
Chris@0
|
2460 {
|
Chris@0
|
2461 if (!checkSaveModified()) return;
|
Chris@0
|
2462
|
Chris@0
|
2463 QString orig = m_audioFile;
|
Chris@0
|
2464 if (orig == "") orig = ".";
|
Chris@0
|
2465 else orig = QFileInfo(orig).absoluteDir().canonicalPath();
|
Chris@0
|
2466
|
Chris@88
|
2467 QString path = getOpenFileName(FileFinder::SessionFile);
|
Chris@0
|
2468
|
Chris@0
|
2469 if (path.isEmpty()) return;
|
Chris@0
|
2470
|
Chris@82
|
2471 if (openSessionFile(path) == FileOpenFailed) {
|
Chris@0
|
2472 QMessageBox::critical(this, tr("Failed to open file"),
|
Chris@0
|
2473 tr("Session file \"%1\" could not be opened").arg(path));
|
Chris@0
|
2474 }
|
Chris@0
|
2475 }
|
Chris@0
|
2476
|
Chris@0
|
2477 void
|
Chris@0
|
2478 MainWindow::openSomething()
|
Chris@0
|
2479 {
|
Chris@0
|
2480 QString orig = m_audioFile;
|
Chris@0
|
2481 if (orig == "") orig = ".";
|
Chris@0
|
2482 else orig = QFileInfo(orig).absoluteDir().canonicalPath();
|
Chris@0
|
2483
|
Chris@0
|
2484 bool canImportLayer = (getMainModel() != 0 &&
|
Chris@0
|
2485 m_paneStack != 0 &&
|
Chris@0
|
2486 m_paneStack->getCurrentPane() != 0);
|
Chris@0
|
2487
|
Chris@88
|
2488 QString path = getOpenFileName(FileFinder::AnyFile);
|
Chris@0
|
2489
|
Chris@0
|
2490 if (path.isEmpty()) return;
|
Chris@0
|
2491
|
Chris@0
|
2492 if (path.endsWith(".sv")) {
|
Chris@0
|
2493
|
Chris@0
|
2494 if (!checkSaveModified()) return;
|
Chris@0
|
2495
|
Chris@82
|
2496 if (openSessionFile(path) == FileOpenFailed) {
|
Chris@0
|
2497 QMessageBox::critical(this, tr("Failed to open file"),
|
Chris@0
|
2498 tr("Session file \"%1\" could not be opened").arg(path));
|
Chris@0
|
2499 }
|
Chris@0
|
2500
|
Chris@0
|
2501 } else {
|
Chris@0
|
2502
|
Chris@82
|
2503 if (openAudioFile(path, AskUser) == FileOpenFailed) {
|
Chris@82
|
2504
|
Chris@82
|
2505 if (!canImportLayer || (openLayerFile(path) == FileOpenFailed)) {
|
Chris@0
|
2506
|
Chris@0
|
2507 QMessageBox::critical(this, tr("Failed to open file"),
|
Chris@0
|
2508 tr("File \"%1\" could not be opened").arg(path));
|
Chris@0
|
2509 }
|
Chris@0
|
2510 }
|
Chris@0
|
2511 }
|
Chris@0
|
2512 }
|
Chris@0
|
2513
|
Chris@0
|
2514 void
|
Chris@86
|
2515 MainWindow::openLocation()
|
Chris@86
|
2516 {
|
Chris@86
|
2517 bool ok = false;
|
Chris@86
|
2518 QString text = QInputDialog::getText
|
Chris@86
|
2519 (this, tr("Open Location"),
|
Chris@86
|
2520 tr("Please enter the URL of the location to open:"),
|
Chris@86
|
2521 QLineEdit::Normal, "", &ok);
|
Chris@86
|
2522 if (!ok || text.isEmpty()) return;
|
Chris@86
|
2523
|
Chris@86
|
2524 if (openURL(QUrl(text)) == FileOpenFailed) {
|
Chris@86
|
2525 QMessageBox::critical(this, tr("Failed to open location"),
|
Chris@86
|
2526 tr("URL \"%1\" could not be opened").arg(text));
|
Chris@86
|
2527 }
|
Chris@86
|
2528 }
|
Chris@86
|
2529
|
Chris@86
|
2530 void
|
Chris@0
|
2531 MainWindow::openRecentFile()
|
Chris@0
|
2532 {
|
Chris@0
|
2533 QObject *obj = sender();
|
Chris@0
|
2534 QAction *action = dynamic_cast<QAction *>(obj);
|
Chris@0
|
2535
|
Chris@0
|
2536 if (!action) {
|
Chris@0
|
2537 std::cerr << "WARNING: MainWindow::openRecentFile: sender is not an action"
|
Chris@0
|
2538 << std::endl;
|
Chris@0
|
2539 return;
|
Chris@0
|
2540 }
|
Chris@0
|
2541
|
Chris@0
|
2542 QString path = action->text();
|
Chris@0
|
2543 if (path == "") return;
|
Chris@0
|
2544
|
Chris@86
|
2545 QUrl url(path);
|
Chris@86
|
2546 if (RemoteFile::canHandleScheme(url)) {
|
Chris@86
|
2547 openURL(url);
|
Chris@86
|
2548 return;
|
Chris@86
|
2549 }
|
Chris@86
|
2550
|
Chris@0
|
2551 if (path.endsWith("sv")) {
|
Chris@0
|
2552
|
Chris@0
|
2553 if (!checkSaveModified()) return ;
|
Chris@0
|
2554
|
Chris@82
|
2555 if (openSessionFile(path) == FileOpenFailed) {
|
Chris@0
|
2556 QMessageBox::critical(this, tr("Failed to open file"),
|
Chris@0
|
2557 tr("Session file \"%1\" could not be opened").arg(path));
|
Chris@0
|
2558 }
|
Chris@0
|
2559
|
Chris@0
|
2560 } else {
|
Chris@0
|
2561
|
Chris@82
|
2562 if (openAudioFile(path, AskUser) == FileOpenFailed) {
|
Chris@0
|
2563
|
Chris@0
|
2564 bool canImportLayer = (getMainModel() != 0 &&
|
Chris@0
|
2565 m_paneStack != 0 &&
|
Chris@0
|
2566 m_paneStack->getCurrentPane() != 0);
|
Chris@0
|
2567
|
Chris@82
|
2568 if (!canImportLayer || (openLayerFile(path) == FileOpenFailed)) {
|
Chris@0
|
2569
|
Chris@0
|
2570 QMessageBox::critical(this, tr("Failed to open file"),
|
Chris@0
|
2571 tr("File \"%1\" could not be opened").arg(path));
|
Chris@0
|
2572 }
|
Chris@0
|
2573 }
|
Chris@0
|
2574 }
|
Chris@0
|
2575 }
|
Chris@0
|
2576
|
Chris@82
|
2577 MainWindow::FileOpenStatus
|
Chris@85
|
2578 MainWindow::openURL(QUrl url)
|
Chris@85
|
2579 {
|
Chris@85
|
2580 if (url.scheme().toLower() == "file") {
|
Chris@85
|
2581 return openSomeFile(url.toLocalFile());
|
Chris@86
|
2582 } else if (!RemoteFile::canHandleScheme(url)) {
|
Chris@85
|
2583 QMessageBox::critical(this, tr("Unsupported scheme in URL"),
|
Chris@85
|
2584 tr("The URL scheme \"%1\" is not supported")
|
Chris@85
|
2585 .arg(url.scheme()));
|
Chris@85
|
2586 return FileOpenFailed;
|
Chris@85
|
2587 } else {
|
Chris@85
|
2588 RemoteFile rf(url);
|
Chris@85
|
2589 rf.wait();
|
Chris@85
|
2590 if (!rf.isOK()) {
|
Chris@85
|
2591 QMessageBox::critical(this, tr("File download failed"),
|
Chris@85
|
2592 tr("Failed to download URL \"%1\": %2")
|
Chris@85
|
2593 .arg(url.toString()).arg(rf.getErrorString()));
|
Chris@85
|
2594 return FileOpenFailed;
|
Chris@85
|
2595 }
|
Chris@88
|
2596 FileOpenStatus status;
|
Chris@88
|
2597 if ((status = openSomeFile(rf.getLocalFilename(), url.toString())) !=
|
Chris@88
|
2598 FileOpenSucceeded) {
|
Chris@88
|
2599 rf.deleteLocalFile();
|
Chris@88
|
2600 }
|
Chris@88
|
2601 return status;
|
Chris@85
|
2602 }
|
Chris@85
|
2603 }
|
Chris@85
|
2604
|
Chris@85
|
2605 MainWindow::FileOpenStatus
|
Chris@54
|
2606 MainWindow::openSomeFile(QString path, AudioFileOpenMode mode)
|
Chris@0
|
2607 {
|
Chris@86
|
2608 return openSomeFile(path, path, mode);
|
Chris@86
|
2609 }
|
Chris@86
|
2610
|
Chris@86
|
2611 MainWindow::FileOpenStatus
|
Chris@86
|
2612 MainWindow::openSomeFile(QString path, QString location,
|
Chris@86
|
2613 AudioFileOpenMode mode)
|
Chris@86
|
2614 {
|
Chris@82
|
2615 FileOpenStatus status;
|
Chris@82
|
2616
|
Chris@85
|
2617 bool canImportLayer = (getMainModel() != 0 &&
|
Chris@85
|
2618 m_paneStack != 0 &&
|
Chris@85
|
2619 m_paneStack->getCurrentPane() != 0);
|
Chris@85
|
2620
|
Chris@86
|
2621 if ((status = openAudioFile(path, location, mode)) != FileOpenFailed) {
|
Chris@82
|
2622 return status;
|
Chris@86
|
2623 } else if ((status = openSessionFile(path, location)) != FileOpenFailed) {
|
Chris@82
|
2624 return status;
|
Chris@85
|
2625 } else if (!canImportLayer) {
|
Chris@85
|
2626 return FileOpenFailed;
|
Chris@86
|
2627 } else if ((status = openLayerFile(path, location)) != FileOpenFailed) {
|
Chris@85
|
2628 return status;
|
Chris@0
|
2629 } else {
|
Chris@82
|
2630 return FileOpenFailed;
|
Chris@0
|
2631 }
|
Chris@0
|
2632 }
|
Chris@0
|
2633
|
Chris@82
|
2634 MainWindow::FileOpenStatus
|
Chris@0
|
2635 MainWindow::openSessionFile(QString path)
|
Chris@0
|
2636 {
|
Chris@86
|
2637 return openSessionFile(path, path);
|
Chris@86
|
2638 }
|
Chris@86
|
2639
|
Chris@86
|
2640 MainWindow::FileOpenStatus
|
Chris@86
|
2641 MainWindow::openSessionFile(QString path, QString location)
|
Chris@86
|
2642 {
|
Chris@0
|
2643 BZipFileDevice bzFile(path);
|
Chris@0
|
2644 if (!bzFile.open(QIODevice::ReadOnly)) {
|
Chris@86
|
2645 std::cerr << "Failed to open session file \"" << location.toStdString()
|
Chris@0
|
2646 << "\": " << bzFile.errorString().toStdString() << std::endl;
|
Chris@82
|
2647 return FileOpenFailed;
|
Chris@0
|
2648 }
|
Chris@0
|
2649
|
Chris@0
|
2650 QString error;
|
Chris@0
|
2651 closeSession();
|
Chris@0
|
2652 createDocument();
|
Chris@0
|
2653
|
Chris@0
|
2654 PaneCallback callback(this);
|
Chris@0
|
2655 m_viewManager->clearSelections();
|
Chris@0
|
2656
|
Chris@87
|
2657 SVFileReader reader(m_document, callback, location);
|
Chris@0
|
2658 QXmlInputSource inputSource(&bzFile);
|
Chris@0
|
2659 reader.parse(inputSource);
|
Chris@0
|
2660
|
Chris@0
|
2661 if (!reader.isOK()) {
|
Chris@0
|
2662 error = tr("SV XML file read error:\n%1").arg(reader.getErrorString());
|
Chris@0
|
2663 }
|
Chris@0
|
2664
|
Chris@0
|
2665 bzFile.close();
|
Chris@0
|
2666
|
Chris@0
|
2667 bool ok = (error == "");
|
Chris@86
|
2668
|
Chris@86
|
2669 bool realFile = (location == path);
|
Chris@0
|
2670
|
Chris@0
|
2671 if (ok) {
|
Chris@86
|
2672
|
Chris@0
|
2673 setWindowTitle(tr("Sonic Visualiser: %1")
|
Chris@86
|
2674 .arg(QFileInfo(location).fileName()));
|
Chris@86
|
2675
|
Chris@86
|
2676 if (realFile) m_sessionFile = path;
|
Chris@86
|
2677
|
Chris@0
|
2678 setupMenus();
|
Chris@0
|
2679 CommandHistory::getInstance()->clear();
|
Chris@0
|
2680 CommandHistory::getInstance()->documentSaved();
|
Chris@0
|
2681 m_documentModified = false;
|
Chris@0
|
2682 updateMenuStates();
|
Chris@86
|
2683
|
Chris@86
|
2684 m_recentFiles.addFile(location);
|
Chris@86
|
2685
|
Chris@86
|
2686 if (realFile) {
|
Chris@88
|
2687 registerLastOpenedFilePath(FileFinder::SessionFile, path); // for file dialog
|
Chris@86
|
2688 }
|
Chris@86
|
2689
|
Chris@0
|
2690 } else {
|
Chris@0
|
2691 setWindowTitle(tr("Sonic Visualiser"));
|
Chris@0
|
2692 }
|
Chris@0
|
2693
|
Chris@82
|
2694 return ok ? FileOpenSucceeded : FileOpenFailed;
|
Chris@0
|
2695 }
|
Chris@0
|
2696
|
Chris@0
|
2697 void
|
Chris@0
|
2698 MainWindow::closeEvent(QCloseEvent *e)
|
Chris@0
|
2699 {
|
Chris@70
|
2700 if (!m_abandoning && !checkSaveModified()) {
|
Chris@0
|
2701 e->ignore();
|
Chris@0
|
2702 return;
|
Chris@0
|
2703 }
|
Chris@0
|
2704
|
Chris@5
|
2705 QSettings settings;
|
Chris@5
|
2706 settings.beginGroup("MainWindow");
|
Chris@5
|
2707 settings.setValue("size", size());
|
Chris@5
|
2708 settings.setValue("position", pos());
|
Chris@5
|
2709 settings.endGroup();
|
Chris@5
|
2710
|
Chris@0
|
2711 e->accept();
|
Chris@0
|
2712 return;
|
Chris@0
|
2713 }
|
Chris@0
|
2714
|
Chris@0
|
2715 bool
|
Chris@11
|
2716 MainWindow::commitData(bool mayAskUser)
|
Chris@11
|
2717 {
|
Chris@11
|
2718 if (mayAskUser) {
|
Chris@11
|
2719 return checkSaveModified();
|
Chris@11
|
2720 } else {
|
Chris@11
|
2721 if (!m_documentModified) return true;
|
Chris@11
|
2722
|
Chris@11
|
2723 // If we can't check with the user first, then we can't save
|
Chris@11
|
2724 // to the original session file (even if we have it) -- have
|
Chris@11
|
2725 // to use a temporary file
|
Chris@11
|
2726
|
Chris@11
|
2727 QString svDirBase = ".sv1";
|
Chris@11
|
2728 QString svDir = QDir::home().filePath(svDirBase);
|
Chris@11
|
2729
|
Chris@11
|
2730 if (!QFileInfo(svDir).exists()) {
|
Chris@11
|
2731 if (!QDir::home().mkdir(svDirBase)) return false;
|
Chris@11
|
2732 } else {
|
Chris@11
|
2733 if (!QFileInfo(svDir).isDir()) return false;
|
Chris@11
|
2734 }
|
Chris@11
|
2735
|
Chris@11
|
2736 // This name doesn't have to be unguessable
|
Chris@93
|
2737 #ifndef _WIN32
|
Chris@11
|
2738 QString fname = QString("tmp-%1-%2.sv")
|
Chris@11
|
2739 .arg(QDateTime::currentDateTime().toString("yyyyMMddhhmmsszzz"))
|
Chris@11
|
2740 .arg(QProcess().pid());
|
Chris@93
|
2741 #else
|
Chris@93
|
2742 QString fname = QString("tmp-%1.sv")
|
Chris@93
|
2743 .arg(QDateTime::currentDateTime().toString("yyyyMMddhhmmsszzz"));
|
Chris@93
|
2744 #endif
|
Chris@11
|
2745 QString fpath = QDir(svDir).filePath(fname);
|
Chris@11
|
2746 if (saveSessionFile(fpath)) {
|
Chris@34
|
2747 m_recentFiles.addFile(fpath);
|
Chris@11
|
2748 return true;
|
Chris@11
|
2749 } else {
|
Chris@11
|
2750 return false;
|
Chris@11
|
2751 }
|
Chris@11
|
2752 }
|
Chris@11
|
2753 }
|
Chris@11
|
2754
|
Chris@11
|
2755 bool
|
Chris@0
|
2756 MainWindow::checkSaveModified()
|
Chris@0
|
2757 {
|
Chris@0
|
2758 // Called before some destructive operation (e.g. new session,
|
Chris@0
|
2759 // exit program). Return true if we can safely proceed, false to
|
Chris@0
|
2760 // cancel.
|
Chris@0
|
2761
|
Chris@0
|
2762 if (!m_documentModified) return true;
|
Chris@0
|
2763
|
Chris@0
|
2764 int button =
|
Chris@0
|
2765 QMessageBox::warning(this,
|
Chris@0
|
2766 tr("Session modified"),
|
Chris@0
|
2767 tr("The current session has been modified.\nDo you want to save it?"),
|
Chris@0
|
2768 QMessageBox::Yes,
|
Chris@0
|
2769 QMessageBox::No,
|
Chris@0
|
2770 QMessageBox::Cancel);
|
Chris@0
|
2771
|
Chris@0
|
2772 if (button == QMessageBox::Yes) {
|
Chris@0
|
2773 saveSession();
|
Chris@0
|
2774 if (m_documentModified) { // save failed -- don't proceed!
|
Chris@0
|
2775 return false;
|
Chris@0
|
2776 } else {
|
Chris@0
|
2777 return true; // saved, so it's safe to continue now
|
Chris@0
|
2778 }
|
Chris@0
|
2779 } else if (button == QMessageBox::No) {
|
Chris@0
|
2780 m_documentModified = false; // so we know to abandon it
|
Chris@0
|
2781 return true;
|
Chris@0
|
2782 }
|
Chris@0
|
2783
|
Chris@0
|
2784 // else cancel
|
Chris@0
|
2785 return false;
|
Chris@0
|
2786 }
|
Chris@0
|
2787
|
Chris@0
|
2788 void
|
Chris@0
|
2789 MainWindow::saveSession()
|
Chris@0
|
2790 {
|
Chris@0
|
2791 if (m_sessionFile != "") {
|
Chris@0
|
2792 if (!saveSessionFile(m_sessionFile)) {
|
Chris@0
|
2793 QMessageBox::critical(this, tr("Failed to save file"),
|
Chris@0
|
2794 tr("Session file \"%1\" could not be saved.").arg(m_sessionFile));
|
Chris@0
|
2795 } else {
|
Chris@0
|
2796 CommandHistory::getInstance()->documentSaved();
|
Chris@0
|
2797 documentRestored();
|
Chris@0
|
2798 }
|
Chris@0
|
2799 } else {
|
Chris@0
|
2800 saveSessionAs();
|
Chris@0
|
2801 }
|
Chris@0
|
2802 }
|
Chris@0
|
2803
|
Chris@0
|
2804 void
|
Chris@0
|
2805 MainWindow::saveSessionAs()
|
Chris@0
|
2806 {
|
Chris@0
|
2807 QString orig = m_audioFile;
|
Chris@0
|
2808 if (orig == "") orig = ".";
|
Chris@0
|
2809 else orig = QFileInfo(orig).absoluteDir().canonicalPath();
|
Chris@0
|
2810
|
Chris@88
|
2811 QString path = getSaveFileName(FileFinder::SessionFile);
|
Chris@81
|
2812
|
Chris@81
|
2813 if (path == "") return;
|
Chris@0
|
2814
|
Chris@0
|
2815 if (!saveSessionFile(path)) {
|
Chris@0
|
2816 QMessageBox::critical(this, tr("Failed to save file"),
|
Chris@79
|
2817 tr("Session file \"%1\" could not be saved.").arg(path));
|
Chris@0
|
2818 } else {
|
Chris@0
|
2819 setWindowTitle(tr("Sonic Visualiser: %1")
|
Chris@0
|
2820 .arg(QFileInfo(path).fileName()));
|
Chris@0
|
2821 m_sessionFile = path;
|
Chris@0
|
2822 CommandHistory::getInstance()->documentSaved();
|
Chris@0
|
2823 documentRestored();
|
Chris@34
|
2824 m_recentFiles.addFile(path);
|
Chris@0
|
2825 }
|
Chris@0
|
2826 }
|
Chris@0
|
2827
|
Chris@0
|
2828 bool
|
Chris@0
|
2829 MainWindow::saveSessionFile(QString path)
|
Chris@0
|
2830 {
|
Chris@0
|
2831 BZipFileDevice bzFile(path);
|
Chris@0
|
2832 if (!bzFile.open(QIODevice::WriteOnly)) {
|
Chris@0
|
2833 std::cerr << "Failed to open session file \"" << path.toStdString()
|
Chris@0
|
2834 << "\" for writing: "
|
Chris@0
|
2835 << bzFile.errorString().toStdString() << std::endl;
|
Chris@0
|
2836 return false;
|
Chris@0
|
2837 }
|
Chris@0
|
2838
|
Chris@0
|
2839 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
|
Chris@0
|
2840
|
Chris@0
|
2841 QTextStream out(&bzFile);
|
Chris@0
|
2842 toXml(out);
|
Chris@0
|
2843 out.flush();
|
Chris@0
|
2844
|
Chris@0
|
2845 QApplication::restoreOverrideCursor();
|
Chris@0
|
2846
|
Chris@84
|
2847 if (!bzFile.isOK()) {
|
Chris@0
|
2848 QMessageBox::critical(this, tr("Failed to write file"),
|
Chris@0
|
2849 tr("Failed to write to file \"%1\": %2")
|
Chris@0
|
2850 .arg(path).arg(bzFile.errorString()));
|
Chris@0
|
2851 bzFile.close();
|
Chris@0
|
2852 return false;
|
Chris@0
|
2853 }
|
Chris@0
|
2854
|
Chris@0
|
2855 bzFile.close();
|
Chris@0
|
2856 return true;
|
Chris@0
|
2857 }
|
Chris@0
|
2858
|
Chris@0
|
2859 void
|
Chris@0
|
2860 MainWindow::toXml(QTextStream &out)
|
Chris@0
|
2861 {
|
Chris@0
|
2862 QString indent(" ");
|
Chris@0
|
2863
|
Chris@0
|
2864 out << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
|
Chris@0
|
2865 out << "<!DOCTYPE sonic-visualiser>\n";
|
Chris@0
|
2866 out << "<sv>\n";
|
Chris@0
|
2867
|
Chris@0
|
2868 m_document->toXml(out, "", "");
|
Chris@0
|
2869
|
Chris@0
|
2870 out << "<display>\n";
|
Chris@0
|
2871
|
Chris@0
|
2872 out << QString(" <window width=\"%1\" height=\"%2\"/>\n")
|
Chris@0
|
2873 .arg(width()).arg(height());
|
Chris@0
|
2874
|
Chris@0
|
2875 for (int i = 0; i < m_paneStack->getPaneCount(); ++i) {
|
Chris@0
|
2876
|
Chris@0
|
2877 Pane *pane = m_paneStack->getPane(i);
|
Chris@0
|
2878
|
Chris@0
|
2879 if (pane) {
|
Chris@0
|
2880 pane->toXml(out, indent);
|
Chris@0
|
2881 }
|
Chris@0
|
2882 }
|
Chris@0
|
2883
|
Chris@0
|
2884 out << "</display>\n";
|
Chris@0
|
2885
|
Chris@0
|
2886 m_viewManager->getSelection().toXml(out);
|
Chris@0
|
2887
|
Chris@0
|
2888 out << "</sv>\n";
|
Chris@0
|
2889 }
|
Chris@0
|
2890
|
Chris@0
|
2891 Pane *
|
Chris@0
|
2892 MainWindow::addPaneToStack()
|
Chris@0
|
2893 {
|
Chris@0
|
2894 AddPaneCommand *command = new AddPaneCommand(this);
|
Chris@0
|
2895 CommandHistory::getInstance()->addCommand(command);
|
Chris@0
|
2896 return command->getPane();
|
Chris@0
|
2897 }
|
Chris@0
|
2898
|
Chris@0
|
2899 void
|
Chris@0
|
2900 MainWindow::zoomIn()
|
Chris@0
|
2901 {
|
Chris@0
|
2902 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@0
|
2903 if (currentPane) currentPane->zoom(true);
|
Chris@0
|
2904 }
|
Chris@0
|
2905
|
Chris@0
|
2906 void
|
Chris@0
|
2907 MainWindow::zoomOut()
|
Chris@0
|
2908 {
|
Chris@0
|
2909 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@0
|
2910 if (currentPane) currentPane->zoom(false);
|
Chris@0
|
2911 }
|
Chris@0
|
2912
|
Chris@0
|
2913 void
|
Chris@0
|
2914 MainWindow::zoomToFit()
|
Chris@0
|
2915 {
|
Chris@0
|
2916 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@0
|
2917 if (!currentPane) return;
|
Chris@0
|
2918
|
Chris@0
|
2919 Model *model = getMainModel();
|
Chris@0
|
2920 if (!model) return;
|
Chris@0
|
2921
|
Chris@0
|
2922 size_t start = model->getStartFrame();
|
Chris@0
|
2923 size_t end = model->getEndFrame();
|
Chris@0
|
2924 size_t pixels = currentPane->width();
|
Chris@0
|
2925 size_t zoomLevel = (end - start) / pixels;
|
Chris@0
|
2926
|
Chris@0
|
2927 currentPane->setZoomLevel(zoomLevel);
|
Chris@0
|
2928 currentPane->setStartFrame(start);
|
Chris@0
|
2929 }
|
Chris@0
|
2930
|
Chris@0
|
2931 void
|
Chris@0
|
2932 MainWindow::zoomDefault()
|
Chris@0
|
2933 {
|
Chris@0
|
2934 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@0
|
2935 if (currentPane) currentPane->setZoomLevel(1024);
|
Chris@0
|
2936 }
|
Chris@0
|
2937
|
Chris@0
|
2938 void
|
Chris@0
|
2939 MainWindow::scrollLeft()
|
Chris@0
|
2940 {
|
Chris@0
|
2941 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@0
|
2942 if (currentPane) currentPane->scroll(false, false);
|
Chris@0
|
2943 }
|
Chris@0
|
2944
|
Chris@0
|
2945 void
|
Chris@0
|
2946 MainWindow::jumpLeft()
|
Chris@0
|
2947 {
|
Chris@0
|
2948 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@0
|
2949 if (currentPane) currentPane->scroll(false, true);
|
Chris@0
|
2950 }
|
Chris@0
|
2951
|
Chris@0
|
2952 void
|
Chris@0
|
2953 MainWindow::scrollRight()
|
Chris@0
|
2954 {
|
Chris@0
|
2955 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@0
|
2956 if (currentPane) currentPane->scroll(true, false);
|
Chris@0
|
2957 }
|
Chris@0
|
2958
|
Chris@0
|
2959 void
|
Chris@0
|
2960 MainWindow::jumpRight()
|
Chris@0
|
2961 {
|
Chris@0
|
2962 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@0
|
2963 if (currentPane) currentPane->scroll(true, true);
|
Chris@0
|
2964 }
|
Chris@0
|
2965
|
Chris@0
|
2966 void
|
Chris@0
|
2967 MainWindow::showNoOverlays()
|
Chris@0
|
2968 {
|
Chris@0
|
2969 m_viewManager->setOverlayMode(ViewManager::NoOverlays);
|
Chris@0
|
2970 }
|
Chris@0
|
2971
|
Chris@0
|
2972 void
|
Chris@90
|
2973 MainWindow::showMinimalOverlays()
|
Chris@0
|
2974 {
|
Chris@90
|
2975 m_viewManager->setOverlayMode(ViewManager::MinimalOverlays);
|
Chris@0
|
2976 }
|
Chris@0
|
2977
|
Chris@0
|
2978 void
|
Chris@90
|
2979 MainWindow::showStandardOverlays()
|
Chris@90
|
2980 {
|
Chris@90
|
2981 m_viewManager->setOverlayMode(ViewManager::StandardOverlays);
|
Chris@90
|
2982 }
|
Chris@90
|
2983
|
Chris@90
|
2984 void
|
Chris@90
|
2985 MainWindow::showAllOverlays()
|
Chris@0
|
2986 {
|
Chris@0
|
2987 m_viewManager->setOverlayMode(ViewManager::AllOverlays);
|
Chris@0
|
2988 }
|
Chris@0
|
2989
|
Chris@0
|
2990 void
|
Chris@7
|
2991 MainWindow::toggleZoomWheels()
|
Chris@7
|
2992 {
|
Chris@7
|
2993 if (m_viewManager->getZoomWheelsEnabled()) {
|
Chris@7
|
2994 m_viewManager->setZoomWheelsEnabled(false);
|
Chris@7
|
2995 } else {
|
Chris@7
|
2996 m_viewManager->setZoomWheelsEnabled(true);
|
Chris@7
|
2997 }
|
Chris@7
|
2998 }
|
Chris@7
|
2999
|
Chris@7
|
3000 void
|
Chris@72
|
3001 MainWindow::togglePropertyBoxes()
|
Chris@72
|
3002 {
|
Chris@72
|
3003 if (m_paneStack->getLayoutStyle() == PaneStack::NoPropertyStacks) {
|
Chris@72
|
3004 if (Preferences::getInstance()->getPropertyBoxLayout() ==
|
Chris@72
|
3005 Preferences::VerticallyStacked) {
|
Chris@72
|
3006 m_paneStack->setLayoutStyle(PaneStack::PropertyStackPerPaneLayout);
|
Chris@72
|
3007 } else {
|
Chris@72
|
3008 m_paneStack->setLayoutStyle(PaneStack::SinglePropertyStackLayout);
|
Chris@72
|
3009 }
|
Chris@72
|
3010 } else {
|
Chris@72
|
3011 m_paneStack->setLayoutStyle(PaneStack::NoPropertyStacks);
|
Chris@72
|
3012 }
|
Chris@72
|
3013 }
|
Chris@72
|
3014
|
Chris@72
|
3015 void
|
Chris@90
|
3016 MainWindow::toggleStatusBar()
|
Chris@90
|
3017 {
|
Chris@90
|
3018 QSettings settings;
|
Chris@90
|
3019 settings.beginGroup("MainWindow");
|
Chris@90
|
3020 bool sb = settings.value("showstatusbar", true).toBool();
|
Chris@90
|
3021
|
Chris@90
|
3022 if (sb) {
|
Chris@90
|
3023 statusBar()->hide();
|
Chris@90
|
3024 } else {
|
Chris@90
|
3025 statusBar()->show();
|
Chris@90
|
3026 }
|
Chris@90
|
3027
|
Chris@90
|
3028 settings.setValue("showstatusbar", !sb);
|
Chris@90
|
3029
|
Chris@90
|
3030 settings.endGroup();
|
Chris@90
|
3031 }
|
Chris@90
|
3032
|
Chris@90
|
3033 void
|
Chris@72
|
3034 MainWindow::preferenceChanged(PropertyContainer::PropertyName name)
|
Chris@72
|
3035 {
|
Chris@72
|
3036 if (name == "Property Box Layout") {
|
Chris@72
|
3037 if (m_paneStack->getLayoutStyle() != PaneStack::NoPropertyStacks) {
|
Chris@72
|
3038 if (Preferences::getInstance()->getPropertyBoxLayout() ==
|
Chris@72
|
3039 Preferences::VerticallyStacked) {
|
Chris@72
|
3040 m_paneStack->setLayoutStyle(PaneStack::PropertyStackPerPaneLayout);
|
Chris@72
|
3041 } else {
|
Chris@72
|
3042 m_paneStack->setLayoutStyle(PaneStack::SinglePropertyStackLayout);
|
Chris@72
|
3043 }
|
Chris@72
|
3044 }
|
Chris@72
|
3045 }
|
Chris@72
|
3046 }
|
Chris@72
|
3047
|
Chris@72
|
3048 void
|
Chris@0
|
3049 MainWindow::play()
|
Chris@0
|
3050 {
|
Chris@0
|
3051 if (m_playSource->isPlaying()) {
|
Chris@0
|
3052 m_playSource->stop();
|
Chris@0
|
3053 } else {
|
Chris@0
|
3054 m_playSource->play(m_viewManager->getPlaybackFrame());
|
Chris@0
|
3055 }
|
Chris@0
|
3056 }
|
Chris@0
|
3057
|
Chris@0
|
3058 void
|
Chris@0
|
3059 MainWindow::ffwd()
|
Chris@0
|
3060 {
|
Chris@0
|
3061 if (!getMainModel()) return;
|
Chris@0
|
3062
|
Chris@0
|
3063 int frame = m_viewManager->getPlaybackFrame();
|
Chris@0
|
3064 ++frame;
|
Chris@0
|
3065
|
Chris@0
|
3066 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@0
|
3067 if (!pane) return;
|
Chris@0
|
3068
|
Chris@0
|
3069 Layer *layer = pane->getSelectedLayer();
|
Chris@0
|
3070
|
Chris@0
|
3071 if (!dynamic_cast<TimeInstantLayer *>(layer) &&
|
Chris@0
|
3072 !dynamic_cast<TimeValueLayer *>(layer)) return;
|
Chris@0
|
3073
|
Chris@0
|
3074 size_t resolution = 0;
|
Chris@0
|
3075 if (!layer->snapToFeatureFrame(pane, frame, resolution, Layer::SnapRight)) {
|
Chris@0
|
3076 frame = getMainModel()->getEndFrame();
|
Chris@0
|
3077 }
|
Chris@0
|
3078
|
Chris@0
|
3079 m_viewManager->setPlaybackFrame(frame);
|
Chris@0
|
3080 }
|
Chris@0
|
3081
|
Chris@0
|
3082 void
|
Chris@0
|
3083 MainWindow::ffwdEnd()
|
Chris@0
|
3084 {
|
Chris@0
|
3085 if (!getMainModel()) return;
|
Chris@0
|
3086 m_viewManager->setPlaybackFrame(getMainModel()->getEndFrame());
|
Chris@0
|
3087 }
|
Chris@0
|
3088
|
Chris@0
|
3089 void
|
Chris@0
|
3090 MainWindow::rewind()
|
Chris@0
|
3091 {
|
Chris@0
|
3092 if (!getMainModel()) return;
|
Chris@0
|
3093
|
Chris@0
|
3094 int frame = m_viewManager->getPlaybackFrame();
|
Chris@0
|
3095 if (frame > 0) --frame;
|
Chris@0
|
3096
|
Chris@0
|
3097 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@0
|
3098 if (!pane) return;
|
Chris@0
|
3099
|
Chris@0
|
3100 Layer *layer = pane->getSelectedLayer();
|
Chris@0
|
3101
|
Chris@0
|
3102 if (!dynamic_cast<TimeInstantLayer *>(layer) &&
|
Chris@0
|
3103 !dynamic_cast<TimeValueLayer *>(layer)) return;
|
Chris@0
|
3104
|
Chris@0
|
3105 size_t resolution = 0;
|
Chris@0
|
3106 if (!layer->snapToFeatureFrame(pane, frame, resolution, Layer::SnapLeft)) {
|
Chris@0
|
3107 frame = getMainModel()->getEndFrame();
|
Chris@0
|
3108 }
|
Chris@0
|
3109
|
Chris@0
|
3110 m_viewManager->setPlaybackFrame(frame);
|
Chris@0
|
3111 }
|
Chris@0
|
3112
|
Chris@0
|
3113 void
|
Chris@0
|
3114 MainWindow::rewindStart()
|
Chris@0
|
3115 {
|
Chris@0
|
3116 if (!getMainModel()) return;
|
Chris@0
|
3117 m_viewManager->setPlaybackFrame(getMainModel()->getStartFrame());
|
Chris@0
|
3118 }
|
Chris@0
|
3119
|
Chris@0
|
3120 void
|
Chris@0
|
3121 MainWindow::stop()
|
Chris@0
|
3122 {
|
Chris@0
|
3123 m_playSource->stop();
|
Chris@0
|
3124 }
|
Chris@0
|
3125
|
Chris@0
|
3126 void
|
Chris@0
|
3127 MainWindow::addPane()
|
Chris@0
|
3128 {
|
Chris@0
|
3129 QObject *s = sender();
|
Chris@0
|
3130 QAction *action = dynamic_cast<QAction *>(s);
|
Chris@0
|
3131
|
Chris@0
|
3132 if (!action) {
|
Chris@0
|
3133 std::cerr << "WARNING: MainWindow::addPane: sender is not an action"
|
Chris@0
|
3134 << std::endl;
|
Chris@0
|
3135 return;
|
Chris@0
|
3136 }
|
Chris@0
|
3137
|
Chris@0
|
3138 PaneActionMap::iterator i = m_paneActions.find(action);
|
Chris@0
|
3139
|
Chris@0
|
3140 if (i == m_paneActions.end()) {
|
Chris@0
|
3141 std::cerr << "WARNING: MainWindow::addPane: unknown action "
|
Chris@0
|
3142 << action->objectName().toStdString() << std::endl;
|
Chris@0
|
3143 return;
|
Chris@0
|
3144 }
|
Chris@0
|
3145
|
Chris@69
|
3146 addPane(i->second, action->text());
|
Chris@69
|
3147 }
|
Chris@69
|
3148
|
Chris@69
|
3149 void
|
Chris@69
|
3150 MainWindow::addPane(const PaneConfiguration &configuration, QString text)
|
Chris@69
|
3151 {
|
Chris@69
|
3152 CommandHistory::getInstance()->startCompoundOperation(text, true);
|
Chris@0
|
3153
|
Chris@0
|
3154 AddPaneCommand *command = new AddPaneCommand(this);
|
Chris@0
|
3155 CommandHistory::getInstance()->addCommand(command);
|
Chris@0
|
3156
|
Chris@0
|
3157 Pane *pane = command->getPane();
|
Chris@0
|
3158
|
Chris@69
|
3159 if (configuration.layer == LayerFactory::Spectrum) {
|
Chris@7
|
3160 pane->setPlaybackFollow(View::PlaybackScrollContinuous);
|
Chris@7
|
3161 }
|
Chris@7
|
3162
|
Chris@69
|
3163 if (configuration.layer != LayerFactory::TimeRuler &&
|
Chris@69
|
3164 configuration.layer != LayerFactory::Spectrum) {
|
Chris@8
|
3165
|
Chris@0
|
3166 if (!m_timeRulerLayer) {
|
Chris@0
|
3167 // std::cerr << "no time ruler layer, creating one" << std::endl;
|
Chris@0
|
3168 m_timeRulerLayer = m_document->createMainModelLayer
|
Chris@0
|
3169 (LayerFactory::TimeRuler);
|
Chris@0
|
3170 }
|
Chris@0
|
3171
|
Chris@0
|
3172 // std::cerr << "adding time ruler layer " << m_timeRulerLayer << std::endl;
|
Chris@0
|
3173
|
Chris@0
|
3174 m_document->addLayerToView(pane, m_timeRulerLayer);
|
Chris@0
|
3175 }
|
Chris@0
|
3176
|
Chris@69
|
3177 Layer *newLayer = m_document->createLayer(configuration.layer);
|
Chris@69
|
3178
|
Chris@69
|
3179 Model *suggestedModel = configuration.sourceModel;
|
Chris@66
|
3180 Model *model = 0;
|
Chris@66
|
3181
|
Chris@66
|
3182 if (suggestedModel) {
|
Chris@66
|
3183
|
Chris@66
|
3184 // check its validity
|
Chris@66
|
3185 std::vector<Model *> inputModels = m_document->getTransformInputModels();
|
Chris@66
|
3186 for (size_t j = 0; j < inputModels.size(); ++j) {
|
Chris@66
|
3187 if (inputModels[j] == suggestedModel) {
|
Chris@66
|
3188 model = suggestedModel;
|
Chris@66
|
3189 break;
|
Chris@66
|
3190 }
|
Chris@66
|
3191 }
|
Chris@66
|
3192
|
Chris@66
|
3193 if (!model) {
|
Chris@66
|
3194 std::cerr << "WARNING: Model " << (void *)suggestedModel
|
Chris@66
|
3195 << " appears in pane action map, but is not reported "
|
Chris@66
|
3196 << "by document as a valid transform source" << std::endl;
|
Chris@66
|
3197 }
|
Chris@66
|
3198 }
|
Chris@66
|
3199
|
Chris@66
|
3200 if (!model) model = m_document->getMainModel();
|
Chris@66
|
3201
|
Chris@66
|
3202 m_document->setModel(newLayer, model);
|
Chris@66
|
3203
|
Chris@69
|
3204 m_document->setChannel(newLayer, configuration.channel);
|
Chris@0
|
3205 m_document->addLayerToView(pane, newLayer);
|
Chris@0
|
3206
|
Chris@0
|
3207 m_paneStack->setCurrentPane(pane);
|
Chris@70
|
3208 m_paneStack->setCurrentLayer(pane, newLayer);
|
Chris@0
|
3209
|
Chris@73
|
3210 std::cerr << "MainWindow::addPane: global centre frame is "
|
Chris@73
|
3211 << m_viewManager->getGlobalCentreFrame() << std::endl;
|
Chris@73
|
3212 pane->setCentreFrame(m_viewManager->getGlobalCentreFrame());
|
Chris@73
|
3213
|
Chris@0
|
3214 CommandHistory::getInstance()->endCompoundOperation();
|
Chris@0
|
3215
|
Chris@0
|
3216 updateMenuStates();
|
Chris@0
|
3217 }
|
Chris@0
|
3218
|
Chris@0
|
3219 MainWindow::AddPaneCommand::AddPaneCommand(MainWindow *mw) :
|
Chris@0
|
3220 m_mw(mw),
|
Chris@0
|
3221 m_pane(0),
|
Chris@0
|
3222 m_prevCurrentPane(0),
|
Chris@0
|
3223 m_added(false)
|
Chris@0
|
3224 {
|
Chris@0
|
3225 }
|
Chris@0
|
3226
|
Chris@0
|
3227 MainWindow::AddPaneCommand::~AddPaneCommand()
|
Chris@0
|
3228 {
|
Chris@0
|
3229 if (m_pane && !m_added) {
|
Chris@0
|
3230 m_mw->m_paneStack->deletePane(m_pane);
|
Chris@0
|
3231 }
|
Chris@0
|
3232 }
|
Chris@0
|
3233
|
Chris@0
|
3234 QString
|
Chris@0
|
3235 MainWindow::AddPaneCommand::getName() const
|
Chris@0
|
3236 {
|
Chris@0
|
3237 return tr("Add Pane");
|
Chris@0
|
3238 }
|
Chris@0
|
3239
|
Chris@0
|
3240 void
|
Chris@0
|
3241 MainWindow::AddPaneCommand::execute()
|
Chris@0
|
3242 {
|
Chris@0
|
3243 if (!m_pane) {
|
Chris@0
|
3244 m_prevCurrentPane = m_mw->m_paneStack->getCurrentPane();
|
Chris@0
|
3245 m_pane = m_mw->m_paneStack->addPane();
|
Chris@90
|
3246
|
Chris@90
|
3247 connect(m_pane, SIGNAL(contextHelpChanged(const QString &)),
|
Chris@90
|
3248 m_mw->statusBar(), SLOT(showMessage(const QString &)));
|
Chris@0
|
3249 } else {
|
Chris@0
|
3250 m_mw->m_paneStack->showPane(m_pane);
|
Chris@0
|
3251 }
|
Chris@0
|
3252
|
Chris@0
|
3253 m_mw->m_paneStack->setCurrentPane(m_pane);
|
Chris@65
|
3254 m_mw->m_overview->registerView(m_pane);
|
Chris@0
|
3255 m_added = true;
|
Chris@0
|
3256 }
|
Chris@0
|
3257
|
Chris@0
|
3258 void
|
Chris@0
|
3259 MainWindow::AddPaneCommand::unexecute()
|
Chris@0
|
3260 {
|
Chris@0
|
3261 m_mw->m_paneStack->hidePane(m_pane);
|
Chris@0
|
3262 m_mw->m_paneStack->setCurrentPane(m_prevCurrentPane);
|
Chris@65
|
3263 m_mw->m_overview->unregisterView(m_pane);
|
Chris@0
|
3264 m_added = false;
|
Chris@0
|
3265 }
|
Chris@0
|
3266
|
Chris@0
|
3267 MainWindow::RemovePaneCommand::RemovePaneCommand(MainWindow *mw, Pane *pane) :
|
Chris@0
|
3268 m_mw(mw),
|
Chris@0
|
3269 m_pane(pane),
|
Chris@0
|
3270 m_added(true)
|
Chris@0
|
3271 {
|
Chris@0
|
3272 }
|
Chris@0
|
3273
|
Chris@0
|
3274 MainWindow::RemovePaneCommand::~RemovePaneCommand()
|
Chris@0
|
3275 {
|
Chris@0
|
3276 if (m_pane && !m_added) {
|
Chris@0
|
3277 m_mw->m_paneStack->deletePane(m_pane);
|
Chris@0
|
3278 }
|
Chris@0
|
3279 }
|
Chris@0
|
3280
|
Chris@0
|
3281 QString
|
Chris@0
|
3282 MainWindow::RemovePaneCommand::getName() const
|
Chris@0
|
3283 {
|
Chris@0
|
3284 return tr("Remove Pane");
|
Chris@0
|
3285 }
|
Chris@0
|
3286
|
Chris@0
|
3287 void
|
Chris@0
|
3288 MainWindow::RemovePaneCommand::execute()
|
Chris@0
|
3289 {
|
Chris@0
|
3290 m_prevCurrentPane = m_mw->m_paneStack->getCurrentPane();
|
Chris@0
|
3291 m_mw->m_paneStack->hidePane(m_pane);
|
Chris@65
|
3292 m_mw->m_overview->unregisterView(m_pane);
|
Chris@0
|
3293 m_added = false;
|
Chris@0
|
3294 }
|
Chris@0
|
3295
|
Chris@0
|
3296 void
|
Chris@0
|
3297 MainWindow::RemovePaneCommand::unexecute()
|
Chris@0
|
3298 {
|
Chris@0
|
3299 m_mw->m_paneStack->showPane(m_pane);
|
Chris@0
|
3300 m_mw->m_paneStack->setCurrentPane(m_prevCurrentPane);
|
Chris@65
|
3301 m_mw->m_overview->registerView(m_pane);
|
Chris@0
|
3302 m_added = true;
|
Chris@0
|
3303 }
|
Chris@0
|
3304
|
Chris@0
|
3305 void
|
Chris@0
|
3306 MainWindow::addLayer()
|
Chris@0
|
3307 {
|
Chris@0
|
3308 QObject *s = sender();
|
Chris@0
|
3309 QAction *action = dynamic_cast<QAction *>(s);
|
Chris@0
|
3310
|
Chris@0
|
3311 if (!action) {
|
Chris@0
|
3312 std::cerr << "WARNING: MainWindow::addLayer: sender is not an action"
|
Chris@0
|
3313 << std::endl;
|
Chris@0
|
3314 return;
|
Chris@0
|
3315 }
|
Chris@0
|
3316
|
Chris@0
|
3317 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@0
|
3318
|
Chris@0
|
3319 if (!pane) {
|
Chris@0
|
3320 std::cerr << "WARNING: MainWindow::addLayer: no current pane" << std::endl;
|
Chris@0
|
3321 return;
|
Chris@0
|
3322 }
|
Chris@0
|
3323
|
Chris@0
|
3324 ExistingLayerActionMap::iterator ei = m_existingLayerActions.find(action);
|
Chris@0
|
3325
|
Chris@0
|
3326 if (ei != m_existingLayerActions.end()) {
|
Chris@0
|
3327 Layer *newLayer = ei->second;
|
Chris@0
|
3328 m_document->addLayerToView(pane, newLayer);
|
Chris@0
|
3329 m_paneStack->setCurrentLayer(pane, newLayer);
|
Chris@0
|
3330 return;
|
Chris@0
|
3331 }
|
Chris@0
|
3332
|
Chris@34
|
3333 TransformActionMap::iterator i = m_transformActions.find(action);
|
Chris@34
|
3334
|
Chris@34
|
3335 if (i == m_transformActions.end()) {
|
Chris@0
|
3336
|
Chris@0
|
3337 LayerActionMap::iterator i = m_layerActions.find(action);
|
Chris@0
|
3338
|
Chris@0
|
3339 if (i == m_layerActions.end()) {
|
Chris@0
|
3340 std::cerr << "WARNING: MainWindow::addLayer: unknown action "
|
Chris@0
|
3341 << action->objectName().toStdString() << std::endl;
|
Chris@0
|
3342 return;
|
Chris@0
|
3343 }
|
Chris@0
|
3344
|
Chris@0
|
3345 LayerFactory::LayerType type = i->second;
|
Chris@0
|
3346
|
Chris@0
|
3347 LayerFactory::LayerTypeSet emptyTypes =
|
Chris@0
|
3348 LayerFactory::getInstance()->getValidEmptyLayerTypes();
|
Chris@0
|
3349
|
Chris@0
|
3350 Layer *newLayer;
|
Chris@0
|
3351
|
Chris@0
|
3352 if (emptyTypes.find(type) != emptyTypes.end()) {
|
Chris@0
|
3353
|
Chris@0
|
3354 newLayer = m_document->createEmptyLayer(type);
|
Chris@0
|
3355 m_toolActions[ViewManager::DrawMode]->trigger();
|
Chris@0
|
3356
|
Chris@0
|
3357 } else {
|
Chris@0
|
3358
|
Chris@0
|
3359 newLayer = m_document->createMainModelLayer(type);
|
Chris@0
|
3360 }
|
Chris@0
|
3361
|
Chris@0
|
3362 m_document->addLayerToView(pane, newLayer);
|
Chris@0
|
3363 m_paneStack->setCurrentLayer(pane, newLayer);
|
Chris@0
|
3364
|
Chris@0
|
3365 return;
|
Chris@0
|
3366 }
|
Chris@0
|
3367
|
Chris@0
|
3368 TransformName transform = i->second;
|
Chris@0
|
3369 TransformFactory *factory = TransformFactory::getInstance();
|
Chris@0
|
3370
|
Chris@0
|
3371 QString configurationXml;
|
Chris@0
|
3372
|
Chris@0
|
3373 int channel = -1;
|
Chris@0
|
3374 // pick up the default channel from any existing layers on the same pane
|
Chris@0
|
3375 for (int j = 0; j < pane->getLayerCount(); ++j) {
|
Chris@0
|
3376 int c = LayerFactory::getInstance()->getChannel(pane->getLayer(j));
|
Chris@0
|
3377 if (c != -1) {
|
Chris@0
|
3378 channel = c;
|
Chris@0
|
3379 break;
|
Chris@0
|
3380 }
|
Chris@0
|
3381 }
|
Chris@0
|
3382
|
Chris@33
|
3383 // We always ask for configuration, even if the plugin isn't
|
Chris@33
|
3384 // supposed to be configurable, because we need to let the user
|
Chris@33
|
3385 // change the execution context (block size etc).
|
Chris@0
|
3386
|
Chris@27
|
3387 PluginTransform::ExecutionContext context(channel);
|
Chris@27
|
3388
|
Chris@66
|
3389 std::vector<Model *> candidateInputModels =
|
Chris@66
|
3390 m_document->getTransformInputModels();
|
Chris@53
|
3391
|
Chris@54
|
3392 Model *inputModel = factory->getConfigurationForTransform(transform,
|
Chris@54
|
3393 candidateInputModels,
|
Chris@54
|
3394 context,
|
Chris@54
|
3395 configurationXml,
|
Chris@54
|
3396 m_playSource);
|
Chris@54
|
3397 if (!inputModel) return;
|
Chris@54
|
3398
|
Chris@54
|
3399 std::cerr << "Input model is " << inputModel << " \"" << inputModel->objectName().toStdString() << std::endl;
|
Chris@0
|
3400
|
Chris@0
|
3401 Layer *newLayer = m_document->createDerivedLayer(transform,
|
Chris@54
|
3402 inputModel,
|
Chris@27
|
3403 context,
|
Chris@0
|
3404 configurationXml);
|
Chris@0
|
3405
|
Chris@0
|
3406 if (newLayer) {
|
Chris@0
|
3407 m_document->addLayerToView(pane, newLayer);
|
Chris@27
|
3408 m_document->setChannel(newLayer, context.channel);
|
Chris@34
|
3409 m_recentTransforms.add(transform);
|
Chris@70
|
3410 m_paneStack->setCurrentLayer(pane, newLayer);
|
Chris@0
|
3411 }
|
Chris@0
|
3412
|
Chris@0
|
3413 updateMenuStates();
|
Chris@0
|
3414 }
|
Chris@0
|
3415
|
Chris@0
|
3416 void
|
Chris@0
|
3417 MainWindow::deleteCurrentPane()
|
Chris@0
|
3418 {
|
Chris@0
|
3419 CommandHistory::getInstance()->startCompoundOperation
|
Chris@0
|
3420 (tr("Delete Pane"), true);
|
Chris@0
|
3421
|
Chris@0
|
3422 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@0
|
3423 if (pane) {
|
Chris@0
|
3424 while (pane->getLayerCount() > 0) {
|
Chris@0
|
3425 Layer *layer = pane->getLayer(0);
|
Chris@0
|
3426 if (layer) {
|
Chris@0
|
3427 m_document->removeLayerFromView(pane, layer);
|
Chris@0
|
3428 } else {
|
Chris@0
|
3429 break;
|
Chris@0
|
3430 }
|
Chris@0
|
3431 }
|
Chris@0
|
3432
|
Chris@0
|
3433 RemovePaneCommand *command = new RemovePaneCommand(this, pane);
|
Chris@0
|
3434 CommandHistory::getInstance()->addCommand(command);
|
Chris@0
|
3435 }
|
Chris@0
|
3436
|
Chris@0
|
3437 CommandHistory::getInstance()->endCompoundOperation();
|
Chris@0
|
3438
|
Chris@0
|
3439 updateMenuStates();
|
Chris@0
|
3440 }
|
Chris@0
|
3441
|
Chris@0
|
3442 void
|
Chris@0
|
3443 MainWindow::deleteCurrentLayer()
|
Chris@0
|
3444 {
|
Chris@0
|
3445 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@0
|
3446 if (pane) {
|
Chris@0
|
3447 Layer *layer = pane->getSelectedLayer();
|
Chris@0
|
3448 if (layer) {
|
Chris@0
|
3449 m_document->removeLayerFromView(pane, layer);
|
Chris@0
|
3450 }
|
Chris@0
|
3451 }
|
Chris@0
|
3452 updateMenuStates();
|
Chris@0
|
3453 }
|
Chris@0
|
3454
|
Chris@0
|
3455 void
|
Chris@0
|
3456 MainWindow::renameCurrentLayer()
|
Chris@0
|
3457 {
|
Chris@0
|
3458 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@0
|
3459 if (pane) {
|
Chris@0
|
3460 Layer *layer = pane->getSelectedLayer();
|
Chris@0
|
3461 if (layer) {
|
Chris@0
|
3462 bool ok = false;
|
Chris@0
|
3463 QString newName = QInputDialog::getText
|
Chris@0
|
3464 (this, tr("Rename Layer"),
|
Chris@0
|
3465 tr("New name for this layer:"),
|
Chris@0
|
3466 QLineEdit::Normal, layer->objectName(), &ok);
|
Chris@0
|
3467 if (ok) {
|
Chris@0
|
3468 layer->setObjectName(newName);
|
Chris@0
|
3469 setupExistingLayersMenu();
|
Chris@0
|
3470 }
|
Chris@0
|
3471 }
|
Chris@0
|
3472 }
|
Chris@0
|
3473 }
|
Chris@0
|
3474
|
Chris@0
|
3475 void
|
Chris@59
|
3476 MainWindow::playSpeedChanged(int position)
|
Chris@0
|
3477 {
|
Chris@59
|
3478 PlaySpeedRangeMapper mapper(0, 200);
|
Chris@60
|
3479
|
Chris@60
|
3480 float percent = m_playSpeed->mappedValue();
|
Chris@60
|
3481
|
Chris@60
|
3482 float factor = mapper.getFactorForValue(percent);
|
Chris@60
|
3483
|
Chris@60
|
3484 // float factor = mapper.getFactorForPosition(position);
|
Chris@60
|
3485 // float percent = mapper.getValueForPosition(position);
|
Chris@60
|
3486
|
Chris@60
|
3487 std::cerr << "speed = " << position << " percent = " << percent << " factor = " << factor << std::endl;
|
Chris@60
|
3488
|
Chris@60
|
3489 //!!! bool slow = (position < 100);
|
Chris@59
|
3490 bool something = (position != 100);
|
Chris@60
|
3491 /*!!!
|
Chris@59
|
3492 int pc = lrintf(percent);
|
Chris@21
|
3493
|
Chris@21
|
3494 m_playSpeed->setToolTip(tr("Playback speed: %1%2%")
|
Chris@60
|
3495 .arg(!slow ? "+" : "")
|
Chris@21
|
3496 .arg(pc));
|
Chris@60
|
3497 */
|
Chris@25
|
3498 m_playSharpen->setEnabled(something);
|
Chris@26
|
3499 m_playMono->setEnabled(something);
|
Chris@25
|
3500 bool sharpen = (something && m_playSharpen->isChecked());
|
Chris@26
|
3501 bool mono = (something && m_playMono->isChecked());
|
Chris@26
|
3502 m_playSource->setTimeStretch(factor, sharpen, mono);
|
Chris@16
|
3503 }
|
Chris@16
|
3504
|
Chris@16
|
3505 void
|
Chris@16
|
3506 MainWindow::playSharpenToggled()
|
Chris@16
|
3507 {
|
Chris@21
|
3508 QSettings settings;
|
Chris@21
|
3509 settings.beginGroup("MainWindow");
|
Chris@21
|
3510 settings.setValue("playsharpen", m_playSharpen->isChecked());
|
Chris@21
|
3511 settings.endGroup();
|
Chris@21
|
3512
|
Chris@16
|
3513 playSpeedChanged(m_playSpeed->value());
|
Chris@0
|
3514 }
|
Chris@0
|
3515
|
Chris@0
|
3516 void
|
Chris@26
|
3517 MainWindow::playMonoToggled()
|
Chris@26
|
3518 {
|
Chris@26
|
3519 QSettings settings;
|
Chris@26
|
3520 settings.beginGroup("MainWindow");
|
Chris@26
|
3521 settings.setValue("playmono", m_playMono->isChecked());
|
Chris@26
|
3522 settings.endGroup();
|
Chris@26
|
3523
|
Chris@26
|
3524 playSpeedChanged(m_playSpeed->value());
|
Chris@26
|
3525 }
|
Chris@26
|
3526
|
Chris@26
|
3527 void
|
Chris@0
|
3528 MainWindow::outputLevelsChanged(float left, float right)
|
Chris@0
|
3529 {
|
Chris@0
|
3530 m_fader->setPeakLeft(left);
|
Chris@0
|
3531 m_fader->setPeakRight(right);
|
Chris@0
|
3532 }
|
Chris@0
|
3533
|
Chris@0
|
3534 void
|
Chris@0
|
3535 MainWindow::sampleRateMismatch(size_t requested, size_t actual,
|
Chris@0
|
3536 bool willResample)
|
Chris@0
|
3537 {
|
Chris@0
|
3538 if (!willResample) {
|
Chris@0
|
3539 //!!! more helpful message needed
|
Chris@0
|
3540 QMessageBox::information
|
Chris@0
|
3541 (this, tr("Sample rate mismatch"),
|
Chris@0
|
3542 tr("The sample rate of this audio file (%1 Hz) does not match\nthe current playback rate (%2 Hz).\n\nThe file will play at the wrong speed.")
|
Chris@0
|
3543 .arg(requested).arg(actual));
|
Chris@0
|
3544 }
|
Chris@0
|
3545
|
Chris@0
|
3546 /*!!! Let's not do this for now, and see how we go -- now that we're putting
|
Chris@0
|
3547 sample rate information in the status bar
|
Chris@0
|
3548
|
Chris@0
|
3549 QMessageBox::information
|
Chris@0
|
3550 (this, tr("Sample rate mismatch"),
|
Chris@0
|
3551 tr("The sample rate of this audio file (%1 Hz) does not match\nthat of the output audio device (%2 Hz).\n\nThe file will be resampled automatically during playback.")
|
Chris@0
|
3552 .arg(requested).arg(actual));
|
Chris@0
|
3553 */
|
Chris@0
|
3554
|
Chris@0
|
3555 updateDescriptionLabel();
|
Chris@0
|
3556 }
|
Chris@0
|
3557
|
Chris@0
|
3558 void
|
Chris@42
|
3559 MainWindow::audioOverloadPluginDisabled()
|
Chris@42
|
3560 {
|
Chris@42
|
3561 QMessageBox::information
|
Chris@42
|
3562 (this, tr("Audio processing overload"),
|
Chris@42
|
3563 tr("Audio effects plugin auditioning has been disabled\ndue to a processing overload."));
|
Chris@42
|
3564 }
|
Chris@42
|
3565
|
Chris@42
|
3566 void
|
Chris@0
|
3567 MainWindow::layerAdded(Layer *layer)
|
Chris@0
|
3568 {
|
Chris@0
|
3569 // std::cerr << "MainWindow::layerAdded(" << layer << ")" << std::endl;
|
Chris@0
|
3570 // setupExistingLayersMenu();
|
Chris@0
|
3571 updateMenuStates();
|
Chris@0
|
3572 }
|
Chris@0
|
3573
|
Chris@0
|
3574 void
|
Chris@0
|
3575 MainWindow::layerRemoved(Layer *layer)
|
Chris@0
|
3576 {
|
Chris@0
|
3577 // std::cerr << "MainWindow::layerRemoved(" << layer << ")" << std::endl;
|
Chris@0
|
3578 setupExistingLayersMenu();
|
Chris@0
|
3579 updateMenuStates();
|
Chris@0
|
3580 }
|
Chris@0
|
3581
|
Chris@0
|
3582 void
|
Chris@0
|
3583 MainWindow::layerAboutToBeDeleted(Layer *layer)
|
Chris@0
|
3584 {
|
Chris@0
|
3585 // std::cerr << "MainWindow::layerAboutToBeDeleted(" << layer << ")" << std::endl;
|
Chris@0
|
3586 if (layer == m_timeRulerLayer) {
|
Chris@0
|
3587 // std::cerr << "(this is the time ruler layer)" << std::endl;
|
Chris@0
|
3588 m_timeRulerLayer = 0;
|
Chris@0
|
3589 }
|
Chris@0
|
3590 }
|
Chris@0
|
3591
|
Chris@0
|
3592 void
|
Chris@0
|
3593 MainWindow::layerInAView(Layer *layer, bool inAView)
|
Chris@0
|
3594 {
|
Chris@0
|
3595 // std::cerr << "MainWindow::layerInAView(" << layer << "," << inAView << ")" << std::endl;
|
Chris@0
|
3596
|
Chris@0
|
3597 // Check whether we need to add or remove model from play source
|
Chris@0
|
3598 Model *model = layer->getModel();
|
Chris@0
|
3599 if (model) {
|
Chris@0
|
3600 if (inAView) {
|
Chris@0
|
3601 m_playSource->addModel(model);
|
Chris@0
|
3602 } else {
|
Chris@0
|
3603 bool found = false;
|
Chris@0
|
3604 for (int i = 0; i < m_paneStack->getPaneCount(); ++i) {
|
Chris@0
|
3605 Pane *pane = m_paneStack->getPane(i);
|
Chris@0
|
3606 if (!pane) continue;
|
Chris@0
|
3607 for (int j = 0; j < pane->getLayerCount(); ++j) {
|
Chris@0
|
3608 Layer *pl = pane->getLayer(j);
|
Chris@0
|
3609 if (pl && pl->getModel() == model) {
|
Chris@0
|
3610 found = true;
|
Chris@0
|
3611 break;
|
Chris@0
|
3612 }
|
Chris@0
|
3613 }
|
Chris@0
|
3614 if (found) break;
|
Chris@0
|
3615 }
|
Chris@0
|
3616 if (!found) m_playSource->removeModel(model);
|
Chris@0
|
3617 }
|
Chris@0
|
3618 }
|
Chris@0
|
3619
|
Chris@0
|
3620 setupExistingLayersMenu();
|
Chris@0
|
3621 updateMenuStates();
|
Chris@0
|
3622 }
|
Chris@0
|
3623
|
Chris@0
|
3624 void
|
Chris@0
|
3625 MainWindow::modelAdded(Model *model)
|
Chris@0
|
3626 {
|
Chris@0
|
3627 // std::cerr << "MainWindow::modelAdded(" << model << ")" << std::endl;
|
Chris@0
|
3628 m_playSource->addModel(model);
|
Chris@66
|
3629 if (dynamic_cast<DenseTimeValueModel *>(model)) {
|
Chris@66
|
3630 setupPaneAndLayerMenus();
|
Chris@66
|
3631 }
|
Chris@0
|
3632 }
|
Chris@0
|
3633
|
Chris@0
|
3634 void
|
Chris@0
|
3635 MainWindow::mainModelChanged(WaveFileModel *model)
|
Chris@0
|
3636 {
|
Chris@0
|
3637 // std::cerr << "MainWindow::mainModelChanged(" << model << ")" << std::endl;
|
Chris@0
|
3638 updateDescriptionLabel();
|
Chris@0
|
3639 m_panLayer->setModel(model);
|
Chris@0
|
3640 if (model) m_viewManager->setMainModelSampleRate(model->getSampleRate());
|
Chris@46
|
3641 if (model && !m_playTarget && m_audioOutput) createPlayTarget();
|
Chris@0
|
3642 }
|
Chris@0
|
3643
|
Chris@0
|
3644 void
|
Chris@0
|
3645 MainWindow::modelAboutToBeDeleted(Model *model)
|
Chris@0
|
3646 {
|
Chris@0
|
3647 // std::cerr << "MainWindow::modelAboutToBeDeleted(" << model << ")" << std::endl;
|
Chris@0
|
3648 m_playSource->removeModel(model);
|
Chris@91
|
3649 FFTDataServer::modelAboutToBeDeleted(model);
|
Chris@0
|
3650 }
|
Chris@0
|
3651
|
Chris@0
|
3652 void
|
Chris@0
|
3653 MainWindow::modelGenerationFailed(QString transformName)
|
Chris@0
|
3654 {
|
Chris@0
|
3655 QMessageBox::warning
|
Chris@0
|
3656 (this,
|
Chris@0
|
3657 tr("Failed to generate layer"),
|
Chris@34
|
3658 tr("Failed to generate a derived layer.\n\nThe layer transform \"%1\" failed.\n\nThis probably means that a plugin failed to initialise, perhaps because it\nrejected the processing block size that was requested.")
|
Chris@0
|
3659 .arg(transformName),
|
Chris@0
|
3660 QMessageBox::Ok, 0);
|
Chris@0
|
3661 }
|
Chris@0
|
3662
|
Chris@0
|
3663 void
|
Chris@0
|
3664 MainWindow::modelRegenerationFailed(QString layerName, QString transformName)
|
Chris@0
|
3665 {
|
Chris@0
|
3666 QMessageBox::warning
|
Chris@0
|
3667 (this,
|
Chris@0
|
3668 tr("Failed to regenerate layer"),
|
Chris@34
|
3669 tr("Failed to regenerate derived layer \"%1\".\n\nThe layer transform \"%2\" failed to run.\n\nThis probably means the layer used a plugin that is not currently available.")
|
Chris@0
|
3670 .arg(layerName).arg(transformName),
|
Chris@0
|
3671 QMessageBox::Ok, 0);
|
Chris@0
|
3672 }
|
Chris@0
|
3673
|
Chris@0
|
3674 void
|
Chris@0
|
3675 MainWindow::rightButtonMenuRequested(Pane *pane, QPoint position)
|
Chris@0
|
3676 {
|
Chris@0
|
3677 // std::cerr << "MainWindow::rightButtonMenuRequested(" << pane << ", " << position.x() << ", " << position.y() << ")" << std::endl;
|
Chris@0
|
3678 m_paneStack->setCurrentPane(pane);
|
Chris@0
|
3679 m_rightButtonMenu->popup(position);
|
Chris@0
|
3680 }
|
Chris@0
|
3681
|
Chris@0
|
3682 void
|
Chris@73
|
3683 MainWindow::propertyStacksResized()
|
Chris@73
|
3684 {
|
Chris@73
|
3685 /*
|
Chris@73
|
3686 std::cerr << "MainWindow::propertyStacksResized" << std::endl;
|
Chris@73
|
3687 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@73
|
3688 if (pane && m_overview) {
|
Chris@73
|
3689 std::cerr << "Fixed width: " << pane->width() << std::endl;
|
Chris@73
|
3690 m_overview->setFixedWidth(pane->width());
|
Chris@73
|
3691 }
|
Chris@73
|
3692 */
|
Chris@73
|
3693 }
|
Chris@73
|
3694
|
Chris@73
|
3695 void
|
Chris@0
|
3696 MainWindow::showLayerTree()
|
Chris@0
|
3697 {
|
Chris@0
|
3698 QTreeView *view = new QTreeView();
|
Chris@0
|
3699 LayerTreeModel *tree = new LayerTreeModel(m_paneStack);
|
Chris@0
|
3700 view->expand(tree->index(0, 0, QModelIndex()));
|
Chris@0
|
3701 view->setModel(tree);
|
Chris@0
|
3702 view->show();
|
Chris@0
|
3703 }
|
Chris@0
|
3704
|
Chris@0
|
3705 void
|
Chris@69
|
3706 MainWindow::pollOSC()
|
Chris@69
|
3707 {
|
Chris@70
|
3708 if (!m_oscQueue || m_oscQueue->isEmpty()) return;
|
Chris@69
|
3709 std::cerr << "MainWindow::pollOSC: have " << m_oscQueue->getMessagesAvailable() << " messages" << std::endl;
|
Chris@69
|
3710
|
Chris@70
|
3711 if (m_openingAudioFile) return;
|
Chris@70
|
3712
|
Chris@69
|
3713 OSCMessage message = m_oscQueue->readMessage();
|
Chris@69
|
3714
|
Chris@69
|
3715 if (message.getTarget() != 0) {
|
Chris@69
|
3716 return; //!!! for now -- this class is target 0, others not handled yet
|
Chris@69
|
3717 }
|
Chris@69
|
3718
|
Chris@69
|
3719 handleOSCMessage(message);
|
Chris@69
|
3720 }
|
Chris@69
|
3721
|
Chris@69
|
3722 void
|
Chris@69
|
3723 MainWindow::handleOSCMessage(const OSCMessage &message)
|
Chris@69
|
3724 {
|
Chris@70
|
3725 std::cerr << "MainWindow::handleOSCMessage: thread id = "
|
Chris@70
|
3726 << QThread::currentThreadId() << std::endl;
|
Chris@70
|
3727
|
Chris@69
|
3728 // This large function should really be abstracted out.
|
Chris@69
|
3729
|
Chris@69
|
3730 if (message.getMethod() == "open") {
|
Chris@69
|
3731
|
Chris@69
|
3732 if (message.getArgCount() == 1 &&
|
Chris@69
|
3733 message.getArg(0).canConvert(QVariant::String)) {
|
Chris@69
|
3734 QString path = message.getArg(0).toString();
|
Chris@82
|
3735 if (openSomeFile(path, ReplaceMainModel) != FileOpenSucceeded) {
|
Chris@69
|
3736 std::cerr << "MainWindow::handleOSCMessage: File open failed for path \""
|
Chris@69
|
3737 << path.toStdString() << "\"" << std::endl;
|
Chris@69
|
3738 }
|
Chris@69
|
3739 //!!! we really need to spin here and not return until the
|
Chris@69
|
3740 // file has been completely decoded...
|
Chris@69
|
3741 }
|
Chris@69
|
3742
|
Chris@69
|
3743 } else if (message.getMethod() == "openadditional") {
|
Chris@69
|
3744
|
Chris@69
|
3745 if (message.getArgCount() == 1 &&
|
Chris@69
|
3746 message.getArg(0).canConvert(QVariant::String)) {
|
Chris@69
|
3747 QString path = message.getArg(0).toString();
|
Chris@82
|
3748 if (openSomeFile(path, CreateAdditionalModel) != FileOpenSucceeded) {
|
Chris@69
|
3749 std::cerr << "MainWindow::handleOSCMessage: File open failed for path \""
|
Chris@69
|
3750 << path.toStdString() << "\"" << std::endl;
|
Chris@69
|
3751 }
|
Chris@69
|
3752 }
|
Chris@69
|
3753
|
Chris@69
|
3754 } else if (message.getMethod() == "recent" ||
|
Chris@69
|
3755 message.getMethod() == "last") {
|
Chris@69
|
3756
|
Chris@69
|
3757 int n = 0;
|
Chris@69
|
3758 if (message.getMethod() == "recent" &&
|
Chris@69
|
3759 message.getArgCount() == 1 &&
|
Chris@69
|
3760 message.getArg(0).canConvert(QVariant::Int)) {
|
Chris@69
|
3761 n = message.getArg(0).toInt() - 1;
|
Chris@69
|
3762 }
|
Chris@69
|
3763 std::vector<QString> recent = m_recentFiles.getRecent();
|
Chris@69
|
3764 if (n >= 0 && n < recent.size()) {
|
Chris@82
|
3765 if (openSomeFile(recent[n], ReplaceMainModel) != FileOpenSucceeded) {
|
Chris@69
|
3766 std::cerr << "MainWindow::handleOSCMessage: File open failed for path \""
|
Chris@69
|
3767 << recent[n].toStdString() << "\"" << std::endl;
|
Chris@69
|
3768 }
|
Chris@69
|
3769 }
|
Chris@69
|
3770
|
Chris@69
|
3771 } else if (message.getMethod() == "save") {
|
Chris@69
|
3772
|
Chris@69
|
3773 QString path;
|
Chris@69
|
3774 if (message.getArgCount() == 1 &&
|
Chris@69
|
3775 message.getArg(0).canConvert(QVariant::String)) {
|
Chris@69
|
3776 path = message.getArg(0).toString();
|
Chris@69
|
3777 if (QFileInfo(path).exists()) {
|
Chris@69
|
3778 std::cerr << "MainWindow::handleOSCMessage: Refusing to overwrite existing file in save" << std::endl;
|
Chris@69
|
3779 } else {
|
Chris@69
|
3780 saveSessionFile(path);
|
Chris@69
|
3781 }
|
Chris@69
|
3782 }
|
Chris@69
|
3783
|
Chris@69
|
3784 } else if (message.getMethod() == "export") {
|
Chris@69
|
3785
|
Chris@69
|
3786 QString path;
|
Chris@69
|
3787 if (getMainModel()) {
|
Chris@69
|
3788 if (message.getArgCount() == 1 &&
|
Chris@69
|
3789 message.getArg(0).canConvert(QVariant::String)) {
|
Chris@69
|
3790 path = message.getArg(0).toString();
|
Chris@69
|
3791 if (QFileInfo(path).exists()) {
|
Chris@69
|
3792 std::cerr << "MainWindow::handleOSCMessage: Refusing to overwrite existing file in export" << std::endl;
|
Chris@69
|
3793 } else {
|
Chris@69
|
3794 WavFileWriter writer(path,
|
Chris@69
|
3795 getMainModel()->getSampleRate(),
|
Chris@69
|
3796 getMainModel()->getChannelCount());
|
Chris@69
|
3797 MultiSelection ms = m_viewManager->getSelection();
|
Chris@69
|
3798 if (!ms.getSelections().empty()) {
|
Chris@69
|
3799 writer.writeModel(getMainModel(), &ms);
|
Chris@69
|
3800 } else {
|
Chris@69
|
3801 writer.writeModel(getMainModel());
|
Chris@69
|
3802 }
|
Chris@69
|
3803 }
|
Chris@69
|
3804 }
|
Chris@69
|
3805 }
|
Chris@69
|
3806
|
Chris@69
|
3807 } else if (message.getMethod() == "jump" ||
|
Chris@69
|
3808 message.getMethod() == "play") {
|
Chris@69
|
3809
|
Chris@69
|
3810 if (getMainModel()) {
|
Chris@69
|
3811
|
Chris@69
|
3812 unsigned long frame = m_viewManager->getPlaybackFrame();
|
Chris@69
|
3813 bool selection = false;
|
Chris@69
|
3814 bool play = (message.getMethod() == "play");
|
Chris@69
|
3815
|
Chris@69
|
3816 if (message.getArgCount() == 1) {
|
Chris@69
|
3817
|
Chris@69
|
3818 if (message.getArg(0).canConvert(QVariant::String) &&
|
Chris@69
|
3819 message.getArg(0).toString() == "selection") {
|
Chris@69
|
3820
|
Chris@69
|
3821 selection = true;
|
Chris@69
|
3822
|
Chris@69
|
3823 } else if (message.getArg(0).canConvert(QVariant::String) &&
|
Chris@69
|
3824 message.getArg(0).toString() == "end") {
|
Chris@69
|
3825
|
Chris@69
|
3826 frame = getMainModel()->getEndFrame();
|
Chris@69
|
3827
|
Chris@69
|
3828 } else if (message.getArg(0).canConvert(QVariant::Double)) {
|
Chris@69
|
3829
|
Chris@69
|
3830 double time = message.getArg(0).toDouble();
|
Chris@69
|
3831 if (time < 0.0) time = 0.0;
|
Chris@69
|
3832
|
Chris@69
|
3833 frame = lrint(time * getMainModel()->getSampleRate());
|
Chris@69
|
3834 }
|
Chris@69
|
3835 }
|
Chris@69
|
3836
|
Chris@69
|
3837 if (frame > getMainModel()->getEndFrame()) {
|
Chris@69
|
3838 frame = getMainModel()->getEndFrame();
|
Chris@69
|
3839 }
|
Chris@69
|
3840
|
Chris@69
|
3841 if (play) {
|
Chris@69
|
3842 m_viewManager->setPlaySelectionMode(selection);
|
Chris@69
|
3843 }
|
Chris@69
|
3844
|
Chris@69
|
3845 if (selection) {
|
Chris@69
|
3846 MultiSelection::SelectionList sl = m_viewManager->getSelections();
|
Chris@69
|
3847 if (!sl.empty()) {
|
Chris@69
|
3848 frame = sl.begin()->getStartFrame();
|
Chris@69
|
3849 }
|
Chris@69
|
3850 }
|
Chris@69
|
3851
|
Chris@69
|
3852 m_viewManager->setPlaybackFrame(frame);
|
Chris@69
|
3853
|
Chris@69
|
3854 if (play && !m_playSource->isPlaying()) {
|
Chris@69
|
3855 m_playSource->play(frame);
|
Chris@69
|
3856 }
|
Chris@69
|
3857 }
|
Chris@69
|
3858
|
Chris@69
|
3859 } else if (message.getMethod() == "stop") {
|
Chris@69
|
3860
|
Chris@69
|
3861 if (m_playSource->isPlaying()) m_playSource->stop();
|
Chris@69
|
3862
|
Chris@69
|
3863 } else if (message.getMethod() == "loop") {
|
Chris@69
|
3864
|
Chris@69
|
3865 if (message.getArgCount() == 1 &&
|
Chris@69
|
3866 message.getArg(0).canConvert(QVariant::String)) {
|
Chris@69
|
3867
|
Chris@69
|
3868 QString str = message.getArg(0).toString();
|
Chris@69
|
3869 if (str == "on") {
|
Chris@69
|
3870 m_viewManager->setPlayLoopMode(true);
|
Chris@69
|
3871 } else if (str == "off") {
|
Chris@69
|
3872 m_viewManager->setPlayLoopMode(false);
|
Chris@69
|
3873 }
|
Chris@69
|
3874 }
|
Chris@69
|
3875
|
Chris@69
|
3876 } else if (message.getMethod() == "select" ||
|
Chris@69
|
3877 message.getMethod() == "addselect") {
|
Chris@69
|
3878
|
Chris@69
|
3879 if (getMainModel()) {
|
Chris@69
|
3880
|
Chris@73
|
3881 int f0 = getMainModel()->getStartFrame();
|
Chris@73
|
3882 int f1 = getMainModel()->getEndFrame();
|
Chris@69
|
3883
|
Chris@69
|
3884 bool done = false;
|
Chris@69
|
3885
|
Chris@69
|
3886 if (message.getArgCount() == 2 &&
|
Chris@69
|
3887 message.getArg(0).canConvert(QVariant::Double) &&
|
Chris@69
|
3888 message.getArg(1).canConvert(QVariant::Double)) {
|
Chris@69
|
3889
|
Chris@69
|
3890 double t0 = message.getArg(0).toDouble();
|
Chris@69
|
3891 double t1 = message.getArg(1).toDouble();
|
Chris@69
|
3892 if (t1 < t0) { double temp = t0; t0 = t1; t1 = temp; }
|
Chris@69
|
3893 if (t0 < 0.0) t0 = 0.0;
|
Chris@69
|
3894 if (t1 < 0.0) t1 = 0.0;
|
Chris@69
|
3895
|
Chris@69
|
3896 f0 = lrint(t0 * getMainModel()->getSampleRate());
|
Chris@69
|
3897 f1 = lrint(t1 * getMainModel()->getSampleRate());
|
Chris@73
|
3898
|
Chris@73
|
3899 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@73
|
3900 Layer *layer = 0;
|
Chris@73
|
3901 if (pane) layer = pane->getSelectedLayer();
|
Chris@73
|
3902 if (layer) {
|
Chris@73
|
3903 size_t resolution;
|
Chris@73
|
3904 layer->snapToFeatureFrame(pane, f0, resolution,
|
Chris@73
|
3905 Layer::SnapLeft);
|
Chris@73
|
3906 layer->snapToFeatureFrame(pane, f1, resolution,
|
Chris@73
|
3907 Layer::SnapRight);
|
Chris@73
|
3908 }
|
Chris@69
|
3909
|
Chris@69
|
3910 } else if (message.getArgCount() == 1 &&
|
Chris@69
|
3911 message.getArg(0).canConvert(QVariant::String)) {
|
Chris@69
|
3912
|
Chris@69
|
3913 QString str = message.getArg(0).toString();
|
Chris@69
|
3914 if (str == "none") {
|
Chris@69
|
3915 m_viewManager->clearSelections();
|
Chris@69
|
3916 done = true;
|
Chris@69
|
3917 }
|
Chris@69
|
3918 }
|
Chris@69
|
3919
|
Chris@69
|
3920 if (!done) {
|
Chris@69
|
3921 if (message.getMethod() == "select") {
|
Chris@69
|
3922 m_viewManager->setSelection(Selection(f0, f1));
|
Chris@69
|
3923 } else {
|
Chris@69
|
3924 m_viewManager->addSelection(Selection(f0, f1));
|
Chris@69
|
3925 }
|
Chris@69
|
3926 }
|
Chris@69
|
3927 }
|
Chris@69
|
3928
|
Chris@69
|
3929 } else if (message.getMethod() == "add") {
|
Chris@69
|
3930
|
Chris@69
|
3931 if (getMainModel()) {
|
Chris@69
|
3932
|
Chris@69
|
3933 if (message.getArgCount() >= 1 &&
|
Chris@69
|
3934 message.getArg(0).canConvert(QVariant::String)) {
|
Chris@69
|
3935
|
Chris@69
|
3936 int channel = -1;
|
Chris@69
|
3937 if (message.getArgCount() == 2 &&
|
Chris@69
|
3938 message.getArg(0).canConvert(QVariant::Int)) {
|
Chris@69
|
3939 channel = message.getArg(0).toInt();
|
Chris@69
|
3940 if (channel < -1 ||
|
Chris@69
|
3941 channel > getMainModel()->getChannelCount()) {
|
Chris@69
|
3942 std::cerr << "WARNING: MainWindow::handleOSCMessage: channel "
|
Chris@69
|
3943 << channel << " out of range" << std::endl;
|
Chris@69
|
3944 channel = -1;
|
Chris@69
|
3945 }
|
Chris@69
|
3946 }
|
Chris@69
|
3947
|
Chris@69
|
3948 QString str = message.getArg(0).toString();
|
Chris@69
|
3949
|
Chris@69
|
3950 LayerFactory::LayerType type =
|
Chris@69
|
3951 LayerFactory::getInstance()->getLayerTypeForName(str);
|
Chris@69
|
3952
|
Chris@69
|
3953 if (type == LayerFactory::UnknownLayer) {
|
Chris@69
|
3954 std::cerr << "WARNING: MainWindow::handleOSCMessage: unknown layer "
|
Chris@69
|
3955 << "type " << str.toStdString() << std::endl;
|
Chris@69
|
3956 } else {
|
Chris@69
|
3957
|
Chris@69
|
3958 PaneConfiguration configuration(type,
|
Chris@69
|
3959 getMainModel(),
|
Chris@69
|
3960 channel);
|
Chris@69
|
3961
|
Chris@69
|
3962 addPane(configuration,
|
Chris@69
|
3963 tr("Add %1 Pane")
|
Chris@69
|
3964 .arg(LayerFactory::getInstance()->
|
Chris@69
|
3965 getLayerPresentationName(type)));
|
Chris@69
|
3966 }
|
Chris@69
|
3967 }
|
Chris@69
|
3968 }
|
Chris@69
|
3969
|
Chris@69
|
3970 } else if (message.getMethod() == "undo") {
|
Chris@69
|
3971
|
Chris@69
|
3972 CommandHistory::getInstance()->undo();
|
Chris@69
|
3973
|
Chris@69
|
3974 } else if (message.getMethod() == "redo") {
|
Chris@69
|
3975
|
Chris@69
|
3976 CommandHistory::getInstance()->redo();
|
Chris@69
|
3977
|
Chris@69
|
3978 } else if (message.getMethod() == "set") {
|
Chris@69
|
3979
|
Chris@70
|
3980 if (message.getArgCount() == 2 &&
|
Chris@69
|
3981 message.getArg(0).canConvert(QVariant::String) &&
|
Chris@69
|
3982 message.getArg(1).canConvert(QVariant::Double)) {
|
Chris@69
|
3983
|
Chris@69
|
3984 QString property = message.getArg(0).toString();
|
Chris@69
|
3985 float value = (float)message.getArg(1).toDouble();
|
Chris@69
|
3986
|
Chris@69
|
3987 if (property == "gain") {
|
Chris@69
|
3988 if (value < 0.0) value = 0.0;
|
Chris@69
|
3989 m_fader->setValue(value);
|
Chris@69
|
3990 if (m_playTarget) m_playTarget->setOutputGain(value);
|
Chris@69
|
3991 } else if (property == "speedup") {
|
Chris@69
|
3992 m_playSpeed->setMappedValue(value);
|
Chris@69
|
3993 } else if (property == "overlays") {
|
Chris@69
|
3994 if (value < 0.5) {
|
Chris@69
|
3995 m_viewManager->setOverlayMode(ViewManager::NoOverlays);
|
Chris@69
|
3996 } else if (value < 1.5) {
|
Chris@90
|
3997 m_viewManager->setOverlayMode(ViewManager::MinimalOverlays);
|
Chris@90
|
3998 } else if (value < 2.5) {
|
Chris@90
|
3999 m_viewManager->setOverlayMode(ViewManager::StandardOverlays);
|
Chris@69
|
4000 } else {
|
Chris@69
|
4001 m_viewManager->setOverlayMode(ViewManager::AllOverlays);
|
Chris@69
|
4002 }
|
Chris@70
|
4003 } else if (property == "zoomwheels") {
|
Chris@70
|
4004 m_viewManager->setZoomWheelsEnabled(value > 0.5);
|
Chris@72
|
4005 } else if (property == "propertyboxes") {
|
Chris@72
|
4006 bool toggle = ((value < 0.5) !=
|
Chris@72
|
4007 (m_paneStack->getLayoutStyle() == PaneStack::NoPropertyStacks));
|
Chris@72
|
4008 if (toggle) togglePropertyBoxes();
|
Chris@70
|
4009 }
|
Chris@70
|
4010
|
Chris@70
|
4011 } else {
|
Chris@70
|
4012 PropertyContainer *container = 0;
|
Chris@70
|
4013 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@70
|
4014 if (pane &&
|
Chris@70
|
4015 message.getArgCount() == 3 &&
|
Chris@70
|
4016 message.getArg(0).canConvert(QVariant::String) &&
|
Chris@70
|
4017 message.getArg(1).canConvert(QVariant::String) &&
|
Chris@70
|
4018 message.getArg(2).canConvert(QVariant::String)) {
|
Chris@70
|
4019 if (message.getArg(0).toString() == "pane") {
|
Chris@70
|
4020 container = pane->getPropertyContainer(0);
|
Chris@70
|
4021 } else if (message.getArg(0).toString() == "layer") {
|
Chris@70
|
4022 container = pane->getSelectedLayer();
|
Chris@70
|
4023 }
|
Chris@70
|
4024 }
|
Chris@70
|
4025 if (container) {
|
Chris@70
|
4026 QString nameString = message.getArg(1).toString();
|
Chris@70
|
4027 QString valueString = message.getArg(2).toString();
|
Chris@70
|
4028 container->setPropertyWithCommand(nameString, valueString);
|
Chris@69
|
4029 }
|
Chris@69
|
4030 }
|
Chris@69
|
4031
|
Chris@69
|
4032 } else if (message.getMethod() == "setcurrent") {
|
Chris@69
|
4033
|
Chris@69
|
4034 int paneIndex = -1, layerIndex = -1;
|
Chris@69
|
4035 bool wantLayer = false;
|
Chris@69
|
4036
|
Chris@69
|
4037 if (message.getArgCount() >= 1 &&
|
Chris@69
|
4038 message.getArg(0).canConvert(QVariant::Int)) {
|
Chris@69
|
4039
|
Chris@69
|
4040 paneIndex = message.getArg(0).toInt() - 1;
|
Chris@69
|
4041
|
Chris@69
|
4042 if (message.getArgCount() >= 2 &&
|
Chris@69
|
4043 message.getArg(1).canConvert(QVariant::Int)) {
|
Chris@69
|
4044 wantLayer = true;
|
Chris@69
|
4045 layerIndex = message.getArg(1).toInt() - 1;
|
Chris@69
|
4046 }
|
Chris@69
|
4047 }
|
Chris@69
|
4048
|
Chris@69
|
4049 if (paneIndex >= 0 && paneIndex < m_paneStack->getPaneCount()) {
|
Chris@69
|
4050 Pane *pane = m_paneStack->getPane(paneIndex);
|
Chris@70
|
4051 m_paneStack->setCurrentPane(pane);
|
Chris@69
|
4052 if (layerIndex >= 0 && layerIndex < pane->getLayerCount()) {
|
Chris@69
|
4053 Layer *layer = pane->getLayer(layerIndex);
|
Chris@69
|
4054 m_paneStack->setCurrentLayer(pane, layer);
|
Chris@69
|
4055 } else if (wantLayer && layerIndex == -1) {
|
Chris@69
|
4056 m_paneStack->setCurrentLayer(pane, 0);
|
Chris@69
|
4057 }
|
Chris@69
|
4058 }
|
Chris@69
|
4059
|
Chris@69
|
4060 } else if (message.getMethod() == "delete") {
|
Chris@69
|
4061
|
Chris@69
|
4062 if (message.getArgCount() == 1 &&
|
Chris@69
|
4063 message.getArg(0).canConvert(QVariant::String)) {
|
Chris@69
|
4064
|
Chris@69
|
4065 QString target = message.getArg(0).toString();
|
Chris@69
|
4066
|
Chris@69
|
4067 if (target == "pane") {
|
Chris@69
|
4068
|
Chris@69
|
4069 deleteCurrentPane();
|
Chris@69
|
4070
|
Chris@69
|
4071 } else if (target == "layer") {
|
Chris@69
|
4072
|
Chris@69
|
4073 deleteCurrentLayer();
|
Chris@69
|
4074
|
Chris@69
|
4075 } else {
|
Chris@69
|
4076
|
Chris@69
|
4077 std::cerr << "WARNING: MainWindow::handleOSCMessage: Unknown delete target " << target.toStdString() << std::endl;
|
Chris@69
|
4078 }
|
Chris@69
|
4079 }
|
Chris@69
|
4080
|
Chris@69
|
4081 } else if (message.getMethod() == "zoom") {
|
Chris@69
|
4082
|
Chris@69
|
4083 if (message.getArgCount() == 1) {
|
Chris@69
|
4084 if (message.getArg(0).canConvert(QVariant::String) &&
|
Chris@69
|
4085 message.getArg(0).toString() == "in") {
|
Chris@69
|
4086 zoomIn();
|
Chris@69
|
4087 } else if (message.getArg(0).canConvert(QVariant::String) &&
|
Chris@69
|
4088 message.getArg(0).toString() == "out") {
|
Chris@69
|
4089 zoomOut();
|
Chris@69
|
4090 } else if (message.getArg(0).canConvert(QVariant::String) &&
|
Chris@69
|
4091 message.getArg(0).toString() == "default") {
|
Chris@69
|
4092 zoomDefault();
|
Chris@69
|
4093 } else if (message.getArg(0).canConvert(QVariant::Double)) {
|
Chris@69
|
4094 double level = message.getArg(0).toDouble();
|
Chris@69
|
4095 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@69
|
4096 if (level < 1.0) level = 1.0;
|
Chris@69
|
4097 if (currentPane) currentPane->setZoomLevel(lrint(level));
|
Chris@69
|
4098 }
|
Chris@69
|
4099 }
|
Chris@69
|
4100
|
Chris@73
|
4101 } else if (message.getMethod() == "zoomvertical") {
|
Chris@73
|
4102
|
Chris@73
|
4103 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@73
|
4104 Layer *layer = 0;
|
Chris@73
|
4105 if (pane && pane->getLayerCount() > 0) {
|
Chris@73
|
4106 layer = pane->getLayer(pane->getLayerCount() - 1);
|
Chris@73
|
4107 }
|
Chris@73
|
4108 int defaultStep = 0;
|
Chris@73
|
4109 int steps = 0;
|
Chris@73
|
4110 if (layer) {
|
Chris@73
|
4111 steps = layer->getVerticalZoomSteps(defaultStep);
|
Chris@73
|
4112 if (message.getArgCount() == 1 && steps > 0) {
|
Chris@73
|
4113 if (message.getArg(0).canConvert(QVariant::String) &&
|
Chris@73
|
4114 message.getArg(0).toString() == "in") {
|
Chris@73
|
4115 int step = layer->getCurrentVerticalZoomStep() + 1;
|
Chris@73
|
4116 if (step < steps) layer->setVerticalZoomStep(step);
|
Chris@73
|
4117 } else if (message.getArg(0).canConvert(QVariant::String) &&
|
Chris@73
|
4118 message.getArg(0).toString() == "out") {
|
Chris@73
|
4119 int step = layer->getCurrentVerticalZoomStep() - 1;
|
Chris@73
|
4120 if (step >= 0) layer->setVerticalZoomStep(step);
|
Chris@73
|
4121 } else if (message.getArg(0).canConvert(QVariant::String) &&
|
Chris@73
|
4122 message.getArg(0).toString() == "default") {
|
Chris@73
|
4123 layer->setVerticalZoomStep(defaultStep);
|
Chris@73
|
4124 }
|
Chris@73
|
4125 } else if (message.getArgCount() == 2) {
|
Chris@73
|
4126 if (message.getArg(0).canConvert(QVariant::Double) &&
|
Chris@73
|
4127 message.getArg(1).canConvert(QVariant::Double)) {
|
Chris@73
|
4128 double min = message.getArg(0).toDouble();
|
Chris@73
|
4129 double max = message.getArg(1).toDouble();
|
Chris@73
|
4130 layer->setDisplayExtents(min, max);
|
Chris@73
|
4131 }
|
Chris@73
|
4132 }
|
Chris@73
|
4133 }
|
Chris@73
|
4134
|
Chris@70
|
4135 } else if (message.getMethod() == "quit") {
|
Chris@70
|
4136
|
Chris@70
|
4137 m_abandoning = true;
|
Chris@70
|
4138 close();
|
Chris@70
|
4139
|
Chris@70
|
4140 } else if (message.getMethod() == "resize") {
|
Chris@70
|
4141
|
Chris@70
|
4142 if (message.getArgCount() == 2) {
|
Chris@70
|
4143
|
Chris@70
|
4144 int width = 0, height = 0;
|
Chris@70
|
4145
|
Chris@70
|
4146 if (message.getArg(1).canConvert(QVariant::Int)) {
|
Chris@70
|
4147
|
Chris@70
|
4148 height = message.getArg(1).toInt();
|
Chris@70
|
4149
|
Chris@70
|
4150 if (message.getArg(0).canConvert(QVariant::String) &&
|
Chris@70
|
4151 message.getArg(0).toString() == "pane") {
|
Chris@70
|
4152
|
Chris@70
|
4153 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@70
|
4154 if (pane) pane->resize(pane->width(), height);
|
Chris@70
|
4155
|
Chris@70
|
4156 } else if (message.getArg(0).canConvert(QVariant::Int)) {
|
Chris@70
|
4157
|
Chris@70
|
4158 width = message.getArg(0).toInt();
|
Chris@70
|
4159 resize(width, height);
|
Chris@70
|
4160 }
|
Chris@70
|
4161 }
|
Chris@70
|
4162 }
|
Chris@70
|
4163
|
Chris@70
|
4164 } else if (message.getMethod() == "transform") {
|
Chris@70
|
4165
|
Chris@70
|
4166 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@70
|
4167
|
Chris@70
|
4168 if (getMainModel() &&
|
Chris@70
|
4169 pane &&
|
Chris@70
|
4170 message.getArgCount() == 1 &&
|
Chris@70
|
4171 message.getArg(0).canConvert(QVariant::String)) {
|
Chris@70
|
4172
|
Chris@70
|
4173 TransformName transform = message.getArg(0).toString();
|
Chris@70
|
4174
|
Chris@70
|
4175 Layer *newLayer = m_document->createDerivedLayer
|
Chris@70
|
4176 (transform,
|
Chris@70
|
4177 getMainModel(),
|
Chris@73
|
4178 TransformFactory::getInstance()->getDefaultContextForTransform
|
Chris@73
|
4179 (transform, getMainModel()),
|
Chris@70
|
4180 "");
|
Chris@70
|
4181
|
Chris@70
|
4182 if (newLayer) {
|
Chris@70
|
4183 m_document->addLayerToView(pane, newLayer);
|
Chris@70
|
4184 m_recentTransforms.add(transform);
|
Chris@70
|
4185 m_paneStack->setCurrentLayer(pane, newLayer);
|
Chris@70
|
4186 }
|
Chris@70
|
4187 }
|
Chris@70
|
4188
|
Chris@69
|
4189 } else {
|
Chris@69
|
4190 std::cerr << "WARNING: MainWindow::handleOSCMessage: Unknown or unsupported "
|
Chris@69
|
4191 << "method \"" << message.getMethod().toStdString()
|
Chris@69
|
4192 << "\"" << std::endl;
|
Chris@69
|
4193 }
|
Chris@69
|
4194
|
Chris@69
|
4195 }
|
Chris@69
|
4196
|
Chris@69
|
4197 void
|
Chris@0
|
4198 MainWindow::preferences()
|
Chris@0
|
4199 {
|
Chris@0
|
4200 if (!m_preferencesDialog.isNull()) {
|
Chris@0
|
4201 m_preferencesDialog->show();
|
Chris@0
|
4202 m_preferencesDialog->raise();
|
Chris@0
|
4203 return;
|
Chris@0
|
4204 }
|
Chris@0
|
4205
|
Chris@0
|
4206 m_preferencesDialog = new PreferencesDialog(this);
|
Chris@0
|
4207
|
Chris@0
|
4208 // DeleteOnClose is safe here, because m_preferencesDialog is a
|
Chris@0
|
4209 // QPointer that will be zeroed when the dialog is deleted. We
|
Chris@0
|
4210 // use it in preference to leaving the dialog lying around because
|
Chris@0
|
4211 // if you Cancel the dialog, it resets the preferences state
|
Chris@0
|
4212 // without resetting its own widgets, so its state will be
|
Chris@0
|
4213 // incorrect when next shown unless we construct it afresh
|
Chris@0
|
4214 m_preferencesDialog->setAttribute(Qt::WA_DeleteOnClose);
|
Chris@0
|
4215
|
Chris@0
|
4216 m_preferencesDialog->show();
|
Chris@0
|
4217 }
|
Chris@0
|
4218
|
Chris@0
|
4219 void
|
Chris@90
|
4220 MainWindow::mouseEnteredWidget()
|
Chris@90
|
4221 {
|
Chris@90
|
4222 QWidget *w = dynamic_cast<QWidget *>(sender());
|
Chris@90
|
4223 if (!w) return;
|
Chris@90
|
4224
|
Chris@90
|
4225 if (w == m_fader) {
|
Chris@90
|
4226 statusBar()->showMessage(tr("Adjust the master playback level"));
|
Chris@90
|
4227 } else if (w == m_playSpeed) {
|
Chris@90
|
4228 statusBar()->showMessage(tr("Adjust the master playback speed"));
|
Chris@90
|
4229 } else if (w == m_playSharpen && w->isEnabled()) {
|
Chris@90
|
4230 statusBar()->showMessage(tr("Toggle transient sharpening for playback time scaling"));
|
Chris@90
|
4231 } else if (w == m_playMono && w->isEnabled()) {
|
Chris@90
|
4232 statusBar()->showMessage(tr("Toggle mono mode for playback time scaling"));
|
Chris@90
|
4233 }
|
Chris@90
|
4234 }
|
Chris@90
|
4235
|
Chris@90
|
4236 void
|
Chris@90
|
4237 MainWindow::mouseLeftWidget()
|
Chris@90
|
4238 {
|
Chris@90
|
4239 statusBar()->showMessage("");
|
Chris@90
|
4240 }
|
Chris@90
|
4241
|
Chris@90
|
4242 void
|
Chris@0
|
4243 MainWindow::website()
|
Chris@0
|
4244 {
|
Chris@0
|
4245 openHelpUrl(tr("http://www.sonicvisualiser.org/"));
|
Chris@0
|
4246 }
|
Chris@0
|
4247
|
Chris@0
|
4248 void
|
Chris@0
|
4249 MainWindow::help()
|
Chris@0
|
4250 {
|
Chris@0
|
4251 openHelpUrl(tr("http://www.sonicvisualiser.org/doc/reference/en/"));
|
Chris@0
|
4252 }
|
Chris@0
|
4253
|
Chris@0
|
4254 void
|
Chris@0
|
4255 MainWindow::openHelpUrl(QString url)
|
Chris@0
|
4256 {
|
Chris@0
|
4257 // This method mostly lifted from Qt Assistant source code
|
Chris@0
|
4258
|
Chris@0
|
4259 QProcess *process = new QProcess(this);
|
Chris@0
|
4260 connect(process, SIGNAL(finished(int)), process, SLOT(deleteLater()));
|
Chris@0
|
4261
|
Chris@0
|
4262 QStringList args;
|
Chris@0
|
4263
|
Chris@0
|
4264 #ifdef Q_OS_MAC
|
Chris@0
|
4265 args.append(url);
|
Chris@0
|
4266 process->start("open", args);
|
Chris@0
|
4267 #else
|
Chris@0
|
4268 #ifdef Q_OS_WIN32
|
Chris@0
|
4269
|
Chris@0
|
4270 QString pf(getenv("ProgramFiles"));
|
Chris@0
|
4271 QString command = pf + QString("\\Internet Explorer\\IEXPLORE.EXE");
|
Chris@0
|
4272
|
Chris@0
|
4273 args.append(url);
|
Chris@0
|
4274 process->start(command, args);
|
Chris@0
|
4275
|
Chris@0
|
4276 #else
|
Chris@0
|
4277 #ifdef Q_WS_X11
|
Chris@0
|
4278 if (!qgetenv("KDE_FULL_SESSION").isEmpty()) {
|
Chris@0
|
4279 args.append("exec");
|
Chris@0
|
4280 args.append(url);
|
Chris@0
|
4281 process->start("kfmclient", args);
|
Chris@0
|
4282 } else if (!qgetenv("BROWSER").isEmpty()) {
|
Chris@0
|
4283 args.append(url);
|
Chris@0
|
4284 process->start(qgetenv("BROWSER"), args);
|
Chris@0
|
4285 } else {
|
Chris@0
|
4286 args.append(url);
|
Chris@0
|
4287 process->start("firefox", args);
|
Chris@0
|
4288 }
|
Chris@0
|
4289 #endif
|
Chris@0
|
4290 #endif
|
Chris@0
|
4291 #endif
|
Chris@0
|
4292 }
|
Chris@0
|
4293
|
Chris@0
|
4294 void
|
Chris@0
|
4295 MainWindow::about()
|
Chris@0
|
4296 {
|
Chris@0
|
4297 bool debug = false;
|
Chris@0
|
4298 QString version = "(unknown version)";
|
Chris@0
|
4299
|
Chris@0
|
4300 #ifdef BUILD_DEBUG
|
Chris@0
|
4301 debug = true;
|
Chris@0
|
4302 #endif
|
Chris@0
|
4303 #ifdef SV_VERSION
|
Chris@0
|
4304 #ifdef SVNREV
|
Chris@0
|
4305 version = tr("Release %1 : Revision %2").arg(SV_VERSION).arg(SVNREV);
|
Chris@0
|
4306 #else
|
Chris@0
|
4307 version = tr("Release %1").arg(SV_VERSION);
|
Chris@0
|
4308 #endif
|
Chris@0
|
4309 #else
|
Chris@0
|
4310 #ifdef SVNREV
|
Chris@0
|
4311 version = tr("Unreleased : Revision %1").arg(SVNREV);
|
Chris@0
|
4312 #endif
|
Chris@0
|
4313 #endif
|
Chris@0
|
4314
|
Chris@0
|
4315 QString aboutText;
|
Chris@0
|
4316
|
Chris@0
|
4317 aboutText += tr("<h3>About Sonic Visualiser</h3>");
|
Chris@90
|
4318 aboutText += tr("<p>Sonic Visualiser is a program for viewing and exploring audio data for<br>semantic music analysis and annotation.</p>");
|
Chris@0
|
4319 aboutText += tr("<p>%1 : %2 build</p>")
|
Chris@0
|
4320 .arg(version)
|
Chris@0
|
4321 .arg(debug ? tr("Debug") : tr("Release"));
|
Chris@0
|
4322
|
Chris@0
|
4323 #ifdef BUILD_STATIC
|
Chris@0
|
4324 aboutText += tr("<p>Statically linked");
|
Chris@0
|
4325 #ifndef QT_SHARED
|
Chris@0
|
4326 aboutText += tr("<br>With Qt (v%1) © Trolltech AS").arg(QT_VERSION_STR);
|
Chris@0
|
4327 #endif
|
Chris@0
|
4328 #ifdef HAVE_JACK
|
Chris@93
|
4329 #ifdef JACK_VERSION
|
Chris@0
|
4330 aboutText += tr("<br>With JACK audio output (v%1) © Paul Davis and Jack O'Quin").arg(JACK_VERSION);
|
Chris@93
|
4331 #else
|
Chris@93
|
4332 aboutText += tr("<br>With JACK audio output © Paul Davis and Jack O'Quin");
|
Chris@93
|
4333 #endif
|
Chris@0
|
4334 #endif
|
Chris@0
|
4335 #ifdef HAVE_PORTAUDIO
|
Chris@0
|
4336 aboutText += tr("<br>With PortAudio audio output © Ross Bencina and Phil Burk");
|
Chris@0
|
4337 #endif
|
Chris@0
|
4338 #ifdef HAVE_OGGZ
|
Chris@93
|
4339 #ifdef OGGZ_VERSION
|
Chris@0
|
4340 aboutText += tr("<br>With Ogg file decoder (oggz v%1, fishsound v%2) © CSIRO Australia").arg(OGGZ_VERSION).arg(FISHSOUND_VERSION);
|
Chris@93
|
4341 #else
|
Chris@93
|
4342 aboutText += tr("<br>With Ogg file decoder © CSIRO Australia");
|
Chris@93
|
4343 #endif
|
Chris@0
|
4344 #endif
|
Chris@0
|
4345 #ifdef HAVE_MAD
|
Chris@93
|
4346 #ifdef MAD_VERSION
|
Chris@0
|
4347 aboutText += tr("<br>With MAD mp3 decoder (v%1) © Underbit Technologies Inc").arg(MAD_VERSION);
|
Chris@93
|
4348 #else
|
Chris@93
|
4349 aboutText += tr("<br>With MAD mp3 decoder © Underbit Technologies Inc");
|
Chris@93
|
4350 #endif
|
Chris@0
|
4351 #endif
|
Chris@0
|
4352 #ifdef HAVE_SAMPLERATE
|
Chris@93
|
4353 #ifdef SAMPLERATE_VERSION
|
Chris@0
|
4354 aboutText += tr("<br>With libsamplerate (v%1) © Erik de Castro Lopo").arg(SAMPLERATE_VERSION);
|
Chris@93
|
4355 #else
|
Chris@93
|
4356 aboutText += tr("<br>With libsamplerate © Erik de Castro Lopo");
|
Chris@93
|
4357 #endif
|
Chris@0
|
4358 #endif
|
Chris@0
|
4359 #ifdef HAVE_SNDFILE
|
Chris@93
|
4360 #ifdef SNDFILE_VERSION
|
Chris@0
|
4361 aboutText += tr("<br>With libsndfile (v%1) © Erik de Castro Lopo").arg(SNDFILE_VERSION);
|
Chris@93
|
4362 #else
|
Chris@93
|
4363 aboutText += tr("<br>With libsndfile © Erik de Castro Lopo");
|
Chris@93
|
4364 #endif
|
Chris@0
|
4365 #endif
|
Chris@0
|
4366 #ifdef HAVE_FFTW3
|
Chris@93
|
4367 #ifdef FFTW3_VERSION
|
Chris@0
|
4368 aboutText += tr("<br>With FFTW3 (v%1) © Matteo Frigo and MIT").arg(FFTW3_VERSION);
|
Chris@93
|
4369 #else
|
Chris@93
|
4370 aboutText += tr("<br>With FFTW3 © Matteo Frigo and MIT");
|
Chris@93
|
4371 #endif
|
Chris@0
|
4372 #endif
|
Chris@0
|
4373 #ifdef HAVE_VAMP
|
Chris@0
|
4374 aboutText += tr("<br>With Vamp plugin support (API v%1, SDK v%2) © Chris Cannam").arg(VAMP_API_VERSION).arg(VAMP_SDK_VERSION);
|
Chris@0
|
4375 #endif
|
Chris@0
|
4376 aboutText += tr("<br>With LADSPA plugin support (API v%1) © Richard Furse, Paul Davis, Stefan Westerfeld").arg(LADSPA_VERSION);
|
Chris@0
|
4377 aboutText += tr("<br>With DSSI plugin support (API v%1) © Chris Cannam, Steve Harris, Sean Bolton").arg(DSSI_VERSION);
|
Chris@69
|
4378 #ifdef HAVE_LIBLO
|
Chris@93
|
4379 #ifdef LIBLO_VERSION
|
Chris@69
|
4380 aboutText += tr("<br>With liblo Lite OSC library (v%1) © Steve Harris").arg(LIBLO_VERSION);
|
Chris@93
|
4381 #else
|
Chris@93
|
4382 aboutText += tr("<br>With liblo Lite OSC library © Steve Harris").arg(LIBLO_VERSION);
|
Chris@93
|
4383 #endif
|
Chris@70
|
4384 if (m_oscQueue && m_oscQueue->isOK()) {
|
Chris@69
|
4385 aboutText += tr("<p>The OSC URL for this instance is: \"%1\"").arg(m_oscQueue->getOSCURL());
|
Chris@69
|
4386 }
|
Chris@69
|
4387 #endif
|
Chris@0
|
4388 aboutText += "</p>";
|
Chris@0
|
4389 #endif
|
Chris@0
|
4390
|
Chris@0
|
4391 aboutText +=
|
Chris@90
|
4392 "<p>Sonic Visualiser Copyright © 2005 - 2007 Chris Cannam and<br>"
|
Chris@90
|
4393 "Queen Mary, University of London.</p>"
|
Chris@0
|
4394 "<p>This program is free software; you can redistribute it and/or<br>"
|
Chris@0
|
4395 "modify it under the terms of the GNU General Public License as<br>"
|
Chris@0
|
4396 "published by the Free Software Foundation; either version 2 of the<br>"
|
Chris@0
|
4397 "License, or (at your option) any later version.<br>See the file "
|
Chris@0
|
4398 "COPYING included with this distribution for more information.</p>";
|
Chris@0
|
4399
|
Chris@0
|
4400 QMessageBox::about(this, tr("About Sonic Visualiser"), aboutText);
|
Chris@0
|
4401 }
|
Chris@0
|
4402
|
Chris@0
|
4403
|
Chris@0
|
4404 #ifdef INCLUDE_MOCFILES
|
Chris@0
|
4405 #include "MainWindow.moc.cpp"
|
Chris@0
|
4406 #endif
|