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