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