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@188
|
407 emit canPlay(haveMainModel && 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@190
|
534 // If a model in this pane is derived from something else,
|
Chris@190
|
535 // then we want to play that model as well -- if the model
|
Chris@190
|
536 // that's derived from it is not something that is itself
|
Chris@190
|
537 // individually playable (e.g. a waveform)
|
Chris@190
|
538 if (*mi &&
|
Chris@190
|
539 !dynamic_cast<RangeSummarisableTimeValueModel *>(*mi) &&
|
Chris@190
|
540 (*mi)->getSourceModel()) {
|
Chris@57
|
541 sources.insert((*mi)->getSourceModel());
|
Chris@57
|
542 }
|
Chris@57
|
543 }
|
Chris@57
|
544 for (View::ModelSet::iterator mi = sources.begin();
|
Chris@57
|
545 mi != sources.end(); ++mi) {
|
Chris@57
|
546 soloModels.insert(*mi);
|
Chris@57
|
547 }
|
Chris@57
|
548
|
Chris@60
|
549 //!!! Need an "atomic" way of telling the play source that the
|
Chris@60
|
550 //playback model has changed, and changing it on ViewManager --
|
Chris@60
|
551 //the play source should be making the setPlaybackModel call to
|
Chris@60
|
552 //ViewManager
|
Chris@60
|
553
|
Chris@45
|
554 for (View::ModelSet::iterator mi = soloModels.begin();
|
Chris@45
|
555 mi != soloModels.end(); ++mi) {
|
Chris@45
|
556 if (dynamic_cast<RangeSummarisableTimeValueModel *>(*mi)) {
|
Chris@45
|
557 m_viewManager->setPlaybackModel(*mi);
|
Chris@45
|
558 }
|
Chris@45
|
559 }
|
Chris@45
|
560
|
Chris@45
|
561 RangeSummarisableTimeValueModel *a =
|
Chris@45
|
562 dynamic_cast<RangeSummarisableTimeValueModel *>(prevPlaybackModel);
|
Chris@45
|
563 RangeSummarisableTimeValueModel *b =
|
Chris@45
|
564 dynamic_cast<RangeSummarisableTimeValueModel *>(m_viewManager->
|
Chris@45
|
565 getPlaybackModel());
|
Chris@45
|
566
|
Chris@45
|
567 m_playSource->setSoloModelSet(soloModels);
|
Chris@45
|
568
|
Chris@45
|
569 if (a && b && (a != b)) {
|
Chris@60
|
570 if (m_playSource->isPlaying()) m_playSource->play(frame);
|
Chris@45
|
571 }
|
Chris@45
|
572 }
|
Chris@45
|
573
|
Chris@45
|
574 void
|
Chris@45
|
575 MainWindowBase::currentLayerChanged(Pane *p, Layer *)
|
Chris@45
|
576 {
|
Chris@45
|
577 updateMenuStates();
|
Chris@45
|
578 updateVisibleRangeDisplay(p);
|
Chris@45
|
579 }
|
Chris@45
|
580
|
Chris@45
|
581 void
|
Chris@45
|
582 MainWindowBase::selectAll()
|
Chris@45
|
583 {
|
Chris@45
|
584 if (!getMainModel()) return;
|
Chris@45
|
585 m_viewManager->setSelection(Selection(getMainModel()->getStartFrame(),
|
Chris@45
|
586 getMainModel()->getEndFrame()));
|
Chris@45
|
587 }
|
Chris@45
|
588
|
Chris@45
|
589 void
|
Chris@45
|
590 MainWindowBase::selectToStart()
|
Chris@45
|
591 {
|
Chris@45
|
592 if (!getMainModel()) return;
|
Chris@45
|
593 m_viewManager->setSelection(Selection(getMainModel()->getStartFrame(),
|
Chris@45
|
594 m_viewManager->getGlobalCentreFrame()));
|
Chris@45
|
595 }
|
Chris@45
|
596
|
Chris@45
|
597 void
|
Chris@45
|
598 MainWindowBase::selectToEnd()
|
Chris@45
|
599 {
|
Chris@45
|
600 if (!getMainModel()) return;
|
Chris@45
|
601 m_viewManager->setSelection(Selection(m_viewManager->getGlobalCentreFrame(),
|
Chris@45
|
602 getMainModel()->getEndFrame()));
|
Chris@45
|
603 }
|
Chris@45
|
604
|
Chris@45
|
605 void
|
Chris@45
|
606 MainWindowBase::selectVisible()
|
Chris@45
|
607 {
|
Chris@45
|
608 Model *model = getMainModel();
|
Chris@45
|
609 if (!model) return;
|
Chris@45
|
610
|
Chris@45
|
611 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@45
|
612 if (!currentPane) return;
|
Chris@45
|
613
|
Chris@45
|
614 size_t startFrame, endFrame;
|
Chris@45
|
615
|
Chris@45
|
616 if (currentPane->getStartFrame() < 0) startFrame = 0;
|
Chris@45
|
617 else startFrame = currentPane->getStartFrame();
|
Chris@45
|
618
|
Chris@45
|
619 if (currentPane->getEndFrame() > model->getEndFrame()) endFrame = model->getEndFrame();
|
Chris@45
|
620 else endFrame = currentPane->getEndFrame();
|
Chris@45
|
621
|
Chris@45
|
622 m_viewManager->setSelection(Selection(startFrame, endFrame));
|
Chris@45
|
623 }
|
Chris@45
|
624
|
Chris@45
|
625 void
|
Chris@45
|
626 MainWindowBase::clearSelection()
|
Chris@45
|
627 {
|
Chris@45
|
628 m_viewManager->clearSelections();
|
Chris@45
|
629 }
|
Chris@45
|
630
|
Chris@45
|
631 void
|
Chris@45
|
632 MainWindowBase::cut()
|
Chris@45
|
633 {
|
Chris@45
|
634 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@45
|
635 if (!currentPane) return;
|
Chris@45
|
636
|
Chris@45
|
637 Layer *layer = currentPane->getSelectedLayer();
|
Chris@45
|
638 if (!layer) return;
|
Chris@45
|
639
|
Chris@45
|
640 Clipboard &clipboard = m_viewManager->getClipboard();
|
Chris@45
|
641 clipboard.clear();
|
Chris@45
|
642
|
Chris@45
|
643 MultiSelection::SelectionList selections = m_viewManager->getSelections();
|
Chris@45
|
644
|
Chris@45
|
645 CommandHistory::getInstance()->startCompoundOperation(tr("Cut"), true);
|
Chris@45
|
646
|
Chris@45
|
647 for (MultiSelection::SelectionList::iterator i = selections.begin();
|
Chris@45
|
648 i != selections.end(); ++i) {
|
Chris@86
|
649 layer->copy(currentPane, *i, clipboard);
|
Chris@45
|
650 layer->deleteSelection(*i);
|
Chris@45
|
651 }
|
Chris@45
|
652
|
Chris@45
|
653 CommandHistory::getInstance()->endCompoundOperation();
|
Chris@45
|
654 }
|
Chris@45
|
655
|
Chris@45
|
656 void
|
Chris@45
|
657 MainWindowBase::copy()
|
Chris@45
|
658 {
|
Chris@45
|
659 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@45
|
660 if (!currentPane) return;
|
Chris@45
|
661
|
Chris@45
|
662 Layer *layer = currentPane->getSelectedLayer();
|
Chris@45
|
663 if (!layer) return;
|
Chris@45
|
664
|
Chris@45
|
665 Clipboard &clipboard = m_viewManager->getClipboard();
|
Chris@45
|
666 clipboard.clear();
|
Chris@45
|
667
|
Chris@45
|
668 MultiSelection::SelectionList selections = m_viewManager->getSelections();
|
Chris@45
|
669
|
Chris@45
|
670 for (MultiSelection::SelectionList::iterator i = selections.begin();
|
Chris@45
|
671 i != selections.end(); ++i) {
|
Chris@86
|
672 layer->copy(currentPane, *i, clipboard);
|
Chris@45
|
673 }
|
Chris@45
|
674 }
|
Chris@45
|
675
|
Chris@45
|
676 void
|
Chris@45
|
677 MainWindowBase::paste()
|
Chris@45
|
678 {
|
Chris@215
|
679 pasteRelative(0);
|
Chris@215
|
680 }
|
Chris@215
|
681
|
Chris@215
|
682 void
|
Chris@215
|
683 MainWindowBase::pasteAtPlaybackPosition()
|
Chris@215
|
684 {
|
Chris@215
|
685 unsigned long pos = getFrame();
|
Chris@215
|
686 Clipboard &clipboard = m_viewManager->getClipboard();
|
Chris@215
|
687 if (!clipboard.empty()) {
|
Chris@215
|
688 long firstEventFrame = clipboard.getPoints()[0].getFrame();
|
Chris@215
|
689 long offset = 0;
|
Chris@215
|
690 if (firstEventFrame < 0) {
|
Chris@215
|
691 offset = long(pos) - firstEventFrame;
|
Chris@215
|
692 } else if (firstEventFrame < pos) {
|
Chris@215
|
693 offset = pos - firstEventFrame;
|
Chris@215
|
694 } else {
|
Chris@215
|
695 offset = -(firstEventFrame - pos);
|
Chris@215
|
696 }
|
Chris@215
|
697 pasteRelative(offset);
|
Chris@215
|
698 }
|
Chris@215
|
699 }
|
Chris@215
|
700
|
Chris@215
|
701 void
|
Chris@215
|
702 MainWindowBase::pasteRelative(int offset)
|
Chris@215
|
703 {
|
Chris@45
|
704 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@45
|
705 if (!currentPane) return;
|
Chris@45
|
706
|
Chris@45
|
707 Layer *layer = currentPane->getSelectedLayer();
|
Chris@45
|
708
|
Chris@45
|
709 Clipboard &clipboard = m_viewManager->getClipboard();
|
Chris@87
|
710
|
Chris@98
|
711 bool inCompound = false;
|
Chris@87
|
712
|
Chris@87
|
713 if (!layer || !layer->isLayerEditable()) {
|
Chris@87
|
714
|
Chris@87
|
715 CommandHistory::getInstance()->startCompoundOperation
|
Chris@87
|
716 (tr("Paste"), true);
|
Chris@87
|
717
|
Chris@87
|
718 // no suitable current layer: create one of the most
|
Chris@87
|
719 // appropriate sort
|
Chris@87
|
720 LayerFactory::LayerType type =
|
Chris@87
|
721 LayerFactory::getInstance()->getLayerTypeForClipboardContents(clipboard);
|
Chris@87
|
722 layer = m_document->createEmptyLayer(type);
|
Chris@87
|
723
|
Chris@87
|
724 if (!layer) {
|
Chris@87
|
725 CommandHistory::getInstance()->endCompoundOperation();
|
Chris@87
|
726 return;
|
Chris@45
|
727 }
|
Chris@87
|
728
|
Chris@87
|
729 m_document->addLayerToView(currentPane, layer);
|
Chris@87
|
730 m_paneStack->setCurrentLayer(currentPane, layer);
|
Chris@87
|
731
|
Chris@87
|
732 inCompound = true;
|
Chris@45
|
733 }
|
Chris@45
|
734
|
Chris@215
|
735 layer->paste(currentPane, clipboard, offset, true);
|
Chris@45
|
736
|
Chris@87
|
737 if (inCompound) CommandHistory::getInstance()->endCompoundOperation();
|
Chris@45
|
738 }
|
Chris@45
|
739
|
Chris@45
|
740 void
|
Chris@45
|
741 MainWindowBase::deleteSelected()
|
Chris@45
|
742 {
|
Chris@45
|
743 if (m_paneStack->getCurrentPane() &&
|
Chris@45
|
744 m_paneStack->getCurrentPane()->getSelectedLayer()) {
|
Chris@45
|
745
|
Chris@45
|
746 Layer *layer = m_paneStack->getCurrentPane()->getSelectedLayer();
|
Chris@45
|
747
|
Chris@45
|
748 if (m_viewManager &&
|
Chris@45
|
749 (m_viewManager->getToolMode() == ViewManager::MeasureMode)) {
|
Chris@45
|
750
|
Chris@45
|
751 layer->deleteCurrentMeasureRect();
|
Chris@45
|
752
|
Chris@45
|
753 } else {
|
Chris@45
|
754
|
Chris@45
|
755 MultiSelection::SelectionList selections =
|
Chris@45
|
756 m_viewManager->getSelections();
|
Chris@45
|
757
|
Chris@45
|
758 for (MultiSelection::SelectionList::iterator i = selections.begin();
|
Chris@45
|
759 i != selections.end(); ++i) {
|
Chris@45
|
760 layer->deleteSelection(*i);
|
Chris@45
|
761 }
|
Chris@45
|
762 }
|
Chris@45
|
763 }
|
Chris@45
|
764 }
|
Chris@45
|
765
|
Chris@161
|
766 // FrameTimer method
|
Chris@161
|
767
|
Chris@161
|
768 unsigned long
|
Chris@161
|
769 MainWindowBase::getFrame() const
|
Chris@161
|
770 {
|
Chris@161
|
771 if (m_playSource && m_playSource->isPlaying()) {
|
Chris@161
|
772 return m_playSource->getCurrentPlayingFrame();
|
Chris@161
|
773 } else {
|
Chris@161
|
774 return m_viewManager->getPlaybackFrame();
|
Chris@161
|
775 }
|
Chris@161
|
776 }
|
Chris@161
|
777
|
Chris@45
|
778 void
|
Chris@45
|
779 MainWindowBase::insertInstant()
|
Chris@45
|
780 {
|
Chris@161
|
781 insertInstantAt(getFrame());
|
Chris@45
|
782 }
|
Chris@45
|
783
|
Chris@45
|
784 void
|
Chris@45
|
785 MainWindowBase::insertInstantsAtBoundaries()
|
Chris@45
|
786 {
|
Chris@45
|
787 MultiSelection::SelectionList selections = m_viewManager->getSelections();
|
Chris@45
|
788 for (MultiSelection::SelectionList::iterator i = selections.begin();
|
Chris@45
|
789 i != selections.end(); ++i) {
|
Chris@45
|
790 size_t start = i->getStartFrame();
|
Chris@45
|
791 size_t end = i->getEndFrame();
|
Chris@45
|
792 if (start != end) {
|
Chris@184
|
793 insertInstantAt(start);
|
Chris@184
|
794 insertInstantAt(end);
|
Chris@45
|
795 }
|
Chris@45
|
796 }
|
Chris@45
|
797 }
|
Chris@45
|
798
|
Chris@45
|
799 void
|
Chris@45
|
800 MainWindowBase::insertInstantAt(size_t frame)
|
Chris@45
|
801 {
|
Chris@45
|
802 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@45
|
803 if (!pane) {
|
Chris@45
|
804 return;
|
Chris@45
|
805 }
|
Chris@45
|
806
|
Chris@74
|
807 frame = pane->alignFromReference(frame);
|
Chris@74
|
808
|
Chris@45
|
809 Layer *layer = dynamic_cast<TimeInstantLayer *>
|
Chris@45
|
810 (pane->getSelectedLayer());
|
Chris@45
|
811
|
Chris@45
|
812 if (!layer) {
|
Chris@45
|
813 for (int i = pane->getLayerCount(); i > 0; --i) {
|
Chris@45
|
814 layer = dynamic_cast<TimeInstantLayer *>(pane->getLayer(i - 1));
|
Chris@45
|
815 if (layer) break;
|
Chris@45
|
816 }
|
Chris@45
|
817
|
Chris@45
|
818 if (!layer) {
|
Chris@45
|
819 CommandHistory::getInstance()->startCompoundOperation
|
Chris@45
|
820 (tr("Add Point"), true);
|
Chris@45
|
821 layer = m_document->createEmptyLayer(LayerFactory::TimeInstants);
|
Chris@45
|
822 if (layer) {
|
Chris@45
|
823 m_document->addLayerToView(pane, layer);
|
Chris@45
|
824 m_paneStack->setCurrentLayer(pane, layer);
|
Chris@45
|
825 }
|
Chris@45
|
826 CommandHistory::getInstance()->endCompoundOperation();
|
Chris@45
|
827 }
|
Chris@45
|
828 }
|
Chris@45
|
829
|
Chris@45
|
830 if (layer) {
|
Chris@45
|
831
|
Chris@45
|
832 Model *model = layer->getModel();
|
Chris@45
|
833 SparseOneDimensionalModel *sodm = dynamic_cast<SparseOneDimensionalModel *>
|
Chris@45
|
834 (model);
|
Chris@45
|
835
|
Chris@45
|
836 if (sodm) {
|
Chris@45
|
837 SparseOneDimensionalModel::Point point(frame, "");
|
Chris@45
|
838
|
Chris@45
|
839 SparseOneDimensionalModel::Point prevPoint(0);
|
Chris@45
|
840 bool havePrevPoint = false;
|
Chris@45
|
841
|
Chris@45
|
842 SparseOneDimensionalModel::EditCommand *command =
|
Chris@45
|
843 new SparseOneDimensionalModel::EditCommand(sodm, tr("Add Point"));
|
Chris@45
|
844
|
Chris@74
|
845 if (m_labeller->requiresPrevPoint()) {
|
Chris@45
|
846
|
Chris@45
|
847 SparseOneDimensionalModel::PointList prevPoints =
|
Chris@45
|
848 sodm->getPreviousPoints(frame);
|
Chris@45
|
849
|
Chris@45
|
850 if (!prevPoints.empty()) {
|
Chris@45
|
851 prevPoint = *prevPoints.begin();
|
Chris@45
|
852 havePrevPoint = true;
|
Chris@45
|
853 }
|
Chris@45
|
854 }
|
Chris@45
|
855
|
Chris@45
|
856 if (m_labeller) {
|
Chris@45
|
857
|
Chris@45
|
858 m_labeller->setSampleRate(sodm->getSampleRate());
|
Chris@45
|
859
|
Chris@74
|
860 if (m_labeller->actingOnPrevPoint()) {
|
Chris@45
|
861 command->deletePoint(prevPoint);
|
Chris@45
|
862 }
|
Chris@45
|
863
|
Chris@45
|
864 m_labeller->label<SparseOneDimensionalModel::Point>
|
Chris@45
|
865 (point, havePrevPoint ? &prevPoint : 0);
|
Chris@45
|
866
|
Chris@74
|
867 if (m_labeller->actingOnPrevPoint()) {
|
Chris@45
|
868 command->addPoint(prevPoint);
|
Chris@45
|
869 }
|
Chris@45
|
870 }
|
Chris@45
|
871
|
Chris@45
|
872 command->addPoint(point);
|
Chris@45
|
873
|
Chris@45
|
874 command->setName(tr("Add Point at %1 s")
|
Chris@45
|
875 .arg(RealTime::frame2RealTime
|
Chris@45
|
876 (frame,
|
Chris@45
|
877 sodm->getSampleRate())
|
Chris@45
|
878 .toText(false).c_str()));
|
Chris@45
|
879
|
Chris@108
|
880 Command *c = command->finish();
|
Chris@108
|
881 if (c) CommandHistory::getInstance()->addCommand(c, false);
|
Chris@45
|
882 }
|
Chris@45
|
883 }
|
Chris@45
|
884 }
|
Chris@45
|
885
|
Chris@45
|
886 void
|
Chris@184
|
887 MainWindowBase::insertItemAtSelection()
|
Chris@184
|
888 {
|
Chris@184
|
889 MultiSelection::SelectionList selections = m_viewManager->getSelections();
|
Chris@184
|
890 for (MultiSelection::SelectionList::iterator i = selections.begin();
|
Chris@184
|
891 i != selections.end(); ++i) {
|
Chris@184
|
892 size_t start = i->getStartFrame();
|
Chris@184
|
893 size_t end = i->getEndFrame();
|
Chris@184
|
894 if (start < end) {
|
Chris@184
|
895 insertItemAt(start, end - start);
|
Chris@184
|
896 }
|
Chris@184
|
897 }
|
Chris@184
|
898 }
|
Chris@184
|
899
|
Chris@184
|
900 void
|
Chris@184
|
901 MainWindowBase::insertItemAt(size_t frame, size_t duration)
|
Chris@184
|
902 {
|
Chris@184
|
903 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@184
|
904 if (!pane) {
|
Chris@184
|
905 return;
|
Chris@184
|
906 }
|
Chris@184
|
907
|
Chris@184
|
908 // ugh!
|
Chris@184
|
909
|
Chris@184
|
910 size_t alignedStart = pane->alignFromReference(frame);
|
Chris@184
|
911 size_t alignedEnd = pane->alignFromReference(frame + duration);
|
Chris@184
|
912 if (alignedStart >= alignedEnd) return;
|
Chris@184
|
913 size_t alignedDuration = alignedEnd - alignedStart;
|
Chris@184
|
914
|
Chris@184
|
915 Command *c = 0;
|
Chris@184
|
916
|
Chris@184
|
917 QString name = tr("Add Item at %1 s")
|
Chris@184
|
918 .arg(RealTime::frame2RealTime
|
Chris@184
|
919 (alignedStart,
|
Chris@184
|
920 getMainModel()->getSampleRate())
|
Chris@184
|
921 .toText(false).c_str());
|
Chris@184
|
922
|
Chris@184
|
923 Layer *layer = pane->getSelectedLayer();
|
Chris@184
|
924 if (!layer) return;
|
Chris@184
|
925
|
Chris@184
|
926 RegionModel *rm = dynamic_cast<RegionModel *>(layer->getModel());
|
Chris@184
|
927 if (rm) {
|
Chris@184
|
928 RegionModel::Point point(alignedStart,
|
Chris@185
|
929 rm->getValueMaximum() + 1,
|
Chris@184
|
930 alignedDuration,
|
Chris@184
|
931 "");
|
Chris@184
|
932 RegionModel::EditCommand *command =
|
Chris@184
|
933 new RegionModel::EditCommand(rm, tr("Add Point"));
|
Chris@184
|
934 command->addPoint(point);
|
Chris@184
|
935 command->setName(name);
|
Chris@184
|
936 c = command->finish();
|
Chris@184
|
937 }
|
Chris@184
|
938
|
Chris@184
|
939 if (c) {
|
Chris@184
|
940 CommandHistory::getInstance()->addCommand(c, false);
|
Chris@184
|
941 return;
|
Chris@184
|
942 }
|
Chris@184
|
943
|
Chris@184
|
944 NoteModel *nm = dynamic_cast<NoteModel *>(layer->getModel());
|
Chris@184
|
945 if (nm) {
|
Chris@184
|
946 NoteModel::Point point(alignedStart,
|
Chris@184
|
947 rm->getValueMinimum(),
|
Chris@184
|
948 alignedDuration,
|
Chris@184
|
949 1.f,
|
Chris@184
|
950 "");
|
Chris@184
|
951 NoteModel::EditCommand *command =
|
Chris@184
|
952 new NoteModel::EditCommand(nm, tr("Add Point"));
|
Chris@184
|
953 command->addPoint(point);
|
Chris@184
|
954 command->setName(name);
|
Chris@184
|
955 c = command->finish();
|
Chris@184
|
956 }
|
Chris@184
|
957
|
Chris@184
|
958 if (c) {
|
Chris@184
|
959 CommandHistory::getInstance()->addCommand(c, false);
|
Chris@184
|
960 return;
|
Chris@184
|
961 }
|
Chris@184
|
962 }
|
Chris@184
|
963
|
Chris@184
|
964 void
|
Chris@45
|
965 MainWindowBase::renumberInstants()
|
Chris@45
|
966 {
|
Chris@45
|
967 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@45
|
968 if (!pane) return;
|
Chris@45
|
969
|
Chris@45
|
970 Layer *layer = dynamic_cast<TimeInstantLayer *>(pane->getSelectedLayer());
|
Chris@45
|
971 if (!layer) return;
|
Chris@45
|
972
|
Chris@45
|
973 MultiSelection ms(m_viewManager->getSelection());
|
Chris@45
|
974
|
Chris@45
|
975 Model *model = layer->getModel();
|
Chris@45
|
976 SparseOneDimensionalModel *sodm = dynamic_cast<SparseOneDimensionalModel *>
|
Chris@45
|
977 (model);
|
Chris@45
|
978 if (!sodm) return;
|
Chris@45
|
979
|
Chris@45
|
980 if (!m_labeller) return;
|
Chris@45
|
981
|
Chris@45
|
982 Labeller labeller(*m_labeller);
|
Chris@45
|
983 labeller.setSampleRate(sodm->getSampleRate());
|
Chris@45
|
984
|
Chris@45
|
985 // This uses a command
|
Chris@45
|
986
|
Chris@45
|
987 labeller.labelAll<SparseOneDimensionalModel::Point>(*sodm, &ms);
|
Chris@45
|
988 }
|
Chris@45
|
989
|
Chris@45
|
990 MainWindowBase::FileOpenStatus
|
Chris@45
|
991 MainWindowBase::open(QString fileOrUrl, AudioFileOpenMode mode)
|
Chris@45
|
992 {
|
Chris@134
|
993 ProgressDialog dialog(tr("Opening file or URL..."), true, 2000, this);
|
Chris@134
|
994 connect(&dialog, SIGNAL(showing()), this, SIGNAL(hideSplash()));
|
Chris@109
|
995 return open(FileSource(fileOrUrl, &dialog), mode);
|
Chris@45
|
996 }
|
Chris@45
|
997
|
Chris@45
|
998 MainWindowBase::FileOpenStatus
|
Chris@45
|
999 MainWindowBase::open(FileSource source, AudioFileOpenMode mode)
|
Chris@45
|
1000 {
|
Chris@45
|
1001 FileOpenStatus status;
|
Chris@45
|
1002
|
Chris@45
|
1003 if (!source.isAvailable()) return FileOpenFailed;
|
Chris@45
|
1004 source.waitForData();
|
Chris@45
|
1005
|
Chris@45
|
1006 bool canImportLayer = (getMainModel() != 0 &&
|
Chris@45
|
1007 m_paneStack != 0 &&
|
Chris@45
|
1008 m_paneStack->getCurrentPane() != 0);
|
Chris@45
|
1009
|
Chris@152
|
1010 bool rdf = (source.getExtension().toLower() == "rdf" ||
|
Chris@152
|
1011 source.getExtension().toLower() == "n3" ||
|
Chris@152
|
1012 source.getExtension().toLower() == "ttl");
|
Chris@152
|
1013
|
Chris@152
|
1014 bool audio = AudioFileReaderFactory::getKnownExtensions().contains
|
Chris@152
|
1015 (source.getExtension().toLower());
|
Chris@145
|
1016
|
Chris@145
|
1017 bool rdfSession = false;
|
Chris@145
|
1018 if (rdf) {
|
Chris@145
|
1019 RDFImporter::RDFDocumentType rdfType =
|
Chris@145
|
1020 RDFImporter::identifyDocumentType
|
Chris@145
|
1021 (QUrl::fromLocalFile(source.getLocalFilename()).toString());
|
Chris@148
|
1022 // std::cerr << "RDF type: " << (int)rdfType << std::endl;
|
Chris@145
|
1023 if (rdfType == RDFImporter::AudioRefAndAnnotations ||
|
Chris@145
|
1024 rdfType == RDFImporter::AudioRef) {
|
Chris@145
|
1025 rdfSession = true;
|
Chris@145
|
1026 } else if (rdfType == RDFImporter::NotRDF) {
|
Chris@145
|
1027 rdf = false;
|
Chris@145
|
1028 }
|
Chris@145
|
1029 }
|
Chris@145
|
1030
|
Chris@145
|
1031 if (rdf) {
|
Chris@145
|
1032 if (rdfSession) {
|
Chris@147
|
1033 bool cancel = false;
|
Chris@147
|
1034 if (!canImportLayer || shouldCreateNewSessionForRDFAudio(&cancel)) {
|
Chris@145
|
1035 return openSession(source);
|
Chris@147
|
1036 } else if (cancel) {
|
Chris@147
|
1037 return FileOpenCancelled;
|
Chris@145
|
1038 } else {
|
Chris@145
|
1039 return openLayer(source);
|
Chris@145
|
1040 }
|
Chris@145
|
1041 } else {
|
Chris@145
|
1042 if ((status = openSession(source)) != FileOpenFailed) {
|
Chris@145
|
1043 return status;
|
Chris@145
|
1044 } else if (!canImportLayer) {
|
Chris@145
|
1045 return FileOpenWrongMode;
|
Chris@145
|
1046 } else if ((status = openLayer(source)) != FileOpenFailed) {
|
Chris@145
|
1047 return status;
|
Chris@145
|
1048 } else {
|
Chris@145
|
1049 return FileOpenFailed;
|
Chris@145
|
1050 }
|
Chris@145
|
1051 }
|
Chris@145
|
1052 }
|
Chris@145
|
1053
|
Chris@152
|
1054 if (audio && (status = openAudio(source, mode)) != FileOpenFailed) {
|
Chris@45
|
1055 return status;
|
Chris@45
|
1056 } else if ((status = openSession(source)) != FileOpenFailed) {
|
Chris@45
|
1057 return status;
|
Chris@45
|
1058 } else if ((status = openPlaylist(source, mode)) != FileOpenFailed) {
|
Chris@45
|
1059 return status;
|
Chris@45
|
1060 } else if (!canImportLayer) {
|
Chris@45
|
1061 return FileOpenWrongMode;
|
Chris@45
|
1062 } else if ((status = openImage(source)) != FileOpenFailed) {
|
Chris@45
|
1063 return status;
|
Chris@45
|
1064 } else if ((status = openLayer(source)) != FileOpenFailed) {
|
Chris@45
|
1065 return status;
|
Chris@45
|
1066 } else {
|
Chris@45
|
1067 return FileOpenFailed;
|
Chris@45
|
1068 }
|
Chris@45
|
1069 }
|
Chris@45
|
1070
|
Chris@45
|
1071 MainWindowBase::FileOpenStatus
|
dan@210
|
1072 MainWindowBase::openAudio(FileSource source, AudioFileOpenMode mode, QString templateName)
|
Chris@45
|
1073 {
|
Chris@132
|
1074 // std::cerr << "MainWindowBase::openAudio(" << source.getLocation().toStdString() << ")" << std::endl;
|
Chris@45
|
1075
|
Chris@45
|
1076 if (!source.isAvailable()) return FileOpenFailed;
|
Chris@45
|
1077 source.waitForData();
|
Chris@45
|
1078
|
Chris@45
|
1079 m_openingAudioFile = true;
|
Chris@45
|
1080
|
Chris@45
|
1081 size_t rate = 0;
|
Chris@45
|
1082
|
Chris@45
|
1083 if (Preferences::getInstance()->getResampleOnLoad()) {
|
Chris@45
|
1084 rate = m_playSource->getSourceSampleRate();
|
Chris@45
|
1085 }
|
Chris@45
|
1086
|
Chris@45
|
1087 WaveFileModel *newModel = new WaveFileModel(source, rate);
|
Chris@45
|
1088
|
Chris@45
|
1089 if (!newModel->isOK()) {
|
Chris@45
|
1090 delete newModel;
|
Chris@45
|
1091 m_openingAudioFile = false;
|
Chris@45
|
1092 return FileOpenFailed;
|
Chris@45
|
1093 }
|
Chris@45
|
1094
|
Chris@132
|
1095 // std::cerr << "mode = " << mode << std::endl;
|
Chris@45
|
1096
|
Chris@45
|
1097 if (mode == AskUser) {
|
Chris@45
|
1098 if (getMainModel()) {
|
Chris@45
|
1099
|
Chris@147
|
1100 QSettings settings;
|
Chris@147
|
1101 settings.beginGroup("MainWindow");
|
Chris@147
|
1102 bool prevSetAsMain = settings.value("newsessionforaudio", true).toBool();
|
Chris@147
|
1103 settings.endGroup();
|
Chris@45
|
1104 bool setAsMain = true;
|
Chris@45
|
1105
|
Chris@45
|
1106 QStringList items;
|
Chris@45
|
1107 items << tr("Replace the existing main waveform")
|
Chris@45
|
1108 << tr("Load this file into a new waveform pane");
|
Chris@45
|
1109
|
Chris@45
|
1110 bool ok = false;
|
Chris@45
|
1111 QString item = ListInputDialog::getItem
|
Chris@45
|
1112 (this, tr("Select target for import"),
|
Chris@155
|
1113 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
|
1114 items, prevSetAsMain ? 0 : 1, &ok);
|
Chris@45
|
1115
|
Chris@45
|
1116 if (!ok || item.isEmpty()) {
|
Chris@45
|
1117 delete newModel;
|
Chris@45
|
1118 m_openingAudioFile = false;
|
Chris@45
|
1119 return FileOpenCancelled;
|
Chris@45
|
1120 }
|
Chris@45
|
1121
|
Chris@45
|
1122 setAsMain = (item == items[0]);
|
Chris@147
|
1123 settings.beginGroup("MainWindow");
|
Chris@147
|
1124 settings.setValue("newsessionforaudio", setAsMain);
|
Chris@147
|
1125 settings.endGroup();
|
Chris@45
|
1126
|
Chris@45
|
1127 if (setAsMain) mode = ReplaceMainModel;
|
Chris@45
|
1128 else mode = CreateAdditionalModel;
|
Chris@45
|
1129
|
Chris@45
|
1130 } else {
|
Chris@45
|
1131 mode = ReplaceMainModel;
|
Chris@45
|
1132 }
|
Chris@45
|
1133 }
|
Chris@45
|
1134
|
Chris@45
|
1135 if (mode == ReplaceCurrentPane) {
|
Chris@45
|
1136
|
Chris@45
|
1137 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@45
|
1138 if (pane) {
|
Chris@45
|
1139 if (getMainModel()) {
|
Chris@45
|
1140 View::ModelSet models(pane->getModels());
|
Chris@45
|
1141 if (models.find(getMainModel()) != models.end()) {
|
Chris@45
|
1142 mode = ReplaceMainModel;
|
Chris@45
|
1143 }
|
Chris@45
|
1144 } else {
|
Chris@45
|
1145 mode = ReplaceMainModel;
|
Chris@45
|
1146 }
|
Chris@45
|
1147 } else {
|
Chris@45
|
1148 mode = CreateAdditionalModel;
|
Chris@45
|
1149 }
|
Chris@45
|
1150 }
|
Chris@45
|
1151
|
Chris@45
|
1152 if (mode == CreateAdditionalModel && !getMainModel()) {
|
Chris@45
|
1153 mode = ReplaceMainModel;
|
Chris@45
|
1154 }
|
Chris@45
|
1155
|
dan@210
|
1156 bool loadedTemplate = false;
|
dan@210
|
1157 if ((mode == ReplaceMainModel) && (templateName.length() != 0)) {
|
dan@210
|
1158 QString tplPath = "file::templates/" + templateName + ".xml";
|
dan@210
|
1159 std::cerr << "SV looking for template " << tplPath.toStdString() << std::endl;
|
dan@210
|
1160 FileOpenStatus tplStatus = openSessionFile(tplPath);
|
dan@210
|
1161 if(tplStatus != FileOpenFailed) {
|
dan@210
|
1162 loadedTemplate = true;
|
dan@210
|
1163 mode = ReplaceMainModel;
|
dan@210
|
1164 }
|
dan@210
|
1165 }
|
dan@210
|
1166
|
Chris@164
|
1167 emit activity(tr("Import audio file \"%1\"").arg(source.getLocation()));
|
Chris@164
|
1168
|
Chris@45
|
1169 if (mode == ReplaceMainModel) {
|
Chris@45
|
1170
|
Chris@45
|
1171 Model *prevMain = getMainModel();
|
Chris@45
|
1172 if (prevMain) {
|
Chris@45
|
1173 m_playSource->removeModel(prevMain);
|
Chris@108
|
1174 PlayParameterRepository::getInstance()->removePlayable(prevMain);
|
Chris@45
|
1175 }
|
Chris@108
|
1176 PlayParameterRepository::getInstance()->addPlayable(newModel);
|
Chris@45
|
1177
|
Chris@45
|
1178 m_document->setMainModel(newModel);
|
Chris@45
|
1179
|
Chris@45
|
1180 setupMenus();
|
Chris@45
|
1181
|
dan@210
|
1182 if (loadedTemplate || (m_sessionFile == "")) {
|
Chris@45
|
1183 //!!! shouldn't be dealing directly with title from here -- call a method
|
Chris@57
|
1184 setWindowTitle(tr("%1: %2")
|
Chris@57
|
1185 .arg(QApplication::applicationName())
|
Chris@45
|
1186 .arg(source.getLocation()));
|
Chris@45
|
1187 CommandHistory::getInstance()->clear();
|
Chris@45
|
1188 CommandHistory::getInstance()->documentSaved();
|
Chris@45
|
1189 m_documentModified = false;
|
Chris@45
|
1190 } else {
|
Chris@57
|
1191 setWindowTitle(tr("%1: %2 [%3]")
|
Chris@57
|
1192 .arg(QApplication::applicationName())
|
Chris@45
|
1193 .arg(QFileInfo(m_sessionFile).fileName())
|
Chris@45
|
1194 .arg(source.getLocation()));
|
Chris@45
|
1195 if (m_documentModified) {
|
Chris@45
|
1196 m_documentModified = false;
|
Chris@45
|
1197 documentModified(); // so as to restore "(modified)" window title
|
Chris@45
|
1198 }
|
Chris@45
|
1199 }
|
Chris@45
|
1200
|
Chris@45
|
1201 if (!source.isRemote()) m_audioFile = source.getLocalFilename();
|
Chris@45
|
1202
|
Chris@45
|
1203 } else if (mode == CreateAdditionalModel) {
|
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 AddPaneCommand *command = new AddPaneCommand(this);
|
Chris@45
|
1211 CommandHistory::getInstance()->addCommand(command);
|
Chris@45
|
1212
|
Chris@45
|
1213 Pane *pane = command->getPane();
|
Chris@45
|
1214
|
Chris@47
|
1215 if (m_timeRulerLayer) {
|
Chris@47
|
1216 m_document->addLayerToView(pane, m_timeRulerLayer);
|
Chris@47
|
1217 }
|
Chris@45
|
1218
|
Chris@45
|
1219 Layer *newLayer = m_document->createImportedLayer(newModel);
|
Chris@45
|
1220
|
Chris@45
|
1221 if (newLayer) {
|
Chris@45
|
1222 m_document->addLayerToView(pane, newLayer);
|
Chris@45
|
1223 }
|
Chris@45
|
1224
|
Chris@45
|
1225 CommandHistory::getInstance()->endCompoundOperation();
|
Chris@45
|
1226
|
Chris@45
|
1227 } else if (mode == ReplaceCurrentPane) {
|
Chris@45
|
1228
|
Chris@45
|
1229 // We know there is a current pane, otherwise we would have
|
Chris@45
|
1230 // reset the mode to CreateAdditionalModel above; and we know
|
Chris@45
|
1231 // the current pane does not contain the main model, otherwise
|
Chris@45
|
1232 // we would have reset it to ReplaceMainModel. But we don't
|
Chris@45
|
1233 // know whether the pane contains a waveform model at all.
|
Chris@45
|
1234
|
Chris@45
|
1235 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@45
|
1236 Layer *replace = 0;
|
Chris@45
|
1237
|
Chris@45
|
1238 for (int i = 0; i < pane->getLayerCount(); ++i) {
|
Chris@45
|
1239 Layer *layer = pane->getLayer(i);
|
Chris@45
|
1240 if (dynamic_cast<WaveformLayer *>(layer)) {
|
Chris@45
|
1241 replace = layer;
|
Chris@45
|
1242 break;
|
Chris@45
|
1243 }
|
Chris@45
|
1244 }
|
Chris@45
|
1245
|
Chris@45
|
1246 CommandHistory::getInstance()->startCompoundOperation
|
Chris@45
|
1247 (tr("Import \"%1\"").arg(source.getLocation()), true);
|
Chris@45
|
1248
|
Chris@45
|
1249 m_document->addImportedModel(newModel);
|
Chris@45
|
1250
|
Chris@45
|
1251 if (replace) {
|
Chris@45
|
1252 m_document->removeLayerFromView(pane, replace);
|
Chris@45
|
1253 }
|
Chris@45
|
1254
|
Chris@45
|
1255 Layer *newLayer = m_document->createImportedLayer(newModel);
|
Chris@45
|
1256
|
Chris@45
|
1257 if (newLayer) {
|
Chris@45
|
1258 m_document->addLayerToView(pane, newLayer);
|
Chris@45
|
1259 }
|
Chris@45
|
1260
|
Chris@45
|
1261 CommandHistory::getInstance()->endCompoundOperation();
|
Chris@45
|
1262 }
|
Chris@45
|
1263
|
Chris@45
|
1264 updateMenuStates();
|
Chris@45
|
1265 m_recentFiles.addFile(source.getLocation());
|
Chris@45
|
1266 if (!source.isRemote()) {
|
Chris@45
|
1267 // for file dialog
|
Chris@45
|
1268 registerLastOpenedFilePath(FileFinder::AudioFile,
|
Chris@45
|
1269 source.getLocalFilename());
|
Chris@45
|
1270 }
|
Chris@45
|
1271 m_openingAudioFile = false;
|
Chris@45
|
1272
|
Chris@45
|
1273 currentPaneChanged(m_paneStack->getCurrentPane());
|
Chris@45
|
1274
|
Chris@45
|
1275 return FileOpenSucceeded;
|
Chris@45
|
1276 }
|
Chris@45
|
1277
|
Chris@45
|
1278 MainWindowBase::FileOpenStatus
|
Chris@45
|
1279 MainWindowBase::openPlaylist(FileSource source, AudioFileOpenMode mode)
|
Chris@45
|
1280 {
|
Chris@135
|
1281 std::cerr << "MainWindowBase::openPlaylist(" << source.getLocation().toStdString() << ")" << std::endl;
|
Chris@135
|
1282
|
Chris@45
|
1283 std::set<QString> extensions;
|
Chris@45
|
1284 PlaylistFileReader::getSupportedExtensions(extensions);
|
Chris@152
|
1285 QString extension = source.getExtension().toLower();
|
Chris@45
|
1286 if (extensions.find(extension) == extensions.end()) return FileOpenFailed;
|
Chris@45
|
1287
|
Chris@45
|
1288 if (!source.isAvailable()) return FileOpenFailed;
|
Chris@45
|
1289 source.waitForData();
|
Chris@45
|
1290
|
Chris@45
|
1291 PlaylistFileReader reader(source.getLocalFilename());
|
Chris@45
|
1292 if (!reader.isOK()) return FileOpenFailed;
|
Chris@45
|
1293
|
Chris@45
|
1294 PlaylistFileReader::Playlist playlist = reader.load();
|
Chris@45
|
1295
|
Chris@45
|
1296 bool someSuccess = false;
|
Chris@45
|
1297
|
Chris@45
|
1298 for (PlaylistFileReader::Playlist::const_iterator i = playlist.begin();
|
Chris@45
|
1299 i != playlist.end(); ++i) {
|
Chris@45
|
1300
|
Chris@134
|
1301 ProgressDialog dialog(tr("Opening playlist..."), true, 2000, this);
|
Chris@134
|
1302 connect(&dialog, SIGNAL(showing()), this, SIGNAL(hideSplash()));
|
Chris@109
|
1303 FileOpenStatus status = openAudio(FileSource(*i, &dialog), mode);
|
Chris@45
|
1304
|
Chris@45
|
1305 if (status == FileOpenCancelled) {
|
Chris@45
|
1306 return FileOpenCancelled;
|
Chris@45
|
1307 }
|
Chris@45
|
1308
|
Chris@45
|
1309 if (status == FileOpenSucceeded) {
|
Chris@45
|
1310 someSuccess = true;
|
Chris@45
|
1311 mode = CreateAdditionalModel;
|
Chris@45
|
1312 }
|
Chris@45
|
1313 }
|
Chris@45
|
1314
|
Chris@45
|
1315 if (someSuccess) return FileOpenSucceeded;
|
Chris@45
|
1316 else return FileOpenFailed;
|
Chris@45
|
1317 }
|
Chris@45
|
1318
|
Chris@45
|
1319 MainWindowBase::FileOpenStatus
|
Chris@45
|
1320 MainWindowBase::openLayer(FileSource source)
|
Chris@45
|
1321 {
|
Chris@135
|
1322 std::cerr << "MainWindowBase::openLayer(" << source.getLocation().toStdString() << ")" << std::endl;
|
Chris@135
|
1323
|
Chris@45
|
1324 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@45
|
1325
|
Chris@45
|
1326 if (!pane) {
|
Chris@45
|
1327 // shouldn't happen, as the menu action should have been disabled
|
Chris@45
|
1328 std::cerr << "WARNING: MainWindowBase::openLayer: no current pane" << std::endl;
|
Chris@45
|
1329 return FileOpenWrongMode;
|
Chris@45
|
1330 }
|
Chris@45
|
1331
|
Chris@45
|
1332 if (!getMainModel()) {
|
Chris@45
|
1333 // shouldn't happen, as the menu action should have been disabled
|
Chris@45
|
1334 std::cerr << "WARNING: MainWindowBase::openLayer: No main model -- hence no default sample rate available" << std::endl;
|
Chris@45
|
1335 return FileOpenWrongMode;
|
Chris@45
|
1336 }
|
Chris@45
|
1337
|
Chris@45
|
1338 if (!source.isAvailable()) return FileOpenFailed;
|
Chris@45
|
1339 source.waitForData();
|
Chris@45
|
1340
|
Chris@45
|
1341 QString path = source.getLocalFilename();
|
Chris@45
|
1342
|
Chris@145
|
1343 RDFImporter::RDFDocumentType rdfType =
|
Chris@145
|
1344 RDFImporter::identifyDocumentType(QUrl::fromLocalFile(path).toString());
|
Chris@145
|
1345
|
Chris@148
|
1346 // std::cerr << "RDF type: (in layer) " << (int) rdfType << std::endl;
|
Chris@148
|
1347
|
Chris@145
|
1348 if (rdfType != RDFImporter::NotRDF) {
|
Chris@145
|
1349
|
Chris@145
|
1350 return openLayersFromRDF(source);
|
Chris@134
|
1351
|
Chris@152
|
1352 } else if (source.getExtension().toLower() == "svl" ||
|
Chris@152
|
1353 (source.getExtension().toLower() == "xml" &&
|
Chris@140
|
1354 (SVFileReader::identifyXmlFile(source.getLocalFilename())
|
Chris@140
|
1355 == SVFileReader::SVLayerFile))) {
|
Chris@45
|
1356
|
Chris@45
|
1357 PaneCallback callback(this);
|
Chris@45
|
1358 QFile file(path);
|
Chris@45
|
1359
|
Chris@45
|
1360 if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
Chris@45
|
1361 std::cerr << "ERROR: MainWindowBase::openLayer("
|
Chris@45
|
1362 << source.getLocation().toStdString()
|
Chris@45
|
1363 << "): Failed to open file for reading" << std::endl;
|
Chris@45
|
1364 return FileOpenFailed;
|
Chris@45
|
1365 }
|
Chris@45
|
1366
|
Chris@45
|
1367 SVFileReader reader(m_document, callback, source.getLocation());
|
Chris@79
|
1368 connect
|
Chris@79
|
1369 (&reader, SIGNAL(modelRegenerationFailed(QString, QString, QString)),
|
Chris@79
|
1370 this, SLOT(modelRegenerationFailed(QString, QString, QString)));
|
Chris@79
|
1371 connect
|
Chris@79
|
1372 (&reader, SIGNAL(modelRegenerationWarning(QString, QString, QString)),
|
Chris@79
|
1373 this, SLOT(modelRegenerationWarning(QString, QString, QString)));
|
Chris@45
|
1374 reader.setCurrentPane(pane);
|
Chris@45
|
1375
|
Chris@45
|
1376 QXmlInputSource inputSource(&file);
|
Chris@45
|
1377 reader.parse(inputSource);
|
Chris@45
|
1378
|
Chris@45
|
1379 if (!reader.isOK()) {
|
Chris@45
|
1380 std::cerr << "ERROR: MainWindowBase::openLayer("
|
Chris@45
|
1381 << source.getLocation().toStdString()
|
Chris@45
|
1382 << "): Failed to read XML file: "
|
Chris@45
|
1383 << reader.getErrorString().toStdString() << std::endl;
|
Chris@45
|
1384 return FileOpenFailed;
|
Chris@45
|
1385 }
|
Chris@45
|
1386
|
Chris@164
|
1387 emit activity(tr("Import layer XML file \"%1\"").arg(source.getLocation()));
|
Chris@164
|
1388
|
Chris@45
|
1389 m_recentFiles.addFile(source.getLocation());
|
Chris@45
|
1390
|
Chris@45
|
1391 if (!source.isRemote()) {
|
Chris@45
|
1392 registerLastOpenedFilePath(FileFinder::LayerFile, path); // for file dialog
|
Chris@45
|
1393 }
|
Chris@45
|
1394
|
Chris@75
|
1395 return FileOpenSucceeded;
|
Chris@75
|
1396
|
Chris@45
|
1397 } else {
|
Chris@45
|
1398
|
Chris@45
|
1399 try {
|
Chris@45
|
1400
|
Chris@109
|
1401 MIDIFileImportDialog midiDlg(this);
|
Chris@109
|
1402
|
Chris@109
|
1403 Model *model = DataFileReaderFactory::loadNonCSV
|
Chris@109
|
1404 (path, &midiDlg, getMainModel()->getSampleRate());
|
Chris@45
|
1405
|
Chris@109
|
1406 if (!model) {
|
Chris@196
|
1407 CSVFormat format(path);
|
Chris@196
|
1408 format.setSampleRate(getMainModel()->getSampleRate());
|
Chris@196
|
1409 CSVFormatDialog *dialog = new CSVFormatDialog(this, format);
|
Chris@109
|
1410 if (dialog->exec() == QDialog::Accepted) {
|
Chris@109
|
1411 model = DataFileReaderFactory::loadCSV
|
Chris@109
|
1412 (path, dialog->getFormat(),
|
Chris@109
|
1413 getMainModel()->getSampleRate());
|
Chris@109
|
1414 }
|
Chris@109
|
1415 }
|
Chris@109
|
1416
|
Chris@45
|
1417 if (model) {
|
Chris@45
|
1418
|
Chris@45
|
1419 std::cerr << "MainWindowBase::openLayer: Have model" << std::endl;
|
Chris@45
|
1420
|
Chris@164
|
1421 emit activity(tr("Import MIDI file \"%1\"").arg(source.getLocation()));
|
Chris@164
|
1422
|
Chris@45
|
1423 Layer *newLayer = m_document->createImportedLayer(model);
|
Chris@45
|
1424
|
Chris@45
|
1425 if (newLayer) {
|
Chris@45
|
1426
|
Chris@45
|
1427 m_document->addLayerToView(pane, newLayer);
|
Chris@88
|
1428 m_paneStack->setCurrentLayer(pane, newLayer);
|
Chris@88
|
1429
|
Chris@45
|
1430 m_recentFiles.addFile(source.getLocation());
|
Chris@45
|
1431
|
Chris@45
|
1432 if (!source.isRemote()) {
|
Chris@45
|
1433 registerLastOpenedFilePath
|
Chris@45
|
1434 (FileFinder::LayerFile,
|
Chris@45
|
1435 path); // for file dialog
|
Chris@45
|
1436 }
|
Chris@88
|
1437
|
Chris@45
|
1438 return FileOpenSucceeded;
|
Chris@45
|
1439 }
|
Chris@45
|
1440 }
|
Chris@45
|
1441 } catch (DataFileReaderFactory::Exception e) {
|
Chris@45
|
1442 if (e == DataFileReaderFactory::ImportCancelled) {
|
Chris@45
|
1443 return FileOpenCancelled;
|
Chris@45
|
1444 }
|
Chris@45
|
1445 }
|
Chris@45
|
1446 }
|
Chris@45
|
1447
|
Chris@45
|
1448 return FileOpenFailed;
|
Chris@45
|
1449 }
|
Chris@45
|
1450
|
Chris@45
|
1451 MainWindowBase::FileOpenStatus
|
Chris@45
|
1452 MainWindowBase::openImage(FileSource source)
|
Chris@45
|
1453 {
|
Chris@135
|
1454 std::cerr << "MainWindowBase::openImage(" << source.getLocation().toStdString() << ")" << std::endl;
|
Chris@135
|
1455
|
Chris@45
|
1456 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@45
|
1457
|
Chris@45
|
1458 if (!pane) {
|
Chris@45
|
1459 // shouldn't happen, as the menu action should have been disabled
|
Chris@45
|
1460 std::cerr << "WARNING: MainWindowBase::openImage: no current pane" << std::endl;
|
Chris@45
|
1461 return FileOpenWrongMode;
|
Chris@45
|
1462 }
|
Chris@45
|
1463
|
Chris@45
|
1464 if (!m_document->getMainModel()) {
|
Chris@45
|
1465 return FileOpenWrongMode;
|
Chris@45
|
1466 }
|
Chris@45
|
1467
|
Chris@45
|
1468 bool newLayer = false;
|
Chris@45
|
1469
|
Chris@45
|
1470 ImageLayer *il = dynamic_cast<ImageLayer *>(pane->getSelectedLayer());
|
Chris@45
|
1471 if (!il) {
|
Chris@45
|
1472 for (int i = pane->getLayerCount()-1; i >= 0; --i) {
|
Chris@45
|
1473 il = dynamic_cast<ImageLayer *>(pane->getLayer(i));
|
Chris@45
|
1474 if (il) break;
|
Chris@45
|
1475 }
|
Chris@45
|
1476 }
|
Chris@45
|
1477 if (!il) {
|
Chris@45
|
1478 il = dynamic_cast<ImageLayer *>
|
Chris@45
|
1479 (m_document->createEmptyLayer(LayerFactory::Image));
|
Chris@45
|
1480 if (!il) return FileOpenFailed;
|
Chris@45
|
1481 newLayer = true;
|
Chris@45
|
1482 }
|
Chris@45
|
1483
|
Chris@45
|
1484 // We don't put the image file in Recent Files
|
Chris@45
|
1485
|
Chris@45
|
1486 std::cerr << "openImage: trying location \"" << source.getLocation().toStdString() << "\" in image layer" << std::endl;
|
Chris@45
|
1487
|
Chris@45
|
1488 if (!il->addImage(m_viewManager->getGlobalCentreFrame(), source.getLocation())) {
|
Chris@45
|
1489 if (newLayer) {
|
Chris@52
|
1490 m_document->deleteLayer(il); // also releases its model
|
Chris@45
|
1491 }
|
Chris@45
|
1492 return FileOpenFailed;
|
Chris@45
|
1493 } else {
|
Chris@45
|
1494 if (newLayer) {
|
Chris@45
|
1495 m_document->addLayerToView(pane, il);
|
Chris@45
|
1496 }
|
Chris@45
|
1497 m_paneStack->setCurrentLayer(pane, il);
|
Chris@45
|
1498 }
|
Chris@45
|
1499
|
Chris@45
|
1500 return FileOpenSucceeded;
|
Chris@45
|
1501 }
|
Chris@45
|
1502
|
Chris@45
|
1503 MainWindowBase::FileOpenStatus
|
Chris@45
|
1504 MainWindowBase::openSessionFile(QString fileOrUrl)
|
Chris@45
|
1505 {
|
Chris@134
|
1506 ProgressDialog dialog(tr("Opening session..."), true, 2000, this);
|
Chris@134
|
1507 connect(&dialog, SIGNAL(showing()), this, SIGNAL(hideSplash()));
|
Chris@109
|
1508 return openSession(FileSource(fileOrUrl, &dialog));
|
Chris@45
|
1509 }
|
Chris@45
|
1510
|
Chris@45
|
1511 MainWindowBase::FileOpenStatus
|
Chris@45
|
1512 MainWindowBase::openSession(FileSource source)
|
Chris@45
|
1513 {
|
Chris@135
|
1514 std::cerr << "MainWindowBase::openSession(" << source.getLocation().toStdString() << ")" << std::endl;
|
Chris@135
|
1515
|
Chris@45
|
1516 if (!source.isAvailable()) return FileOpenFailed;
|
Chris@145
|
1517 source.waitForData();
|
Chris@141
|
1518
|
Chris@152
|
1519 if (source.getExtension().toLower() != "sv") {
|
Chris@145
|
1520
|
Chris@145
|
1521 RDFImporter::RDFDocumentType rdfType =
|
Chris@145
|
1522 RDFImporter::identifyDocumentType
|
Chris@145
|
1523 (QUrl::fromLocalFile(source.getLocalFilename()).toString());
|
Chris@145
|
1524
|
Chris@148
|
1525 // std::cerr << "RDF type: " << (int)rdfType << std::endl;
|
Chris@148
|
1526
|
Chris@145
|
1527 if (rdfType == RDFImporter::AudioRefAndAnnotations ||
|
Chris@145
|
1528 rdfType == RDFImporter::AudioRef) {
|
Chris@145
|
1529 return openSessionFromRDF(source);
|
Chris@145
|
1530 } else if (rdfType != RDFImporter::NotRDF) {
|
Chris@145
|
1531 return FileOpenFailed;
|
Chris@145
|
1532 }
|
Chris@145
|
1533
|
Chris@152
|
1534 if (source.getExtension().toLower() == "xml") {
|
Chris@140
|
1535 if (SVFileReader::identifyXmlFile(source.getLocalFilename()) ==
|
Chris@140
|
1536 SVFileReader::SVSessionFile) {
|
Chris@140
|
1537 std::cerr << "This XML file looks like a session file, attempting to open it as a session" << std::endl;
|
Chris@140
|
1538 } else {
|
Chris@140
|
1539 return FileOpenFailed;
|
Chris@140
|
1540 }
|
Chris@140
|
1541 } else {
|
Chris@140
|
1542 return FileOpenFailed;
|
Chris@140
|
1543 }
|
Chris@140
|
1544 }
|
Chris@45
|
1545
|
Chris@140
|
1546 QXmlInputSource *inputSource = 0;
|
Chris@140
|
1547 BZipFileDevice *bzFile = 0;
|
Chris@140
|
1548 QFile *rawFile = 0;
|
Chris@140
|
1549
|
Chris@152
|
1550 if (source.getExtension().toLower() == "sv") {
|
Chris@140
|
1551 bzFile = new BZipFileDevice(source.getLocalFilename());
|
Chris@140
|
1552 if (!bzFile->open(QIODevice::ReadOnly)) {
|
Chris@140
|
1553 delete bzFile;
|
Chris@140
|
1554 return FileOpenFailed;
|
Chris@140
|
1555 }
|
Chris@140
|
1556 inputSource = new QXmlInputSource(bzFile);
|
Chris@140
|
1557 } else {
|
Chris@140
|
1558 rawFile = new QFile(source.getLocalFilename());
|
Chris@140
|
1559 inputSource = new QXmlInputSource(rawFile);
|
Chris@140
|
1560 }
|
Chris@140
|
1561
|
Chris@140
|
1562 if (!checkSaveModified()) {
|
Chris@140
|
1563 if (bzFile) bzFile->close();
|
Chris@140
|
1564 delete inputSource;
|
Chris@140
|
1565 delete bzFile;
|
Chris@140
|
1566 delete rawFile;
|
Chris@140
|
1567 return FileOpenCancelled;
|
Chris@140
|
1568 }
|
Chris@45
|
1569
|
Chris@45
|
1570 QString error;
|
Chris@45
|
1571 closeSession();
|
Chris@45
|
1572 createDocument();
|
Chris@45
|
1573
|
Chris@45
|
1574 PaneCallback callback(this);
|
Chris@45
|
1575 m_viewManager->clearSelections();
|
Chris@45
|
1576
|
Chris@45
|
1577 SVFileReader reader(m_document, callback, source.getLocation());
|
Chris@79
|
1578 connect
|
Chris@79
|
1579 (&reader, SIGNAL(modelRegenerationFailed(QString, QString, QString)),
|
Chris@79
|
1580 this, SLOT(modelRegenerationFailed(QString, QString, QString)));
|
Chris@79
|
1581 connect
|
Chris@79
|
1582 (&reader, SIGNAL(modelRegenerationWarning(QString, QString, QString)),
|
Chris@79
|
1583 this, SLOT(modelRegenerationWarning(QString, QString, QString)));
|
Chris@140
|
1584
|
Chris@140
|
1585 reader.parse(*inputSource);
|
Chris@45
|
1586
|
Chris@45
|
1587 if (!reader.isOK()) {
|
Chris@45
|
1588 error = tr("SV XML file read error:\n%1").arg(reader.getErrorString());
|
Chris@45
|
1589 }
|
Chris@45
|
1590
|
Chris@140
|
1591 if (bzFile) bzFile->close();
|
Chris@140
|
1592
|
Chris@140
|
1593 delete inputSource;
|
Chris@140
|
1594 delete bzFile;
|
Chris@140
|
1595 delete rawFile;
|
Chris@45
|
1596
|
Chris@45
|
1597 bool ok = (error == "");
|
Chris@45
|
1598
|
Chris@45
|
1599 if (ok) {
|
Chris@45
|
1600
|
Chris@164
|
1601 emit activity(tr("Import session file \"%1\"").arg(source.getLocation()));
|
Chris@164
|
1602
|
Chris@57
|
1603 setWindowTitle(tr("%1: %2")
|
Chris@57
|
1604 .arg(QApplication::applicationName())
|
Chris@45
|
1605 .arg(source.getLocation()));
|
Chris@45
|
1606
|
Chris@45
|
1607 if (!source.isRemote()) m_sessionFile = source.getLocalFilename();
|
Chris@45
|
1608
|
Chris@45
|
1609 setupMenus();
|
Chris@45
|
1610
|
Chris@45
|
1611 CommandHistory::getInstance()->clear();
|
Chris@45
|
1612 CommandHistory::getInstance()->documentSaved();
|
Chris@45
|
1613 m_documentModified = false;
|
Chris@45
|
1614 updateMenuStates();
|
Chris@45
|
1615
|
Chris@45
|
1616 m_recentFiles.addFile(source.getLocation());
|
Chris@45
|
1617
|
Chris@45
|
1618 if (!source.isRemote()) {
|
Chris@45
|
1619 // for file dialog
|
Chris@45
|
1620 registerLastOpenedFilePath(FileFinder::SessionFile,
|
Chris@45
|
1621 source.getLocalFilename());
|
Chris@45
|
1622 }
|
Chris@45
|
1623
|
Chris@45
|
1624 } else {
|
Chris@57
|
1625 setWindowTitle(QApplication::applicationName());
|
Chris@45
|
1626 }
|
Chris@45
|
1627
|
Chris@45
|
1628 return ok ? FileOpenSucceeded : FileOpenFailed;
|
Chris@45
|
1629 }
|
Chris@45
|
1630
|
Chris@141
|
1631 MainWindowBase::FileOpenStatus
|
Chris@141
|
1632 MainWindowBase::openSessionFromRDF(FileSource source)
|
Chris@141
|
1633 {
|
Chris@141
|
1634 std::cerr << "MainWindowBase::openSessionFromRDF(" << source.getLocation().toStdString() << ")" << std::endl;
|
Chris@141
|
1635
|
Chris@141
|
1636 if (!source.isAvailable()) return FileOpenFailed;
|
Chris@141
|
1637 source.waitForData();
|
Chris@141
|
1638
|
Chris@145
|
1639 if (!checkSaveModified()) {
|
Chris@145
|
1640 return FileOpenCancelled;
|
Chris@141
|
1641 }
|
Chris@143
|
1642
|
Chris@145
|
1643 closeSession();
|
Chris@145
|
1644 createDocument();
|
Chris@145
|
1645
|
Chris@145
|
1646 FileOpenStatus status = openLayersFromRDF(source);
|
Chris@141
|
1647
|
Chris@141
|
1648 setupMenus();
|
Chris@141
|
1649
|
Chris@141
|
1650 setWindowTitle(tr("%1: %2")
|
Chris@141
|
1651 .arg(QApplication::applicationName())
|
Chris@141
|
1652 .arg(source.getLocation()));
|
Chris@141
|
1653 CommandHistory::getInstance()->clear();
|
Chris@141
|
1654 CommandHistory::getInstance()->documentSaved();
|
Chris@141
|
1655 m_documentModified = false;
|
Chris@145
|
1656
|
Chris@145
|
1657 return status;
|
Chris@145
|
1658 }
|
Chris@145
|
1659
|
Chris@145
|
1660 MainWindowBase::FileOpenStatus
|
Chris@145
|
1661 MainWindowBase::openLayersFromRDF(FileSource source)
|
Chris@145
|
1662 {
|
Chris@145
|
1663 size_t rate = 0;
|
Chris@145
|
1664
|
Chris@186
|
1665 std::cerr << "MainWindowBase::openLayersFromRDF" << std::endl;
|
Chris@186
|
1666
|
Chris@145
|
1667 ProgressDialog dialog(tr("Importing from RDF..."), true, 2000, this);
|
Chris@145
|
1668 connect(&dialog, SIGNAL(showing()), this, SIGNAL(hideSplash()));
|
Chris@145
|
1669
|
Chris@145
|
1670 if (getMainModel()) {
|
Chris@145
|
1671 rate = getMainModel()->getSampleRate();
|
Chris@145
|
1672 } else if (Preferences::getInstance()->getResampleOnLoad()) {
|
Chris@145
|
1673 rate = m_playSource->getSourceSampleRate();
|
Chris@145
|
1674 }
|
Chris@145
|
1675
|
Chris@145
|
1676 RDFImporter importer
|
Chris@145
|
1677 (QUrl::fromLocalFile(source.getLocalFilename()).toString(), rate);
|
Chris@145
|
1678
|
Chris@145
|
1679 if (!importer.isOK()) {
|
Chris@147
|
1680 if (importer.getErrorString() != "") {
|
Chris@147
|
1681 QMessageBox::critical
|
Chris@147
|
1682 (this, tr("Failed to import RDF"),
|
Chris@147
|
1683 tr("<b>Failed to import RDF</b><p>Importing data from RDF document at \"%1\" failed: %2</p>")
|
Chris@147
|
1684 .arg(source.getLocation()).arg(importer.getErrorString()));
|
Chris@147
|
1685 }
|
Chris@145
|
1686 return FileOpenFailed;
|
Chris@145
|
1687 }
|
Chris@145
|
1688
|
Chris@145
|
1689 std::vector<Model *> models = importer.getDataModels(&dialog);
|
Chris@145
|
1690
|
Chris@145
|
1691 dialog.setMessage(tr("Importing from RDF..."));
|
Chris@145
|
1692
|
Chris@145
|
1693 if (models.empty()) {
|
Chris@186
|
1694 QMessageBox::critical
|
Chris@186
|
1695 (this, tr("Failed to import RDF"),
|
Chris@186
|
1696 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
|
1697 return FileOpenFailed;
|
Chris@145
|
1698 }
|
Chris@145
|
1699
|
Chris@164
|
1700 emit activity(tr("Import RDF document \"%1\"").arg(source.getLocation()));
|
Chris@164
|
1701
|
Chris@145
|
1702 std::set<Model *> added;
|
Chris@145
|
1703
|
Chris@145
|
1704 for (int i = 0; i < models.size(); ++i) {
|
Chris@145
|
1705
|
Chris@145
|
1706 Model *m = models[i];
|
Chris@145
|
1707 WaveFileModel *w = dynamic_cast<WaveFileModel *>(m);
|
Chris@145
|
1708
|
Chris@145
|
1709 if (w) {
|
Chris@145
|
1710
|
Chris@145
|
1711 Pane *pane = addPaneToStack();
|
Chris@145
|
1712 Layer *layer = 0;
|
Chris@145
|
1713
|
Chris@145
|
1714 if (m_timeRulerLayer) {
|
Chris@145
|
1715 m_document->addLayerToView(pane, m_timeRulerLayer);
|
Chris@145
|
1716 }
|
Chris@145
|
1717
|
Chris@145
|
1718 if (!getMainModel()) {
|
Chris@145
|
1719 m_document->setMainModel(w);
|
Chris@145
|
1720 layer = m_document->createMainModelLayer(LayerFactory::Waveform);
|
Chris@145
|
1721 } else {
|
Chris@145
|
1722 layer = m_document->createImportedLayer(w);
|
Chris@145
|
1723 }
|
Chris@145
|
1724
|
Chris@145
|
1725 m_document->addLayerToView(pane, layer);
|
Chris@145
|
1726
|
Chris@145
|
1727 added.insert(w);
|
Chris@145
|
1728
|
Chris@145
|
1729 for (int j = 0; j < models.size(); ++j) {
|
Chris@145
|
1730
|
Chris@145
|
1731 Model *dm = models[j];
|
Chris@145
|
1732
|
Chris@145
|
1733 if (dm == m) continue;
|
Chris@145
|
1734 if (dm->getSourceModel() != m) continue;
|
Chris@145
|
1735
|
Chris@145
|
1736 layer = m_document->createImportedLayer(dm);
|
Chris@145
|
1737
|
Chris@145
|
1738 if (layer->isLayerOpaque() ||
|
Chris@145
|
1739 dynamic_cast<Colour3DPlotLayer *>(layer)) {
|
Chris@145
|
1740
|
Chris@156
|
1741 // these always go in a new pane, with nothing
|
Chris@156
|
1742 // else going in the same pane
|
Chris@156
|
1743
|
Chris@145
|
1744 Pane *singleLayerPane = addPaneToStack();
|
Chris@145
|
1745 if (m_timeRulerLayer) {
|
Chris@145
|
1746 m_document->addLayerToView(singleLayerPane, m_timeRulerLayer);
|
Chris@145
|
1747 }
|
Chris@145
|
1748 m_document->addLayerToView(singleLayerPane, layer);
|
Chris@145
|
1749
|
Chris@156
|
1750 } else if (layer->getLayerColourSignificance() ==
|
Chris@156
|
1751 Layer::ColourHasMeaningfulValue) {
|
Chris@156
|
1752
|
Chris@156
|
1753 // these can go in a pane with something else, but
|
Chris@156
|
1754 // only if none of the something elses also have
|
Chris@156
|
1755 // this quality
|
Chris@156
|
1756
|
Chris@156
|
1757 bool needNewPane = false;
|
Chris@156
|
1758 for (int i = 0; i < pane->getLayerCount(); ++i) {
|
Chris@156
|
1759 Layer *otherLayer = pane->getLayer(i);
|
Chris@156
|
1760 if (otherLayer &&
|
Chris@156
|
1761 (otherLayer->getLayerColourSignificance() ==
|
Chris@156
|
1762 Layer::ColourHasMeaningfulValue)) {
|
Chris@156
|
1763 needNewPane = true;
|
Chris@156
|
1764 break;
|
Chris@156
|
1765 }
|
Chris@156
|
1766 }
|
Chris@156
|
1767 if (needNewPane) {
|
Chris@156
|
1768 pane = addPaneToStack();
|
Chris@156
|
1769 }
|
Chris@156
|
1770
|
Chris@156
|
1771 m_document->addLayerToView(pane, layer);
|
Chris@156
|
1772
|
Chris@145
|
1773 } else {
|
Chris@145
|
1774
|
Chris@145
|
1775 if (pane->getLayerCount() > 4) {
|
Chris@145
|
1776 pane = addPaneToStack();
|
Chris@145
|
1777 }
|
Chris@145
|
1778
|
Chris@145
|
1779 m_document->addLayerToView(pane, layer);
|
Chris@145
|
1780 }
|
Chris@145
|
1781
|
Chris@145
|
1782 added.insert(dm);
|
Chris@145
|
1783 }
|
Chris@145
|
1784 }
|
Chris@145
|
1785 }
|
Chris@145
|
1786
|
Chris@145
|
1787 for (int i = 0; i < models.size(); ++i) {
|
Chris@145
|
1788
|
Chris@145
|
1789 Model *m = models[i];
|
Chris@145
|
1790
|
Chris@145
|
1791 if (added.find(m) == added.end()) {
|
Chris@145
|
1792
|
Chris@145
|
1793 Layer *layer = m_document->createImportedLayer(m);
|
Chris@145
|
1794 if (!layer) return FileOpenFailed;
|
Chris@145
|
1795
|
Chris@145
|
1796 Pane *singleLayerPane = addPaneToStack();
|
Chris@145
|
1797 if (m_timeRulerLayer) {
|
Chris@145
|
1798 m_document->addLayerToView(singleLayerPane, m_timeRulerLayer);
|
Chris@145
|
1799 }
|
Chris@145
|
1800 m_document->addLayerToView(singleLayerPane, layer);
|
Chris@145
|
1801 }
|
Chris@145
|
1802 }
|
Chris@145
|
1803
|
Chris@145
|
1804 m_recentFiles.addFile(source.getLocation());
|
Chris@145
|
1805 return FileOpenSucceeded;
|
Chris@141
|
1806 }
|
Chris@141
|
1807
|
Chris@45
|
1808 void
|
Chris@45
|
1809 MainWindowBase::createPlayTarget()
|
Chris@45
|
1810 {
|
Chris@45
|
1811 if (m_playTarget) return;
|
Chris@45
|
1812
|
Chris@126
|
1813 QSettings settings;
|
Chris@126
|
1814 settings.beginGroup("Preferences");
|
Chris@126
|
1815 QString targetName = settings.value("audio-target", "").toString();
|
Chris@126
|
1816 settings.endGroup();
|
Chris@126
|
1817
|
Chris@126
|
1818 AudioTargetFactory *factory = AudioTargetFactory::getInstance();
|
Chris@126
|
1819
|
Chris@126
|
1820 factory->setDefaultCallbackTarget(targetName);
|
Chris@126
|
1821 m_playTarget = factory->createCallbackTarget(m_playSource);
|
Chris@126
|
1822
|
Chris@45
|
1823 if (!m_playTarget) {
|
Chris@104
|
1824 emit hideSplash();
|
Chris@126
|
1825
|
Chris@126
|
1826 if (factory->isAutoCallbackTarget(targetName)) {
|
Chris@128
|
1827 QMessageBox::warning
|
Chris@45
|
1828 (this, tr("Couldn't open audio device"),
|
Chris@126
|
1829 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
|
1830 QMessageBox::Ok);
|
Chris@126
|
1831 } else {
|
Chris@126
|
1832 QMessageBox::warning
|
Chris@126
|
1833 (this, tr("Couldn't open audio device"),
|
Chris@126
|
1834 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
|
1835 .arg(factory->getCallbackTargetDescription(targetName)),
|
Chris@126
|
1836 QMessageBox::Ok);
|
Chris@126
|
1837 }
|
Chris@45
|
1838 }
|
Chris@45
|
1839 }
|
Chris@45
|
1840
|
Chris@45
|
1841 WaveFileModel *
|
Chris@45
|
1842 MainWindowBase::getMainModel()
|
Chris@45
|
1843 {
|
Chris@45
|
1844 if (!m_document) return 0;
|
Chris@45
|
1845 return m_document->getMainModel();
|
Chris@45
|
1846 }
|
Chris@45
|
1847
|
Chris@45
|
1848 const WaveFileModel *
|
Chris@45
|
1849 MainWindowBase::getMainModel() const
|
Chris@45
|
1850 {
|
Chris@45
|
1851 if (!m_document) return 0;
|
Chris@45
|
1852 return m_document->getMainModel();
|
Chris@45
|
1853 }
|
Chris@45
|
1854
|
Chris@45
|
1855 void
|
Chris@45
|
1856 MainWindowBase::createDocument()
|
Chris@45
|
1857 {
|
Chris@45
|
1858 m_document = new Document;
|
Chris@45
|
1859
|
Chris@45
|
1860 connect(m_document, SIGNAL(layerAdded(Layer *)),
|
Chris@45
|
1861 this, SLOT(layerAdded(Layer *)));
|
Chris@45
|
1862 connect(m_document, SIGNAL(layerRemoved(Layer *)),
|
Chris@45
|
1863 this, SLOT(layerRemoved(Layer *)));
|
Chris@45
|
1864 connect(m_document, SIGNAL(layerAboutToBeDeleted(Layer *)),
|
Chris@45
|
1865 this, SLOT(layerAboutToBeDeleted(Layer *)));
|
Chris@45
|
1866 connect(m_document, SIGNAL(layerInAView(Layer *, bool)),
|
Chris@45
|
1867 this, SLOT(layerInAView(Layer *, bool)));
|
Chris@45
|
1868
|
Chris@45
|
1869 connect(m_document, SIGNAL(modelAdded(Model *)),
|
Chris@45
|
1870 this, SLOT(modelAdded(Model *)));
|
Chris@45
|
1871 connect(m_document, SIGNAL(mainModelChanged(WaveFileModel *)),
|
Chris@45
|
1872 this, SLOT(mainModelChanged(WaveFileModel *)));
|
Chris@45
|
1873 connect(m_document, SIGNAL(modelAboutToBeDeleted(Model *)),
|
Chris@45
|
1874 this, SLOT(modelAboutToBeDeleted(Model *)));
|
Chris@45
|
1875
|
Chris@78
|
1876 connect(m_document, SIGNAL(modelGenerationFailed(QString, QString)),
|
Chris@78
|
1877 this, SLOT(modelGenerationFailed(QString, QString)));
|
Chris@78
|
1878 connect(m_document, SIGNAL(modelRegenerationWarning(QString, QString, QString)),
|
Chris@78
|
1879 this, SLOT(modelRegenerationWarning(QString, QString, QString)));
|
Chris@78
|
1880 connect(m_document, SIGNAL(modelGenerationFailed(QString, QString)),
|
Chris@78
|
1881 this, SLOT(modelGenerationFailed(QString, QString)));
|
Chris@78
|
1882 connect(m_document, SIGNAL(modelRegenerationWarning(QString, QString, QString)),
|
Chris@78
|
1883 this, SLOT(modelRegenerationWarning(QString, QString, QString)));
|
Chris@78
|
1884 connect(m_document, SIGNAL(alignmentFailed(QString, QString)),
|
Chris@78
|
1885 this, SLOT(alignmentFailed(QString, QString)));
|
Chris@160
|
1886
|
Chris@160
|
1887 emit replacedDocument();
|
Chris@45
|
1888 }
|
Chris@45
|
1889
|
Chris@45
|
1890 bool
|
Chris@45
|
1891 MainWindowBase::saveSessionFile(QString path)
|
Chris@45
|
1892 {
|
Chris@45
|
1893 BZipFileDevice bzFile(path);
|
Chris@45
|
1894 if (!bzFile.open(QIODevice::WriteOnly)) {
|
Chris@45
|
1895 std::cerr << "Failed to open session file \"" << path.toStdString()
|
Chris@45
|
1896 << "\" for writing: "
|
Chris@45
|
1897 << bzFile.errorString().toStdString() << std::endl;
|
Chris@45
|
1898 return false;
|
Chris@45
|
1899 }
|
Chris@45
|
1900
|
Chris@45
|
1901 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
|
Chris@45
|
1902
|
Chris@45
|
1903 QTextStream out(&bzFile);
|
Chris@45
|
1904 toXml(out);
|
Chris@45
|
1905 out.flush();
|
Chris@45
|
1906
|
Chris@45
|
1907 QApplication::restoreOverrideCursor();
|
Chris@45
|
1908
|
Chris@45
|
1909 if (!bzFile.isOK()) {
|
Chris@45
|
1910 QMessageBox::critical(this, tr("Failed to write file"),
|
Chris@45
|
1911 tr("<b>Save failed</b><p>Failed to write to file \"%1\": %2")
|
Chris@45
|
1912 .arg(path).arg(bzFile.errorString()));
|
Chris@45
|
1913 bzFile.close();
|
Chris@45
|
1914 return false;
|
Chris@45
|
1915 }
|
Chris@45
|
1916
|
Chris@45
|
1917 bzFile.close();
|
Chris@45
|
1918 return true;
|
Chris@45
|
1919 }
|
Chris@45
|
1920
|
Chris@45
|
1921 void
|
Chris@45
|
1922 MainWindowBase::toXml(QTextStream &out)
|
Chris@45
|
1923 {
|
Chris@45
|
1924 QString indent(" ");
|
Chris@45
|
1925
|
Chris@45
|
1926 out << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
|
Chris@45
|
1927 out << "<!DOCTYPE sonic-visualiser>\n";
|
Chris@45
|
1928 out << "<sv>\n";
|
Chris@45
|
1929
|
Chris@45
|
1930 m_document->toXml(out, "", "");
|
Chris@45
|
1931
|
Chris@45
|
1932 out << "<display>\n";
|
Chris@45
|
1933
|
Chris@45
|
1934 out << QString(" <window width=\"%1\" height=\"%2\"/>\n")
|
Chris@45
|
1935 .arg(width()).arg(height());
|
Chris@45
|
1936
|
Chris@45
|
1937 for (int i = 0; i < m_paneStack->getPaneCount(); ++i) {
|
Chris@45
|
1938
|
Chris@45
|
1939 Pane *pane = m_paneStack->getPane(i);
|
Chris@45
|
1940
|
Chris@45
|
1941 if (pane) {
|
Chris@45
|
1942 pane->toXml(out, indent);
|
Chris@45
|
1943 }
|
Chris@45
|
1944 }
|
Chris@45
|
1945
|
Chris@45
|
1946 out << "</display>\n";
|
Chris@45
|
1947
|
Chris@45
|
1948 m_viewManager->getSelection().toXml(out);
|
Chris@45
|
1949
|
Chris@45
|
1950 out << "</sv>\n";
|
Chris@45
|
1951 }
|
Chris@45
|
1952
|
Chris@45
|
1953 Pane *
|
Chris@45
|
1954 MainWindowBase::addPaneToStack()
|
Chris@45
|
1955 {
|
Chris@45
|
1956 AddPaneCommand *command = new AddPaneCommand(this);
|
Chris@45
|
1957 CommandHistory::getInstance()->addCommand(command);
|
Chris@57
|
1958 Pane *pane = command->getPane();
|
Chris@57
|
1959 return pane;
|
Chris@45
|
1960 }
|
Chris@45
|
1961
|
Chris@45
|
1962 void
|
Chris@45
|
1963 MainWindowBase::zoomIn()
|
Chris@45
|
1964 {
|
Chris@45
|
1965 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@45
|
1966 if (currentPane) currentPane->zoom(true);
|
Chris@45
|
1967 }
|
Chris@45
|
1968
|
Chris@45
|
1969 void
|
Chris@45
|
1970 MainWindowBase::zoomOut()
|
Chris@45
|
1971 {
|
Chris@45
|
1972 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@45
|
1973 if (currentPane) currentPane->zoom(false);
|
Chris@45
|
1974 }
|
Chris@45
|
1975
|
Chris@45
|
1976 void
|
Chris@45
|
1977 MainWindowBase::zoomToFit()
|
Chris@45
|
1978 {
|
Chris@45
|
1979 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@45
|
1980 if (!currentPane) return;
|
Chris@45
|
1981
|
Chris@45
|
1982 Model *model = getMainModel();
|
Chris@45
|
1983 if (!model) return;
|
Chris@45
|
1984
|
Chris@45
|
1985 size_t start = model->getStartFrame();
|
Chris@45
|
1986 size_t end = model->getEndFrame();
|
Chris@60
|
1987 if (m_playSource) end = std::max(end, m_playSource->getPlayEndFrame());
|
Chris@45
|
1988 size_t pixels = currentPane->width();
|
Chris@45
|
1989
|
Chris@45
|
1990 size_t sw = currentPane->getVerticalScaleWidth();
|
Chris@45
|
1991 if (pixels > sw * 2) pixels -= sw * 2;
|
Chris@45
|
1992 else pixels = 1;
|
Chris@45
|
1993 if (pixels > 4) pixels -= 4;
|
Chris@45
|
1994
|
Chris@45
|
1995 size_t zoomLevel = (end - start) / pixels;
|
Chris@150
|
1996 if (zoomLevel < 1) zoomLevel = 1;
|
Chris@45
|
1997
|
Chris@45
|
1998 currentPane->setZoomLevel(zoomLevel);
|
Chris@45
|
1999 currentPane->setCentreFrame((start + end) / 2);
|
Chris@45
|
2000 }
|
Chris@45
|
2001
|
Chris@45
|
2002 void
|
Chris@45
|
2003 MainWindowBase::zoomDefault()
|
Chris@45
|
2004 {
|
Chris@45
|
2005 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@45
|
2006 if (currentPane) currentPane->setZoomLevel(1024);
|
Chris@45
|
2007 }
|
Chris@45
|
2008
|
Chris@45
|
2009 void
|
Chris@45
|
2010 MainWindowBase::scrollLeft()
|
Chris@45
|
2011 {
|
Chris@45
|
2012 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@45
|
2013 if (currentPane) currentPane->scroll(false, false);
|
Chris@45
|
2014 }
|
Chris@45
|
2015
|
Chris@45
|
2016 void
|
Chris@45
|
2017 MainWindowBase::jumpLeft()
|
Chris@45
|
2018 {
|
Chris@45
|
2019 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@45
|
2020 if (currentPane) currentPane->scroll(false, true);
|
Chris@45
|
2021 }
|
Chris@45
|
2022
|
Chris@45
|
2023 void
|
Chris@162
|
2024 MainWindowBase::peekLeft()
|
Chris@162
|
2025 {
|
Chris@162
|
2026 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@162
|
2027 if (currentPane) currentPane->scroll(false, false, false);
|
Chris@162
|
2028 }
|
Chris@162
|
2029
|
Chris@162
|
2030 void
|
Chris@45
|
2031 MainWindowBase::scrollRight()
|
Chris@45
|
2032 {
|
Chris@45
|
2033 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@45
|
2034 if (currentPane) currentPane->scroll(true, false);
|
Chris@45
|
2035 }
|
Chris@45
|
2036
|
Chris@45
|
2037 void
|
Chris@45
|
2038 MainWindowBase::jumpRight()
|
Chris@45
|
2039 {
|
Chris@45
|
2040 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@45
|
2041 if (currentPane) currentPane->scroll(true, true);
|
Chris@45
|
2042 }
|
Chris@45
|
2043
|
Chris@45
|
2044 void
|
Chris@162
|
2045 MainWindowBase::peekRight()
|
Chris@162
|
2046 {
|
Chris@162
|
2047 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@162
|
2048 if (currentPane) currentPane->scroll(true, false, false);
|
Chris@162
|
2049 }
|
Chris@162
|
2050
|
Chris@162
|
2051 void
|
Chris@45
|
2052 MainWindowBase::showNoOverlays()
|
Chris@45
|
2053 {
|
Chris@45
|
2054 m_viewManager->setOverlayMode(ViewManager::NoOverlays);
|
Chris@45
|
2055 }
|
Chris@45
|
2056
|
Chris@45
|
2057 void
|
Chris@45
|
2058 MainWindowBase::showMinimalOverlays()
|
Chris@45
|
2059 {
|
Chris@45
|
2060 m_viewManager->setOverlayMode(ViewManager::MinimalOverlays);
|
Chris@45
|
2061 }
|
Chris@45
|
2062
|
Chris@45
|
2063 void
|
Chris@45
|
2064 MainWindowBase::showStandardOverlays()
|
Chris@45
|
2065 {
|
Chris@45
|
2066 m_viewManager->setOverlayMode(ViewManager::StandardOverlays);
|
Chris@45
|
2067 }
|
Chris@45
|
2068
|
Chris@45
|
2069 void
|
Chris@45
|
2070 MainWindowBase::showAllOverlays()
|
Chris@45
|
2071 {
|
Chris@45
|
2072 m_viewManager->setOverlayMode(ViewManager::AllOverlays);
|
Chris@45
|
2073 }
|
Chris@45
|
2074
|
Chris@45
|
2075 void
|
Chris@211
|
2076 MainWindowBase::toggleTimeRulers()
|
Chris@211
|
2077 {
|
Chris@211
|
2078 bool haveRulers = false;
|
Chris@211
|
2079 bool someHidden = false;
|
Chris@211
|
2080
|
Chris@211
|
2081 for (int i = 0; i < m_paneStack->getPaneCount(); ++i) {
|
Chris@211
|
2082
|
Chris@211
|
2083 Pane *pane = m_paneStack->getPane(i);
|
Chris@211
|
2084 if (!pane) continue;
|
Chris@211
|
2085
|
Chris@211
|
2086 for (int j = 0; j < pane->getLayerCount(); ++j) {
|
Chris@211
|
2087
|
Chris@211
|
2088 Layer *layer = pane->getLayer(j);
|
Chris@211
|
2089 if (!dynamic_cast<TimeRulerLayer *>(layer)) continue;
|
Chris@211
|
2090
|
Chris@211
|
2091 haveRulers = true;
|
Chris@211
|
2092 if (layer->isLayerDormant(pane)) someHidden = true;
|
Chris@211
|
2093 }
|
Chris@211
|
2094 }
|
Chris@211
|
2095
|
Chris@211
|
2096 if (haveRulers) {
|
Chris@211
|
2097
|
Chris@211
|
2098 bool show = someHidden;
|
Chris@211
|
2099
|
Chris@211
|
2100 for (int i = 0; i < m_paneStack->getPaneCount(); ++i) {
|
Chris@211
|
2101
|
Chris@211
|
2102 Pane *pane = m_paneStack->getPane(i);
|
Chris@211
|
2103 if (!pane) continue;
|
Chris@211
|
2104
|
Chris@211
|
2105 for (int j = 0; j < pane->getLayerCount(); ++j) {
|
Chris@211
|
2106
|
Chris@211
|
2107 Layer *layer = pane->getLayer(j);
|
Chris@211
|
2108 if (!dynamic_cast<TimeRulerLayer *>(layer)) continue;
|
Chris@211
|
2109
|
Chris@211
|
2110 layer->showLayer(pane, show);
|
Chris@211
|
2111 }
|
Chris@211
|
2112 }
|
Chris@211
|
2113 }
|
Chris@211
|
2114 }
|
Chris@211
|
2115
|
Chris@211
|
2116 void
|
Chris@45
|
2117 MainWindowBase::toggleZoomWheels()
|
Chris@45
|
2118 {
|
Chris@45
|
2119 if (m_viewManager->getZoomWheelsEnabled()) {
|
Chris@45
|
2120 m_viewManager->setZoomWheelsEnabled(false);
|
Chris@45
|
2121 } else {
|
Chris@45
|
2122 m_viewManager->setZoomWheelsEnabled(true);
|
Chris@45
|
2123 }
|
Chris@45
|
2124 }
|
Chris@45
|
2125
|
Chris@45
|
2126 void
|
Chris@45
|
2127 MainWindowBase::togglePropertyBoxes()
|
Chris@45
|
2128 {
|
Chris@45
|
2129 if (m_paneStack->getLayoutStyle() == PaneStack::NoPropertyStacks) {
|
Chris@45
|
2130 if (Preferences::getInstance()->getPropertyBoxLayout() ==
|
Chris@45
|
2131 Preferences::VerticallyStacked) {
|
Chris@45
|
2132 m_paneStack->setLayoutStyle(PaneStack::PropertyStackPerPaneLayout);
|
Chris@45
|
2133 } else {
|
Chris@45
|
2134 m_paneStack->setLayoutStyle(PaneStack::SinglePropertyStackLayout);
|
Chris@45
|
2135 }
|
Chris@45
|
2136 } else {
|
Chris@45
|
2137 m_paneStack->setLayoutStyle(PaneStack::NoPropertyStacks);
|
Chris@45
|
2138 }
|
Chris@45
|
2139 }
|
Chris@45
|
2140
|
Chris@45
|
2141 void
|
Chris@45
|
2142 MainWindowBase::toggleStatusBar()
|
Chris@45
|
2143 {
|
Chris@45
|
2144 QSettings settings;
|
Chris@45
|
2145 settings.beginGroup("MainWindow");
|
Chris@45
|
2146 bool sb = settings.value("showstatusbar", true).toBool();
|
Chris@45
|
2147
|
Chris@45
|
2148 if (sb) {
|
Chris@45
|
2149 statusBar()->hide();
|
Chris@45
|
2150 } else {
|
Chris@45
|
2151 statusBar()->show();
|
Chris@45
|
2152 }
|
Chris@45
|
2153
|
Chris@45
|
2154 settings.setValue("showstatusbar", !sb);
|
Chris@45
|
2155
|
Chris@45
|
2156 settings.endGroup();
|
Chris@45
|
2157 }
|
Chris@45
|
2158
|
Chris@45
|
2159 void
|
Chris@45
|
2160 MainWindowBase::preferenceChanged(PropertyContainer::PropertyName name)
|
Chris@45
|
2161 {
|
Chris@45
|
2162 if (name == "Property Box Layout") {
|
Chris@45
|
2163 if (m_paneStack->getLayoutStyle() != PaneStack::NoPropertyStacks) {
|
Chris@45
|
2164 if (Preferences::getInstance()->getPropertyBoxLayout() ==
|
Chris@45
|
2165 Preferences::VerticallyStacked) {
|
Chris@45
|
2166 m_paneStack->setLayoutStyle(PaneStack::PropertyStackPerPaneLayout);
|
Chris@45
|
2167 } else {
|
Chris@45
|
2168 m_paneStack->setLayoutStyle(PaneStack::SinglePropertyStackLayout);
|
Chris@45
|
2169 }
|
Chris@45
|
2170 }
|
Chris@45
|
2171 } else if (name == "Background Mode" && m_viewManager) {
|
Chris@45
|
2172 Preferences::BackgroundMode mode =
|
Chris@45
|
2173 Preferences::getInstance()->getBackgroundMode();
|
Chris@45
|
2174 if (mode == Preferences::BackgroundFromTheme) {
|
Chris@45
|
2175 m_viewManager->setGlobalDarkBackground(m_initialDarkBackground);
|
Chris@45
|
2176 } else if (mode == Preferences::DarkBackground) {
|
Chris@45
|
2177 m_viewManager->setGlobalDarkBackground(true);
|
Chris@45
|
2178 } else {
|
Chris@45
|
2179 m_viewManager->setGlobalDarkBackground(false);
|
Chris@45
|
2180 }
|
Chris@45
|
2181 }
|
Chris@45
|
2182 }
|
Chris@45
|
2183
|
Chris@45
|
2184 void
|
Chris@45
|
2185 MainWindowBase::play()
|
Chris@45
|
2186 {
|
Chris@45
|
2187 if (m_playSource->isPlaying()) {
|
Chris@45
|
2188 stop();
|
Chris@45
|
2189 } else {
|
Chris@45
|
2190 playbackFrameChanged(m_viewManager->getPlaybackFrame());
|
Chris@45
|
2191 m_playSource->play(m_viewManager->getPlaybackFrame());
|
Chris@45
|
2192 }
|
Chris@45
|
2193 }
|
Chris@45
|
2194
|
Chris@45
|
2195 void
|
Chris@45
|
2196 MainWindowBase::ffwd()
|
Chris@45
|
2197 {
|
Chris@45
|
2198 if (!getMainModel()) return;
|
Chris@45
|
2199
|
Chris@45
|
2200 int frame = m_viewManager->getPlaybackFrame();
|
Chris@45
|
2201 ++frame;
|
Chris@45
|
2202
|
Chris@85
|
2203 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@45
|
2204 Layer *layer = getSnapLayer();
|
Chris@45
|
2205 size_t sr = getMainModel()->getSampleRate();
|
Chris@45
|
2206
|
Chris@45
|
2207 if (!layer) {
|
Chris@45
|
2208
|
Chris@45
|
2209 frame = RealTime::realTime2Frame
|
Chris@45
|
2210 (RealTime::frame2RealTime(frame, sr) + RealTime(2, 0), sr);
|
Chris@45
|
2211 if (frame > int(getMainModel()->getEndFrame())) {
|
Chris@45
|
2212 frame = getMainModel()->getEndFrame();
|
Chris@45
|
2213 }
|
Chris@45
|
2214
|
Chris@45
|
2215 } else {
|
Chris@45
|
2216
|
Chris@45
|
2217 size_t resolution = 0;
|
Chris@166
|
2218 if (pane) frame = pane->alignFromReference(frame);
|
Chris@85
|
2219 if (layer->snapToFeatureFrame(m_paneStack->getCurrentPane(),
|
Chris@85
|
2220 frame, resolution, Layer::SnapRight)) {
|
Chris@85
|
2221 if (pane) frame = pane->alignToReference(frame);
|
Chris@85
|
2222 } else {
|
Chris@45
|
2223 frame = getMainModel()->getEndFrame();
|
Chris@45
|
2224 }
|
Chris@45
|
2225 }
|
Chris@45
|
2226
|
Chris@45
|
2227 if (frame < 0) frame = 0;
|
Chris@45
|
2228
|
Chris@45
|
2229 if (m_viewManager->getPlaySelectionMode()) {
|
Chris@45
|
2230 frame = m_viewManager->constrainFrameToSelection(size_t(frame));
|
Chris@45
|
2231 }
|
Chris@45
|
2232
|
Chris@45
|
2233 m_viewManager->setPlaybackFrame(frame);
|
Chris@166
|
2234
|
Chris@166
|
2235 if (frame == getMainModel()->getEndFrame() &&
|
Chris@166
|
2236 m_playSource &&
|
Chris@166
|
2237 m_playSource->isPlaying() &&
|
Chris@166
|
2238 !m_viewManager->getPlayLoopMode()) {
|
Chris@166
|
2239 stop();
|
Chris@166
|
2240 }
|
Chris@45
|
2241 }
|
Chris@45
|
2242
|
Chris@45
|
2243 void
|
Chris@45
|
2244 MainWindowBase::ffwdEnd()
|
Chris@45
|
2245 {
|
Chris@45
|
2246 if (!getMainModel()) return;
|
Chris@45
|
2247
|
Chris@139
|
2248 if (m_playSource &&
|
Chris@139
|
2249 m_playSource->isPlaying() &&
|
Chris@139
|
2250 !m_viewManager->getPlayLoopMode()) {
|
Chris@139
|
2251 stop();
|
Chris@139
|
2252 }
|
Chris@139
|
2253
|
Chris@45
|
2254 size_t frame = getMainModel()->getEndFrame();
|
Chris@45
|
2255
|
Chris@45
|
2256 if (m_viewManager->getPlaySelectionMode()) {
|
Chris@45
|
2257 frame = m_viewManager->constrainFrameToSelection(frame);
|
Chris@45
|
2258 }
|
Chris@45
|
2259
|
Chris@45
|
2260 m_viewManager->setPlaybackFrame(frame);
|
Chris@45
|
2261 }
|
Chris@45
|
2262
|
Chris@45
|
2263 void
|
Chris@166
|
2264 MainWindowBase::ffwdSimilar()
|
Chris@166
|
2265 {
|
Chris@166
|
2266 if (!getMainModel()) return;
|
Chris@166
|
2267
|
Chris@166
|
2268 Layer *layer = getSnapLayer();
|
Chris@166
|
2269 if (!layer) { ffwd(); return; }
|
Chris@166
|
2270
|
Chris@166
|
2271 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@166
|
2272 size_t sr = getMainModel()->getSampleRate();
|
Chris@166
|
2273
|
Chris@166
|
2274 int frame = m_viewManager->getPlaybackFrame();
|
Chris@166
|
2275
|
Chris@166
|
2276 size_t resolution = 0;
|
Chris@166
|
2277 if (pane) frame = pane->alignFromReference(frame);
|
Chris@166
|
2278 if (layer->snapToSimilarFeature(m_paneStack->getCurrentPane(),
|
Chris@166
|
2279 frame, resolution, Layer::SnapRight)) {
|
Chris@166
|
2280 if (pane) frame = pane->alignToReference(frame);
|
Chris@166
|
2281 } else {
|
Chris@166
|
2282 frame = getMainModel()->getEndFrame();
|
Chris@166
|
2283 }
|
Chris@166
|
2284
|
Chris@166
|
2285 if (frame < 0) frame = 0;
|
Chris@166
|
2286
|
Chris@166
|
2287 if (m_viewManager->getPlaySelectionMode()) {
|
Chris@166
|
2288 frame = m_viewManager->constrainFrameToSelection(size_t(frame));
|
Chris@166
|
2289 }
|
Chris@166
|
2290
|
Chris@166
|
2291 m_viewManager->setPlaybackFrame(frame);
|
Chris@166
|
2292
|
Chris@166
|
2293 if (frame == getMainModel()->getEndFrame() &&
|
Chris@166
|
2294 m_playSource &&
|
Chris@166
|
2295 m_playSource->isPlaying() &&
|
Chris@166
|
2296 !m_viewManager->getPlayLoopMode()) {
|
Chris@166
|
2297 stop();
|
Chris@166
|
2298 }
|
Chris@166
|
2299 }
|
Chris@166
|
2300
|
Chris@166
|
2301 void
|
Chris@45
|
2302 MainWindowBase::rewind()
|
Chris@45
|
2303 {
|
Chris@45
|
2304 if (!getMainModel()) return;
|
Chris@45
|
2305
|
Chris@45
|
2306 int frame = m_viewManager->getPlaybackFrame();
|
Chris@45
|
2307 if (frame > 0) --frame;
|
Chris@45
|
2308
|
Chris@85
|
2309 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@45
|
2310 Layer *layer = getSnapLayer();
|
Chris@45
|
2311 size_t sr = getMainModel()->getSampleRate();
|
Chris@45
|
2312
|
Chris@45
|
2313 // when rewinding during playback, we want to allow a period
|
Chris@45
|
2314 // following a rewind target point at which the rewind will go to
|
Chris@45
|
2315 // the prior point instead of the immediately neighbouring one
|
Chris@45
|
2316 if (m_playSource && m_playSource->isPlaying()) {
|
Chris@45
|
2317 RealTime ct = RealTime::frame2RealTime(frame, sr);
|
Chris@45
|
2318 ct = ct - RealTime::fromSeconds(0.25);
|
Chris@45
|
2319 if (ct < RealTime::zeroTime) ct = RealTime::zeroTime;
|
Chris@45
|
2320 frame = RealTime::realTime2Frame(ct, sr);
|
Chris@45
|
2321 }
|
Chris@45
|
2322
|
Chris@45
|
2323 if (!layer) {
|
Chris@45
|
2324
|
Chris@45
|
2325 frame = RealTime::realTime2Frame
|
Chris@45
|
2326 (RealTime::frame2RealTime(frame, sr) - RealTime(2, 0), sr);
|
Chris@45
|
2327 if (frame < int(getMainModel()->getStartFrame())) {
|
Chris@45
|
2328 frame = getMainModel()->getStartFrame();
|
Chris@45
|
2329 }
|
Chris@45
|
2330
|
Chris@45
|
2331 } else {
|
Chris@45
|
2332
|
Chris@45
|
2333 size_t resolution = 0;
|
Chris@166
|
2334 if (pane) frame = pane->alignFromReference(frame);
|
Chris@85
|
2335 if (layer->snapToFeatureFrame(m_paneStack->getCurrentPane(),
|
Chris@85
|
2336 frame, resolution, Layer::SnapLeft)) {
|
Chris@85
|
2337 if (pane) frame = pane->alignToReference(frame);
|
Chris@85
|
2338 } else {
|
Chris@45
|
2339 frame = getMainModel()->getStartFrame();
|
Chris@45
|
2340 }
|
Chris@45
|
2341 }
|
Chris@45
|
2342
|
Chris@45
|
2343 if (frame < 0) frame = 0;
|
Chris@45
|
2344
|
Chris@45
|
2345 if (m_viewManager->getPlaySelectionMode()) {
|
Chris@45
|
2346 frame = m_viewManager->constrainFrameToSelection(size_t(frame));
|
Chris@45
|
2347 }
|
Chris@45
|
2348
|
Chris@45
|
2349 m_viewManager->setPlaybackFrame(frame);
|
Chris@45
|
2350 }
|
Chris@45
|
2351
|
Chris@45
|
2352 void
|
Chris@45
|
2353 MainWindowBase::rewindStart()
|
Chris@45
|
2354 {
|
Chris@45
|
2355 if (!getMainModel()) return;
|
Chris@45
|
2356
|
Chris@45
|
2357 size_t frame = getMainModel()->getStartFrame();
|
Chris@45
|
2358
|
Chris@45
|
2359 if (m_viewManager->getPlaySelectionMode()) {
|
Chris@45
|
2360 frame = m_viewManager->constrainFrameToSelection(frame);
|
Chris@45
|
2361 }
|
Chris@45
|
2362
|
Chris@45
|
2363 m_viewManager->setPlaybackFrame(frame);
|
Chris@45
|
2364 }
|
Chris@45
|
2365
|
Chris@166
|
2366 void
|
Chris@166
|
2367 MainWindowBase::rewindSimilar()
|
Chris@166
|
2368 {
|
Chris@166
|
2369 if (!getMainModel()) return;
|
Chris@166
|
2370
|
Chris@166
|
2371 Layer *layer = getSnapLayer();
|
Chris@166
|
2372 if (!layer) { rewind(); return; }
|
Chris@166
|
2373
|
Chris@166
|
2374 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@166
|
2375 size_t sr = getMainModel()->getSampleRate();
|
Chris@166
|
2376
|
Chris@166
|
2377 int frame = m_viewManager->getPlaybackFrame();
|
Chris@166
|
2378
|
Chris@166
|
2379 size_t resolution = 0;
|
Chris@166
|
2380 if (pane) frame = pane->alignFromReference(frame);
|
Chris@166
|
2381 if (layer->snapToSimilarFeature(m_paneStack->getCurrentPane(),
|
Chris@166
|
2382 frame, resolution, Layer::SnapLeft)) {
|
Chris@166
|
2383 if (pane) frame = pane->alignToReference(frame);
|
Chris@166
|
2384 } else {
|
Chris@166
|
2385 frame = getMainModel()->getStartFrame();
|
Chris@166
|
2386 }
|
Chris@166
|
2387
|
Chris@166
|
2388 if (frame < 0) frame = 0;
|
Chris@166
|
2389
|
Chris@166
|
2390 if (m_viewManager->getPlaySelectionMode()) {
|
Chris@166
|
2391 frame = m_viewManager->constrainFrameToSelection(size_t(frame));
|
Chris@166
|
2392 }
|
Chris@166
|
2393
|
Chris@166
|
2394 m_viewManager->setPlaybackFrame(frame);
|
Chris@166
|
2395 }
|
Chris@166
|
2396
|
Chris@45
|
2397 Layer *
|
Chris@45
|
2398 MainWindowBase::getSnapLayer() const
|
Chris@45
|
2399 {
|
Chris@45
|
2400 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@45
|
2401 if (!pane) return 0;
|
Chris@45
|
2402
|
Chris@45
|
2403 Layer *layer = pane->getSelectedLayer();
|
Chris@45
|
2404
|
Chris@45
|
2405 if (!dynamic_cast<TimeInstantLayer *>(layer) &&
|
Chris@45
|
2406 !dynamic_cast<TimeValueLayer *>(layer) &&
|
Chris@194
|
2407 !dynamic_cast<RegionLayer *>(layer) &&
|
Chris@45
|
2408 !dynamic_cast<TimeRulerLayer *>(layer)) {
|
Chris@45
|
2409
|
Chris@45
|
2410 layer = 0;
|
Chris@45
|
2411
|
Chris@45
|
2412 for (int i = pane->getLayerCount(); i > 0; --i) {
|
Chris@45
|
2413 Layer *l = pane->getLayer(i-1);
|
Chris@45
|
2414 if (dynamic_cast<TimeRulerLayer *>(l)) {
|
Chris@45
|
2415 layer = l;
|
Chris@45
|
2416 break;
|
Chris@45
|
2417 }
|
Chris@45
|
2418 }
|
Chris@45
|
2419 }
|
Chris@45
|
2420
|
Chris@45
|
2421 return layer;
|
Chris@45
|
2422 }
|
Chris@45
|
2423
|
Chris@45
|
2424 void
|
Chris@45
|
2425 MainWindowBase::stop()
|
Chris@45
|
2426 {
|
Chris@45
|
2427 m_playSource->stop();
|
Chris@45
|
2428
|
Chris@45
|
2429 if (m_paneStack && m_paneStack->getCurrentPane()) {
|
Chris@45
|
2430 updateVisibleRangeDisplay(m_paneStack->getCurrentPane());
|
Chris@45
|
2431 } else {
|
Chris@45
|
2432 m_myStatusMessage = "";
|
Chris@45
|
2433 statusBar()->showMessage("");
|
Chris@45
|
2434 }
|
Chris@45
|
2435 }
|
Chris@45
|
2436
|
Chris@45
|
2437 MainWindowBase::AddPaneCommand::AddPaneCommand(MainWindowBase *mw) :
|
Chris@45
|
2438 m_mw(mw),
|
Chris@45
|
2439 m_pane(0),
|
Chris@45
|
2440 m_prevCurrentPane(0),
|
Chris@45
|
2441 m_added(false)
|
Chris@45
|
2442 {
|
Chris@45
|
2443 }
|
Chris@45
|
2444
|
Chris@45
|
2445 MainWindowBase::AddPaneCommand::~AddPaneCommand()
|
Chris@45
|
2446 {
|
Chris@45
|
2447 if (m_pane && !m_added) {
|
Chris@45
|
2448 m_mw->m_paneStack->deletePane(m_pane);
|
Chris@45
|
2449 }
|
Chris@45
|
2450 }
|
Chris@45
|
2451
|
Chris@45
|
2452 QString
|
Chris@45
|
2453 MainWindowBase::AddPaneCommand::getName() const
|
Chris@45
|
2454 {
|
Chris@45
|
2455 return tr("Add Pane");
|
Chris@45
|
2456 }
|
Chris@45
|
2457
|
Chris@45
|
2458 void
|
Chris@45
|
2459 MainWindowBase::AddPaneCommand::execute()
|
Chris@45
|
2460 {
|
Chris@45
|
2461 if (!m_pane) {
|
Chris@45
|
2462 m_prevCurrentPane = m_mw->m_paneStack->getCurrentPane();
|
Chris@45
|
2463 m_pane = m_mw->m_paneStack->addPane();
|
Chris@45
|
2464
|
Chris@45
|
2465 connect(m_pane, SIGNAL(contextHelpChanged(const QString &)),
|
Chris@45
|
2466 m_mw, SLOT(contextHelpChanged(const QString &)));
|
Chris@45
|
2467 } else {
|
Chris@45
|
2468 m_mw->m_paneStack->showPane(m_pane);
|
Chris@45
|
2469 }
|
Chris@45
|
2470
|
Chris@45
|
2471 m_mw->m_paneStack->setCurrentPane(m_pane);
|
Chris@45
|
2472 m_added = true;
|
Chris@45
|
2473 }
|
Chris@45
|
2474
|
Chris@45
|
2475 void
|
Chris@45
|
2476 MainWindowBase::AddPaneCommand::unexecute()
|
Chris@45
|
2477 {
|
Chris@45
|
2478 m_mw->m_paneStack->hidePane(m_pane);
|
Chris@45
|
2479 m_mw->m_paneStack->setCurrentPane(m_prevCurrentPane);
|
Chris@45
|
2480 m_added = false;
|
Chris@45
|
2481 }
|
Chris@45
|
2482
|
Chris@45
|
2483 MainWindowBase::RemovePaneCommand::RemovePaneCommand(MainWindowBase *mw, Pane *pane) :
|
Chris@45
|
2484 m_mw(mw),
|
Chris@45
|
2485 m_pane(pane),
|
Chris@45
|
2486 m_added(true)
|
Chris@45
|
2487 {
|
Chris@45
|
2488 }
|
Chris@45
|
2489
|
Chris@45
|
2490 MainWindowBase::RemovePaneCommand::~RemovePaneCommand()
|
Chris@45
|
2491 {
|
Chris@45
|
2492 if (m_pane && !m_added) {
|
Chris@45
|
2493 m_mw->m_paneStack->deletePane(m_pane);
|
Chris@45
|
2494 }
|
Chris@45
|
2495 }
|
Chris@45
|
2496
|
Chris@45
|
2497 QString
|
Chris@45
|
2498 MainWindowBase::RemovePaneCommand::getName() const
|
Chris@45
|
2499 {
|
Chris@45
|
2500 return tr("Remove Pane");
|
Chris@45
|
2501 }
|
Chris@45
|
2502
|
Chris@45
|
2503 void
|
Chris@45
|
2504 MainWindowBase::RemovePaneCommand::execute()
|
Chris@45
|
2505 {
|
Chris@45
|
2506 m_prevCurrentPane = m_mw->m_paneStack->getCurrentPane();
|
Chris@45
|
2507 m_mw->m_paneStack->hidePane(m_pane);
|
Chris@45
|
2508 m_added = false;
|
Chris@45
|
2509 }
|
Chris@45
|
2510
|
Chris@45
|
2511 void
|
Chris@45
|
2512 MainWindowBase::RemovePaneCommand::unexecute()
|
Chris@45
|
2513 {
|
Chris@45
|
2514 m_mw->m_paneStack->showPane(m_pane);
|
Chris@45
|
2515 m_mw->m_paneStack->setCurrentPane(m_prevCurrentPane);
|
Chris@45
|
2516 m_added = true;
|
Chris@45
|
2517 }
|
Chris@45
|
2518
|
Chris@45
|
2519 void
|
Chris@45
|
2520 MainWindowBase::deleteCurrentPane()
|
Chris@45
|
2521 {
|
Chris@45
|
2522 CommandHistory::getInstance()->startCompoundOperation
|
Chris@45
|
2523 (tr("Delete Pane"), true);
|
Chris@45
|
2524
|
Chris@45
|
2525 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@45
|
2526 if (pane) {
|
Chris@45
|
2527 while (pane->getLayerCount() > 0) {
|
Chris@45
|
2528 Layer *layer = pane->getLayer(0);
|
Chris@45
|
2529 if (layer) {
|
Chris@45
|
2530 m_document->removeLayerFromView(pane, layer);
|
Chris@45
|
2531 } else {
|
Chris@45
|
2532 break;
|
Chris@45
|
2533 }
|
Chris@45
|
2534 }
|
Chris@45
|
2535
|
Chris@45
|
2536 RemovePaneCommand *command = new RemovePaneCommand(this, pane);
|
Chris@45
|
2537 CommandHistory::getInstance()->addCommand(command);
|
Chris@45
|
2538 }
|
Chris@45
|
2539
|
Chris@45
|
2540 CommandHistory::getInstance()->endCompoundOperation();
|
Chris@45
|
2541
|
Chris@45
|
2542 updateMenuStates();
|
Chris@45
|
2543 }
|
Chris@45
|
2544
|
Chris@45
|
2545 void
|
Chris@45
|
2546 MainWindowBase::deleteCurrentLayer()
|
Chris@45
|
2547 {
|
Chris@45
|
2548 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@45
|
2549 if (pane) {
|
Chris@45
|
2550 Layer *layer = pane->getSelectedLayer();
|
Chris@45
|
2551 if (layer) {
|
Chris@45
|
2552 m_document->removeLayerFromView(pane, layer);
|
Chris@45
|
2553 }
|
Chris@45
|
2554 }
|
Chris@45
|
2555 updateMenuStates();
|
Chris@45
|
2556 }
|
Chris@45
|
2557
|
Chris@45
|
2558 void
|
Chris@123
|
2559 MainWindowBase::editCurrentLayer()
|
Chris@123
|
2560 {
|
Chris@123
|
2561 Layer *layer = 0;
|
Chris@123
|
2562 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@123
|
2563 if (pane) layer = pane->getSelectedLayer();
|
Chris@123
|
2564 if (!layer) return;
|
Chris@123
|
2565
|
Chris@123
|
2566 Model *model = layer->getModel();
|
Chris@123
|
2567 if (!model) return;
|
Chris@123
|
2568
|
Chris@124
|
2569 TabularModel *tabular = dynamic_cast<TabularModel *>(model);
|
Chris@124
|
2570 if (!tabular) {
|
Chris@124
|
2571 //!!! how to prevent this function from being active if not
|
Chris@124
|
2572 //appropriate model type? or will we ultimately support
|
Chris@124
|
2573 //tabular display for all editable models?
|
Chris@124
|
2574 std::cerr << "NOTE: Not a tabular model" << std::endl;
|
Chris@124
|
2575 return;
|
Chris@124
|
2576 }
|
Chris@124
|
2577
|
Chris@123
|
2578 if (m_layerDataDialogMap.find(layer) != m_layerDataDialogMap.end()) {
|
Chris@126
|
2579 if (!m_layerDataDialogMap[layer].isNull()) {
|
Chris@126
|
2580 m_layerDataDialogMap[layer]->show();
|
Chris@126
|
2581 m_layerDataDialogMap[layer]->raise();
|
Chris@126
|
2582 return;
|
Chris@126
|
2583 }
|
Chris@123
|
2584 }
|
Chris@123
|
2585
|
Chris@125
|
2586 QString title = layer->getLayerPresentationName();
|
Chris@125
|
2587
|
Chris@125
|
2588 ModelDataTableDialog *dialog = new ModelDataTableDialog(tabular, title, this);
|
Chris@128
|
2589 dialog->setAttribute(Qt::WA_DeleteOnClose);
|
Chris@128
|
2590
|
Chris@128
|
2591 connectLayerEditDialog(dialog);
|
Chris@123
|
2592
|
Chris@128
|
2593 m_layerDataDialogMap[layer] = dialog;
|
Chris@128
|
2594 m_viewDataDialogMap[pane].insert(dialog);
|
Chris@128
|
2595
|
Chris@128
|
2596 dialog->show();
|
Chris@128
|
2597 }
|
Chris@128
|
2598
|
Chris@128
|
2599 void
|
Chris@128
|
2600 MainWindowBase::connectLayerEditDialog(ModelDataTableDialog *dialog)
|
Chris@128
|
2601 {
|
Chris@123
|
2602 connect(m_viewManager,
|
Chris@123
|
2603 SIGNAL(globalCentreFrameChanged(unsigned long)),
|
Chris@123
|
2604 dialog,
|
Chris@127
|
2605 SLOT(userScrolledToFrame(unsigned long)));
|
Chris@127
|
2606
|
Chris@127
|
2607 connect(m_viewManager,
|
Chris@127
|
2608 SIGNAL(playbackFrameChanged(unsigned long)),
|
Chris@127
|
2609 dialog,
|
Chris@127
|
2610 SLOT(playbackScrolledToFrame(unsigned long)));
|
Chris@127
|
2611
|
Chris@123
|
2612 connect(dialog,
|
Chris@123
|
2613 SIGNAL(scrollToFrame(unsigned long)),
|
Chris@123
|
2614 m_viewManager,
|
Chris@123
|
2615 SLOT(setGlobalCentreFrame(unsigned long)));
|
Chris@129
|
2616
|
Chris@129
|
2617 connect(dialog,
|
Chris@129
|
2618 SIGNAL(scrollToFrame(unsigned long)),
|
Chris@129
|
2619 m_viewManager,
|
Chris@129
|
2620 SLOT(setPlaybackFrame(unsigned long)));
|
Chris@128
|
2621 }
|
Chris@123
|
2622
|
Chris@123
|
2623 void
|
Chris@73
|
2624 MainWindowBase::previousPane()
|
Chris@73
|
2625 {
|
Chris@73
|
2626 if (!m_paneStack) return;
|
Chris@73
|
2627
|
Chris@73
|
2628 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@73
|
2629 if (!currentPane) return;
|
Chris@73
|
2630
|
Chris@73
|
2631 for (int i = 0; i < m_paneStack->getPaneCount(); ++i) {
|
Chris@73
|
2632 if (m_paneStack->getPane(i) == currentPane) {
|
Chris@73
|
2633 if (i == 0) return;
|
Chris@73
|
2634 m_paneStack->setCurrentPane(m_paneStack->getPane(i-1));
|
Chris@73
|
2635 updateMenuStates();
|
Chris@73
|
2636 return;
|
Chris@73
|
2637 }
|
Chris@73
|
2638 }
|
Chris@73
|
2639 }
|
Chris@73
|
2640
|
Chris@73
|
2641 void
|
Chris@73
|
2642 MainWindowBase::nextPane()
|
Chris@73
|
2643 {
|
Chris@73
|
2644 if (!m_paneStack) return;
|
Chris@73
|
2645
|
Chris@73
|
2646 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@73
|
2647 if (!currentPane) return;
|
Chris@73
|
2648
|
Chris@73
|
2649 for (int i = 0; i < m_paneStack->getPaneCount(); ++i) {
|
Chris@73
|
2650 if (m_paneStack->getPane(i) == currentPane) {
|
Chris@73
|
2651 if (i == m_paneStack->getPaneCount()-1) return;
|
Chris@73
|
2652 m_paneStack->setCurrentPane(m_paneStack->getPane(i+1));
|
Chris@73
|
2653 updateMenuStates();
|
Chris@73
|
2654 return;
|
Chris@73
|
2655 }
|
Chris@73
|
2656 }
|
Chris@73
|
2657 }
|
Chris@73
|
2658
|
Chris@73
|
2659 void
|
Chris@73
|
2660 MainWindowBase::previousLayer()
|
Chris@73
|
2661 {
|
Chris@73
|
2662 //!!! Not right -- pane lists layers in stacking order
|
Chris@73
|
2663
|
Chris@73
|
2664 if (!m_paneStack) return;
|
Chris@73
|
2665
|
Chris@73
|
2666 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@73
|
2667 if (!currentPane) return;
|
Chris@73
|
2668
|
Chris@73
|
2669 Layer *currentLayer = currentPane->getSelectedLayer();
|
Chris@73
|
2670 if (!currentLayer) return;
|
Chris@73
|
2671
|
Chris@73
|
2672 for (int i = 0; i < currentPane->getLayerCount(); ++i) {
|
Chris@73
|
2673 if (currentPane->getLayer(i) == currentLayer) {
|
Chris@73
|
2674 if (i == 0) return;
|
Chris@73
|
2675 m_paneStack->setCurrentLayer(currentPane,
|
Chris@73
|
2676 currentPane->getLayer(i-1));
|
Chris@73
|
2677 updateMenuStates();
|
Chris@73
|
2678 return;
|
Chris@73
|
2679 }
|
Chris@73
|
2680 }
|
Chris@73
|
2681 }
|
Chris@73
|
2682
|
Chris@73
|
2683 void
|
Chris@73
|
2684 MainWindowBase::nextLayer()
|
Chris@73
|
2685 {
|
Chris@73
|
2686 //!!! Not right -- pane lists layers in stacking order
|
Chris@73
|
2687
|
Chris@73
|
2688 if (!m_paneStack) return;
|
Chris@73
|
2689
|
Chris@73
|
2690 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@73
|
2691 if (!currentPane) return;
|
Chris@73
|
2692
|
Chris@73
|
2693 Layer *currentLayer = currentPane->getSelectedLayer();
|
Chris@73
|
2694 if (!currentLayer) return;
|
Chris@73
|
2695
|
Chris@73
|
2696 for (int i = 0; i < currentPane->getLayerCount(); ++i) {
|
Chris@73
|
2697 if (currentPane->getLayer(i) == currentLayer) {
|
Chris@73
|
2698 if (i == currentPane->getLayerCount()-1) return;
|
Chris@73
|
2699 m_paneStack->setCurrentLayer(currentPane,
|
Chris@73
|
2700 currentPane->getLayer(i+1));
|
Chris@73
|
2701 updateMenuStates();
|
Chris@73
|
2702 return;
|
Chris@73
|
2703 }
|
Chris@73
|
2704 }
|
Chris@73
|
2705 }
|
Chris@73
|
2706
|
Chris@73
|
2707 void
|
Chris@45
|
2708 MainWindowBase::playbackFrameChanged(unsigned long frame)
|
Chris@45
|
2709 {
|
Chris@45
|
2710 if (!(m_playSource && m_playSource->isPlaying()) || !getMainModel()) return;
|
Chris@45
|
2711
|
Chris@187
|
2712 updatePositionStatusDisplays();
|
Chris@187
|
2713
|
Chris@45
|
2714 RealTime now = RealTime::frame2RealTime
|
Chris@45
|
2715 (frame, getMainModel()->getSampleRate());
|
Chris@45
|
2716
|
Chris@45
|
2717 if (now.sec == m_lastPlayStatusSec) return;
|
Chris@45
|
2718
|
Chris@45
|
2719 RealTime then = RealTime::frame2RealTime
|
Chris@45
|
2720 (m_playSource->getPlayEndFrame(), getMainModel()->getSampleRate());
|
Chris@45
|
2721
|
Chris@45
|
2722 QString nowStr;
|
Chris@45
|
2723 QString thenStr;
|
Chris@45
|
2724 QString remainingStr;
|
Chris@45
|
2725
|
Chris@45
|
2726 if (then.sec > 10) {
|
Chris@45
|
2727 nowStr = now.toSecText().c_str();
|
Chris@45
|
2728 thenStr = then.toSecText().c_str();
|
Chris@45
|
2729 remainingStr = (then - now).toSecText().c_str();
|
Chris@45
|
2730 m_lastPlayStatusSec = now.sec;
|
Chris@45
|
2731 } else {
|
Chris@45
|
2732 nowStr = now.toText(true).c_str();
|
Chris@45
|
2733 thenStr = then.toText(true).c_str();
|
Chris@45
|
2734 remainingStr = (then - now).toText(true).c_str();
|
Chris@45
|
2735 }
|
Chris@45
|
2736
|
Chris@45
|
2737 m_myStatusMessage = tr("Playing: %1 of %2 (%3 remaining)")
|
Chris@45
|
2738 .arg(nowStr).arg(thenStr).arg(remainingStr);
|
Chris@45
|
2739
|
Chris@45
|
2740 statusBar()->showMessage(m_myStatusMessage);
|
Chris@45
|
2741 }
|
Chris@45
|
2742
|
Chris@45
|
2743 void
|
Chris@45
|
2744 MainWindowBase::globalCentreFrameChanged(unsigned long )
|
Chris@45
|
2745 {
|
Chris@45
|
2746 if ((m_playSource && m_playSource->isPlaying()) || !getMainModel()) return;
|
Chris@45
|
2747 Pane *p = 0;
|
Chris@45
|
2748 if (!m_paneStack || !(p = m_paneStack->getCurrentPane())) return;
|
Chris@45
|
2749 if (!p->getFollowGlobalPan()) return;
|
Chris@45
|
2750 updateVisibleRangeDisplay(p);
|
Chris@45
|
2751 }
|
Chris@45
|
2752
|
Chris@45
|
2753 void
|
Chris@123
|
2754 MainWindowBase::viewCentreFrameChanged(View *v, unsigned long frame)
|
Chris@45
|
2755 {
|
Chris@130
|
2756 // std::cerr << "MainWindowBase::viewCentreFrameChanged(" << v << "," << frame << ")" << std::endl;
|
Chris@123
|
2757
|
Chris@123
|
2758 if (m_viewDataDialogMap.find(v) != m_viewDataDialogMap.end()) {
|
Chris@123
|
2759 for (DataDialogSet::iterator i = m_viewDataDialogMap[v].begin();
|
Chris@123
|
2760 i != m_viewDataDialogMap[v].end(); ++i) {
|
Chris@127
|
2761 (*i)->userScrolledToFrame(frame);
|
Chris@123
|
2762 }
|
Chris@123
|
2763 }
|
Chris@45
|
2764 if ((m_playSource && m_playSource->isPlaying()) || !getMainModel()) return;
|
Chris@45
|
2765 Pane *p = 0;
|
Chris@45
|
2766 if (!m_paneStack || !(p = m_paneStack->getCurrentPane())) return;
|
Chris@45
|
2767 if (v == p) updateVisibleRangeDisplay(p);
|
Chris@45
|
2768 }
|
Chris@45
|
2769
|
Chris@45
|
2770 void
|
Chris@45
|
2771 MainWindowBase::viewZoomLevelChanged(View *v, unsigned long , bool )
|
Chris@45
|
2772 {
|
Chris@45
|
2773 if ((m_playSource && m_playSource->isPlaying()) || !getMainModel()) return;
|
Chris@45
|
2774 Pane *p = 0;
|
Chris@45
|
2775 if (!m_paneStack || !(p = m_paneStack->getCurrentPane())) return;
|
Chris@45
|
2776 if (v == p) updateVisibleRangeDisplay(p);
|
Chris@45
|
2777 }
|
Chris@45
|
2778
|
Chris@45
|
2779 void
|
Chris@45
|
2780 MainWindowBase::layerAdded(Layer *)
|
Chris@45
|
2781 {
|
Chris@45
|
2782 // std::cerr << "MainWindowBase::layerAdded(" << layer << ")" << std::endl;
|
Chris@45
|
2783 updateMenuStates();
|
Chris@45
|
2784 }
|
Chris@45
|
2785
|
Chris@45
|
2786 void
|
Chris@45
|
2787 MainWindowBase::layerRemoved(Layer *)
|
Chris@45
|
2788 {
|
Chris@45
|
2789 // std::cerr << "MainWindowBase::layerRemoved(" << layer << ")" << std::endl;
|
Chris@45
|
2790 updateMenuStates();
|
Chris@45
|
2791 }
|
Chris@45
|
2792
|
Chris@45
|
2793 void
|
Chris@45
|
2794 MainWindowBase::layerAboutToBeDeleted(Layer *layer)
|
Chris@45
|
2795 {
|
Chris@132
|
2796 // std::cerr << "MainWindowBase::layerAboutToBeDeleted(" << layer << ")" << std::endl;
|
Chris@123
|
2797
|
Chris@128
|
2798 removeLayerEditDialog(layer);
|
Chris@123
|
2799
|
Chris@47
|
2800 if (m_timeRulerLayer && (layer == m_timeRulerLayer)) {
|
Chris@45
|
2801 // std::cerr << "(this is the time ruler layer)" << std::endl;
|
Chris@45
|
2802 m_timeRulerLayer = 0;
|
Chris@45
|
2803 }
|
Chris@45
|
2804 }
|
Chris@45
|
2805
|
Chris@45
|
2806 void
|
Chris@45
|
2807 MainWindowBase::layerInAView(Layer *layer, bool inAView)
|
Chris@45
|
2808 {
|
Chris@132
|
2809 // std::cerr << "MainWindowBase::layerInAView(" << layer << "," << inAView << ")" << std::endl;
|
Chris@128
|
2810
|
Chris@128
|
2811 if (!inAView) removeLayerEditDialog(layer);
|
Chris@45
|
2812
|
Chris@45
|
2813 // Check whether we need to add or remove model from play source
|
Chris@45
|
2814 Model *model = layer->getModel();
|
Chris@45
|
2815 if (model) {
|
Chris@45
|
2816 if (inAView) {
|
Chris@45
|
2817 m_playSource->addModel(model);
|
Chris@45
|
2818 } else {
|
Chris@45
|
2819 bool found = false;
|
Chris@45
|
2820 for (int i = 0; i < m_paneStack->getPaneCount(); ++i) {
|
Chris@45
|
2821 Pane *pane = m_paneStack->getPane(i);
|
Chris@45
|
2822 if (!pane) continue;
|
Chris@45
|
2823 for (int j = 0; j < pane->getLayerCount(); ++j) {
|
Chris@45
|
2824 Layer *pl = pane->getLayer(j);
|
Chris@183
|
2825 if (pl &&
|
Chris@183
|
2826 !dynamic_cast<TimeRulerLayer *>(pl) &&
|
Chris@183
|
2827 (pl->getModel() == model)) {
|
Chris@45
|
2828 found = true;
|
Chris@45
|
2829 break;
|
Chris@45
|
2830 }
|
Chris@45
|
2831 }
|
Chris@45
|
2832 if (found) break;
|
Chris@45
|
2833 }
|
Chris@173
|
2834 if (!found) {
|
Chris@173
|
2835 m_playSource->removeModel(model);
|
Chris@173
|
2836 }
|
Chris@45
|
2837 }
|
Chris@45
|
2838 }
|
Chris@45
|
2839
|
Chris@45
|
2840 updateMenuStates();
|
Chris@45
|
2841 }
|
Chris@45
|
2842
|
Chris@45
|
2843 void
|
Chris@128
|
2844 MainWindowBase::removeLayerEditDialog(Layer *layer)
|
Chris@128
|
2845 {
|
Chris@128
|
2846 if (m_layerDataDialogMap.find(layer) != m_layerDataDialogMap.end()) {
|
Chris@128
|
2847
|
Chris@128
|
2848 ModelDataTableDialog *dialog = m_layerDataDialogMap[layer];
|
Chris@128
|
2849
|
Chris@128
|
2850 for (ViewDataDialogMap::iterator vi = m_viewDataDialogMap.begin();
|
Chris@128
|
2851 vi != m_viewDataDialogMap.end(); ++vi) {
|
Chris@128
|
2852 vi->second.erase(dialog);
|
Chris@128
|
2853 }
|
Chris@128
|
2854
|
Chris@128
|
2855 m_layerDataDialogMap.erase(layer);
|
Chris@128
|
2856 delete dialog;
|
Chris@128
|
2857 }
|
Chris@128
|
2858 }
|
Chris@128
|
2859
|
Chris@128
|
2860 void
|
Chris@45
|
2861 MainWindowBase::modelAdded(Model *model)
|
Chris@45
|
2862 {
|
Chris@45
|
2863 // std::cerr << "MainWindowBase::modelAdded(" << model << ")" << std::endl;
|
Chris@45
|
2864 m_playSource->addModel(model);
|
Chris@45
|
2865 }
|
Chris@45
|
2866
|
Chris@45
|
2867 void
|
Chris@45
|
2868 MainWindowBase::mainModelChanged(WaveFileModel *model)
|
Chris@45
|
2869 {
|
Chris@45
|
2870 // std::cerr << "MainWindowBase::mainModelChanged(" << model << ")" << std::endl;
|
Chris@45
|
2871 updateDescriptionLabel();
|
Chris@45
|
2872 if (model) m_viewManager->setMainModelSampleRate(model->getSampleRate());
|
Chris@45
|
2873 if (model && !m_playTarget && m_audioOutput) createPlayTarget();
|
Chris@45
|
2874 }
|
Chris@45
|
2875
|
Chris@45
|
2876 void
|
Chris@45
|
2877 MainWindowBase::modelAboutToBeDeleted(Model *model)
|
Chris@45
|
2878 {
|
Chris@45
|
2879 // std::cerr << "MainWindowBase::modelAboutToBeDeleted(" << model << ")" << std::endl;
|
Chris@45
|
2880 if (model == m_viewManager->getPlaybackModel()) {
|
Chris@45
|
2881 m_viewManager->setPlaybackModel(0);
|
Chris@45
|
2882 }
|
Chris@45
|
2883 m_playSource->removeModel(model);
|
Chris@45
|
2884 FFTDataServer::modelAboutToBeDeleted(model);
|
Chris@45
|
2885 }
|
Chris@45
|
2886
|
Chris@45
|
2887 void
|
Chris@55
|
2888 MainWindowBase::paneDeleteButtonClicked(Pane *pane)
|
Chris@55
|
2889 {
|
Chris@55
|
2890 bool found = false;
|
Chris@55
|
2891 for (int i = 0; i < m_paneStack->getPaneCount(); ++i) {
|
Chris@55
|
2892 if (m_paneStack->getPane(i) == pane) {
|
Chris@55
|
2893 found = true;
|
Chris@55
|
2894 break;
|
Chris@55
|
2895 }
|
Chris@55
|
2896 }
|
Chris@55
|
2897 if (!found) {
|
Chris@55
|
2898 std::cerr << "MainWindowBase::paneDeleteButtonClicked: Unknown pane "
|
Chris@55
|
2899 << pane << std::endl;
|
Chris@55
|
2900 return;
|
Chris@55
|
2901 }
|
Chris@55
|
2902
|
Chris@55
|
2903 CommandHistory::getInstance()->startCompoundOperation
|
Chris@55
|
2904 (tr("Delete Pane"), true);
|
Chris@55
|
2905
|
Chris@55
|
2906 while (pane->getLayerCount() > 0) {
|
Chris@55
|
2907 Layer *layer = pane->getLayer(0);
|
Chris@55
|
2908 if (layer) {
|
Chris@55
|
2909 m_document->removeLayerFromView(pane, layer);
|
Chris@55
|
2910 } else {
|
Chris@55
|
2911 break;
|
Chris@55
|
2912 }
|
Chris@55
|
2913 }
|
Chris@55
|
2914
|
Chris@55
|
2915 RemovePaneCommand *command = new RemovePaneCommand(this, pane);
|
Chris@55
|
2916 CommandHistory::getInstance()->addCommand(command);
|
Chris@55
|
2917
|
Chris@55
|
2918 CommandHistory::getInstance()->endCompoundOperation();
|
Chris@55
|
2919
|
Chris@55
|
2920 updateMenuStates();
|
Chris@55
|
2921 }
|
Chris@55
|
2922
|
Chris@55
|
2923 void
|
Chris@45
|
2924 MainWindowBase::pollOSC()
|
Chris@45
|
2925 {
|
Chris@45
|
2926 if (!m_oscQueue || m_oscQueue->isEmpty()) return;
|
Chris@45
|
2927 std::cerr << "MainWindowBase::pollOSC: have " << m_oscQueue->getMessagesAvailable() << " messages" << std::endl;
|
Chris@45
|
2928
|
Chris@45
|
2929 if (m_openingAudioFile) return;
|
Chris@45
|
2930
|
Chris@45
|
2931 OSCMessage message = m_oscQueue->readMessage();
|
Chris@45
|
2932
|
Chris@45
|
2933 if (message.getTarget() != 0) {
|
Chris@45
|
2934 return; //!!! for now -- this class is target 0, others not handled yet
|
Chris@45
|
2935 }
|
Chris@45
|
2936
|
Chris@45
|
2937 handleOSCMessage(message);
|
Chris@45
|
2938 }
|
Chris@45
|
2939
|
Chris@45
|
2940 void
|
Chris@45
|
2941 MainWindowBase::inProgressSelectionChanged()
|
Chris@45
|
2942 {
|
Chris@45
|
2943 Pane *currentPane = 0;
|
Chris@45
|
2944 if (m_paneStack) currentPane = m_paneStack->getCurrentPane();
|
Chris@45
|
2945 if (currentPane) updateVisibleRangeDisplay(currentPane);
|
Chris@45
|
2946 }
|
Chris@45
|
2947
|
Chris@45
|
2948 void
|
Chris@45
|
2949 MainWindowBase::contextHelpChanged(const QString &s)
|
Chris@45
|
2950 {
|
Chris@45
|
2951 if (s == "" && m_myStatusMessage != "") {
|
Chris@45
|
2952 statusBar()->showMessage(m_myStatusMessage);
|
Chris@45
|
2953 return;
|
Chris@45
|
2954 }
|
Chris@45
|
2955 statusBar()->showMessage(s);
|
Chris@45
|
2956 }
|
Chris@45
|
2957
|
Chris@45
|
2958 void
|
Chris@45
|
2959 MainWindowBase::openHelpUrl(QString url)
|
Chris@45
|
2960 {
|
Chris@45
|
2961 // This method mostly lifted from Qt Assistant source code
|
Chris@45
|
2962
|
Chris@45
|
2963 QProcess *process = new QProcess(this);
|
Chris@45
|
2964 connect(process, SIGNAL(finished(int)), process, SLOT(deleteLater()));
|
Chris@45
|
2965
|
Chris@45
|
2966 QStringList args;
|
Chris@45
|
2967
|
Chris@45
|
2968 #ifdef Q_OS_MAC
|
Chris@45
|
2969 args.append(url);
|
Chris@45
|
2970 process->start("open", args);
|
Chris@45
|
2971 #else
|
Chris@45
|
2972 #ifdef Q_OS_WIN32
|
Chris@45
|
2973
|
Chris@45
|
2974 QString pf(getenv("ProgramFiles"));
|
Chris@45
|
2975 QString command = pf + QString("\\Internet Explorer\\IEXPLORE.EXE");
|
Chris@45
|
2976
|
Chris@45
|
2977 args.append(url);
|
Chris@45
|
2978 process->start(command, args);
|
Chris@45
|
2979
|
Chris@45
|
2980 #else
|
Chris@45
|
2981 #ifdef Q_WS_X11
|
Chris@45
|
2982 if (!qgetenv("KDE_FULL_SESSION").isEmpty()) {
|
Chris@45
|
2983 args.append("exec");
|
Chris@45
|
2984 args.append(url);
|
Chris@45
|
2985 process->start("kfmclient", args);
|
Chris@45
|
2986 } else if (!qgetenv("BROWSER").isEmpty()) {
|
Chris@45
|
2987 args.append(url);
|
Chris@45
|
2988 process->start(qgetenv("BROWSER"), args);
|
Chris@45
|
2989 } else {
|
Chris@45
|
2990 args.append(url);
|
Chris@45
|
2991 process->start("firefox", args);
|
Chris@45
|
2992 }
|
Chris@45
|
2993 #endif
|
Chris@45
|
2994 #endif
|
Chris@45
|
2995 #endif
|
Chris@45
|
2996 }
|
Chris@45
|
2997
|
Chris@180
|
2998
|