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