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