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