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