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