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