Chris@45
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@45
|
2
|
Chris@45
|
3 /*
|
Chris@45
|
4 Sonic Visualiser
|
Chris@45
|
5 An audio file viewer and annotation editor.
|
Chris@45
|
6 Centre for Digital Music, Queen Mary, University of London.
|
Chris@45
|
7 This file copyright 2006-2007 Chris Cannam and QMUL.
|
Chris@45
|
8
|
Chris@45
|
9 This program is free software; you can redistribute it and/or
|
Chris@45
|
10 modify it under the terms of the GNU General Public License as
|
Chris@45
|
11 published by the Free Software Foundation; either version 2 of the
|
Chris@45
|
12 License, or (at your option) any later version. See the file
|
Chris@45
|
13 COPYING included with this distribution for more information.
|
Chris@45
|
14 */
|
Chris@45
|
15
|
Chris@45
|
16 #include "MainWindowBase.h"
|
Chris@46
|
17 #include "Document.h"
|
Chris@45
|
18
|
Chris@45
|
19
|
Chris@45
|
20 #include "view/Pane.h"
|
Chris@45
|
21 #include "view/PaneStack.h"
|
Chris@45
|
22 #include "data/model/WaveFileModel.h"
|
Chris@45
|
23 #include "data/model/SparseOneDimensionalModel.h"
|
Chris@45
|
24 #include "data/model/NoteModel.h"
|
Chris@45
|
25 #include "data/model/Labeller.h"
|
Chris@45
|
26 #include "view/ViewManager.h"
|
Chris@45
|
27
|
Chris@45
|
28 #include "layer/WaveformLayer.h"
|
Chris@45
|
29 #include "layer/TimeRulerLayer.h"
|
Chris@45
|
30 #include "layer/TimeInstantLayer.h"
|
Chris@45
|
31 #include "layer/TimeValueLayer.h"
|
Chris@45
|
32 #include "layer/Colour3DPlotLayer.h"
|
Chris@45
|
33 #include "layer/SliceLayer.h"
|
Chris@45
|
34 #include "layer/SliceableLayer.h"
|
Chris@45
|
35 #include "layer/ImageLayer.h"
|
Chris@45
|
36
|
Chris@45
|
37 #include "widgets/ListInputDialog.h"
|
Chris@105
|
38 #include "widgets/CommandHistory.h"
|
Chris@109
|
39 #include "widgets/ProgressDialog.h"
|
Chris@109
|
40 #include "widgets/MIDIFileImportDialog.h"
|
Chris@109
|
41 #include "widgets/CSVFormatDialog.h"
|
Chris@45
|
42
|
Chris@45
|
43 #include "audioio/AudioCallbackPlaySource.h"
|
Chris@45
|
44 #include "audioio/AudioCallbackPlayTarget.h"
|
Chris@45
|
45 #include "audioio/AudioTargetFactory.h"
|
Chris@45
|
46 #include "audioio/PlaySpeedRangeMapper.h"
|
Chris@45
|
47 #include "data/fileio/DataFileReaderFactory.h"
|
Chris@45
|
48 #include "data/fileio/PlaylistFileReader.h"
|
Chris@45
|
49 #include "data/fileio/WavFileWriter.h"
|
Chris@45
|
50 #include "data/fileio/CSVFileWriter.h"
|
Chris@45
|
51 #include "data/fileio/MIDIFileWriter.h"
|
Chris@45
|
52 #include "data/fileio/BZipFileDevice.h"
|
Chris@45
|
53 #include "data/fileio/FileSource.h"
|
Chris@45
|
54
|
Chris@45
|
55 #include "data/fft/FFTDataServer.h"
|
Chris@45
|
56
|
Chris@45
|
57 #include "base/RecentFiles.h"
|
Chris@45
|
58
|
Chris@45
|
59 #include "base/PlayParameterRepository.h"
|
Chris@45
|
60 #include "base/XmlExportable.h"
|
Chris@45
|
61 #include "base/Profiler.h"
|
Chris@45
|
62 #include "base/Preferences.h"
|
Chris@45
|
63
|
Chris@45
|
64 #include "data/osc/OSCQueue.h"
|
Chris@45
|
65
|
Chris@45
|
66 #include <QApplication>
|
Chris@45
|
67 #include <QMessageBox>
|
Chris@45
|
68 #include <QGridLayout>
|
Chris@45
|
69 #include <QLabel>
|
Chris@45
|
70 #include <QAction>
|
Chris@45
|
71 #include <QMenuBar>
|
Chris@45
|
72 #include <QToolBar>
|
Chris@45
|
73 #include <QInputDialog>
|
Chris@45
|
74 #include <QStatusBar>
|
Chris@45
|
75 #include <QTreeView>
|
Chris@45
|
76 #include <QFile>
|
Chris@45
|
77 #include <QFileInfo>
|
Chris@45
|
78 #include <QDir>
|
Chris@45
|
79 #include <QTextStream>
|
Chris@45
|
80 #include <QProcess>
|
Chris@45
|
81 #include <QShortcut>
|
Chris@45
|
82 #include <QSettings>
|
Chris@45
|
83 #include <QDateTime>
|
Chris@45
|
84 #include <QProcess>
|
Chris@45
|
85 #include <QCheckBox>
|
Chris@45
|
86 #include <QRegExp>
|
Chris@45
|
87 #include <QScrollArea>
|
Chris@45
|
88
|
Chris@45
|
89 #include <iostream>
|
Chris@45
|
90 #include <cstdio>
|
Chris@45
|
91 #include <errno.h>
|
Chris@45
|
92
|
Chris@45
|
93 using std::cerr;
|
Chris@45
|
94 using std::endl;
|
Chris@45
|
95
|
Chris@45
|
96 using std::vector;
|
Chris@45
|
97 using std::map;
|
Chris@45
|
98 using std::set;
|
Chris@45
|
99
|
Chris@45
|
100
|
Chris@45
|
101 MainWindowBase::MainWindowBase(bool withAudioOutput, bool withOSCSupport) :
|
Chris@45
|
102 m_document(0),
|
Chris@45
|
103 m_paneStack(0),
|
Chris@45
|
104 m_viewManager(0),
|
Chris@45
|
105 m_timeRulerLayer(0),
|
Chris@45
|
106 m_audioOutput(withAudioOutput),
|
Chris@45
|
107 m_playSource(0),
|
Chris@45
|
108 m_playTarget(0),
|
Chris@113
|
109 m_oscQueue(0),
|
Chris@113
|
110 m_oscQueueStarter(0),
|
Chris@45
|
111 m_recentFiles("RecentFiles", 20),
|
Chris@54
|
112 m_recentTransforms("RecentTransforms", 20),
|
Chris@45
|
113 m_documentModified(false),
|
Chris@45
|
114 m_openingAudioFile(false),
|
Chris@45
|
115 m_abandoning(false),
|
Chris@45
|
116 m_labeller(0)
|
Chris@45
|
117 {
|
Chris@113
|
118 Profiler profiler("MainWindowBase::MainWindowBase");
|
Chris@113
|
119
|
Chris@45
|
120 connect(CommandHistory::getInstance(), SIGNAL(commandExecuted()),
|
Chris@45
|
121 this, SLOT(documentModified()));
|
Chris@45
|
122 connect(CommandHistory::getInstance(), SIGNAL(documentRestored()),
|
Chris@45
|
123 this, SLOT(documentRestored()));
|
Chris@45
|
124
|
Chris@45
|
125 m_viewManager = new ViewManager();
|
Chris@45
|
126 connect(m_viewManager, SIGNAL(selectionChanged()),
|
Chris@45
|
127 this, SLOT(updateMenuStates()));
|
Chris@45
|
128 connect(m_viewManager, SIGNAL(inProgressSelectionChanged()),
|
Chris@45
|
129 this, SLOT(inProgressSelectionChanged()));
|
Chris@45
|
130
|
Chris@105
|
131 // set a sensible default font size for views -- cannot do this
|
Chris@105
|
132 // in Preferences, which is in base and not supposed to use QtGui
|
Chris@105
|
133 int viewFontSize = QApplication::font().pointSize() * 0.9;
|
Chris@105
|
134 QSettings settings;
|
Chris@105
|
135 settings.beginGroup("Preferences");
|
Chris@105
|
136 viewFontSize = settings.value("view-font-size", viewFontSize).toInt();
|
Chris@105
|
137 settings.setValue("view-font-size", viewFontSize);
|
Chris@105
|
138 settings.endGroup();
|
Chris@105
|
139
|
Chris@45
|
140 Preferences::BackgroundMode mode =
|
Chris@45
|
141 Preferences::getInstance()->getBackgroundMode();
|
Chris@45
|
142 m_initialDarkBackground = m_viewManager->getGlobalDarkBackground();
|
Chris@45
|
143 if (mode != Preferences::BackgroundFromTheme) {
|
Chris@45
|
144 m_viewManager->setGlobalDarkBackground
|
Chris@45
|
145 (mode == Preferences::DarkBackground);
|
Chris@45
|
146 }
|
Chris@45
|
147
|
Chris@45
|
148 m_paneStack = new PaneStack(0, m_viewManager);
|
Chris@45
|
149 connect(m_paneStack, SIGNAL(currentPaneChanged(Pane *)),
|
Chris@45
|
150 this, SLOT(currentPaneChanged(Pane *)));
|
Chris@45
|
151 connect(m_paneStack, SIGNAL(currentLayerChanged(Pane *, Layer *)),
|
Chris@45
|
152 this, SLOT(currentLayerChanged(Pane *, Layer *)));
|
Chris@45
|
153 connect(m_paneStack, SIGNAL(rightButtonMenuRequested(Pane *, QPoint)),
|
Chris@45
|
154 this, SLOT(rightButtonMenuRequested(Pane *, QPoint)));
|
Chris@45
|
155 connect(m_paneStack, SIGNAL(contextHelpChanged(const QString &)),
|
Chris@45
|
156 this, SLOT(contextHelpChanged(const QString &)));
|
Chris@45
|
157 connect(m_paneStack, SIGNAL(paneAdded(Pane *)),
|
Chris@45
|
158 this, SLOT(paneAdded(Pane *)));
|
Chris@45
|
159 connect(m_paneStack, SIGNAL(paneHidden(Pane *)),
|
Chris@45
|
160 this, SLOT(paneHidden(Pane *)));
|
Chris@45
|
161 connect(m_paneStack, SIGNAL(paneAboutToBeDeleted(Pane *)),
|
Chris@45
|
162 this, SLOT(paneAboutToBeDeleted(Pane *)));
|
Chris@45
|
163 connect(m_paneStack, SIGNAL(dropAccepted(Pane *, QStringList)),
|
Chris@45
|
164 this, SLOT(paneDropAccepted(Pane *, QStringList)));
|
Chris@45
|
165 connect(m_paneStack, SIGNAL(dropAccepted(Pane *, QString)),
|
Chris@45
|
166 this, SLOT(paneDropAccepted(Pane *, QString)));
|
Chris@55
|
167 connect(m_paneStack, SIGNAL(paneDeleteButtonClicked(Pane *)),
|
Chris@55
|
168 this, SLOT(paneDeleteButtonClicked(Pane *)));
|
Chris@45
|
169
|
Chris@57
|
170 m_playSource = new AudioCallbackPlaySource(m_viewManager,
|
Chris@57
|
171 QApplication::applicationName());
|
Chris@45
|
172
|
Chris@45
|
173 connect(m_playSource, SIGNAL(sampleRateMismatch(size_t, size_t, bool)),
|
Chris@45
|
174 this, SLOT(sampleRateMismatch(size_t, size_t, bool)));
|
Chris@45
|
175 connect(m_playSource, SIGNAL(audioOverloadPluginDisabled()),
|
Chris@45
|
176 this, SLOT(audioOverloadPluginDisabled()));
|
Chris@45
|
177
|
Chris@45
|
178 connect(m_viewManager, SIGNAL(outputLevelsChanged(float, float)),
|
Chris@45
|
179 this, SLOT(outputLevelsChanged(float, float)));
|
Chris@45
|
180
|
Chris@45
|
181 connect(m_viewManager, SIGNAL(playbackFrameChanged(unsigned long)),
|
Chris@45
|
182 this, SLOT(playbackFrameChanged(unsigned long)));
|
Chris@45
|
183
|
Chris@45
|
184 connect(m_viewManager, SIGNAL(globalCentreFrameChanged(unsigned long)),
|
Chris@45
|
185 this, SLOT(globalCentreFrameChanged(unsigned long)));
|
Chris@45
|
186
|
Chris@45
|
187 connect(m_viewManager, SIGNAL(viewCentreFrameChanged(View *, unsigned long)),
|
Chris@45
|
188 this, SLOT(viewCentreFrameChanged(View *, unsigned long)));
|
Chris@45
|
189
|
Chris@45
|
190 connect(m_viewManager, SIGNAL(viewZoomLevelChanged(View *, unsigned long, bool)),
|
Chris@45
|
191 this, SLOT(viewZoomLevelChanged(View *, unsigned long, bool)));
|
Chris@45
|
192
|
Chris@45
|
193 connect(Preferences::getInstance(),
|
Chris@45
|
194 SIGNAL(propertyChanged(PropertyContainer::PropertyName)),
|
Chris@45
|
195 this,
|
Chris@45
|
196 SLOT(preferenceChanged(PropertyContainer::PropertyName)));
|
Chris@45
|
197
|
Chris@45
|
198 Labeller::ValueType labellerType = Labeller::ValueFromTwoLevelCounter;
|
Chris@45
|
199 settings.beginGroup("MainWindow");
|
Chris@45
|
200 labellerType = (Labeller::ValueType)
|
Chris@45
|
201 settings.value("labellertype", (int)labellerType).toInt();
|
Chris@45
|
202 int cycle = settings.value("labellercycle", 4).toInt();
|
Chris@45
|
203 settings.endGroup();
|
Chris@45
|
204
|
Chris@45
|
205 m_labeller = new Labeller(labellerType);
|
Chris@45
|
206 m_labeller->setCounterCycleSize(cycle);
|
Chris@113
|
207
|
Chris@113
|
208 if (withOSCSupport) {
|
Chris@113
|
209 m_oscQueueStarter = new OSCQueueStarter(this);
|
Chris@113
|
210 connect(m_oscQueueStarter, SIGNAL(finished()), this, SLOT(oscReady()));
|
Chris@113
|
211 m_oscQueueStarter->start();
|
Chris@113
|
212 }
|
Chris@45
|
213 }
|
Chris@45
|
214
|
Chris@45
|
215 MainWindowBase::~MainWindowBase()
|
Chris@45
|
216 {
|
Chris@70
|
217 if (m_playTarget) m_playTarget->shutdown();
|
Chris@70
|
218 // delete m_playTarget;
|
Chris@45
|
219 delete m_playSource;
|
Chris@45
|
220 delete m_viewManager;
|
Chris@45
|
221 delete m_oscQueue;
|
Chris@45
|
222 Profiles::getInstance()->dump();
|
Chris@45
|
223 }
|
Chris@45
|
224
|
Chris@113
|
225 void
|
Chris@113
|
226 MainWindowBase::oscReady()
|
Chris@113
|
227 {
|
Chris@113
|
228 if (m_oscQueue && m_oscQueue->isOK()) {
|
Chris@113
|
229 connect(m_oscQueue, SIGNAL(messagesAvailable()), this, SLOT(pollOSC()));
|
Chris@113
|
230 QTimer *oscTimer = new QTimer(this);
|
Chris@113
|
231 connect(oscTimer, SIGNAL(timeout()), this, SLOT(pollOSC()));
|
Chris@113
|
232 oscTimer->start(1000);
|
Chris@113
|
233 std::cerr << "Finished setting up OSC interface" << std::endl;
|
Chris@113
|
234 }
|
Chris@113
|
235 }
|
Chris@113
|
236
|
Chris@45
|
237 QString
|
Chris@45
|
238 MainWindowBase::getOpenFileName(FileFinder::FileType type)
|
Chris@45
|
239 {
|
Chris@45
|
240 FileFinder *ff = FileFinder::getInstance();
|
Chris@45
|
241 switch (type) {
|
Chris@45
|
242 case FileFinder::SessionFile:
|
Chris@45
|
243 return ff->getOpenFileName(type, m_sessionFile);
|
Chris@45
|
244 case FileFinder::AudioFile:
|
Chris@45
|
245 return ff->getOpenFileName(type, m_audioFile);
|
Chris@45
|
246 case FileFinder::LayerFile:
|
Chris@45
|
247 return ff->getOpenFileName(type, m_sessionFile);
|
Chris@45
|
248 case FileFinder::LayerFileNoMidi:
|
Chris@45
|
249 return ff->getOpenFileName(type, m_sessionFile);
|
Chris@45
|
250 case FileFinder::SessionOrAudioFile:
|
Chris@45
|
251 return ff->getOpenFileName(type, m_sessionFile);
|
Chris@45
|
252 case FileFinder::ImageFile:
|
Chris@45
|
253 return ff->getOpenFileName(type, m_sessionFile);
|
Chris@45
|
254 case FileFinder::AnyFile:
|
Chris@45
|
255 if (getMainModel() != 0 &&
|
Chris@45
|
256 m_paneStack != 0 &&
|
Chris@45
|
257 m_paneStack->getCurrentPane() != 0) { // can import a layer
|
Chris@45
|
258 return ff->getOpenFileName(FileFinder::AnyFile, m_sessionFile);
|
Chris@45
|
259 } else {
|
Chris@45
|
260 return ff->getOpenFileName(FileFinder::SessionOrAudioFile,
|
Chris@45
|
261 m_sessionFile);
|
Chris@45
|
262 }
|
Chris@45
|
263 }
|
Chris@45
|
264 return "";
|
Chris@45
|
265 }
|
Chris@45
|
266
|
Chris@45
|
267 QString
|
Chris@45
|
268 MainWindowBase::getSaveFileName(FileFinder::FileType type)
|
Chris@45
|
269 {
|
Chris@45
|
270 FileFinder *ff = FileFinder::getInstance();
|
Chris@45
|
271 switch (type) {
|
Chris@45
|
272 case FileFinder::SessionFile:
|
Chris@45
|
273 return ff->getSaveFileName(type, m_sessionFile);
|
Chris@45
|
274 case FileFinder::AudioFile:
|
Chris@45
|
275 return ff->getSaveFileName(type, m_audioFile);
|
Chris@45
|
276 case FileFinder::LayerFile:
|
Chris@45
|
277 return ff->getSaveFileName(type, m_sessionFile);
|
Chris@45
|
278 case FileFinder::LayerFileNoMidi:
|
Chris@45
|
279 return ff->getSaveFileName(type, m_sessionFile);
|
Chris@45
|
280 case FileFinder::SessionOrAudioFile:
|
Chris@45
|
281 return ff->getSaveFileName(type, m_sessionFile);
|
Chris@45
|
282 case FileFinder::ImageFile:
|
Chris@45
|
283 return ff->getSaveFileName(type, m_sessionFile);
|
Chris@45
|
284 case FileFinder::AnyFile:
|
Chris@45
|
285 return ff->getSaveFileName(type, m_sessionFile);
|
Chris@45
|
286 }
|
Chris@45
|
287 return "";
|
Chris@45
|
288 }
|
Chris@45
|
289
|
Chris@45
|
290 void
|
Chris@45
|
291 MainWindowBase::registerLastOpenedFilePath(FileFinder::FileType type, QString path)
|
Chris@45
|
292 {
|
Chris@45
|
293 FileFinder *ff = FileFinder::getInstance();
|
Chris@45
|
294 ff->registerLastOpenedFilePath(type, path);
|
Chris@45
|
295 }
|
Chris@45
|
296
|
Chris@45
|
297 void
|
Chris@45
|
298 MainWindowBase::updateMenuStates()
|
Chris@45
|
299 {
|
Chris@45
|
300 Pane *currentPane = 0;
|
Chris@45
|
301 Layer *currentLayer = 0;
|
Chris@45
|
302
|
Chris@45
|
303 if (m_paneStack) currentPane = m_paneStack->getCurrentPane();
|
Chris@45
|
304 if (currentPane) currentLayer = currentPane->getSelectedLayer();
|
Chris@45
|
305
|
Chris@73
|
306 bool havePrevPane = false, haveNextPane = false;
|
Chris@73
|
307 bool havePrevLayer = false, haveNextLayer = false;
|
Chris@73
|
308
|
Chris@73
|
309 if (currentPane) {
|
Chris@73
|
310 for (int i = 0; i < m_paneStack->getPaneCount(); ++i) {
|
Chris@73
|
311 if (m_paneStack->getPane(i) == currentPane) {
|
Chris@73
|
312 if (i > 0) havePrevPane = true;
|
Chris@73
|
313 if (i < m_paneStack->getPaneCount()-1) haveNextPane = true;
|
Chris@73
|
314 break;
|
Chris@73
|
315 }
|
Chris@73
|
316 }
|
Chris@73
|
317 if (currentLayer) {
|
Chris@73
|
318 for (int i = 0; i < currentPane->getLayerCount(); ++i) {
|
Chris@73
|
319 if (currentPane->getLayer(i) == currentLayer) {
|
Chris@73
|
320 if (i > 0) havePrevLayer = true;
|
Chris@73
|
321 if (i < currentPane->getLayerCount()-1) haveNextLayer = true;
|
Chris@73
|
322 break;
|
Chris@73
|
323 }
|
Chris@73
|
324 }
|
Chris@73
|
325 }
|
Chris@73
|
326 }
|
Chris@73
|
327
|
Chris@45
|
328 bool haveCurrentPane =
|
Chris@45
|
329 (currentPane != 0);
|
Chris@45
|
330 bool haveCurrentLayer =
|
Chris@45
|
331 (haveCurrentPane &&
|
Chris@45
|
332 (currentLayer != 0));
|
Chris@45
|
333 bool haveMainModel =
|
Chris@45
|
334 (getMainModel() != 0);
|
Chris@45
|
335 bool havePlayTarget =
|
Chris@45
|
336 (m_playTarget != 0);
|
Chris@45
|
337 bool haveSelection =
|
Chris@45
|
338 (m_viewManager &&
|
Chris@45
|
339 !m_viewManager->getSelections().empty());
|
Chris@45
|
340 bool haveCurrentEditableLayer =
|
Chris@45
|
341 (haveCurrentLayer &&
|
Chris@45
|
342 currentLayer->isLayerEditable());
|
Chris@45
|
343 bool haveCurrentTimeInstantsLayer =
|
Chris@45
|
344 (haveCurrentLayer &&
|
Chris@45
|
345 dynamic_cast<TimeInstantLayer *>(currentLayer));
|
Chris@45
|
346 bool haveCurrentColour3DPlot =
|
Chris@45
|
347 (haveCurrentLayer &&
|
Chris@45
|
348 dynamic_cast<Colour3DPlotLayer *>(currentLayer));
|
Chris@45
|
349 bool haveClipboardContents =
|
Chris@45
|
350 (m_viewManager &&
|
Chris@45
|
351 !m_viewManager->getClipboard().empty());
|
Chris@45
|
352
|
Chris@45
|
353 emit canAddPane(haveMainModel);
|
Chris@45
|
354 emit canDeleteCurrentPane(haveCurrentPane);
|
Chris@45
|
355 emit canZoom(haveMainModel && haveCurrentPane);
|
Chris@45
|
356 emit canScroll(haveMainModel && haveCurrentPane);
|
Chris@45
|
357 emit canAddLayer(haveMainModel && haveCurrentPane);
|
Chris@45
|
358 emit canImportMoreAudio(haveMainModel);
|
Chris@45
|
359 emit canImportLayer(haveMainModel && haveCurrentPane);
|
Chris@45
|
360 emit canExportAudio(haveMainModel);
|
Chris@45
|
361 emit canExportLayer(haveMainModel &&
|
Chris@45
|
362 (haveCurrentEditableLayer || haveCurrentColour3DPlot));
|
Chris@45
|
363 emit canExportImage(haveMainModel && haveCurrentPane);
|
Chris@45
|
364 emit canDeleteCurrentLayer(haveCurrentLayer);
|
Chris@45
|
365 emit canRenameLayer(haveCurrentLayer);
|
Chris@45
|
366 emit canEditLayer(haveCurrentEditableLayer);
|
Chris@45
|
367 emit canMeasureLayer(haveCurrentLayer);
|
Chris@45
|
368 emit canSelect(haveMainModel && haveCurrentPane);
|
Chris@45
|
369 emit canPlay(havePlayTarget);
|
Chris@45
|
370 emit canFfwd(true);
|
Chris@45
|
371 emit canRewind(true);
|
Chris@87
|
372 emit canPaste(haveClipboardContents);
|
Chris@45
|
373 emit canInsertInstant(haveCurrentPane);
|
Chris@45
|
374 emit canInsertInstantsAtBoundaries(haveCurrentPane && haveSelection);
|
Chris@45
|
375 emit canRenumberInstants(haveCurrentTimeInstantsLayer && haveSelection);
|
Chris@45
|
376 emit canPlaySelection(haveMainModel && havePlayTarget && haveSelection);
|
Chris@45
|
377 emit canClearSelection(haveSelection);
|
Chris@45
|
378 emit canEditSelection(haveSelection && haveCurrentEditableLayer);
|
Chris@45
|
379 emit canSave(m_sessionFile != "" && m_documentModified);
|
Chris@73
|
380 emit canSelectPreviousPane(havePrevPane);
|
Chris@73
|
381 emit canSelectNextPane(haveNextPane);
|
Chris@73
|
382 emit canSelectPreviousLayer(havePrevLayer);
|
Chris@73
|
383 emit canSelectNextLayer(haveNextLayer);
|
Chris@45
|
384 }
|
Chris@45
|
385
|
Chris@45
|
386 void
|
Chris@45
|
387 MainWindowBase::documentModified()
|
Chris@45
|
388 {
|
Chris@45
|
389 // std::cerr << "MainWindowBase::documentModified" << std::endl;
|
Chris@45
|
390
|
Chris@45
|
391 if (!m_documentModified) {
|
Chris@45
|
392 //!!! this in subclass implementation?
|
Chris@45
|
393 setWindowTitle(tr("%1 (modified)").arg(windowTitle()));
|
Chris@45
|
394 }
|
Chris@45
|
395
|
Chris@45
|
396 m_documentModified = true;
|
Chris@45
|
397 updateMenuStates();
|
Chris@45
|
398 }
|
Chris@45
|
399
|
Chris@45
|
400 void
|
Chris@45
|
401 MainWindowBase::documentRestored()
|
Chris@45
|
402 {
|
Chris@45
|
403 // std::cerr << "MainWindowBase::documentRestored" << std::endl;
|
Chris@45
|
404
|
Chris@45
|
405 if (m_documentModified) {
|
Chris@45
|
406 //!!! this in subclass implementation?
|
Chris@45
|
407 QString wt(windowTitle());
|
Chris@45
|
408 wt.replace(tr(" (modified)"), "");
|
Chris@45
|
409 setWindowTitle(wt);
|
Chris@45
|
410 }
|
Chris@45
|
411
|
Chris@45
|
412 m_documentModified = false;
|
Chris@45
|
413 updateMenuStates();
|
Chris@45
|
414 }
|
Chris@45
|
415
|
Chris@45
|
416 void
|
Chris@45
|
417 MainWindowBase::playLoopToggled()
|
Chris@45
|
418 {
|
Chris@45
|
419 QAction *action = dynamic_cast<QAction *>(sender());
|
Chris@45
|
420
|
Chris@45
|
421 if (action) {
|
Chris@45
|
422 m_viewManager->setPlayLoopMode(action->isChecked());
|
Chris@45
|
423 } else {
|
Chris@45
|
424 m_viewManager->setPlayLoopMode(!m_viewManager->getPlayLoopMode());
|
Chris@45
|
425 }
|
Chris@45
|
426 }
|
Chris@45
|
427
|
Chris@45
|
428 void
|
Chris@45
|
429 MainWindowBase::playSelectionToggled()
|
Chris@45
|
430 {
|
Chris@45
|
431 QAction *action = dynamic_cast<QAction *>(sender());
|
Chris@45
|
432
|
Chris@45
|
433 if (action) {
|
Chris@45
|
434 m_viewManager->setPlaySelectionMode(action->isChecked());
|
Chris@45
|
435 } else {
|
Chris@45
|
436 m_viewManager->setPlaySelectionMode(!m_viewManager->getPlaySelectionMode());
|
Chris@45
|
437 }
|
Chris@45
|
438 }
|
Chris@45
|
439
|
Chris@45
|
440 void
|
Chris@45
|
441 MainWindowBase::playSoloToggled()
|
Chris@45
|
442 {
|
Chris@45
|
443 QAction *action = dynamic_cast<QAction *>(sender());
|
Chris@45
|
444
|
Chris@45
|
445 if (action) {
|
Chris@45
|
446 m_viewManager->setPlaySoloMode(action->isChecked());
|
Chris@45
|
447 } else {
|
Chris@45
|
448 m_viewManager->setPlaySoloMode(!m_viewManager->getPlaySoloMode());
|
Chris@45
|
449 }
|
Chris@45
|
450
|
Chris@45
|
451 if (m_viewManager->getPlaySoloMode()) {
|
Chris@45
|
452 currentPaneChanged(m_paneStack->getCurrentPane());
|
Chris@45
|
453 } else {
|
Chris@45
|
454 m_viewManager->setPlaybackModel(0);
|
Chris@45
|
455 if (m_playSource) {
|
Chris@45
|
456 m_playSource->clearSoloModelSet();
|
Chris@45
|
457 }
|
Chris@45
|
458 }
|
Chris@45
|
459 }
|
Chris@45
|
460
|
Chris@45
|
461 void
|
Chris@45
|
462 MainWindowBase::currentPaneChanged(Pane *p)
|
Chris@45
|
463 {
|
Chris@45
|
464 updateMenuStates();
|
Chris@45
|
465 updateVisibleRangeDisplay(p);
|
Chris@45
|
466
|
Chris@45
|
467 if (!p) return;
|
Chris@45
|
468
|
Chris@45
|
469 if (!(m_viewManager &&
|
Chris@45
|
470 m_playSource &&
|
Chris@45
|
471 m_viewManager->getPlaySoloMode())) {
|
Chris@45
|
472 if (m_viewManager) m_viewManager->setPlaybackModel(0);
|
Chris@45
|
473 return;
|
Chris@45
|
474 }
|
Chris@45
|
475
|
Chris@45
|
476 Model *prevPlaybackModel = m_viewManager->getPlaybackModel();
|
Chris@60
|
477
|
Chris@93
|
478 // What we want here is not the currently playing frame (unless we
|
Chris@93
|
479 // are about to clear out the audio playback buffers -- which may
|
Chris@93
|
480 // or may not be possible, depending on the audio driver). What
|
Chris@93
|
481 // we want is the frame that was last committed to the soundcard
|
Chris@93
|
482 // buffers, as the audio driver will continue playing up to that
|
Chris@93
|
483 // frame before switching to whichever one we decide we want to
|
Chris@93
|
484 // switch to, regardless of our efforts.
|
Chris@93
|
485
|
Chris@93
|
486 int frame = m_playSource->getCurrentBufferedFrame();
|
Chris@93
|
487
|
Chris@93
|
488 // std::cerr << "currentPaneChanged: current frame (in ref model) = " << frame << std::endl;
|
Chris@45
|
489
|
Chris@45
|
490 View::ModelSet soloModels = p->getModels();
|
Chris@45
|
491
|
Chris@57
|
492 View::ModelSet sources;
|
Chris@57
|
493 for (View::ModelSet::iterator mi = soloModels.begin();
|
Chris@57
|
494 mi != soloModels.end(); ++mi) {
|
Chris@57
|
495 if (*mi && (*mi)->getSourceModel()) {
|
Chris@57
|
496 sources.insert((*mi)->getSourceModel());
|
Chris@57
|
497 }
|
Chris@57
|
498 }
|
Chris@57
|
499 for (View::ModelSet::iterator mi = sources.begin();
|
Chris@57
|
500 mi != sources.end(); ++mi) {
|
Chris@57
|
501 soloModels.insert(*mi);
|
Chris@57
|
502 }
|
Chris@57
|
503
|
Chris@60
|
504 //!!! Need an "atomic" way of telling the play source that the
|
Chris@60
|
505 //playback model has changed, and changing it on ViewManager --
|
Chris@60
|
506 //the play source should be making the setPlaybackModel call to
|
Chris@60
|
507 //ViewManager
|
Chris@60
|
508
|
Chris@45
|
509 for (View::ModelSet::iterator mi = soloModels.begin();
|
Chris@45
|
510 mi != soloModels.end(); ++mi) {
|
Chris@45
|
511 if (dynamic_cast<RangeSummarisableTimeValueModel *>(*mi)) {
|
Chris@45
|
512 m_viewManager->setPlaybackModel(*mi);
|
Chris@45
|
513 }
|
Chris@45
|
514 }
|
Chris@45
|
515
|
Chris@45
|
516 RangeSummarisableTimeValueModel *a =
|
Chris@45
|
517 dynamic_cast<RangeSummarisableTimeValueModel *>(prevPlaybackModel);
|
Chris@45
|
518 RangeSummarisableTimeValueModel *b =
|
Chris@45
|
519 dynamic_cast<RangeSummarisableTimeValueModel *>(m_viewManager->
|
Chris@45
|
520 getPlaybackModel());
|
Chris@45
|
521
|
Chris@45
|
522 m_playSource->setSoloModelSet(soloModels);
|
Chris@45
|
523
|
Chris@45
|
524 if (a && b && (a != b)) {
|
Chris@60
|
525 if (m_playSource->isPlaying()) m_playSource->play(frame);
|
Chris@45
|
526 }
|
Chris@45
|
527 }
|
Chris@45
|
528
|
Chris@45
|
529 void
|
Chris@45
|
530 MainWindowBase::currentLayerChanged(Pane *p, Layer *)
|
Chris@45
|
531 {
|
Chris@45
|
532 updateMenuStates();
|
Chris@45
|
533 updateVisibleRangeDisplay(p);
|
Chris@45
|
534 }
|
Chris@45
|
535
|
Chris@45
|
536 void
|
Chris@45
|
537 MainWindowBase::selectAll()
|
Chris@45
|
538 {
|
Chris@45
|
539 if (!getMainModel()) return;
|
Chris@45
|
540 m_viewManager->setSelection(Selection(getMainModel()->getStartFrame(),
|
Chris@45
|
541 getMainModel()->getEndFrame()));
|
Chris@45
|
542 }
|
Chris@45
|
543
|
Chris@45
|
544 void
|
Chris@45
|
545 MainWindowBase::selectToStart()
|
Chris@45
|
546 {
|
Chris@45
|
547 if (!getMainModel()) return;
|
Chris@45
|
548 m_viewManager->setSelection(Selection(getMainModel()->getStartFrame(),
|
Chris@45
|
549 m_viewManager->getGlobalCentreFrame()));
|
Chris@45
|
550 }
|
Chris@45
|
551
|
Chris@45
|
552 void
|
Chris@45
|
553 MainWindowBase::selectToEnd()
|
Chris@45
|
554 {
|
Chris@45
|
555 if (!getMainModel()) return;
|
Chris@45
|
556 m_viewManager->setSelection(Selection(m_viewManager->getGlobalCentreFrame(),
|
Chris@45
|
557 getMainModel()->getEndFrame()));
|
Chris@45
|
558 }
|
Chris@45
|
559
|
Chris@45
|
560 void
|
Chris@45
|
561 MainWindowBase::selectVisible()
|
Chris@45
|
562 {
|
Chris@45
|
563 Model *model = getMainModel();
|
Chris@45
|
564 if (!model) return;
|
Chris@45
|
565
|
Chris@45
|
566 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@45
|
567 if (!currentPane) return;
|
Chris@45
|
568
|
Chris@45
|
569 size_t startFrame, endFrame;
|
Chris@45
|
570
|
Chris@45
|
571 if (currentPane->getStartFrame() < 0) startFrame = 0;
|
Chris@45
|
572 else startFrame = currentPane->getStartFrame();
|
Chris@45
|
573
|
Chris@45
|
574 if (currentPane->getEndFrame() > model->getEndFrame()) endFrame = model->getEndFrame();
|
Chris@45
|
575 else endFrame = currentPane->getEndFrame();
|
Chris@45
|
576
|
Chris@45
|
577 m_viewManager->setSelection(Selection(startFrame, endFrame));
|
Chris@45
|
578 }
|
Chris@45
|
579
|
Chris@45
|
580 void
|
Chris@45
|
581 MainWindowBase::clearSelection()
|
Chris@45
|
582 {
|
Chris@45
|
583 m_viewManager->clearSelections();
|
Chris@45
|
584 }
|
Chris@45
|
585
|
Chris@45
|
586 void
|
Chris@45
|
587 MainWindowBase::cut()
|
Chris@45
|
588 {
|
Chris@45
|
589 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@45
|
590 if (!currentPane) return;
|
Chris@45
|
591
|
Chris@45
|
592 Layer *layer = currentPane->getSelectedLayer();
|
Chris@45
|
593 if (!layer) return;
|
Chris@45
|
594
|
Chris@45
|
595 Clipboard &clipboard = m_viewManager->getClipboard();
|
Chris@45
|
596 clipboard.clear();
|
Chris@45
|
597
|
Chris@45
|
598 MultiSelection::SelectionList selections = m_viewManager->getSelections();
|
Chris@45
|
599
|
Chris@45
|
600 CommandHistory::getInstance()->startCompoundOperation(tr("Cut"), true);
|
Chris@45
|
601
|
Chris@45
|
602 for (MultiSelection::SelectionList::iterator i = selections.begin();
|
Chris@45
|
603 i != selections.end(); ++i) {
|
Chris@86
|
604 layer->copy(currentPane, *i, clipboard);
|
Chris@45
|
605 layer->deleteSelection(*i);
|
Chris@45
|
606 }
|
Chris@45
|
607
|
Chris@45
|
608 CommandHistory::getInstance()->endCompoundOperation();
|
Chris@45
|
609 }
|
Chris@45
|
610
|
Chris@45
|
611 void
|
Chris@45
|
612 MainWindowBase::copy()
|
Chris@45
|
613 {
|
Chris@45
|
614 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@45
|
615 if (!currentPane) return;
|
Chris@45
|
616
|
Chris@45
|
617 Layer *layer = currentPane->getSelectedLayer();
|
Chris@45
|
618 if (!layer) return;
|
Chris@45
|
619
|
Chris@45
|
620 Clipboard &clipboard = m_viewManager->getClipboard();
|
Chris@45
|
621 clipboard.clear();
|
Chris@45
|
622
|
Chris@45
|
623 MultiSelection::SelectionList selections = m_viewManager->getSelections();
|
Chris@45
|
624
|
Chris@45
|
625 for (MultiSelection::SelectionList::iterator i = selections.begin();
|
Chris@45
|
626 i != selections.end(); ++i) {
|
Chris@86
|
627 layer->copy(currentPane, *i, clipboard);
|
Chris@45
|
628 }
|
Chris@45
|
629 }
|
Chris@45
|
630
|
Chris@45
|
631 void
|
Chris@45
|
632 MainWindowBase::paste()
|
Chris@45
|
633 {
|
Chris@45
|
634 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@45
|
635 if (!currentPane) return;
|
Chris@45
|
636
|
Chris@45
|
637 Layer *layer = currentPane->getSelectedLayer();
|
Chris@45
|
638
|
Chris@45
|
639 Clipboard &clipboard = m_viewManager->getClipboard();
|
Chris@87
|
640 // Clipboard::PointList contents = clipboard.getPoints();
|
Chris@87
|
641
|
Chris@98
|
642 bool inCompound = false;
|
Chris@87
|
643
|
Chris@87
|
644 if (!layer || !layer->isLayerEditable()) {
|
Chris@87
|
645
|
Chris@87
|
646 CommandHistory::getInstance()->startCompoundOperation
|
Chris@87
|
647 (tr("Paste"), true);
|
Chris@87
|
648
|
Chris@87
|
649 // no suitable current layer: create one of the most
|
Chris@87
|
650 // appropriate sort
|
Chris@87
|
651 LayerFactory::LayerType type =
|
Chris@87
|
652 LayerFactory::getInstance()->getLayerTypeForClipboardContents(clipboard);
|
Chris@87
|
653 layer = m_document->createEmptyLayer(type);
|
Chris@87
|
654
|
Chris@87
|
655 if (!layer) {
|
Chris@87
|
656 CommandHistory::getInstance()->endCompoundOperation();
|
Chris@87
|
657 return;
|
Chris@45
|
658 }
|
Chris@87
|
659
|
Chris@87
|
660 m_document->addLayerToView(currentPane, layer);
|
Chris@87
|
661 m_paneStack->setCurrentLayer(currentPane, layer);
|
Chris@87
|
662
|
Chris@87
|
663 inCompound = true;
|
Chris@45
|
664 }
|
Chris@45
|
665
|
Chris@87
|
666 layer->paste(currentPane, clipboard, 0, true);
|
Chris@45
|
667
|
Chris@87
|
668 if (inCompound) CommandHistory::getInstance()->endCompoundOperation();
|
Chris@45
|
669 }
|
Chris@45
|
670
|
Chris@45
|
671 void
|
Chris@45
|
672 MainWindowBase::deleteSelected()
|
Chris@45
|
673 {
|
Chris@45
|
674 if (m_paneStack->getCurrentPane() &&
|
Chris@45
|
675 m_paneStack->getCurrentPane()->getSelectedLayer()) {
|
Chris@45
|
676
|
Chris@45
|
677 Layer *layer = m_paneStack->getCurrentPane()->getSelectedLayer();
|
Chris@45
|
678
|
Chris@45
|
679 if (m_viewManager &&
|
Chris@45
|
680 (m_viewManager->getToolMode() == ViewManager::MeasureMode)) {
|
Chris@45
|
681
|
Chris@45
|
682 layer->deleteCurrentMeasureRect();
|
Chris@45
|
683
|
Chris@45
|
684 } else {
|
Chris@45
|
685
|
Chris@45
|
686 MultiSelection::SelectionList selections =
|
Chris@45
|
687 m_viewManager->getSelections();
|
Chris@45
|
688
|
Chris@45
|
689 for (MultiSelection::SelectionList::iterator i = selections.begin();
|
Chris@45
|
690 i != selections.end(); ++i) {
|
Chris@45
|
691 layer->deleteSelection(*i);
|
Chris@45
|
692 }
|
Chris@45
|
693 }
|
Chris@45
|
694 }
|
Chris@45
|
695 }
|
Chris@45
|
696
|
Chris@45
|
697 void
|
Chris@45
|
698 MainWindowBase::insertInstant()
|
Chris@45
|
699 {
|
Chris@45
|
700 int frame = m_viewManager->getPlaybackFrame();
|
Chris@45
|
701 insertInstantAt(frame);
|
Chris@45
|
702 }
|
Chris@45
|
703
|
Chris@45
|
704 void
|
Chris@45
|
705 MainWindowBase::insertInstantsAtBoundaries()
|
Chris@45
|
706 {
|
Chris@45
|
707 MultiSelection::SelectionList selections = m_viewManager->getSelections();
|
Chris@45
|
708 for (MultiSelection::SelectionList::iterator i = selections.begin();
|
Chris@45
|
709 i != selections.end(); ++i) {
|
Chris@45
|
710 size_t start = i->getStartFrame();
|
Chris@45
|
711 size_t end = i->getEndFrame();
|
Chris@45
|
712 if (start != end) {
|
Chris@45
|
713 insertInstantAt(i->getStartFrame());
|
Chris@45
|
714 insertInstantAt(i->getEndFrame());
|
Chris@45
|
715 }
|
Chris@45
|
716 }
|
Chris@45
|
717 }
|
Chris@45
|
718
|
Chris@45
|
719 void
|
Chris@45
|
720 MainWindowBase::insertInstantAt(size_t frame)
|
Chris@45
|
721 {
|
Chris@45
|
722 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@45
|
723 if (!pane) {
|
Chris@45
|
724 return;
|
Chris@45
|
725 }
|
Chris@45
|
726
|
Chris@74
|
727 frame = pane->alignFromReference(frame);
|
Chris@74
|
728
|
Chris@45
|
729 Layer *layer = dynamic_cast<TimeInstantLayer *>
|
Chris@45
|
730 (pane->getSelectedLayer());
|
Chris@45
|
731
|
Chris@45
|
732 if (!layer) {
|
Chris@45
|
733 for (int i = pane->getLayerCount(); i > 0; --i) {
|
Chris@45
|
734 layer = dynamic_cast<TimeInstantLayer *>(pane->getLayer(i - 1));
|
Chris@45
|
735 if (layer) break;
|
Chris@45
|
736 }
|
Chris@45
|
737
|
Chris@45
|
738 if (!layer) {
|
Chris@45
|
739 CommandHistory::getInstance()->startCompoundOperation
|
Chris@45
|
740 (tr("Add Point"), true);
|
Chris@45
|
741 layer = m_document->createEmptyLayer(LayerFactory::TimeInstants);
|
Chris@45
|
742 if (layer) {
|
Chris@45
|
743 m_document->addLayerToView(pane, layer);
|
Chris@45
|
744 m_paneStack->setCurrentLayer(pane, layer);
|
Chris@45
|
745 }
|
Chris@45
|
746 CommandHistory::getInstance()->endCompoundOperation();
|
Chris@45
|
747 }
|
Chris@45
|
748 }
|
Chris@45
|
749
|
Chris@45
|
750 if (layer) {
|
Chris@45
|
751
|
Chris@45
|
752 Model *model = layer->getModel();
|
Chris@45
|
753 SparseOneDimensionalModel *sodm = dynamic_cast<SparseOneDimensionalModel *>
|
Chris@45
|
754 (model);
|
Chris@45
|
755
|
Chris@45
|
756 if (sodm) {
|
Chris@45
|
757 SparseOneDimensionalModel::Point point(frame, "");
|
Chris@45
|
758
|
Chris@45
|
759 SparseOneDimensionalModel::Point prevPoint(0);
|
Chris@45
|
760 bool havePrevPoint = false;
|
Chris@45
|
761
|
Chris@45
|
762 SparseOneDimensionalModel::EditCommand *command =
|
Chris@45
|
763 new SparseOneDimensionalModel::EditCommand(sodm, tr("Add Point"));
|
Chris@45
|
764
|
Chris@74
|
765 if (m_labeller->requiresPrevPoint()) {
|
Chris@45
|
766
|
Chris@45
|
767 SparseOneDimensionalModel::PointList prevPoints =
|
Chris@45
|
768 sodm->getPreviousPoints(frame);
|
Chris@45
|
769
|
Chris@45
|
770 if (!prevPoints.empty()) {
|
Chris@45
|
771 prevPoint = *prevPoints.begin();
|
Chris@45
|
772 havePrevPoint = true;
|
Chris@45
|
773 }
|
Chris@45
|
774 }
|
Chris@45
|
775
|
Chris@45
|
776 if (m_labeller) {
|
Chris@45
|
777
|
Chris@45
|
778 m_labeller->setSampleRate(sodm->getSampleRate());
|
Chris@45
|
779
|
Chris@74
|
780 if (m_labeller->actingOnPrevPoint()) {
|
Chris@45
|
781 command->deletePoint(prevPoint);
|
Chris@45
|
782 }
|
Chris@45
|
783
|
Chris@45
|
784 m_labeller->label<SparseOneDimensionalModel::Point>
|
Chris@45
|
785 (point, havePrevPoint ? &prevPoint : 0);
|
Chris@45
|
786
|
Chris@74
|
787 if (m_labeller->actingOnPrevPoint()) {
|
Chris@45
|
788 command->addPoint(prevPoint);
|
Chris@45
|
789 }
|
Chris@45
|
790 }
|
Chris@45
|
791
|
Chris@45
|
792 command->addPoint(point);
|
Chris@45
|
793
|
Chris@45
|
794 command->setName(tr("Add Point at %1 s")
|
Chris@45
|
795 .arg(RealTime::frame2RealTime
|
Chris@45
|
796 (frame,
|
Chris@45
|
797 sodm->getSampleRate())
|
Chris@45
|
798 .toText(false).c_str()));
|
Chris@45
|
799
|
Chris@108
|
800 Command *c = command->finish();
|
Chris@108
|
801 if (c) CommandHistory::getInstance()->addCommand(c, false);
|
Chris@45
|
802 }
|
Chris@45
|
803 }
|
Chris@45
|
804 }
|
Chris@45
|
805
|
Chris@45
|
806 void
|
Chris@45
|
807 MainWindowBase::renumberInstants()
|
Chris@45
|
808 {
|
Chris@45
|
809 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@45
|
810 if (!pane) return;
|
Chris@45
|
811
|
Chris@45
|
812 Layer *layer = dynamic_cast<TimeInstantLayer *>(pane->getSelectedLayer());
|
Chris@45
|
813 if (!layer) return;
|
Chris@45
|
814
|
Chris@45
|
815 MultiSelection ms(m_viewManager->getSelection());
|
Chris@45
|
816
|
Chris@45
|
817 Model *model = layer->getModel();
|
Chris@45
|
818 SparseOneDimensionalModel *sodm = dynamic_cast<SparseOneDimensionalModel *>
|
Chris@45
|
819 (model);
|
Chris@45
|
820 if (!sodm) return;
|
Chris@45
|
821
|
Chris@45
|
822 if (!m_labeller) return;
|
Chris@45
|
823
|
Chris@45
|
824 Labeller labeller(*m_labeller);
|
Chris@45
|
825 labeller.setSampleRate(sodm->getSampleRate());
|
Chris@45
|
826
|
Chris@45
|
827 // This uses a command
|
Chris@45
|
828
|
Chris@45
|
829 labeller.labelAll<SparseOneDimensionalModel::Point>(*sodm, &ms);
|
Chris@45
|
830 }
|
Chris@45
|
831
|
Chris@45
|
832 MainWindowBase::FileOpenStatus
|
Chris@45
|
833 MainWindowBase::open(QString fileOrUrl, AudioFileOpenMode mode)
|
Chris@45
|
834 {
|
Chris@109
|
835 ProgressDialog dialog(tr("Opening file or URL..."), true, 2000);
|
Chris@109
|
836 return open(FileSource(fileOrUrl, &dialog), mode);
|
Chris@45
|
837 }
|
Chris@45
|
838
|
Chris@45
|
839 MainWindowBase::FileOpenStatus
|
Chris@45
|
840 MainWindowBase::open(FileSource source, AudioFileOpenMode mode)
|
Chris@45
|
841 {
|
Chris@45
|
842 FileOpenStatus status;
|
Chris@45
|
843
|
Chris@45
|
844 if (!source.isAvailable()) return FileOpenFailed;
|
Chris@45
|
845 source.waitForData();
|
Chris@45
|
846
|
Chris@45
|
847 bool canImportLayer = (getMainModel() != 0 &&
|
Chris@45
|
848 m_paneStack != 0 &&
|
Chris@45
|
849 m_paneStack->getCurrentPane() != 0);
|
Chris@45
|
850
|
Chris@45
|
851 if ((status = openAudio(source, mode)) != FileOpenFailed) {
|
Chris@45
|
852 return status;
|
Chris@45
|
853 } else if ((status = openSession(source)) != FileOpenFailed) {
|
Chris@45
|
854 return status;
|
Chris@45
|
855 } else if ((status = openPlaylist(source, mode)) != FileOpenFailed) {
|
Chris@45
|
856 return status;
|
Chris@45
|
857 } else if (!canImportLayer) {
|
Chris@45
|
858 return FileOpenWrongMode;
|
Chris@45
|
859 } else if ((status = openImage(source)) != FileOpenFailed) {
|
Chris@45
|
860 return status;
|
Chris@45
|
861 } else if ((status = openLayer(source)) != FileOpenFailed) {
|
Chris@45
|
862 return status;
|
Chris@45
|
863 } else {
|
Chris@45
|
864 return FileOpenFailed;
|
Chris@45
|
865 }
|
Chris@45
|
866 }
|
Chris@45
|
867
|
Chris@45
|
868 MainWindowBase::FileOpenStatus
|
Chris@45
|
869 MainWindowBase::openAudio(FileSource source, AudioFileOpenMode mode)
|
Chris@45
|
870 {
|
Chris@45
|
871 std::cerr << "MainWindowBase::openAudio(" << source.getLocation().toStdString() << ")" << std::endl;
|
Chris@45
|
872
|
Chris@45
|
873 if (!source.isAvailable()) return FileOpenFailed;
|
Chris@45
|
874 source.waitForData();
|
Chris@45
|
875
|
Chris@45
|
876 m_openingAudioFile = true;
|
Chris@45
|
877
|
Chris@45
|
878 size_t rate = 0;
|
Chris@45
|
879
|
Chris@45
|
880 if (Preferences::getInstance()->getResampleOnLoad()) {
|
Chris@45
|
881 rate = m_playSource->getSourceSampleRate();
|
Chris@45
|
882 }
|
Chris@45
|
883
|
Chris@45
|
884 WaveFileModel *newModel = new WaveFileModel(source, rate);
|
Chris@45
|
885
|
Chris@45
|
886 if (!newModel->isOK()) {
|
Chris@45
|
887 delete newModel;
|
Chris@45
|
888 m_openingAudioFile = false;
|
Chris@45
|
889 return FileOpenFailed;
|
Chris@45
|
890 }
|
Chris@45
|
891
|
Chris@45
|
892 std::cerr << "mode = " << mode << std::endl;
|
Chris@45
|
893
|
Chris@45
|
894 if (mode == AskUser) {
|
Chris@45
|
895 if (getMainModel()) {
|
Chris@45
|
896
|
Chris@45
|
897 static bool prevSetAsMain = true;
|
Chris@45
|
898 bool setAsMain = true;
|
Chris@45
|
899
|
Chris@45
|
900 QStringList items;
|
Chris@45
|
901 items << tr("Replace the existing main waveform")
|
Chris@45
|
902 << tr("Load this file into a new waveform pane");
|
Chris@45
|
903
|
Chris@45
|
904 bool ok = false;
|
Chris@45
|
905 QString item = ListInputDialog::getItem
|
Chris@45
|
906 (this, tr("Select target for import"),
|
Chris@45
|
907 tr("You already have an audio waveform loaded.\nWhat would you like to do with the new audio file?"),
|
Chris@45
|
908 items, prevSetAsMain ? 0 : 1, &ok);
|
Chris@45
|
909
|
Chris@45
|
910 if (!ok || item.isEmpty()) {
|
Chris@45
|
911 delete newModel;
|
Chris@45
|
912 m_openingAudioFile = false;
|
Chris@45
|
913 return FileOpenCancelled;
|
Chris@45
|
914 }
|
Chris@45
|
915
|
Chris@45
|
916 setAsMain = (item == items[0]);
|
Chris@45
|
917 prevSetAsMain = setAsMain;
|
Chris@45
|
918
|
Chris@45
|
919 if (setAsMain) mode = ReplaceMainModel;
|
Chris@45
|
920 else mode = CreateAdditionalModel;
|
Chris@45
|
921
|
Chris@45
|
922 } else {
|
Chris@45
|
923 mode = ReplaceMainModel;
|
Chris@45
|
924 }
|
Chris@45
|
925 }
|
Chris@45
|
926
|
Chris@45
|
927 if (mode == ReplaceCurrentPane) {
|
Chris@45
|
928
|
Chris@45
|
929 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@45
|
930 if (pane) {
|
Chris@45
|
931 if (getMainModel()) {
|
Chris@45
|
932 View::ModelSet models(pane->getModels());
|
Chris@45
|
933 if (models.find(getMainModel()) != models.end()) {
|
Chris@45
|
934 mode = ReplaceMainModel;
|
Chris@45
|
935 }
|
Chris@45
|
936 } else {
|
Chris@45
|
937 mode = ReplaceMainModel;
|
Chris@45
|
938 }
|
Chris@45
|
939 } else {
|
Chris@45
|
940 mode = CreateAdditionalModel;
|
Chris@45
|
941 }
|
Chris@45
|
942 }
|
Chris@45
|
943
|
Chris@45
|
944 if (mode == CreateAdditionalModel && !getMainModel()) {
|
Chris@45
|
945 mode = ReplaceMainModel;
|
Chris@45
|
946 }
|
Chris@45
|
947
|
Chris@45
|
948 if (mode == ReplaceMainModel) {
|
Chris@45
|
949
|
Chris@45
|
950 Model *prevMain = getMainModel();
|
Chris@45
|
951 if (prevMain) {
|
Chris@45
|
952 m_playSource->removeModel(prevMain);
|
Chris@108
|
953 PlayParameterRepository::getInstance()->removePlayable(prevMain);
|
Chris@45
|
954 }
|
Chris@108
|
955 PlayParameterRepository::getInstance()->addPlayable(newModel);
|
Chris@45
|
956
|
Chris@45
|
957 m_document->setMainModel(newModel);
|
Chris@45
|
958
|
Chris@45
|
959 setupMenus();
|
Chris@45
|
960
|
Chris@45
|
961 if (m_sessionFile == "") {
|
Chris@45
|
962 //!!! shouldn't be dealing directly with title from here -- call a method
|
Chris@57
|
963 setWindowTitle(tr("%1: %2")
|
Chris@57
|
964 .arg(QApplication::applicationName())
|
Chris@45
|
965 .arg(source.getLocation()));
|
Chris@45
|
966 CommandHistory::getInstance()->clear();
|
Chris@45
|
967 CommandHistory::getInstance()->documentSaved();
|
Chris@45
|
968 m_documentModified = false;
|
Chris@45
|
969 } else {
|
Chris@57
|
970 setWindowTitle(tr("%1: %2 [%3]")
|
Chris@57
|
971 .arg(QApplication::applicationName())
|
Chris@45
|
972 .arg(QFileInfo(m_sessionFile).fileName())
|
Chris@45
|
973 .arg(source.getLocation()));
|
Chris@45
|
974 if (m_documentModified) {
|
Chris@45
|
975 m_documentModified = false;
|
Chris@45
|
976 documentModified(); // so as to restore "(modified)" window title
|
Chris@45
|
977 }
|
Chris@45
|
978 }
|
Chris@45
|
979
|
Chris@45
|
980 if (!source.isRemote()) m_audioFile = source.getLocalFilename();
|
Chris@45
|
981
|
Chris@45
|
982 } else if (mode == CreateAdditionalModel) {
|
Chris@45
|
983
|
Chris@45
|
984 CommandHistory::getInstance()->startCompoundOperation
|
Chris@45
|
985 (tr("Import \"%1\"").arg(source.getLocation()), true);
|
Chris@45
|
986
|
Chris@45
|
987 m_document->addImportedModel(newModel);
|
Chris@45
|
988
|
Chris@45
|
989 AddPaneCommand *command = new AddPaneCommand(this);
|
Chris@45
|
990 CommandHistory::getInstance()->addCommand(command);
|
Chris@45
|
991
|
Chris@45
|
992 Pane *pane = command->getPane();
|
Chris@45
|
993
|
Chris@47
|
994 if (m_timeRulerLayer) {
|
Chris@47
|
995 m_document->addLayerToView(pane, m_timeRulerLayer);
|
Chris@47
|
996 }
|
Chris@45
|
997
|
Chris@45
|
998 Layer *newLayer = m_document->createImportedLayer(newModel);
|
Chris@45
|
999
|
Chris@45
|
1000 if (newLayer) {
|
Chris@45
|
1001 m_document->addLayerToView(pane, newLayer);
|
Chris@45
|
1002 }
|
Chris@45
|
1003
|
Chris@45
|
1004 CommandHistory::getInstance()->endCompoundOperation();
|
Chris@45
|
1005
|
Chris@45
|
1006 } else if (mode == ReplaceCurrentPane) {
|
Chris@45
|
1007
|
Chris@45
|
1008 // We know there is a current pane, otherwise we would have
|
Chris@45
|
1009 // reset the mode to CreateAdditionalModel above; and we know
|
Chris@45
|
1010 // the current pane does not contain the main model, otherwise
|
Chris@45
|
1011 // we would have reset it to ReplaceMainModel. But we don't
|
Chris@45
|
1012 // know whether the pane contains a waveform model at all.
|
Chris@45
|
1013
|
Chris@45
|
1014 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@45
|
1015 Layer *replace = 0;
|
Chris@45
|
1016
|
Chris@45
|
1017 for (int i = 0; i < pane->getLayerCount(); ++i) {
|
Chris@45
|
1018 Layer *layer = pane->getLayer(i);
|
Chris@45
|
1019 if (dynamic_cast<WaveformLayer *>(layer)) {
|
Chris@45
|
1020 replace = layer;
|
Chris@45
|
1021 break;
|
Chris@45
|
1022 }
|
Chris@45
|
1023 }
|
Chris@45
|
1024
|
Chris@45
|
1025 CommandHistory::getInstance()->startCompoundOperation
|
Chris@45
|
1026 (tr("Import \"%1\"").arg(source.getLocation()), true);
|
Chris@45
|
1027
|
Chris@45
|
1028 m_document->addImportedModel(newModel);
|
Chris@45
|
1029
|
Chris@45
|
1030 if (replace) {
|
Chris@45
|
1031 m_document->removeLayerFromView(pane, replace);
|
Chris@45
|
1032 }
|
Chris@45
|
1033
|
Chris@45
|
1034 Layer *newLayer = m_document->createImportedLayer(newModel);
|
Chris@45
|
1035
|
Chris@45
|
1036 if (newLayer) {
|
Chris@45
|
1037 m_document->addLayerToView(pane, newLayer);
|
Chris@45
|
1038 }
|
Chris@45
|
1039
|
Chris@45
|
1040 CommandHistory::getInstance()->endCompoundOperation();
|
Chris@45
|
1041 }
|
Chris@45
|
1042
|
Chris@45
|
1043 updateMenuStates();
|
Chris@45
|
1044 m_recentFiles.addFile(source.getLocation());
|
Chris@45
|
1045 if (!source.isRemote()) {
|
Chris@45
|
1046 // for file dialog
|
Chris@45
|
1047 registerLastOpenedFilePath(FileFinder::AudioFile,
|
Chris@45
|
1048 source.getLocalFilename());
|
Chris@45
|
1049 }
|
Chris@45
|
1050 m_openingAudioFile = false;
|
Chris@45
|
1051
|
Chris@45
|
1052 currentPaneChanged(m_paneStack->getCurrentPane());
|
Chris@45
|
1053
|
Chris@45
|
1054 return FileOpenSucceeded;
|
Chris@45
|
1055 }
|
Chris@45
|
1056
|
Chris@45
|
1057 MainWindowBase::FileOpenStatus
|
Chris@45
|
1058 MainWindowBase::openPlaylist(FileSource source, AudioFileOpenMode mode)
|
Chris@45
|
1059 {
|
Chris@45
|
1060 std::set<QString> extensions;
|
Chris@45
|
1061 PlaylistFileReader::getSupportedExtensions(extensions);
|
Chris@45
|
1062 QString extension = source.getExtension();
|
Chris@45
|
1063 if (extensions.find(extension) == extensions.end()) return FileOpenFailed;
|
Chris@45
|
1064
|
Chris@45
|
1065 if (!source.isAvailable()) return FileOpenFailed;
|
Chris@45
|
1066 source.waitForData();
|
Chris@45
|
1067
|
Chris@45
|
1068 PlaylistFileReader reader(source.getLocalFilename());
|
Chris@45
|
1069 if (!reader.isOK()) return FileOpenFailed;
|
Chris@45
|
1070
|
Chris@45
|
1071 PlaylistFileReader::Playlist playlist = reader.load();
|
Chris@45
|
1072
|
Chris@45
|
1073 bool someSuccess = false;
|
Chris@45
|
1074
|
Chris@45
|
1075 for (PlaylistFileReader::Playlist::const_iterator i = playlist.begin();
|
Chris@45
|
1076 i != playlist.end(); ++i) {
|
Chris@45
|
1077
|
Chris@109
|
1078 ProgressDialog dialog(tr("Opening playlist..."), true, 2000);
|
Chris@109
|
1079 FileOpenStatus status = openAudio(FileSource(*i, &dialog), mode);
|
Chris@45
|
1080
|
Chris@45
|
1081 if (status == FileOpenCancelled) {
|
Chris@45
|
1082 return FileOpenCancelled;
|
Chris@45
|
1083 }
|
Chris@45
|
1084
|
Chris@45
|
1085 if (status == FileOpenSucceeded) {
|
Chris@45
|
1086 someSuccess = true;
|
Chris@45
|
1087 mode = CreateAdditionalModel;
|
Chris@45
|
1088 }
|
Chris@45
|
1089 }
|
Chris@45
|
1090
|
Chris@45
|
1091 if (someSuccess) return FileOpenSucceeded;
|
Chris@45
|
1092 else return FileOpenFailed;
|
Chris@45
|
1093 }
|
Chris@45
|
1094
|
Chris@45
|
1095 MainWindowBase::FileOpenStatus
|
Chris@45
|
1096 MainWindowBase::openLayer(FileSource source)
|
Chris@45
|
1097 {
|
Chris@45
|
1098 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@45
|
1099
|
Chris@45
|
1100 if (!pane) {
|
Chris@45
|
1101 // shouldn't happen, as the menu action should have been disabled
|
Chris@45
|
1102 std::cerr << "WARNING: MainWindowBase::openLayer: no current pane" << std::endl;
|
Chris@45
|
1103 return FileOpenWrongMode;
|
Chris@45
|
1104 }
|
Chris@45
|
1105
|
Chris@45
|
1106 if (!getMainModel()) {
|
Chris@45
|
1107 // shouldn't happen, as the menu action should have been disabled
|
Chris@45
|
1108 std::cerr << "WARNING: MainWindowBase::openLayer: No main model -- hence no default sample rate available" << std::endl;
|
Chris@45
|
1109 return FileOpenWrongMode;
|
Chris@45
|
1110 }
|
Chris@45
|
1111
|
Chris@45
|
1112 if (!source.isAvailable()) return FileOpenFailed;
|
Chris@45
|
1113 source.waitForData();
|
Chris@45
|
1114
|
Chris@45
|
1115 QString path = source.getLocalFilename();
|
Chris@45
|
1116
|
Chris@45
|
1117 if (source.getExtension() == "svl" || source.getExtension() == "xml") {
|
Chris@45
|
1118
|
Chris@45
|
1119 PaneCallback callback(this);
|
Chris@45
|
1120 QFile file(path);
|
Chris@45
|
1121
|
Chris@45
|
1122 if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
Chris@45
|
1123 std::cerr << "ERROR: MainWindowBase::openLayer("
|
Chris@45
|
1124 << source.getLocation().toStdString()
|
Chris@45
|
1125 << "): Failed to open file for reading" << std::endl;
|
Chris@45
|
1126 return FileOpenFailed;
|
Chris@45
|
1127 }
|
Chris@45
|
1128
|
Chris@45
|
1129 SVFileReader reader(m_document, callback, source.getLocation());
|
Chris@79
|
1130 connect
|
Chris@79
|
1131 (&reader, SIGNAL(modelRegenerationFailed(QString, QString, QString)),
|
Chris@79
|
1132 this, SLOT(modelRegenerationFailed(QString, QString, QString)));
|
Chris@79
|
1133 connect
|
Chris@79
|
1134 (&reader, SIGNAL(modelRegenerationWarning(QString, QString, QString)),
|
Chris@79
|
1135 this, SLOT(modelRegenerationWarning(QString, QString, QString)));
|
Chris@45
|
1136 reader.setCurrentPane(pane);
|
Chris@45
|
1137
|
Chris@45
|
1138 QXmlInputSource inputSource(&file);
|
Chris@45
|
1139 reader.parse(inputSource);
|
Chris@45
|
1140
|
Chris@45
|
1141 if (!reader.isOK()) {
|
Chris@45
|
1142 std::cerr << "ERROR: MainWindowBase::openLayer("
|
Chris@45
|
1143 << source.getLocation().toStdString()
|
Chris@45
|
1144 << "): Failed to read XML file: "
|
Chris@45
|
1145 << reader.getErrorString().toStdString() << std::endl;
|
Chris@45
|
1146 return FileOpenFailed;
|
Chris@45
|
1147 }
|
Chris@45
|
1148
|
Chris@45
|
1149 m_recentFiles.addFile(source.getLocation());
|
Chris@45
|
1150
|
Chris@45
|
1151 if (!source.isRemote()) {
|
Chris@45
|
1152 registerLastOpenedFilePath(FileFinder::LayerFile, path); // for file dialog
|
Chris@45
|
1153 }
|
Chris@45
|
1154
|
Chris@75
|
1155 return FileOpenSucceeded;
|
Chris@75
|
1156
|
Chris@45
|
1157 } else {
|
Chris@45
|
1158
|
Chris@45
|
1159 try {
|
Chris@45
|
1160
|
Chris@109
|
1161 MIDIFileImportDialog midiDlg(this);
|
Chris@109
|
1162
|
Chris@109
|
1163 Model *model = DataFileReaderFactory::loadNonCSV
|
Chris@109
|
1164 (path, &midiDlg, getMainModel()->getSampleRate());
|
Chris@45
|
1165
|
Chris@109
|
1166 if (!model) {
|
Chris@109
|
1167 CSVFormatDialog *dialog = new CSVFormatDialog
|
Chris@109
|
1168 (this, CSVFormat(path), getMainModel()->getSampleRate());
|
Chris@109
|
1169 if (dialog->exec() == QDialog::Accepted) {
|
Chris@109
|
1170 model = DataFileReaderFactory::loadCSV
|
Chris@109
|
1171 (path, dialog->getFormat(),
|
Chris@109
|
1172 getMainModel()->getSampleRate());
|
Chris@109
|
1173 }
|
Chris@109
|
1174 }
|
Chris@109
|
1175
|
Chris@45
|
1176 if (model) {
|
Chris@45
|
1177
|
Chris@45
|
1178 std::cerr << "MainWindowBase::openLayer: Have model" << std::endl;
|
Chris@45
|
1179
|
Chris@45
|
1180 Layer *newLayer = m_document->createImportedLayer(model);
|
Chris@45
|
1181
|
Chris@45
|
1182 if (newLayer) {
|
Chris@45
|
1183
|
Chris@45
|
1184 m_document->addLayerToView(pane, newLayer);
|
Chris@88
|
1185 m_paneStack->setCurrentLayer(pane, newLayer);
|
Chris@88
|
1186
|
Chris@45
|
1187 m_recentFiles.addFile(source.getLocation());
|
Chris@45
|
1188
|
Chris@45
|
1189 if (!source.isRemote()) {
|
Chris@45
|
1190 registerLastOpenedFilePath
|
Chris@45
|
1191 (FileFinder::LayerFile,
|
Chris@45
|
1192 path); // for file dialog
|
Chris@45
|
1193 }
|
Chris@88
|
1194
|
Chris@45
|
1195 return FileOpenSucceeded;
|
Chris@45
|
1196 }
|
Chris@45
|
1197 }
|
Chris@45
|
1198 } catch (DataFileReaderFactory::Exception e) {
|
Chris@45
|
1199 if (e == DataFileReaderFactory::ImportCancelled) {
|
Chris@45
|
1200 return FileOpenCancelled;
|
Chris@45
|
1201 }
|
Chris@45
|
1202 }
|
Chris@45
|
1203 }
|
Chris@45
|
1204
|
Chris@45
|
1205 return FileOpenFailed;
|
Chris@45
|
1206 }
|
Chris@45
|
1207
|
Chris@45
|
1208 MainWindowBase::FileOpenStatus
|
Chris@45
|
1209 MainWindowBase::openImage(FileSource source)
|
Chris@45
|
1210 {
|
Chris@45
|
1211 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@45
|
1212
|
Chris@45
|
1213 if (!pane) {
|
Chris@45
|
1214 // shouldn't happen, as the menu action should have been disabled
|
Chris@45
|
1215 std::cerr << "WARNING: MainWindowBase::openImage: no current pane" << std::endl;
|
Chris@45
|
1216 return FileOpenWrongMode;
|
Chris@45
|
1217 }
|
Chris@45
|
1218
|
Chris@45
|
1219 if (!m_document->getMainModel()) {
|
Chris@45
|
1220 return FileOpenWrongMode;
|
Chris@45
|
1221 }
|
Chris@45
|
1222
|
Chris@45
|
1223 bool newLayer = false;
|
Chris@45
|
1224
|
Chris@45
|
1225 ImageLayer *il = dynamic_cast<ImageLayer *>(pane->getSelectedLayer());
|
Chris@45
|
1226 if (!il) {
|
Chris@45
|
1227 for (int i = pane->getLayerCount()-1; i >= 0; --i) {
|
Chris@45
|
1228 il = dynamic_cast<ImageLayer *>(pane->getLayer(i));
|
Chris@45
|
1229 if (il) break;
|
Chris@45
|
1230 }
|
Chris@45
|
1231 }
|
Chris@45
|
1232 if (!il) {
|
Chris@45
|
1233 il = dynamic_cast<ImageLayer *>
|
Chris@45
|
1234 (m_document->createEmptyLayer(LayerFactory::Image));
|
Chris@45
|
1235 if (!il) return FileOpenFailed;
|
Chris@45
|
1236 newLayer = true;
|
Chris@45
|
1237 }
|
Chris@45
|
1238
|
Chris@45
|
1239 // We don't put the image file in Recent Files
|
Chris@45
|
1240
|
Chris@45
|
1241 std::cerr << "openImage: trying location \"" << source.getLocation().toStdString() << "\" in image layer" << std::endl;
|
Chris@45
|
1242
|
Chris@45
|
1243 if (!il->addImage(m_viewManager->getGlobalCentreFrame(), source.getLocation())) {
|
Chris@45
|
1244 if (newLayer) {
|
Chris@52
|
1245 m_document->deleteLayer(il); // also releases its model
|
Chris@45
|
1246 }
|
Chris@45
|
1247 return FileOpenFailed;
|
Chris@45
|
1248 } else {
|
Chris@45
|
1249 if (newLayer) {
|
Chris@45
|
1250 m_document->addLayerToView(pane, il);
|
Chris@45
|
1251 }
|
Chris@45
|
1252 m_paneStack->setCurrentLayer(pane, il);
|
Chris@45
|
1253 }
|
Chris@45
|
1254
|
Chris@45
|
1255 return FileOpenSucceeded;
|
Chris@45
|
1256 }
|
Chris@45
|
1257
|
Chris@45
|
1258 MainWindowBase::FileOpenStatus
|
Chris@45
|
1259 MainWindowBase::openSessionFile(QString fileOrUrl)
|
Chris@45
|
1260 {
|
Chris@109
|
1261 ProgressDialog dialog(tr("Opening session..."), true, 2000);
|
Chris@109
|
1262 return openSession(FileSource(fileOrUrl, &dialog));
|
Chris@45
|
1263 }
|
Chris@45
|
1264
|
Chris@45
|
1265 MainWindowBase::FileOpenStatus
|
Chris@45
|
1266 MainWindowBase::openSession(FileSource source)
|
Chris@45
|
1267 {
|
Chris@45
|
1268 if (!source.isAvailable()) return FileOpenFailed;
|
Chris@45
|
1269 if (source.getExtension() != "sv") return FileOpenFailed;
|
Chris@45
|
1270 source.waitForData();
|
Chris@45
|
1271
|
Chris@45
|
1272 BZipFileDevice bzFile(source.getLocalFilename());
|
Chris@45
|
1273 if (!bzFile.open(QIODevice::ReadOnly)) return FileOpenFailed;
|
Chris@45
|
1274
|
Chris@45
|
1275 if (!checkSaveModified()) return FileOpenCancelled;
|
Chris@45
|
1276
|
Chris@45
|
1277 QString error;
|
Chris@45
|
1278 closeSession();
|
Chris@45
|
1279 createDocument();
|
Chris@45
|
1280
|
Chris@45
|
1281 PaneCallback callback(this);
|
Chris@45
|
1282 m_viewManager->clearSelections();
|
Chris@45
|
1283
|
Chris@45
|
1284 SVFileReader reader(m_document, callback, source.getLocation());
|
Chris@79
|
1285 connect
|
Chris@79
|
1286 (&reader, SIGNAL(modelRegenerationFailed(QString, QString, QString)),
|
Chris@79
|
1287 this, SLOT(modelRegenerationFailed(QString, QString, QString)));
|
Chris@79
|
1288 connect
|
Chris@79
|
1289 (&reader, SIGNAL(modelRegenerationWarning(QString, QString, QString)),
|
Chris@79
|
1290 this, SLOT(modelRegenerationWarning(QString, QString, QString)));
|
Chris@45
|
1291 QXmlInputSource inputSource(&bzFile);
|
Chris@45
|
1292 reader.parse(inputSource);
|
Chris@45
|
1293
|
Chris@45
|
1294 if (!reader.isOK()) {
|
Chris@45
|
1295 error = tr("SV XML file read error:\n%1").arg(reader.getErrorString());
|
Chris@45
|
1296 }
|
Chris@45
|
1297
|
Chris@45
|
1298 bzFile.close();
|
Chris@45
|
1299
|
Chris@45
|
1300 bool ok = (error == "");
|
Chris@45
|
1301
|
Chris@45
|
1302 if (ok) {
|
Chris@45
|
1303
|
Chris@57
|
1304 setWindowTitle(tr("%1: %2")
|
Chris@57
|
1305 .arg(QApplication::applicationName())
|
Chris@45
|
1306 .arg(source.getLocation()));
|
Chris@45
|
1307
|
Chris@45
|
1308 if (!source.isRemote()) m_sessionFile = source.getLocalFilename();
|
Chris@45
|
1309
|
Chris@45
|
1310 setupMenus();
|
Chris@45
|
1311
|
Chris@45
|
1312 CommandHistory::getInstance()->clear();
|
Chris@45
|
1313 CommandHistory::getInstance()->documentSaved();
|
Chris@45
|
1314 m_documentModified = false;
|
Chris@45
|
1315 updateMenuStates();
|
Chris@45
|
1316
|
Chris@45
|
1317 m_recentFiles.addFile(source.getLocation());
|
Chris@45
|
1318
|
Chris@45
|
1319 if (!source.isRemote()) {
|
Chris@45
|
1320 // for file dialog
|
Chris@45
|
1321 registerLastOpenedFilePath(FileFinder::SessionFile,
|
Chris@45
|
1322 source.getLocalFilename());
|
Chris@45
|
1323 }
|
Chris@45
|
1324
|
Chris@45
|
1325 } else {
|
Chris@57
|
1326 setWindowTitle(QApplication::applicationName());
|
Chris@45
|
1327 }
|
Chris@45
|
1328
|
Chris@45
|
1329 return ok ? FileOpenSucceeded : FileOpenFailed;
|
Chris@45
|
1330 }
|
Chris@45
|
1331
|
Chris@45
|
1332 void
|
Chris@45
|
1333 MainWindowBase::createPlayTarget()
|
Chris@45
|
1334 {
|
Chris@45
|
1335 if (m_playTarget) return;
|
Chris@45
|
1336
|
Chris@45
|
1337 m_playTarget = AudioTargetFactory::createCallbackTarget(m_playSource);
|
Chris@45
|
1338 if (!m_playTarget) {
|
Chris@104
|
1339 emit hideSplash();
|
Chris@45
|
1340 QMessageBox::warning
|
Chris@45
|
1341 (this, tr("Couldn't open audio device"),
|
Chris@45
|
1342 tr("<b>No audio available</b><p>Could not open an audio device for playback.<p>Audio playback will not be available during this session."),
|
Chris@45
|
1343 QMessageBox::Ok);
|
Chris@45
|
1344 }
|
Chris@45
|
1345 }
|
Chris@45
|
1346
|
Chris@45
|
1347 WaveFileModel *
|
Chris@45
|
1348 MainWindowBase::getMainModel()
|
Chris@45
|
1349 {
|
Chris@45
|
1350 if (!m_document) return 0;
|
Chris@45
|
1351 return m_document->getMainModel();
|
Chris@45
|
1352 }
|
Chris@45
|
1353
|
Chris@45
|
1354 const WaveFileModel *
|
Chris@45
|
1355 MainWindowBase::getMainModel() const
|
Chris@45
|
1356 {
|
Chris@45
|
1357 if (!m_document) return 0;
|
Chris@45
|
1358 return m_document->getMainModel();
|
Chris@45
|
1359 }
|
Chris@45
|
1360
|
Chris@45
|
1361 void
|
Chris@45
|
1362 MainWindowBase::createDocument()
|
Chris@45
|
1363 {
|
Chris@45
|
1364 m_document = new Document;
|
Chris@45
|
1365
|
Chris@45
|
1366 connect(m_document, SIGNAL(layerAdded(Layer *)),
|
Chris@45
|
1367 this, SLOT(layerAdded(Layer *)));
|
Chris@45
|
1368 connect(m_document, SIGNAL(layerRemoved(Layer *)),
|
Chris@45
|
1369 this, SLOT(layerRemoved(Layer *)));
|
Chris@45
|
1370 connect(m_document, SIGNAL(layerAboutToBeDeleted(Layer *)),
|
Chris@45
|
1371 this, SLOT(layerAboutToBeDeleted(Layer *)));
|
Chris@45
|
1372 connect(m_document, SIGNAL(layerInAView(Layer *, bool)),
|
Chris@45
|
1373 this, SLOT(layerInAView(Layer *, bool)));
|
Chris@45
|
1374
|
Chris@45
|
1375 connect(m_document, SIGNAL(modelAdded(Model *)),
|
Chris@45
|
1376 this, SLOT(modelAdded(Model *)));
|
Chris@45
|
1377 connect(m_document, SIGNAL(mainModelChanged(WaveFileModel *)),
|
Chris@45
|
1378 this, SLOT(mainModelChanged(WaveFileModel *)));
|
Chris@45
|
1379 connect(m_document, SIGNAL(modelAboutToBeDeleted(Model *)),
|
Chris@45
|
1380 this, SLOT(modelAboutToBeDeleted(Model *)));
|
Chris@45
|
1381
|
Chris@78
|
1382 connect(m_document, SIGNAL(modelGenerationFailed(QString, QString)),
|
Chris@78
|
1383 this, SLOT(modelGenerationFailed(QString, QString)));
|
Chris@78
|
1384 connect(m_document, SIGNAL(modelRegenerationWarning(QString, QString, QString)),
|
Chris@78
|
1385 this, SLOT(modelRegenerationWarning(QString, QString, QString)));
|
Chris@78
|
1386 connect(m_document, SIGNAL(modelGenerationFailed(QString, QString)),
|
Chris@78
|
1387 this, SLOT(modelGenerationFailed(QString, QString)));
|
Chris@78
|
1388 connect(m_document, SIGNAL(modelRegenerationWarning(QString, QString, QString)),
|
Chris@78
|
1389 this, SLOT(modelRegenerationWarning(QString, QString, QString)));
|
Chris@78
|
1390 connect(m_document, SIGNAL(alignmentFailed(QString, QString)),
|
Chris@78
|
1391 this, SLOT(alignmentFailed(QString, QString)));
|
Chris@45
|
1392 }
|
Chris@45
|
1393
|
Chris@45
|
1394 bool
|
Chris@45
|
1395 MainWindowBase::saveSessionFile(QString path)
|
Chris@45
|
1396 {
|
Chris@45
|
1397 BZipFileDevice bzFile(path);
|
Chris@45
|
1398 if (!bzFile.open(QIODevice::WriteOnly)) {
|
Chris@45
|
1399 std::cerr << "Failed to open session file \"" << path.toStdString()
|
Chris@45
|
1400 << "\" for writing: "
|
Chris@45
|
1401 << bzFile.errorString().toStdString() << std::endl;
|
Chris@45
|
1402 return false;
|
Chris@45
|
1403 }
|
Chris@45
|
1404
|
Chris@45
|
1405 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
|
Chris@45
|
1406
|
Chris@45
|
1407 QTextStream out(&bzFile);
|
Chris@45
|
1408 toXml(out);
|
Chris@45
|
1409 out.flush();
|
Chris@45
|
1410
|
Chris@45
|
1411 QApplication::restoreOverrideCursor();
|
Chris@45
|
1412
|
Chris@45
|
1413 if (!bzFile.isOK()) {
|
Chris@45
|
1414 QMessageBox::critical(this, tr("Failed to write file"),
|
Chris@45
|
1415 tr("<b>Save failed</b><p>Failed to write to file \"%1\": %2")
|
Chris@45
|
1416 .arg(path).arg(bzFile.errorString()));
|
Chris@45
|
1417 bzFile.close();
|
Chris@45
|
1418 return false;
|
Chris@45
|
1419 }
|
Chris@45
|
1420
|
Chris@45
|
1421 bzFile.close();
|
Chris@45
|
1422 return true;
|
Chris@45
|
1423 }
|
Chris@45
|
1424
|
Chris@45
|
1425 void
|
Chris@45
|
1426 MainWindowBase::toXml(QTextStream &out)
|
Chris@45
|
1427 {
|
Chris@45
|
1428 QString indent(" ");
|
Chris@45
|
1429
|
Chris@45
|
1430 out << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
|
Chris@45
|
1431 out << "<!DOCTYPE sonic-visualiser>\n";
|
Chris@45
|
1432 out << "<sv>\n";
|
Chris@45
|
1433
|
Chris@45
|
1434 m_document->toXml(out, "", "");
|
Chris@45
|
1435
|
Chris@45
|
1436 out << "<display>\n";
|
Chris@45
|
1437
|
Chris@45
|
1438 out << QString(" <window width=\"%1\" height=\"%2\"/>\n")
|
Chris@45
|
1439 .arg(width()).arg(height());
|
Chris@45
|
1440
|
Chris@45
|
1441 for (int i = 0; i < m_paneStack->getPaneCount(); ++i) {
|
Chris@45
|
1442
|
Chris@45
|
1443 Pane *pane = m_paneStack->getPane(i);
|
Chris@45
|
1444
|
Chris@45
|
1445 if (pane) {
|
Chris@45
|
1446 pane->toXml(out, indent);
|
Chris@45
|
1447 }
|
Chris@45
|
1448 }
|
Chris@45
|
1449
|
Chris@45
|
1450 out << "</display>\n";
|
Chris@45
|
1451
|
Chris@45
|
1452 m_viewManager->getSelection().toXml(out);
|
Chris@45
|
1453
|
Chris@45
|
1454 out << "</sv>\n";
|
Chris@45
|
1455 }
|
Chris@45
|
1456
|
Chris@45
|
1457 Pane *
|
Chris@45
|
1458 MainWindowBase::addPaneToStack()
|
Chris@45
|
1459 {
|
Chris@45
|
1460 AddPaneCommand *command = new AddPaneCommand(this);
|
Chris@45
|
1461 CommandHistory::getInstance()->addCommand(command);
|
Chris@57
|
1462 Pane *pane = command->getPane();
|
Chris@57
|
1463 return pane;
|
Chris@45
|
1464 }
|
Chris@45
|
1465
|
Chris@45
|
1466 void
|
Chris@45
|
1467 MainWindowBase::zoomIn()
|
Chris@45
|
1468 {
|
Chris@45
|
1469 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@45
|
1470 if (currentPane) currentPane->zoom(true);
|
Chris@45
|
1471 }
|
Chris@45
|
1472
|
Chris@45
|
1473 void
|
Chris@45
|
1474 MainWindowBase::zoomOut()
|
Chris@45
|
1475 {
|
Chris@45
|
1476 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@45
|
1477 if (currentPane) currentPane->zoom(false);
|
Chris@45
|
1478 }
|
Chris@45
|
1479
|
Chris@45
|
1480 void
|
Chris@45
|
1481 MainWindowBase::zoomToFit()
|
Chris@45
|
1482 {
|
Chris@45
|
1483 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@45
|
1484 if (!currentPane) return;
|
Chris@45
|
1485
|
Chris@45
|
1486 Model *model = getMainModel();
|
Chris@45
|
1487 if (!model) return;
|
Chris@45
|
1488
|
Chris@45
|
1489 size_t start = model->getStartFrame();
|
Chris@45
|
1490 size_t end = model->getEndFrame();
|
Chris@60
|
1491 if (m_playSource) end = std::max(end, m_playSource->getPlayEndFrame());
|
Chris@45
|
1492 size_t pixels = currentPane->width();
|
Chris@45
|
1493
|
Chris@45
|
1494 size_t sw = currentPane->getVerticalScaleWidth();
|
Chris@45
|
1495 if (pixels > sw * 2) pixels -= sw * 2;
|
Chris@45
|
1496 else pixels = 1;
|
Chris@45
|
1497 if (pixels > 4) pixels -= 4;
|
Chris@45
|
1498
|
Chris@45
|
1499 size_t zoomLevel = (end - start) / pixels;
|
Chris@45
|
1500
|
Chris@45
|
1501 currentPane->setZoomLevel(zoomLevel);
|
Chris@45
|
1502 currentPane->setCentreFrame((start + end) / 2);
|
Chris@45
|
1503 }
|
Chris@45
|
1504
|
Chris@45
|
1505 void
|
Chris@45
|
1506 MainWindowBase::zoomDefault()
|
Chris@45
|
1507 {
|
Chris@45
|
1508 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@45
|
1509 if (currentPane) currentPane->setZoomLevel(1024);
|
Chris@45
|
1510 }
|
Chris@45
|
1511
|
Chris@45
|
1512 void
|
Chris@45
|
1513 MainWindowBase::scrollLeft()
|
Chris@45
|
1514 {
|
Chris@45
|
1515 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@45
|
1516 if (currentPane) currentPane->scroll(false, false);
|
Chris@45
|
1517 }
|
Chris@45
|
1518
|
Chris@45
|
1519 void
|
Chris@45
|
1520 MainWindowBase::jumpLeft()
|
Chris@45
|
1521 {
|
Chris@45
|
1522 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@45
|
1523 if (currentPane) currentPane->scroll(false, true);
|
Chris@45
|
1524 }
|
Chris@45
|
1525
|
Chris@45
|
1526 void
|
Chris@45
|
1527 MainWindowBase::scrollRight()
|
Chris@45
|
1528 {
|
Chris@45
|
1529 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@45
|
1530 if (currentPane) currentPane->scroll(true, false);
|
Chris@45
|
1531 }
|
Chris@45
|
1532
|
Chris@45
|
1533 void
|
Chris@45
|
1534 MainWindowBase::jumpRight()
|
Chris@45
|
1535 {
|
Chris@45
|
1536 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@45
|
1537 if (currentPane) currentPane->scroll(true, true);
|
Chris@45
|
1538 }
|
Chris@45
|
1539
|
Chris@45
|
1540 void
|
Chris@45
|
1541 MainWindowBase::showNoOverlays()
|
Chris@45
|
1542 {
|
Chris@45
|
1543 m_viewManager->setOverlayMode(ViewManager::NoOverlays);
|
Chris@45
|
1544 }
|
Chris@45
|
1545
|
Chris@45
|
1546 void
|
Chris@45
|
1547 MainWindowBase::showMinimalOverlays()
|
Chris@45
|
1548 {
|
Chris@45
|
1549 m_viewManager->setOverlayMode(ViewManager::MinimalOverlays);
|
Chris@45
|
1550 }
|
Chris@45
|
1551
|
Chris@45
|
1552 void
|
Chris@45
|
1553 MainWindowBase::showStandardOverlays()
|
Chris@45
|
1554 {
|
Chris@45
|
1555 m_viewManager->setOverlayMode(ViewManager::StandardOverlays);
|
Chris@45
|
1556 }
|
Chris@45
|
1557
|
Chris@45
|
1558 void
|
Chris@45
|
1559 MainWindowBase::showAllOverlays()
|
Chris@45
|
1560 {
|
Chris@45
|
1561 m_viewManager->setOverlayMode(ViewManager::AllOverlays);
|
Chris@45
|
1562 }
|
Chris@45
|
1563
|
Chris@45
|
1564 void
|
Chris@45
|
1565 MainWindowBase::toggleZoomWheels()
|
Chris@45
|
1566 {
|
Chris@45
|
1567 if (m_viewManager->getZoomWheelsEnabled()) {
|
Chris@45
|
1568 m_viewManager->setZoomWheelsEnabled(false);
|
Chris@45
|
1569 } else {
|
Chris@45
|
1570 m_viewManager->setZoomWheelsEnabled(true);
|
Chris@45
|
1571 }
|
Chris@45
|
1572 }
|
Chris@45
|
1573
|
Chris@45
|
1574 void
|
Chris@45
|
1575 MainWindowBase::togglePropertyBoxes()
|
Chris@45
|
1576 {
|
Chris@45
|
1577 if (m_paneStack->getLayoutStyle() == PaneStack::NoPropertyStacks) {
|
Chris@45
|
1578 if (Preferences::getInstance()->getPropertyBoxLayout() ==
|
Chris@45
|
1579 Preferences::VerticallyStacked) {
|
Chris@45
|
1580 m_paneStack->setLayoutStyle(PaneStack::PropertyStackPerPaneLayout);
|
Chris@45
|
1581 } else {
|
Chris@45
|
1582 m_paneStack->setLayoutStyle(PaneStack::SinglePropertyStackLayout);
|
Chris@45
|
1583 }
|
Chris@45
|
1584 } else {
|
Chris@45
|
1585 m_paneStack->setLayoutStyle(PaneStack::NoPropertyStacks);
|
Chris@45
|
1586 }
|
Chris@45
|
1587 }
|
Chris@45
|
1588
|
Chris@45
|
1589 void
|
Chris@45
|
1590 MainWindowBase::toggleStatusBar()
|
Chris@45
|
1591 {
|
Chris@45
|
1592 QSettings settings;
|
Chris@45
|
1593 settings.beginGroup("MainWindow");
|
Chris@45
|
1594 bool sb = settings.value("showstatusbar", true).toBool();
|
Chris@45
|
1595
|
Chris@45
|
1596 if (sb) {
|
Chris@45
|
1597 statusBar()->hide();
|
Chris@45
|
1598 } else {
|
Chris@45
|
1599 statusBar()->show();
|
Chris@45
|
1600 }
|
Chris@45
|
1601
|
Chris@45
|
1602 settings.setValue("showstatusbar", !sb);
|
Chris@45
|
1603
|
Chris@45
|
1604 settings.endGroup();
|
Chris@45
|
1605 }
|
Chris@45
|
1606
|
Chris@45
|
1607 void
|
Chris@45
|
1608 MainWindowBase::preferenceChanged(PropertyContainer::PropertyName name)
|
Chris@45
|
1609 {
|
Chris@45
|
1610 if (name == "Property Box Layout") {
|
Chris@45
|
1611 if (m_paneStack->getLayoutStyle() != PaneStack::NoPropertyStacks) {
|
Chris@45
|
1612 if (Preferences::getInstance()->getPropertyBoxLayout() ==
|
Chris@45
|
1613 Preferences::VerticallyStacked) {
|
Chris@45
|
1614 m_paneStack->setLayoutStyle(PaneStack::PropertyStackPerPaneLayout);
|
Chris@45
|
1615 } else {
|
Chris@45
|
1616 m_paneStack->setLayoutStyle(PaneStack::SinglePropertyStackLayout);
|
Chris@45
|
1617 }
|
Chris@45
|
1618 }
|
Chris@45
|
1619 } else if (name == "Background Mode" && m_viewManager) {
|
Chris@45
|
1620 Preferences::BackgroundMode mode =
|
Chris@45
|
1621 Preferences::getInstance()->getBackgroundMode();
|
Chris@45
|
1622 if (mode == Preferences::BackgroundFromTheme) {
|
Chris@45
|
1623 m_viewManager->setGlobalDarkBackground(m_initialDarkBackground);
|
Chris@45
|
1624 } else if (mode == Preferences::DarkBackground) {
|
Chris@45
|
1625 m_viewManager->setGlobalDarkBackground(true);
|
Chris@45
|
1626 } else {
|
Chris@45
|
1627 m_viewManager->setGlobalDarkBackground(false);
|
Chris@45
|
1628 }
|
Chris@45
|
1629 }
|
Chris@45
|
1630 }
|
Chris@45
|
1631
|
Chris@45
|
1632 void
|
Chris@45
|
1633 MainWindowBase::play()
|
Chris@45
|
1634 {
|
Chris@45
|
1635 if (m_playSource->isPlaying()) {
|
Chris@45
|
1636 stop();
|
Chris@45
|
1637 } else {
|
Chris@45
|
1638 playbackFrameChanged(m_viewManager->getPlaybackFrame());
|
Chris@45
|
1639 m_playSource->play(m_viewManager->getPlaybackFrame());
|
Chris@45
|
1640 }
|
Chris@45
|
1641 }
|
Chris@45
|
1642
|
Chris@45
|
1643 void
|
Chris@45
|
1644 MainWindowBase::ffwd()
|
Chris@45
|
1645 {
|
Chris@45
|
1646 if (!getMainModel()) return;
|
Chris@45
|
1647
|
Chris@45
|
1648 int frame = m_viewManager->getPlaybackFrame();
|
Chris@45
|
1649 ++frame;
|
Chris@45
|
1650
|
Chris@85
|
1651 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@45
|
1652 Layer *layer = getSnapLayer();
|
Chris@45
|
1653 size_t sr = getMainModel()->getSampleRate();
|
Chris@45
|
1654
|
Chris@45
|
1655 if (!layer) {
|
Chris@45
|
1656
|
Chris@45
|
1657 frame = RealTime::realTime2Frame
|
Chris@45
|
1658 (RealTime::frame2RealTime(frame, sr) + RealTime(2, 0), sr);
|
Chris@45
|
1659 if (frame > int(getMainModel()->getEndFrame())) {
|
Chris@45
|
1660 frame = getMainModel()->getEndFrame();
|
Chris@45
|
1661 }
|
Chris@45
|
1662
|
Chris@45
|
1663 } else {
|
Chris@45
|
1664
|
Chris@45
|
1665 size_t resolution = 0;
|
Chris@85
|
1666 if (layer->snapToFeatureFrame(m_paneStack->getCurrentPane(),
|
Chris@85
|
1667 frame, resolution, Layer::SnapRight)) {
|
Chris@85
|
1668 if (pane) frame = pane->alignToReference(frame);
|
Chris@85
|
1669 } else {
|
Chris@45
|
1670 frame = getMainModel()->getEndFrame();
|
Chris@45
|
1671 }
|
Chris@45
|
1672 }
|
Chris@45
|
1673
|
Chris@45
|
1674 if (frame < 0) frame = 0;
|
Chris@45
|
1675
|
Chris@45
|
1676 if (m_viewManager->getPlaySelectionMode()) {
|
Chris@45
|
1677 frame = m_viewManager->constrainFrameToSelection(size_t(frame));
|
Chris@45
|
1678 }
|
Chris@45
|
1679
|
Chris@45
|
1680 m_viewManager->setPlaybackFrame(frame);
|
Chris@45
|
1681 }
|
Chris@45
|
1682
|
Chris@45
|
1683 void
|
Chris@45
|
1684 MainWindowBase::ffwdEnd()
|
Chris@45
|
1685 {
|
Chris@45
|
1686 if (!getMainModel()) return;
|
Chris@45
|
1687
|
Chris@45
|
1688 size_t frame = getMainModel()->getEndFrame();
|
Chris@45
|
1689
|
Chris@45
|
1690 if (m_viewManager->getPlaySelectionMode()) {
|
Chris@45
|
1691 frame = m_viewManager->constrainFrameToSelection(frame);
|
Chris@45
|
1692 }
|
Chris@45
|
1693
|
Chris@45
|
1694 m_viewManager->setPlaybackFrame(frame);
|
Chris@45
|
1695 }
|
Chris@45
|
1696
|
Chris@45
|
1697 void
|
Chris@45
|
1698 MainWindowBase::rewind()
|
Chris@45
|
1699 {
|
Chris@45
|
1700 if (!getMainModel()) return;
|
Chris@45
|
1701
|
Chris@45
|
1702 int frame = m_viewManager->getPlaybackFrame();
|
Chris@45
|
1703 if (frame > 0) --frame;
|
Chris@45
|
1704
|
Chris@85
|
1705 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@45
|
1706 Layer *layer = getSnapLayer();
|
Chris@45
|
1707 size_t sr = getMainModel()->getSampleRate();
|
Chris@45
|
1708
|
Chris@45
|
1709 // when rewinding during playback, we want to allow a period
|
Chris@45
|
1710 // following a rewind target point at which the rewind will go to
|
Chris@45
|
1711 // the prior point instead of the immediately neighbouring one
|
Chris@45
|
1712 if (m_playSource && m_playSource->isPlaying()) {
|
Chris@45
|
1713 RealTime ct = RealTime::frame2RealTime(frame, sr);
|
Chris@45
|
1714 ct = ct - RealTime::fromSeconds(0.25);
|
Chris@45
|
1715 if (ct < RealTime::zeroTime) ct = RealTime::zeroTime;
|
Chris@45
|
1716 // std::cerr << "rewind: frame " << frame << " -> ";
|
Chris@45
|
1717 frame = RealTime::realTime2Frame(ct, sr);
|
Chris@45
|
1718 // std::cerr << frame << std::endl;
|
Chris@45
|
1719 }
|
Chris@45
|
1720
|
Chris@45
|
1721 if (!layer) {
|
Chris@45
|
1722
|
Chris@45
|
1723 frame = RealTime::realTime2Frame
|
Chris@45
|
1724 (RealTime::frame2RealTime(frame, sr) - RealTime(2, 0), sr);
|
Chris@45
|
1725 if (frame < int(getMainModel()->getStartFrame())) {
|
Chris@45
|
1726 frame = getMainModel()->getStartFrame();
|
Chris@45
|
1727 }
|
Chris@45
|
1728
|
Chris@45
|
1729 } else {
|
Chris@45
|
1730
|
Chris@45
|
1731 size_t resolution = 0;
|
Chris@85
|
1732 if (layer->snapToFeatureFrame(m_paneStack->getCurrentPane(),
|
Chris@85
|
1733 frame, resolution, Layer::SnapLeft)) {
|
Chris@85
|
1734
|
Chris@85
|
1735 if (pane) frame = pane->alignToReference(frame);
|
Chris@85
|
1736 } else {
|
Chris@45
|
1737 frame = getMainModel()->getStartFrame();
|
Chris@45
|
1738 }
|
Chris@45
|
1739 }
|
Chris@45
|
1740
|
Chris@45
|
1741 if (frame < 0) frame = 0;
|
Chris@45
|
1742
|
Chris@45
|
1743 if (m_viewManager->getPlaySelectionMode()) {
|
Chris@45
|
1744 frame = m_viewManager->constrainFrameToSelection(size_t(frame));
|
Chris@45
|
1745 }
|
Chris@45
|
1746
|
Chris@45
|
1747 m_viewManager->setPlaybackFrame(frame);
|
Chris@45
|
1748 }
|
Chris@45
|
1749
|
Chris@45
|
1750 void
|
Chris@45
|
1751 MainWindowBase::rewindStart()
|
Chris@45
|
1752 {
|
Chris@45
|
1753 if (!getMainModel()) return;
|
Chris@45
|
1754
|
Chris@45
|
1755 size_t frame = getMainModel()->getStartFrame();
|
Chris@45
|
1756
|
Chris@45
|
1757 if (m_viewManager->getPlaySelectionMode()) {
|
Chris@45
|
1758 frame = m_viewManager->constrainFrameToSelection(frame);
|
Chris@45
|
1759 }
|
Chris@45
|
1760
|
Chris@45
|
1761 m_viewManager->setPlaybackFrame(frame);
|
Chris@45
|
1762 }
|
Chris@45
|
1763
|
Chris@45
|
1764 Layer *
|
Chris@45
|
1765 MainWindowBase::getSnapLayer() const
|
Chris@45
|
1766 {
|
Chris@45
|
1767 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@45
|
1768 if (!pane) return 0;
|
Chris@45
|
1769
|
Chris@45
|
1770 Layer *layer = pane->getSelectedLayer();
|
Chris@45
|
1771
|
Chris@45
|
1772 if (!dynamic_cast<TimeInstantLayer *>(layer) &&
|
Chris@45
|
1773 !dynamic_cast<TimeValueLayer *>(layer) &&
|
Chris@45
|
1774 !dynamic_cast<TimeRulerLayer *>(layer)) {
|
Chris@45
|
1775
|
Chris@45
|
1776 layer = 0;
|
Chris@45
|
1777
|
Chris@45
|
1778 for (int i = pane->getLayerCount(); i > 0; --i) {
|
Chris@45
|
1779 Layer *l = pane->getLayer(i-1);
|
Chris@45
|
1780 if (dynamic_cast<TimeRulerLayer *>(l)) {
|
Chris@45
|
1781 layer = l;
|
Chris@45
|
1782 break;
|
Chris@45
|
1783 }
|
Chris@45
|
1784 }
|
Chris@45
|
1785 }
|
Chris@45
|
1786
|
Chris@45
|
1787 return layer;
|
Chris@45
|
1788 }
|
Chris@45
|
1789
|
Chris@45
|
1790 void
|
Chris@45
|
1791 MainWindowBase::stop()
|
Chris@45
|
1792 {
|
Chris@45
|
1793 m_playSource->stop();
|
Chris@45
|
1794
|
Chris@45
|
1795 if (m_paneStack && m_paneStack->getCurrentPane()) {
|
Chris@45
|
1796 updateVisibleRangeDisplay(m_paneStack->getCurrentPane());
|
Chris@45
|
1797 } else {
|
Chris@45
|
1798 m_myStatusMessage = "";
|
Chris@45
|
1799 statusBar()->showMessage("");
|
Chris@45
|
1800 }
|
Chris@45
|
1801 }
|
Chris@45
|
1802
|
Chris@45
|
1803 MainWindowBase::AddPaneCommand::AddPaneCommand(MainWindowBase *mw) :
|
Chris@45
|
1804 m_mw(mw),
|
Chris@45
|
1805 m_pane(0),
|
Chris@45
|
1806 m_prevCurrentPane(0),
|
Chris@45
|
1807 m_added(false)
|
Chris@45
|
1808 {
|
Chris@45
|
1809 }
|
Chris@45
|
1810
|
Chris@45
|
1811 MainWindowBase::AddPaneCommand::~AddPaneCommand()
|
Chris@45
|
1812 {
|
Chris@45
|
1813 if (m_pane && !m_added) {
|
Chris@45
|
1814 m_mw->m_paneStack->deletePane(m_pane);
|
Chris@45
|
1815 }
|
Chris@45
|
1816 }
|
Chris@45
|
1817
|
Chris@45
|
1818 QString
|
Chris@45
|
1819 MainWindowBase::AddPaneCommand::getName() const
|
Chris@45
|
1820 {
|
Chris@45
|
1821 return tr("Add Pane");
|
Chris@45
|
1822 }
|
Chris@45
|
1823
|
Chris@45
|
1824 void
|
Chris@45
|
1825 MainWindowBase::AddPaneCommand::execute()
|
Chris@45
|
1826 {
|
Chris@45
|
1827 if (!m_pane) {
|
Chris@45
|
1828 m_prevCurrentPane = m_mw->m_paneStack->getCurrentPane();
|
Chris@45
|
1829 m_pane = m_mw->m_paneStack->addPane();
|
Chris@45
|
1830
|
Chris@45
|
1831 connect(m_pane, SIGNAL(contextHelpChanged(const QString &)),
|
Chris@45
|
1832 m_mw, SLOT(contextHelpChanged(const QString &)));
|
Chris@45
|
1833 } else {
|
Chris@45
|
1834 m_mw->m_paneStack->showPane(m_pane);
|
Chris@45
|
1835 }
|
Chris@45
|
1836
|
Chris@45
|
1837 m_mw->m_paneStack->setCurrentPane(m_pane);
|
Chris@45
|
1838 m_added = true;
|
Chris@45
|
1839 }
|
Chris@45
|
1840
|
Chris@45
|
1841 void
|
Chris@45
|
1842 MainWindowBase::AddPaneCommand::unexecute()
|
Chris@45
|
1843 {
|
Chris@45
|
1844 m_mw->m_paneStack->hidePane(m_pane);
|
Chris@45
|
1845 m_mw->m_paneStack->setCurrentPane(m_prevCurrentPane);
|
Chris@45
|
1846 m_added = false;
|
Chris@45
|
1847 }
|
Chris@45
|
1848
|
Chris@45
|
1849 MainWindowBase::RemovePaneCommand::RemovePaneCommand(MainWindowBase *mw, Pane *pane) :
|
Chris@45
|
1850 m_mw(mw),
|
Chris@45
|
1851 m_pane(pane),
|
Chris@45
|
1852 m_added(true)
|
Chris@45
|
1853 {
|
Chris@45
|
1854 }
|
Chris@45
|
1855
|
Chris@45
|
1856 MainWindowBase::RemovePaneCommand::~RemovePaneCommand()
|
Chris@45
|
1857 {
|
Chris@45
|
1858 if (m_pane && !m_added) {
|
Chris@45
|
1859 m_mw->m_paneStack->deletePane(m_pane);
|
Chris@45
|
1860 }
|
Chris@45
|
1861 }
|
Chris@45
|
1862
|
Chris@45
|
1863 QString
|
Chris@45
|
1864 MainWindowBase::RemovePaneCommand::getName() const
|
Chris@45
|
1865 {
|
Chris@45
|
1866 return tr("Remove Pane");
|
Chris@45
|
1867 }
|
Chris@45
|
1868
|
Chris@45
|
1869 void
|
Chris@45
|
1870 MainWindowBase::RemovePaneCommand::execute()
|
Chris@45
|
1871 {
|
Chris@45
|
1872 m_prevCurrentPane = m_mw->m_paneStack->getCurrentPane();
|
Chris@45
|
1873 m_mw->m_paneStack->hidePane(m_pane);
|
Chris@45
|
1874 m_added = false;
|
Chris@45
|
1875 }
|
Chris@45
|
1876
|
Chris@45
|
1877 void
|
Chris@45
|
1878 MainWindowBase::RemovePaneCommand::unexecute()
|
Chris@45
|
1879 {
|
Chris@45
|
1880 m_mw->m_paneStack->showPane(m_pane);
|
Chris@45
|
1881 m_mw->m_paneStack->setCurrentPane(m_prevCurrentPane);
|
Chris@45
|
1882 m_added = true;
|
Chris@45
|
1883 }
|
Chris@45
|
1884
|
Chris@45
|
1885 void
|
Chris@45
|
1886 MainWindowBase::deleteCurrentPane()
|
Chris@45
|
1887 {
|
Chris@45
|
1888 CommandHistory::getInstance()->startCompoundOperation
|
Chris@45
|
1889 (tr("Delete Pane"), true);
|
Chris@45
|
1890
|
Chris@45
|
1891 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@45
|
1892 if (pane) {
|
Chris@45
|
1893 while (pane->getLayerCount() > 0) {
|
Chris@45
|
1894 Layer *layer = pane->getLayer(0);
|
Chris@45
|
1895 if (layer) {
|
Chris@45
|
1896 m_document->removeLayerFromView(pane, layer);
|
Chris@45
|
1897 } else {
|
Chris@45
|
1898 break;
|
Chris@45
|
1899 }
|
Chris@45
|
1900 }
|
Chris@45
|
1901
|
Chris@45
|
1902 RemovePaneCommand *command = new RemovePaneCommand(this, pane);
|
Chris@45
|
1903 CommandHistory::getInstance()->addCommand(command);
|
Chris@45
|
1904 }
|
Chris@45
|
1905
|
Chris@45
|
1906 CommandHistory::getInstance()->endCompoundOperation();
|
Chris@45
|
1907
|
Chris@45
|
1908 updateMenuStates();
|
Chris@45
|
1909 }
|
Chris@45
|
1910
|
Chris@45
|
1911 void
|
Chris@45
|
1912 MainWindowBase::deleteCurrentLayer()
|
Chris@45
|
1913 {
|
Chris@45
|
1914 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@45
|
1915 if (pane) {
|
Chris@45
|
1916 Layer *layer = pane->getSelectedLayer();
|
Chris@45
|
1917 if (layer) {
|
Chris@45
|
1918 m_document->removeLayerFromView(pane, layer);
|
Chris@45
|
1919 }
|
Chris@45
|
1920 }
|
Chris@45
|
1921 updateMenuStates();
|
Chris@45
|
1922 }
|
Chris@45
|
1923
|
Chris@45
|
1924 void
|
Chris@73
|
1925 MainWindowBase::previousPane()
|
Chris@73
|
1926 {
|
Chris@73
|
1927 if (!m_paneStack) return;
|
Chris@73
|
1928
|
Chris@73
|
1929 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@73
|
1930 if (!currentPane) return;
|
Chris@73
|
1931
|
Chris@73
|
1932 for (int i = 0; i < m_paneStack->getPaneCount(); ++i) {
|
Chris@73
|
1933 if (m_paneStack->getPane(i) == currentPane) {
|
Chris@73
|
1934 if (i == 0) return;
|
Chris@73
|
1935 m_paneStack->setCurrentPane(m_paneStack->getPane(i-1));
|
Chris@73
|
1936 updateMenuStates();
|
Chris@73
|
1937 return;
|
Chris@73
|
1938 }
|
Chris@73
|
1939 }
|
Chris@73
|
1940 }
|
Chris@73
|
1941
|
Chris@73
|
1942 void
|
Chris@73
|
1943 MainWindowBase::nextPane()
|
Chris@73
|
1944 {
|
Chris@73
|
1945 if (!m_paneStack) return;
|
Chris@73
|
1946
|
Chris@73
|
1947 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@73
|
1948 if (!currentPane) return;
|
Chris@73
|
1949
|
Chris@73
|
1950 for (int i = 0; i < m_paneStack->getPaneCount(); ++i) {
|
Chris@73
|
1951 if (m_paneStack->getPane(i) == currentPane) {
|
Chris@73
|
1952 if (i == m_paneStack->getPaneCount()-1) return;
|
Chris@73
|
1953 m_paneStack->setCurrentPane(m_paneStack->getPane(i+1));
|
Chris@73
|
1954 updateMenuStates();
|
Chris@73
|
1955 return;
|
Chris@73
|
1956 }
|
Chris@73
|
1957 }
|
Chris@73
|
1958 }
|
Chris@73
|
1959
|
Chris@73
|
1960 void
|
Chris@73
|
1961 MainWindowBase::previousLayer()
|
Chris@73
|
1962 {
|
Chris@73
|
1963 //!!! Not right -- pane lists layers in stacking order
|
Chris@73
|
1964
|
Chris@73
|
1965 if (!m_paneStack) return;
|
Chris@73
|
1966
|
Chris@73
|
1967 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@73
|
1968 if (!currentPane) return;
|
Chris@73
|
1969
|
Chris@73
|
1970 Layer *currentLayer = currentPane->getSelectedLayer();
|
Chris@73
|
1971 if (!currentLayer) return;
|
Chris@73
|
1972
|
Chris@73
|
1973 for (int i = 0; i < currentPane->getLayerCount(); ++i) {
|
Chris@73
|
1974 if (currentPane->getLayer(i) == currentLayer) {
|
Chris@73
|
1975 if (i == 0) return;
|
Chris@73
|
1976 m_paneStack->setCurrentLayer(currentPane,
|
Chris@73
|
1977 currentPane->getLayer(i-1));
|
Chris@73
|
1978 updateMenuStates();
|
Chris@73
|
1979 return;
|
Chris@73
|
1980 }
|
Chris@73
|
1981 }
|
Chris@73
|
1982 }
|
Chris@73
|
1983
|
Chris@73
|
1984 void
|
Chris@73
|
1985 MainWindowBase::nextLayer()
|
Chris@73
|
1986 {
|
Chris@73
|
1987 //!!! Not right -- pane lists layers in stacking order
|
Chris@73
|
1988
|
Chris@73
|
1989 if (!m_paneStack) return;
|
Chris@73
|
1990
|
Chris@73
|
1991 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@73
|
1992 if (!currentPane) return;
|
Chris@73
|
1993
|
Chris@73
|
1994 Layer *currentLayer = currentPane->getSelectedLayer();
|
Chris@73
|
1995 if (!currentLayer) return;
|
Chris@73
|
1996
|
Chris@73
|
1997 for (int i = 0; i < currentPane->getLayerCount(); ++i) {
|
Chris@73
|
1998 if (currentPane->getLayer(i) == currentLayer) {
|
Chris@73
|
1999 if (i == currentPane->getLayerCount()-1) return;
|
Chris@73
|
2000 m_paneStack->setCurrentLayer(currentPane,
|
Chris@73
|
2001 currentPane->getLayer(i+1));
|
Chris@73
|
2002 updateMenuStates();
|
Chris@73
|
2003 return;
|
Chris@73
|
2004 }
|
Chris@73
|
2005 }
|
Chris@73
|
2006 }
|
Chris@73
|
2007
|
Chris@73
|
2008 void
|
Chris@45
|
2009 MainWindowBase::playbackFrameChanged(unsigned long frame)
|
Chris@45
|
2010 {
|
Chris@45
|
2011 if (!(m_playSource && m_playSource->isPlaying()) || !getMainModel()) return;
|
Chris@45
|
2012
|
Chris@45
|
2013 RealTime now = RealTime::frame2RealTime
|
Chris@45
|
2014 (frame, getMainModel()->getSampleRate());
|
Chris@45
|
2015
|
Chris@45
|
2016 if (now.sec == m_lastPlayStatusSec) return;
|
Chris@45
|
2017
|
Chris@45
|
2018 RealTime then = RealTime::frame2RealTime
|
Chris@45
|
2019 (m_playSource->getPlayEndFrame(), getMainModel()->getSampleRate());
|
Chris@45
|
2020
|
Chris@45
|
2021 QString nowStr;
|
Chris@45
|
2022 QString thenStr;
|
Chris@45
|
2023 QString remainingStr;
|
Chris@45
|
2024
|
Chris@45
|
2025 if (then.sec > 10) {
|
Chris@45
|
2026 nowStr = now.toSecText().c_str();
|
Chris@45
|
2027 thenStr = then.toSecText().c_str();
|
Chris@45
|
2028 remainingStr = (then - now).toSecText().c_str();
|
Chris@45
|
2029 m_lastPlayStatusSec = now.sec;
|
Chris@45
|
2030 } else {
|
Chris@45
|
2031 nowStr = now.toText(true).c_str();
|
Chris@45
|
2032 thenStr = then.toText(true).c_str();
|
Chris@45
|
2033 remainingStr = (then - now).toText(true).c_str();
|
Chris@45
|
2034 }
|
Chris@45
|
2035
|
Chris@45
|
2036 m_myStatusMessage = tr("Playing: %1 of %2 (%3 remaining)")
|
Chris@45
|
2037 .arg(nowStr).arg(thenStr).arg(remainingStr);
|
Chris@45
|
2038
|
Chris@45
|
2039 statusBar()->showMessage(m_myStatusMessage);
|
Chris@45
|
2040 }
|
Chris@45
|
2041
|
Chris@45
|
2042 void
|
Chris@45
|
2043 MainWindowBase::globalCentreFrameChanged(unsigned long )
|
Chris@45
|
2044 {
|
Chris@45
|
2045 if ((m_playSource && m_playSource->isPlaying()) || !getMainModel()) return;
|
Chris@45
|
2046 Pane *p = 0;
|
Chris@45
|
2047 if (!m_paneStack || !(p = m_paneStack->getCurrentPane())) return;
|
Chris@45
|
2048 if (!p->getFollowGlobalPan()) return;
|
Chris@45
|
2049 updateVisibleRangeDisplay(p);
|
Chris@45
|
2050 }
|
Chris@45
|
2051
|
Chris@45
|
2052 void
|
Chris@45
|
2053 MainWindowBase::viewCentreFrameChanged(View *v, unsigned long )
|
Chris@45
|
2054 {
|
Chris@45
|
2055 if ((m_playSource && m_playSource->isPlaying()) || !getMainModel()) return;
|
Chris@45
|
2056 Pane *p = 0;
|
Chris@45
|
2057 if (!m_paneStack || !(p = m_paneStack->getCurrentPane())) return;
|
Chris@45
|
2058 if (v == p) updateVisibleRangeDisplay(p);
|
Chris@45
|
2059 }
|
Chris@45
|
2060
|
Chris@45
|
2061 void
|
Chris@45
|
2062 MainWindowBase::viewZoomLevelChanged(View *v, unsigned long , bool )
|
Chris@45
|
2063 {
|
Chris@45
|
2064 if ((m_playSource && m_playSource->isPlaying()) || !getMainModel()) return;
|
Chris@45
|
2065 Pane *p = 0;
|
Chris@45
|
2066 if (!m_paneStack || !(p = m_paneStack->getCurrentPane())) return;
|
Chris@45
|
2067 if (v == p) updateVisibleRangeDisplay(p);
|
Chris@45
|
2068 }
|
Chris@45
|
2069
|
Chris@45
|
2070 void
|
Chris@45
|
2071 MainWindowBase::layerAdded(Layer *)
|
Chris@45
|
2072 {
|
Chris@45
|
2073 // std::cerr << "MainWindowBase::layerAdded(" << layer << ")" << std::endl;
|
Chris@45
|
2074 updateMenuStates();
|
Chris@45
|
2075 }
|
Chris@45
|
2076
|
Chris@45
|
2077 void
|
Chris@45
|
2078 MainWindowBase::layerRemoved(Layer *)
|
Chris@45
|
2079 {
|
Chris@45
|
2080 // std::cerr << "MainWindowBase::layerRemoved(" << layer << ")" << std::endl;
|
Chris@45
|
2081 updateMenuStates();
|
Chris@45
|
2082 }
|
Chris@45
|
2083
|
Chris@45
|
2084 void
|
Chris@45
|
2085 MainWindowBase::layerAboutToBeDeleted(Layer *layer)
|
Chris@45
|
2086 {
|
Chris@45
|
2087 // std::cerr << "MainWindowBase::layerAboutToBeDeleted(" << layer << ")" << std::endl;
|
Chris@47
|
2088 if (m_timeRulerLayer && (layer == m_timeRulerLayer)) {
|
Chris@45
|
2089 // std::cerr << "(this is the time ruler layer)" << std::endl;
|
Chris@45
|
2090 m_timeRulerLayer = 0;
|
Chris@45
|
2091 }
|
Chris@45
|
2092 }
|
Chris@45
|
2093
|
Chris@45
|
2094 void
|
Chris@45
|
2095 MainWindowBase::layerInAView(Layer *layer, bool inAView)
|
Chris@45
|
2096 {
|
Chris@45
|
2097 // std::cerr << "MainWindowBase::layerInAView(" << layer << "," << inAView << ")" << std::endl;
|
Chris@45
|
2098
|
Chris@45
|
2099 // Check whether we need to add or remove model from play source
|
Chris@45
|
2100 Model *model = layer->getModel();
|
Chris@45
|
2101 if (model) {
|
Chris@45
|
2102 if (inAView) {
|
Chris@45
|
2103 m_playSource->addModel(model);
|
Chris@45
|
2104 } else {
|
Chris@45
|
2105 bool found = false;
|
Chris@45
|
2106 for (int i = 0; i < m_paneStack->getPaneCount(); ++i) {
|
Chris@45
|
2107 Pane *pane = m_paneStack->getPane(i);
|
Chris@45
|
2108 if (!pane) continue;
|
Chris@45
|
2109 for (int j = 0; j < pane->getLayerCount(); ++j) {
|
Chris@45
|
2110 Layer *pl = pane->getLayer(j);
|
Chris@45
|
2111 if (pl && pl->getModel() == model) {
|
Chris@45
|
2112 found = true;
|
Chris@45
|
2113 break;
|
Chris@45
|
2114 }
|
Chris@45
|
2115 }
|
Chris@45
|
2116 if (found) break;
|
Chris@45
|
2117 }
|
Chris@45
|
2118 if (!found) m_playSource->removeModel(model);
|
Chris@45
|
2119 }
|
Chris@45
|
2120 }
|
Chris@45
|
2121
|
Chris@45
|
2122 updateMenuStates();
|
Chris@45
|
2123 }
|
Chris@45
|
2124
|
Chris@45
|
2125 void
|
Chris@45
|
2126 MainWindowBase::modelAdded(Model *model)
|
Chris@45
|
2127 {
|
Chris@45
|
2128 // std::cerr << "MainWindowBase::modelAdded(" << model << ")" << std::endl;
|
Chris@45
|
2129 m_playSource->addModel(model);
|
Chris@45
|
2130 }
|
Chris@45
|
2131
|
Chris@45
|
2132 void
|
Chris@45
|
2133 MainWindowBase::mainModelChanged(WaveFileModel *model)
|
Chris@45
|
2134 {
|
Chris@45
|
2135 // std::cerr << "MainWindowBase::mainModelChanged(" << model << ")" << std::endl;
|
Chris@45
|
2136 updateDescriptionLabel();
|
Chris@45
|
2137 if (model) m_viewManager->setMainModelSampleRate(model->getSampleRate());
|
Chris@45
|
2138 if (model && !m_playTarget && m_audioOutput) createPlayTarget();
|
Chris@45
|
2139 }
|
Chris@45
|
2140
|
Chris@45
|
2141 void
|
Chris@45
|
2142 MainWindowBase::modelAboutToBeDeleted(Model *model)
|
Chris@45
|
2143 {
|
Chris@45
|
2144 // std::cerr << "MainWindowBase::modelAboutToBeDeleted(" << model << ")" << std::endl;
|
Chris@45
|
2145 if (model == m_viewManager->getPlaybackModel()) {
|
Chris@45
|
2146 m_viewManager->setPlaybackModel(0);
|
Chris@45
|
2147 }
|
Chris@45
|
2148 m_playSource->removeModel(model);
|
Chris@45
|
2149 FFTDataServer::modelAboutToBeDeleted(model);
|
Chris@45
|
2150 }
|
Chris@45
|
2151
|
Chris@45
|
2152 void
|
Chris@55
|
2153 MainWindowBase::paneDeleteButtonClicked(Pane *pane)
|
Chris@55
|
2154 {
|
Chris@55
|
2155 bool found = false;
|
Chris@55
|
2156 for (int i = 0; i < m_paneStack->getPaneCount(); ++i) {
|
Chris@55
|
2157 if (m_paneStack->getPane(i) == pane) {
|
Chris@55
|
2158 found = true;
|
Chris@55
|
2159 break;
|
Chris@55
|
2160 }
|
Chris@55
|
2161 }
|
Chris@55
|
2162 if (!found) {
|
Chris@55
|
2163 std::cerr << "MainWindowBase::paneDeleteButtonClicked: Unknown pane "
|
Chris@55
|
2164 << pane << std::endl;
|
Chris@55
|
2165 return;
|
Chris@55
|
2166 }
|
Chris@55
|
2167
|
Chris@55
|
2168 CommandHistory::getInstance()->startCompoundOperation
|
Chris@55
|
2169 (tr("Delete Pane"), true);
|
Chris@55
|
2170
|
Chris@55
|
2171 while (pane->getLayerCount() > 0) {
|
Chris@55
|
2172 Layer *layer = pane->getLayer(0);
|
Chris@55
|
2173 if (layer) {
|
Chris@55
|
2174 m_document->removeLayerFromView(pane, layer);
|
Chris@55
|
2175 } else {
|
Chris@55
|
2176 break;
|
Chris@55
|
2177 }
|
Chris@55
|
2178 }
|
Chris@55
|
2179
|
Chris@55
|
2180 RemovePaneCommand *command = new RemovePaneCommand(this, pane);
|
Chris@55
|
2181 CommandHistory::getInstance()->addCommand(command);
|
Chris@55
|
2182
|
Chris@55
|
2183 CommandHistory::getInstance()->endCompoundOperation();
|
Chris@55
|
2184
|
Chris@55
|
2185 updateMenuStates();
|
Chris@55
|
2186 }
|
Chris@55
|
2187
|
Chris@55
|
2188 void
|
Chris@45
|
2189 MainWindowBase::pollOSC()
|
Chris@45
|
2190 {
|
Chris@45
|
2191 if (!m_oscQueue || m_oscQueue->isEmpty()) return;
|
Chris@45
|
2192 std::cerr << "MainWindowBase::pollOSC: have " << m_oscQueue->getMessagesAvailable() << " messages" << std::endl;
|
Chris@45
|
2193
|
Chris@45
|
2194 if (m_openingAudioFile) return;
|
Chris@45
|
2195
|
Chris@45
|
2196 OSCMessage message = m_oscQueue->readMessage();
|
Chris@45
|
2197
|
Chris@45
|
2198 if (message.getTarget() != 0) {
|
Chris@45
|
2199 return; //!!! for now -- this class is target 0, others not handled yet
|
Chris@45
|
2200 }
|
Chris@45
|
2201
|
Chris@45
|
2202 handleOSCMessage(message);
|
Chris@45
|
2203 }
|
Chris@45
|
2204
|
Chris@45
|
2205 void
|
Chris@45
|
2206 MainWindowBase::inProgressSelectionChanged()
|
Chris@45
|
2207 {
|
Chris@45
|
2208 Pane *currentPane = 0;
|
Chris@45
|
2209 if (m_paneStack) currentPane = m_paneStack->getCurrentPane();
|
Chris@45
|
2210 if (currentPane) updateVisibleRangeDisplay(currentPane);
|
Chris@45
|
2211 }
|
Chris@45
|
2212
|
Chris@45
|
2213 void
|
Chris@45
|
2214 MainWindowBase::contextHelpChanged(const QString &s)
|
Chris@45
|
2215 {
|
Chris@45
|
2216 if (s == "" && m_myStatusMessage != "") {
|
Chris@45
|
2217 statusBar()->showMessage(m_myStatusMessage);
|
Chris@45
|
2218 return;
|
Chris@45
|
2219 }
|
Chris@45
|
2220 statusBar()->showMessage(s);
|
Chris@45
|
2221 }
|
Chris@45
|
2222
|
Chris@45
|
2223 void
|
Chris@45
|
2224 MainWindowBase::openHelpUrl(QString url)
|
Chris@45
|
2225 {
|
Chris@45
|
2226 // This method mostly lifted from Qt Assistant source code
|
Chris@45
|
2227
|
Chris@45
|
2228 QProcess *process = new QProcess(this);
|
Chris@45
|
2229 connect(process, SIGNAL(finished(int)), process, SLOT(deleteLater()));
|
Chris@45
|
2230
|
Chris@45
|
2231 QStringList args;
|
Chris@45
|
2232
|
Chris@45
|
2233 #ifdef Q_OS_MAC
|
Chris@45
|
2234 args.append(url);
|
Chris@45
|
2235 process->start("open", args);
|
Chris@45
|
2236 #else
|
Chris@45
|
2237 #ifdef Q_OS_WIN32
|
Chris@45
|
2238
|
Chris@45
|
2239 QString pf(getenv("ProgramFiles"));
|
Chris@45
|
2240 QString command = pf + QString("\\Internet Explorer\\IEXPLORE.EXE");
|
Chris@45
|
2241
|
Chris@45
|
2242 args.append(url);
|
Chris@45
|
2243 process->start(command, args);
|
Chris@45
|
2244
|
Chris@45
|
2245 #else
|
Chris@45
|
2246 #ifdef Q_WS_X11
|
Chris@45
|
2247 if (!qgetenv("KDE_FULL_SESSION").isEmpty()) {
|
Chris@45
|
2248 args.append("exec");
|
Chris@45
|
2249 args.append(url);
|
Chris@45
|
2250 process->start("kfmclient", args);
|
Chris@45
|
2251 } else if (!qgetenv("BROWSER").isEmpty()) {
|
Chris@45
|
2252 args.append(url);
|
Chris@45
|
2253 process->start(qgetenv("BROWSER"), args);
|
Chris@45
|
2254 } else {
|
Chris@45
|
2255 args.append(url);
|
Chris@45
|
2256 process->start("firefox", args);
|
Chris@45
|
2257 }
|
Chris@45
|
2258 #endif
|
Chris@45
|
2259 #endif
|
Chris@45
|
2260 #endif
|
Chris@45
|
2261 }
|
Chris@45
|
2262
|