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