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