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 #include "view/Pane.h"
|
Chris@45
|
20 #include "view/PaneStack.h"
|
Chris@479
|
21 #include "data/model/ReadOnlyWaveFileModel.h"
|
Chris@477
|
22 #include "data/model/WritableWaveFileModel.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@341
|
48 #include "widgets/InteractiveFileFinder.h"
|
Chris@45
|
49
|
Chris@468
|
50 #include "audio/AudioCallbackPlaySource.h"
|
Chris@574
|
51 #include "audio/AudioCallbackRecordTarget.h"
|
Chris@468
|
52 #include "audio/PlaySpeedRangeMapper.h"
|
Chris@475
|
53
|
Chris@45
|
54 #include "data/fileio/DataFileReaderFactory.h"
|
Chris@45
|
55 #include "data/fileio/PlaylistFileReader.h"
|
Chris@45
|
56 #include "data/fileio/WavFileWriter.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 "base/RecentFiles.h"
|
Chris@45
|
64
|
Chris@45
|
65 #include "base/PlayParameterRepository.h"
|
Chris@45
|
66 #include "base/XmlExportable.h"
|
Chris@45
|
67 #include "base/Profiler.h"
|
Chris@45
|
68 #include "base/Preferences.h"
|
Chris@217
|
69 #include "base/TempWriteFile.h"
|
Chris@217
|
70 #include "base/Exceptions.h"
|
Chris@223
|
71 #include "base/ResourceFinder.h"
|
Chris@45
|
72
|
Chris@45
|
73 #include "data/osc/OSCQueue.h"
|
Chris@157
|
74 #include "data/midi/MIDIInput.h"
|
Chris@45
|
75
|
Chris@468
|
76 #include <bqaudioio/SystemPlaybackTarget.h>
|
Chris@475
|
77 #include <bqaudioio/SystemAudioIO.h>
|
Chris@468
|
78 #include <bqaudioio/AudioFactory.h>
|
Chris@551
|
79 #include <bqaudioio/ResamplerWrapper.h>
|
Chris@468
|
80
|
Chris@45
|
81 #include <QApplication>
|
Chris@45
|
82 #include <QMessageBox>
|
Chris@45
|
83 #include <QGridLayout>
|
Chris@45
|
84 #include <QLabel>
|
Chris@45
|
85 #include <QAction>
|
Chris@45
|
86 #include <QMenuBar>
|
Chris@45
|
87 #include <QToolBar>
|
Chris@45
|
88 #include <QInputDialog>
|
Chris@45
|
89 #include <QStatusBar>
|
Chris@45
|
90 #include <QTreeView>
|
Chris@45
|
91 #include <QFile>
|
Chris@45
|
92 #include <QFileInfo>
|
Chris@45
|
93 #include <QDir>
|
Chris@45
|
94 #include <QTextStream>
|
Chris@432
|
95 #include <QTextCodec>
|
Chris@45
|
96 #include <QProcess>
|
Chris@45
|
97 #include <QShortcut>
|
Chris@45
|
98 #include <QSettings>
|
Chris@45
|
99 #include <QDateTime>
|
Chris@45
|
100 #include <QProcess>
|
Chris@45
|
101 #include <QCheckBox>
|
Chris@45
|
102 #include <QRegExp>
|
Chris@45
|
103 #include <QScrollArea>
|
Chris@168
|
104 #include <QDesktopWidget>
|
Chris@354
|
105 #include <QSignalMapper>
|
Chris@45
|
106
|
Chris@45
|
107 #include <iostream>
|
Chris@45
|
108 #include <cstdio>
|
Chris@45
|
109 #include <errno.h>
|
Chris@45
|
110
|
Chris@45
|
111 using std::vector;
|
Chris@45
|
112 using std::map;
|
Chris@45
|
113 using std::set;
|
Chris@45
|
114
|
Chris@255
|
115 #ifdef Q_WS_X11
|
Chris@255
|
116 #define Window X11Window
|
Chris@255
|
117 #include <X11/Xlib.h>
|
Chris@255
|
118 #include <X11/Xutil.h>
|
Chris@255
|
119 #include <X11/Xatom.h>
|
Chris@255
|
120 #include <X11/SM/SMlib.h>
|
Chris@255
|
121
|
Chris@255
|
122 static int handle_x11_error(Display *dpy, XErrorEvent *err)
|
Chris@255
|
123 {
|
Chris@255
|
124 char errstr[256];
|
Chris@255
|
125 XGetErrorText(dpy, err->error_code, errstr, 256);
|
Chris@255
|
126 if (err->error_code != BadWindow) {
|
Chris@293
|
127 cerr << "Sonic Visualiser: X Error: "
|
Chris@255
|
128 << errstr << " " << int(err->error_code)
|
Chris@255
|
129 << "\nin major opcode: "
|
Chris@293
|
130 << int(err->request_code) << endl;
|
Chris@255
|
131 }
|
Chris@255
|
132 return 0;
|
Chris@255
|
133 }
|
Chris@255
|
134 #undef Window
|
Chris@255
|
135 #endif
|
Chris@45
|
136
|
Chris@475
|
137 MainWindowBase::MainWindowBase(SoundOptions options) :
|
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@475
|
142 m_soundOptions(options),
|
Chris@45
|
143 m_playSource(0),
|
Chris@475
|
144 m_recordTarget(0),
|
Chris@551
|
145 m_resamplerWrapper(0),
|
Chris@45
|
146 m_playTarget(0),
|
Chris@475
|
147 m_audioIO(0),
|
Chris@113
|
148 m_oscQueue(0),
|
Chris@113
|
149 m_oscQueueStarter(0),
|
Chris@157
|
150 m_midiInput(0),
|
Chris@45
|
151 m_recentFiles("RecentFiles", 20),
|
Chris@54
|
152 m_recentTransforms("RecentTransforms", 20),
|
Chris@45
|
153 m_documentModified(false),
|
Chris@45
|
154 m_openingAudioFile(false),
|
Chris@45
|
155 m_abandoning(false),
|
Chris@121
|
156 m_labeller(0),
|
Chris@357
|
157 m_lastPlayStatusSec(0),
|
Chris@357
|
158 m_initialDarkBackground(false),
|
Chris@378
|
159 m_defaultFfwdRwdStep(2, 0),
|
Chris@483
|
160 m_audioRecordMode(RecordCreateAdditionalModel),
|
Chris@390
|
161 m_statusLabel(0),
|
Chris@426
|
162 m_iconsVisibleInMenus(true),
|
Chris@390
|
163 m_menuShortcutMapper(0)
|
Chris@45
|
164 {
|
Chris@113
|
165 Profiler profiler("MainWindowBase::MainWindowBase");
|
Chris@113
|
166
|
Chris@591
|
167 SVDEBUG << "MainWindowBase::MainWindowBase" << endl;
|
Chris@591
|
168
|
Chris@475
|
169 if (options & WithAudioInput) {
|
Chris@475
|
170 if (!(options & WithAudioOutput)) {
|
Chris@591
|
171 SVCERR << "WARNING: MainWindowBase: WithAudioInput requires WithAudioOutput -- recording will not work" << endl;
|
Chris@475
|
172 }
|
Chris@475
|
173 }
|
Chris@475
|
174
|
Chris@438
|
175 qRegisterMetaType<sv_frame_t>("sv_frame_t");
|
Chris@438
|
176 qRegisterMetaType<sv_samplerate_t>("sv_samplerate_t");
|
Chris@438
|
177
|
Chris@255
|
178 #ifdef Q_WS_X11
|
Chris@255
|
179 XSetErrorHandler(handle_x11_error);
|
Chris@255
|
180 #endif
|
Chris@255
|
181
|
Chris@452
|
182 connect(this, SIGNAL(hideSplash()), this, SLOT(emitHideSplash()));
|
Chris@452
|
183
|
Chris@45
|
184 connect(CommandHistory::getInstance(), SIGNAL(commandExecuted()),
|
Chris@45
|
185 this, SLOT(documentModified()));
|
Chris@45
|
186 connect(CommandHistory::getInstance(), SIGNAL(documentRestored()),
|
Chris@45
|
187 this, SLOT(documentRestored()));
|
Chris@45
|
188
|
Chris@591
|
189 SVDEBUG << "MainWindowBase: Creating view manager" << endl;
|
Chris@591
|
190
|
Chris@45
|
191 m_viewManager = new ViewManager();
|
Chris@45
|
192 connect(m_viewManager, SIGNAL(selectionChanged()),
|
Chris@45
|
193 this, SLOT(updateMenuStates()));
|
Chris@45
|
194 connect(m_viewManager, SIGNAL(inProgressSelectionChanged()),
|
Chris@45
|
195 this, SLOT(inProgressSelectionChanged()));
|
Chris@45
|
196
|
Chris@591
|
197 SVDEBUG << "MainWindowBase: Calculating view font size" << endl;
|
Chris@591
|
198
|
Chris@105
|
199 // set a sensible default font size for views -- cannot do this
|
Chris@105
|
200 // in Preferences, which is in base and not supposed to use QtGui
|
Chris@436
|
201 int viewFontSize = int(QApplication::font().pointSize() * 0.9);
|
Chris@105
|
202 QSettings settings;
|
Chris@105
|
203 settings.beginGroup("Preferences");
|
Chris@105
|
204 viewFontSize = settings.value("view-font-size", viewFontSize).toInt();
|
Chris@105
|
205 settings.setValue("view-font-size", viewFontSize);
|
Chris@105
|
206 settings.endGroup();
|
Chris@105
|
207
|
Chris@591
|
208 SVDEBUG << "MainWindowBase: View font size is " << viewFontSize << endl;
|
Chris@591
|
209
|
Chris@511
|
210 #ifdef NOT_DEFINED // This no longer works correctly on any platform AFAICS
|
Chris@45
|
211 Preferences::BackgroundMode mode =
|
Chris@45
|
212 Preferences::getInstance()->getBackgroundMode();
|
Chris@45
|
213 m_initialDarkBackground = m_viewManager->getGlobalDarkBackground();
|
Chris@45
|
214 if (mode != Preferences::BackgroundFromTheme) {
|
Chris@45
|
215 m_viewManager->setGlobalDarkBackground
|
Chris@45
|
216 (mode == Preferences::DarkBackground);
|
Chris@45
|
217 }
|
Chris@511
|
218 #endif
|
Chris@45
|
219
|
Chris@45
|
220 m_paneStack = new PaneStack(0, m_viewManager);
|
Chris@45
|
221 connect(m_paneStack, SIGNAL(currentPaneChanged(Pane *)),
|
Chris@45
|
222 this, SLOT(currentPaneChanged(Pane *)));
|
Chris@45
|
223 connect(m_paneStack, SIGNAL(currentLayerChanged(Pane *, Layer *)),
|
Chris@45
|
224 this, SLOT(currentLayerChanged(Pane *, Layer *)));
|
Chris@45
|
225 connect(m_paneStack, SIGNAL(rightButtonMenuRequested(Pane *, QPoint)),
|
Chris@45
|
226 this, SLOT(rightButtonMenuRequested(Pane *, QPoint)));
|
Chris@45
|
227 connect(m_paneStack, SIGNAL(contextHelpChanged(const QString &)),
|
Chris@45
|
228 this, SLOT(contextHelpChanged(const QString &)));
|
Chris@45
|
229 connect(m_paneStack, SIGNAL(paneAdded(Pane *)),
|
Chris@45
|
230 this, SLOT(paneAdded(Pane *)));
|
Chris@45
|
231 connect(m_paneStack, SIGNAL(paneHidden(Pane *)),
|
Chris@45
|
232 this, SLOT(paneHidden(Pane *)));
|
Chris@45
|
233 connect(m_paneStack, SIGNAL(paneAboutToBeDeleted(Pane *)),
|
Chris@45
|
234 this, SLOT(paneAboutToBeDeleted(Pane *)));
|
Chris@45
|
235 connect(m_paneStack, SIGNAL(dropAccepted(Pane *, QStringList)),
|
Chris@45
|
236 this, SLOT(paneDropAccepted(Pane *, QStringList)));
|
Chris@45
|
237 connect(m_paneStack, SIGNAL(dropAccepted(Pane *, QString)),
|
Chris@45
|
238 this, SLOT(paneDropAccepted(Pane *, QString)));
|
Chris@55
|
239 connect(m_paneStack, SIGNAL(paneDeleteButtonClicked(Pane *)),
|
Chris@55
|
240 this, SLOT(paneDeleteButtonClicked(Pane *)));
|
Chris@591
|
241
|
Chris@591
|
242 SVDEBUG << "MainWindowBase: Creating play source" << endl;
|
Chris@571
|
243
|
Chris@574
|
244 m_playSource = new AudioCallbackPlaySource
|
Chris@574
|
245 (m_viewManager, QApplication::applicationName());
|
Chris@574
|
246
|
Chris@475
|
247 if (m_soundOptions & WithAudioInput) {
|
Chris@591
|
248 SVDEBUG << "MainWindowBase: Creating record target" << endl;
|
Chris@574
|
249 m_recordTarget = new AudioCallbackRecordTarget
|
Chris@574
|
250 (m_viewManager, QApplication::applicationName());
|
Chris@572
|
251 connect(m_recordTarget,
|
Chris@572
|
252 SIGNAL(recordDurationChanged(sv_frame_t, sv_samplerate_t)),
|
Chris@572
|
253 this,
|
Chris@572
|
254 SLOT(recordDurationChanged(sv_frame_t, sv_samplerate_t)));
|
Chris@475
|
255 }
|
Chris@45
|
256
|
Chris@436
|
257 connect(m_playSource, SIGNAL(sampleRateMismatch(sv_samplerate_t, sv_samplerate_t, bool)),
|
Chris@591
|
258 this, SLOT(sampleRateMismatch(sv_samplerate_t, sv_samplerate_t, bool)));
|
Chris@570
|
259 connect(m_playSource, SIGNAL(channelCountIncreased(int)),
|
Chris@570
|
260 this, SLOT(audioChannelCountIncreased(int)));
|
Chris@45
|
261 connect(m_playSource, SIGNAL(audioOverloadPluginDisabled()),
|
Chris@45
|
262 this, SLOT(audioOverloadPluginDisabled()));
|
Chris@130
|
263 connect(m_playSource, SIGNAL(audioTimeStretchMultiChannelDisabled()),
|
Chris@130
|
264 this, SLOT(audioTimeStretchMultiChannelDisabled()));
|
Chris@45
|
265
|
Chris@574
|
266 connect(m_viewManager, SIGNAL(monitoringLevelsChanged(float, float)),
|
Chris@574
|
267 this, SLOT(monitoringLevelsChanged(float, float)));
|
Chris@45
|
268
|
Chris@435
|
269 connect(m_viewManager, SIGNAL(playbackFrameChanged(sv_frame_t)),
|
Chris@435
|
270 this, SLOT(playbackFrameChanged(sv_frame_t)));
|
Chris@435
|
271
|
Chris@435
|
272 connect(m_viewManager, SIGNAL(globalCentreFrameChanged(sv_frame_t)),
|
Chris@435
|
273 this, SLOT(globalCentreFrameChanged(sv_frame_t)));
|
Chris@435
|
274
|
Chris@435
|
275 connect(m_viewManager, SIGNAL(viewCentreFrameChanged(View *, sv_frame_t)),
|
Chris@435
|
276 this, SLOT(viewCentreFrameChanged(View *, sv_frame_t)));
|
Chris@366
|
277
|
Chris@366
|
278 connect(m_viewManager, SIGNAL(viewZoomLevelChanged(View *, int, bool)),
|
Chris@366
|
279 this, SLOT(viewZoomLevelChanged(View *, int, bool)));
|
Chris@45
|
280
|
Chris@45
|
281 connect(Preferences::getInstance(),
|
Chris@45
|
282 SIGNAL(propertyChanged(PropertyContainer::PropertyName)),
|
Chris@45
|
283 this,
|
Chris@45
|
284 SLOT(preferenceChanged(PropertyContainer::PropertyName)));
|
Chris@45
|
285
|
Chris@591
|
286 SVDEBUG << "MainWindowBase: Creating labeller" << endl;
|
Chris@591
|
287
|
Chris@45
|
288 Labeller::ValueType labellerType = Labeller::ValueFromTwoLevelCounter;
|
Chris@45
|
289 settings.beginGroup("MainWindow");
|
Chris@230
|
290
|
Chris@45
|
291 labellerType = (Labeller::ValueType)
|
Chris@45
|
292 settings.value("labellertype", (int)labellerType).toInt();
|
Chris@45
|
293 int cycle = settings.value("labellercycle", 4).toInt();
|
Chris@230
|
294
|
Chris@45
|
295 settings.endGroup();
|
Chris@45
|
296
|
Chris@45
|
297 m_labeller = new Labeller(labellerType);
|
Chris@45
|
298 m_labeller->setCounterCycleSize(cycle);
|
Chris@113
|
299
|
Chris@475
|
300 if (m_soundOptions & WithMIDIInput) {
|
Chris@591
|
301 SVDEBUG << "MainWindowBase: Creating MIDI input" << endl;
|
Chris@161
|
302 m_midiInput = new MIDIInput(QApplication::applicationName(), this);
|
Chris@161
|
303 }
|
Chris@452
|
304
|
Chris@452
|
305 QTimer::singleShot(1500, this, SIGNAL(hideSplash()));
|
Chris@591
|
306
|
Chris@591
|
307 SVDEBUG << "MainWindowBase: Constructor done" << endl;
|
Chris@45
|
308 }
|
Chris@45
|
309
|
Chris@45
|
310 MainWindowBase::~MainWindowBase()
|
Chris@45
|
311 {
|
Chris@233
|
312 SVDEBUG << "MainWindowBase::~MainWindowBase" << endl;
|
Chris@540
|
313
|
Chris@540
|
314 // We have to delete the breakfastquay::SystemPlaybackTarget or
|
Chris@540
|
315 // breakfastquay::SystemAudioIO object (whichever we have -- it
|
Chris@540
|
316 // depends on whether we handle recording or not) before we delete
|
Chris@540
|
317 // the ApplicationPlaybackSource and ApplicationRecordTarget that
|
Chris@540
|
318 // they refer to.
|
Chris@556
|
319
|
Chris@556
|
320 deleteAudioIO();
|
Chris@540
|
321
|
Chris@540
|
322 // Then delete the Application objects.
|
Chris@45
|
323 delete m_playSource;
|
Chris@475
|
324 delete m_recordTarget;
|
Chris@540
|
325
|
Chris@45
|
326 delete m_viewManager;
|
Chris@45
|
327 delete m_oscQueue;
|
Chris@304
|
328 delete m_oscQueueStarter;
|
Chris@157
|
329 delete m_midiInput;
|
Chris@45
|
330 Profiles::getInstance()->dump();
|
Chris@45
|
331 }
|
Chris@45
|
332
|
Chris@113
|
333 void
|
Chris@452
|
334 MainWindowBase::emitHideSplash()
|
Chris@452
|
335 {
|
Chris@591
|
336 SVDEBUG << "MainWindowBase: Hiding splash screen" << endl;
|
Chris@452
|
337 emit hideSplash(this);
|
Chris@452
|
338 }
|
Chris@452
|
339
|
Chris@452
|
340 void
|
Chris@354
|
341 MainWindowBase::finaliseMenus()
|
Chris@354
|
342 {
|
Chris@591
|
343 SVDEBUG << "MainWindowBase::finaliseMenus called" << endl;
|
Chris@591
|
344
|
Chris@390
|
345 delete m_menuShortcutMapper;
|
Chris@390
|
346 m_menuShortcutMapper = 0;
|
Chris@390
|
347
|
Chris@391
|
348 foreach (QShortcut *sc, m_appShortcuts) {
|
Chris@391
|
349 delete sc;
|
Chris@391
|
350 }
|
Chris@391
|
351 m_appShortcuts.clear();
|
Chris@391
|
352
|
Chris@354
|
353 QMenuBar *mb = menuBar();
|
Chris@394
|
354
|
Chris@396
|
355 // This used to find all children of QMenu type, and call
|
Chris@396
|
356 // finaliseMenu on those. But it seems we are getting hold of some
|
Chris@396
|
357 // menus that way that are not actually active in the menu bar and
|
Chris@396
|
358 // are not returned in their parent menu's actions() list, and if
|
Chris@396
|
359 // we finalise those, we end up with duplicate shortcuts in the
|
Chris@396
|
360 // app shortcut mapper. So we should do this by descending the
|
Chris@396
|
361 // menu tree through only those menus accessible via actions()
|
Chris@396
|
362 // from their parents instead.
|
Chris@396
|
363
|
Chris@394
|
364 QList<QMenu *> menus = mb->findChildren<QMenu *>
|
Chris@394
|
365 (QString(), Qt::FindDirectChildrenOnly);
|
Chris@394
|
366
|
Chris@354
|
367 foreach (QMenu *menu, menus) {
|
Chris@354
|
368 if (menu) finaliseMenu(menu);
|
Chris@354
|
369 }
|
Chris@591
|
370
|
Chris@591
|
371 SVDEBUG << "MainWindowBase::finaliseMenus done" << endl;
|
Chris@354
|
372 }
|
Chris@354
|
373
|
Chris@354
|
374 void
|
Chris@426
|
375 MainWindowBase::finaliseMenu(QMenu *menu)
|
Chris@354
|
376 {
|
Chris@426
|
377 foreach (QAction *a, menu->actions()) {
|
Chris@426
|
378 a->setIconVisibleInMenu(m_iconsVisibleInMenus);
|
Chris@426
|
379 }
|
Chris@426
|
380
|
Chris@354
|
381 #ifdef Q_OS_MAC
|
Chris@354
|
382 // See https://bugreports.qt-project.org/browse/QTBUG-38256 and
|
Chris@354
|
383 // our issue #890 http://code.soundsoftware.ac.uk/issues/890 --
|
Chris@354
|
384 // single-key shortcuts that are associated only with a menu
|
Chris@384
|
385 // action (and not with a toolbar button) do not work with Qt 5.x
|
Chris@384
|
386 // under OS/X.
|
Chris@354
|
387 //
|
Chris@354
|
388 // Apparently Cocoa never handled them as a matter of course, but
|
Chris@354
|
389 // earlier versions of Qt picked them up as widget shortcuts and
|
Chris@354
|
390 // handled them anyway. That behaviour was removed to fix a crash
|
Chris@354
|
391 // when invoking a menu while its window was overridden by a modal
|
Chris@354
|
392 // dialog (https://bugreports.qt-project.org/browse/QTBUG-30657).
|
Chris@354
|
393 //
|
Chris@354
|
394 // This workaround restores the single-key shortcut behaviour by
|
Chris@384
|
395 // searching in menus for single-key shortcuts that are associated
|
Chris@384
|
396 // only with the menu and not with a toolbar button, and
|
Chris@384
|
397 // augmenting them with global application shortcuts that invoke
|
Chris@384
|
398 // the relevant actions, testing whether the actions are enabled
|
Chris@384
|
399 // on invocation.
|
Chris@354
|
400 //
|
Chris@384
|
401 // (Previously this acted on all single-key shortcuts in menus,
|
Chris@384
|
402 // and it removed the shortcut from the action when it created
|
Chris@384
|
403 // each new global one, in order to avoid an "ambiguous shortcut"
|
Chris@384
|
404 // error in the case where the action was also associated with a
|
Chris@384
|
405 // toolbar button. But that has the unwelcome side-effect of
|
Chris@384
|
406 // removing the shortcut hint from the menu entry. So now we leave
|
Chris@384
|
407 // the shortcut in the menu action as well as creating a global
|
Chris@384
|
408 // one, and we only act on shortcuts that have no toolbar button,
|
Chris@384
|
409 // i.e. that will not otherwise work. The downside is that if this
|
Chris@384
|
410 // bug is fixed in a future Qt release, we will start getting
|
Chris@384
|
411 // "ambiguous shortcut" errors from the menu entry actions and
|
Chris@384
|
412 // will need to update the code.)
|
Chris@354
|
413
|
Chris@443
|
414 // Update: The bug was fixed in Qt 5.4 for shortcuts with no
|
Chris@443
|
415 // modifier, and I believe it is fixed in Qt 5.5 for shortcuts
|
Chris@443
|
416 // with Shift modifiers. The below reflects that
|
Chris@443
|
417
|
Chris@443
|
418 #if (QT_VERSION < QT_VERSION_CHECK(5, 5, 0))
|
Chris@443
|
419
|
Chris@390
|
420 if (!m_menuShortcutMapper) {
|
Chris@390
|
421 m_menuShortcutMapper = new QSignalMapper(this);
|
Chris@392
|
422 connect(m_menuShortcutMapper, SIGNAL(mapped(QObject *)),
|
Chris@392
|
423 this, SLOT(menuActionMapperInvoked(QObject *)));
|
Chris@390
|
424 }
|
Chris@390
|
425
|
Chris@354
|
426 foreach (QAction *a, menu->actions()) {
|
Chris@394
|
427
|
Chris@394
|
428 if (a->isSeparator()) {
|
Chris@394
|
429 continue;
|
Chris@394
|
430 } else if (a->menu()) {
|
Chris@394
|
431 finaliseMenu(a->menu());
|
Chris@394
|
432 } else {
|
Chris@394
|
433
|
Chris@394
|
434 QWidgetList ww = a->associatedWidgets();
|
Chris@394
|
435 bool hasButton = false;
|
Chris@394
|
436 foreach (QWidget *w, ww) {
|
Chris@394
|
437 if (qobject_cast<QAbstractButton *>(w)) {
|
Chris@394
|
438 hasButton = true;
|
Chris@394
|
439 break;
|
Chris@394
|
440 }
|
Chris@394
|
441 }
|
Chris@394
|
442 if (hasButton) continue;
|
Chris@394
|
443 QKeySequence sc = a->shortcut();
|
Chris@399
|
444
|
Chris@399
|
445 // Note that the set of "single-key shortcuts" that aren't
|
Chris@399
|
446 // working and that we need to handle here includes those
|
Chris@399
|
447 // with the Shift modifier mask as well as those with no
|
Chris@399
|
448 // modifier at all
|
Chris@443
|
449 #if (QT_VERSION >= QT_VERSION_CHECK(5, 5, 0))
|
Chris@443
|
450 // Nothing needed
|
Chris@443
|
451 if (false) {
|
Chris@443
|
452 #elif (QT_VERSION >= QT_VERSION_CHECK(5, 4, 0))
|
Chris@443
|
453 if (sc.count() == 1 &&
|
Chris@443
|
454 (sc[0] & Qt::KeyboardModifierMask) == Qt::ShiftModifier) {
|
Chris@443
|
455 #else
|
Chris@399
|
456 if (sc.count() == 1 &&
|
Chris@399
|
457 ((sc[0] & Qt::KeyboardModifierMask) == Qt::NoModifier ||
|
Chris@399
|
458 (sc[0] & Qt::KeyboardModifierMask) == Qt::ShiftModifier)) {
|
Chris@443
|
459 #endif
|
Chris@394
|
460 QShortcut *newSc = new QShortcut(sc, a->parentWidget());
|
Chris@394
|
461 QObject::connect(newSc, SIGNAL(activated()),
|
Chris@394
|
462 m_menuShortcutMapper, SLOT(map()));
|
Chris@394
|
463 m_menuShortcutMapper->setMapping(newSc, a);
|
Chris@394
|
464 m_appShortcuts.push_back(newSc);
|
Chris@384
|
465 }
|
Chris@384
|
466 }
|
Chris@354
|
467 }
|
Chris@354
|
468 #endif
|
Chris@443
|
469 #endif
|
Chris@354
|
470 }
|
Chris@354
|
471
|
Chris@354
|
472 void
|
Chris@354
|
473 MainWindowBase::menuActionMapperInvoked(QObject *o)
|
Chris@354
|
474 {
|
Chris@354
|
475 QAction *a = qobject_cast<QAction *>(o);
|
Chris@354
|
476 if (a && a->isEnabled()) {
|
Chris@354
|
477 a->trigger();
|
Chris@354
|
478 }
|
Chris@354
|
479 }
|
Chris@354
|
480
|
Chris@354
|
481 void
|
Chris@168
|
482 MainWindowBase::resizeConstrained(QSize size)
|
Chris@168
|
483 {
|
Chris@168
|
484 QDesktopWidget *desktop = QApplication::desktop();
|
Chris@168
|
485 QRect available = desktop->availableGeometry();
|
Chris@168
|
486 QSize actual(std::min(size.width(), available.width()),
|
Chris@168
|
487 std::min(size.height(), available.height()));
|
Chris@168
|
488 resize(actual);
|
Chris@168
|
489 }
|
Chris@168
|
490
|
Chris@168
|
491 void
|
Chris@304
|
492 MainWindowBase::startOSCQueue()
|
Chris@304
|
493 {
|
Chris@304
|
494 m_oscQueueStarter = new OSCQueueStarter(this);
|
Chris@304
|
495 connect(m_oscQueueStarter, SIGNAL(finished()), this, SLOT(oscReady()));
|
Chris@304
|
496 m_oscQueueStarter->start();
|
Chris@304
|
497 }
|
Chris@304
|
498
|
Chris@304
|
499 void
|
Chris@113
|
500 MainWindowBase::oscReady()
|
Chris@113
|
501 {
|
Chris@113
|
502 if (m_oscQueue && m_oscQueue->isOK()) {
|
Chris@113
|
503 connect(m_oscQueue, SIGNAL(messagesAvailable()), this, SLOT(pollOSC()));
|
Chris@113
|
504 QTimer *oscTimer = new QTimer(this);
|
Chris@113
|
505 connect(oscTimer, SIGNAL(timeout()), this, SLOT(pollOSC()));
|
Chris@113
|
506 oscTimer->start(1000);
|
Chris@571
|
507 SVCERR << "Finished setting up OSC interface" << endl;
|
Chris@113
|
508 }
|
Chris@113
|
509 }
|
Chris@113
|
510
|
Chris@45
|
511 QString
|
Chris@45
|
512 MainWindowBase::getOpenFileName(FileFinder::FileType type)
|
Chris@45
|
513 {
|
Chris@45
|
514 FileFinder *ff = FileFinder::getInstance();
|
Chris@358
|
515
|
Chris@358
|
516 if (type == FileFinder::AnyFile) {
|
Chris@45
|
517 if (getMainModel() != 0 &&
|
Chris@45
|
518 m_paneStack != 0 &&
|
Chris@45
|
519 m_paneStack->getCurrentPane() != 0) { // can import a layer
|
Chris@45
|
520 return ff->getOpenFileName(FileFinder::AnyFile, m_sessionFile);
|
Chris@45
|
521 } else {
|
Chris@45
|
522 return ff->getOpenFileName(FileFinder::SessionOrAudioFile,
|
Chris@45
|
523 m_sessionFile);
|
Chris@45
|
524 }
|
Chris@358
|
525 }
|
Chris@358
|
526
|
Chris@358
|
527 QString lastPath = m_sessionFile;
|
Chris@358
|
528
|
Chris@358
|
529 if (type == FileFinder::AudioFile) {
|
Chris@358
|
530 lastPath = m_audioFile;
|
Chris@45
|
531 }
|
Chris@358
|
532
|
Chris@358
|
533 return ff->getOpenFileName(type, lastPath);
|
Chris@45
|
534 }
|
Chris@45
|
535
|
Chris@45
|
536 QString
|
Chris@45
|
537 MainWindowBase::getSaveFileName(FileFinder::FileType type)
|
Chris@45
|
538 {
|
Chris@358
|
539 QString lastPath = m_sessionFile;
|
Chris@358
|
540
|
Chris@358
|
541 if (type == FileFinder::AudioFile) {
|
Chris@358
|
542 lastPath = m_audioFile;
|
Chris@358
|
543 }
|
Chris@358
|
544
|
Chris@45
|
545 FileFinder *ff = FileFinder::getInstance();
|
Chris@358
|
546 return ff->getSaveFileName(type, lastPath);
|
Chris@45
|
547 }
|
Chris@45
|
548
|
Chris@45
|
549 void
|
Chris@45
|
550 MainWindowBase::registerLastOpenedFilePath(FileFinder::FileType type, QString path)
|
Chris@45
|
551 {
|
Chris@45
|
552 FileFinder *ff = FileFinder::getInstance();
|
Chris@45
|
553 ff->registerLastOpenedFilePath(type, path);
|
Chris@45
|
554 }
|
Chris@45
|
555
|
Chris@222
|
556 QString
|
Chris@222
|
557 MainWindowBase::getDefaultSessionTemplate() const
|
Chris@222
|
558 {
|
Chris@231
|
559 QSettings settings;
|
Chris@231
|
560 settings.beginGroup("MainWindow");
|
Chris@231
|
561 QString templateName = settings.value("sessiontemplate", "").toString();
|
Chris@231
|
562 if (templateName == "") templateName = "default";
|
Chris@231
|
563 return templateName;
|
Chris@222
|
564 }
|
Chris@222
|
565
|
Chris@222
|
566 void
|
Chris@251
|
567 MainWindowBase::setDefaultSessionTemplate(QString n)
|
Chris@251
|
568 {
|
Chris@251
|
569 QSettings settings;
|
Chris@251
|
570 settings.beginGroup("MainWindow");
|
Chris@251
|
571 settings.setValue("sessiontemplate", n);
|
Chris@251
|
572 }
|
Chris@251
|
573
|
Chris@251
|
574 void
|
Chris@45
|
575 MainWindowBase::updateMenuStates()
|
Chris@45
|
576 {
|
Chris@45
|
577 Pane *currentPane = 0;
|
Chris@45
|
578 Layer *currentLayer = 0;
|
Chris@45
|
579
|
Chris@45
|
580 if (m_paneStack) currentPane = m_paneStack->getCurrentPane();
|
Chris@45
|
581 if (currentPane) currentLayer = currentPane->getSelectedLayer();
|
Chris@45
|
582
|
Chris@73
|
583 bool havePrevPane = false, haveNextPane = false;
|
Chris@73
|
584 bool havePrevLayer = false, haveNextLayer = false;
|
Chris@73
|
585
|
Chris@73
|
586 if (currentPane) {
|
Chris@73
|
587 for (int i = 0; i < m_paneStack->getPaneCount(); ++i) {
|
Chris@73
|
588 if (m_paneStack->getPane(i) == currentPane) {
|
Chris@73
|
589 if (i > 0) havePrevPane = true;
|
Chris@73
|
590 if (i < m_paneStack->getPaneCount()-1) haveNextPane = true;
|
Chris@73
|
591 break;
|
Chris@73
|
592 }
|
Chris@73
|
593 }
|
Chris@403
|
594 // the prev/next layer commands actually include the pane
|
Chris@403
|
595 // itself as one of the selectables -- so we always have a
|
Chris@403
|
596 // prev and next layer, as long as we have a pane with at
|
Chris@403
|
597 // least one layer in it
|
Chris@403
|
598 if (currentPane->getLayerCount() > 0) {
|
Chris@403
|
599 havePrevLayer = true;
|
Chris@403
|
600 haveNextLayer = true;
|
Chris@73
|
601 }
|
Chris@73
|
602 }
|
Chris@73
|
603
|
Chris@45
|
604 bool haveCurrentPane =
|
Chris@45
|
605 (currentPane != 0);
|
Chris@45
|
606 bool haveCurrentLayer =
|
Chris@45
|
607 (haveCurrentPane &&
|
Chris@45
|
608 (currentLayer != 0));
|
Chris@45
|
609 bool haveMainModel =
|
Chris@45
|
610 (getMainModel() != 0);
|
Chris@45
|
611 bool havePlayTarget =
|
Chris@475
|
612 (m_playTarget != 0 || m_audioIO != 0);
|
Chris@45
|
613 bool haveSelection =
|
Chris@45
|
614 (m_viewManager &&
|
Chris@45
|
615 !m_viewManager->getSelections().empty());
|
Chris@45
|
616 bool haveCurrentEditableLayer =
|
Chris@45
|
617 (haveCurrentLayer &&
|
Chris@45
|
618 currentLayer->isLayerEditable());
|
Chris@45
|
619 bool haveCurrentTimeInstantsLayer =
|
Chris@45
|
620 (haveCurrentLayer &&
|
Chris@45
|
621 dynamic_cast<TimeInstantLayer *>(currentLayer));
|
Chris@184
|
622 bool haveCurrentDurationLayer =
|
Chris@184
|
623 (haveCurrentLayer &&
|
Chris@184
|
624 (dynamic_cast<NoteLayer *>(currentLayer) ||
|
matthiasm@267
|
625 dynamic_cast<FlexiNoteLayer *>(currentLayer) ||
|
Chris@184
|
626 dynamic_cast<RegionLayer *>(currentLayer)));
|
Chris@45
|
627 bool haveCurrentColour3DPlot =
|
Chris@45
|
628 (haveCurrentLayer &&
|
Chris@45
|
629 dynamic_cast<Colour3DPlotLayer *>(currentLayer));
|
Chris@45
|
630 bool haveClipboardContents =
|
Chris@45
|
631 (m_viewManager &&
|
Chris@45
|
632 !m_viewManager->getClipboard().empty());
|
Chris@146
|
633 bool haveTabularLayer =
|
Chris@146
|
634 (haveCurrentLayer &&
|
Chris@146
|
635 dynamic_cast<TabularModel *>(currentLayer->getModel()));
|
Chris@45
|
636
|
Chris@45
|
637 emit canAddPane(haveMainModel);
|
Chris@45
|
638 emit canDeleteCurrentPane(haveCurrentPane);
|
Chris@45
|
639 emit canZoom(haveMainModel && haveCurrentPane);
|
Chris@45
|
640 emit canScroll(haveMainModel && haveCurrentPane);
|
Chris@45
|
641 emit canAddLayer(haveMainModel && haveCurrentPane);
|
Chris@45
|
642 emit canImportMoreAudio(haveMainModel);
|
Chris@259
|
643 emit canReplaceMainAudio(haveMainModel);
|
Chris@45
|
644 emit canImportLayer(haveMainModel && haveCurrentPane);
|
Chris@45
|
645 emit canExportAudio(haveMainModel);
|
Chris@289
|
646 emit canChangeSessionTemplate(haveMainModel);
|
Chris@45
|
647 emit canExportLayer(haveMainModel &&
|
Chris@45
|
648 (haveCurrentEditableLayer || haveCurrentColour3DPlot));
|
Chris@45
|
649 emit canExportImage(haveMainModel && haveCurrentPane);
|
Chris@45
|
650 emit canDeleteCurrentLayer(haveCurrentLayer);
|
Chris@45
|
651 emit canRenameLayer(haveCurrentLayer);
|
Chris@45
|
652 emit canEditLayer(haveCurrentEditableLayer);
|
Chris@146
|
653 emit canEditLayerTabular(haveCurrentEditableLayer || haveTabularLayer);
|
Chris@45
|
654 emit canMeasureLayer(haveCurrentLayer);
|
Chris@45
|
655 emit canSelect(haveMainModel && haveCurrentPane);
|
Chris@188
|
656 emit canPlay(haveMainModel && havePlayTarget);
|
Chris@453
|
657 emit canFfwd(haveMainModel);
|
Chris@453
|
658 emit canRewind(haveMainModel);
|
Chris@87
|
659 emit canPaste(haveClipboardContents);
|
Chris@45
|
660 emit canInsertInstant(haveCurrentPane);
|
Chris@45
|
661 emit canInsertInstantsAtBoundaries(haveCurrentPane && haveSelection);
|
Chris@184
|
662 emit canInsertItemAtSelection(haveCurrentPane && haveSelection && haveCurrentDurationLayer);
|
Chris@45
|
663 emit canRenumberInstants(haveCurrentTimeInstantsLayer && haveSelection);
|
Chris@537
|
664 emit canSubdivideInstants(haveCurrentTimeInstantsLayer && haveSelection);
|
Chris@538
|
665 emit canWinnowInstants(haveCurrentTimeInstantsLayer && haveSelection);
|
Chris@45
|
666 emit canPlaySelection(haveMainModel && havePlayTarget && haveSelection);
|
Chris@45
|
667 emit canClearSelection(haveSelection);
|
Chris@45
|
668 emit canEditSelection(haveSelection && haveCurrentEditableLayer);
|
Chris@45
|
669 emit canSave(m_sessionFile != "" && m_documentModified);
|
Chris@359
|
670 emit canSaveAs(haveMainModel);
|
Chris@73
|
671 emit canSelectPreviousPane(havePrevPane);
|
Chris@73
|
672 emit canSelectNextPane(haveNextPane);
|
Chris@73
|
673 emit canSelectPreviousLayer(havePrevLayer);
|
Chris@73
|
674 emit canSelectNextLayer(haveNextLayer);
|
Chris@586
|
675
|
Chris@586
|
676 // This is quite subtle -- whereas we can play back only if a
|
Chris@586
|
677 // system play target or I/O exists, we can record even if no
|
Chris@586
|
678 // record source (i.e. audioIO) exists because we can record into
|
Chris@586
|
679 // an empty session before the audio device has been
|
Chris@586
|
680 // opened. However, if there is no record *target* then recording
|
Chris@586
|
681 // was actively disabled (flag not set in m_soundOptions). And if
|
Chris@586
|
682 // we have a play target instead of an audioIO, then we must have
|
Chris@586
|
683 // tried to open the device but failed to find any capture source.
|
Chris@586
|
684 bool recordDisabled = (m_recordTarget == nullptr);
|
Chris@586
|
685 bool recordDeviceFailed = (m_playTarget != nullptr && m_audioIO == nullptr);
|
Chris@586
|
686 emit canRecord(!recordDisabled && !recordDeviceFailed);
|
Chris@45
|
687 }
|
Chris@45
|
688
|
Chris@45
|
689 void
|
Chris@45
|
690 MainWindowBase::documentModified()
|
Chris@45
|
691 {
|
Chris@233
|
692 // SVDEBUG << "MainWindowBase::documentModified" << endl;
|
Chris@45
|
693
|
Chris@45
|
694 if (!m_documentModified) {
|
Chris@45
|
695 //!!! this in subclass implementation?
|
Chris@45
|
696 setWindowTitle(tr("%1 (modified)").arg(windowTitle()));
|
Chris@45
|
697 }
|
Chris@45
|
698
|
Chris@45
|
699 m_documentModified = true;
|
Chris@45
|
700 updateMenuStates();
|
Chris@45
|
701 }
|
Chris@45
|
702
|
Chris@45
|
703 void
|
Chris@45
|
704 MainWindowBase::documentRestored()
|
Chris@45
|
705 {
|
Chris@233
|
706 // SVDEBUG << "MainWindowBase::documentRestored" << endl;
|
Chris@45
|
707
|
Chris@45
|
708 if (m_documentModified) {
|
Chris@45
|
709 //!!! this in subclass implementation?
|
Chris@45
|
710 QString wt(windowTitle());
|
Chris@45
|
711 wt.replace(tr(" (modified)"), "");
|
Chris@45
|
712 setWindowTitle(wt);
|
Chris@45
|
713 }
|
Chris@45
|
714
|
Chris@45
|
715 m_documentModified = false;
|
Chris@45
|
716 updateMenuStates();
|
Chris@45
|
717 }
|
Chris@45
|
718
|
Chris@45
|
719 void
|
Chris@45
|
720 MainWindowBase::playLoopToggled()
|
Chris@45
|
721 {
|
Chris@45
|
722 QAction *action = dynamic_cast<QAction *>(sender());
|
Chris@45
|
723
|
Chris@45
|
724 if (action) {
|
Chris@45
|
725 m_viewManager->setPlayLoopMode(action->isChecked());
|
Chris@45
|
726 } else {
|
Chris@45
|
727 m_viewManager->setPlayLoopMode(!m_viewManager->getPlayLoopMode());
|
Chris@45
|
728 }
|
Chris@45
|
729 }
|
Chris@45
|
730
|
Chris@45
|
731 void
|
Chris@45
|
732 MainWindowBase::playSelectionToggled()
|
Chris@45
|
733 {
|
Chris@45
|
734 QAction *action = dynamic_cast<QAction *>(sender());
|
Chris@45
|
735
|
Chris@45
|
736 if (action) {
|
Chris@45
|
737 m_viewManager->setPlaySelectionMode(action->isChecked());
|
Chris@45
|
738 } else {
|
Chris@45
|
739 m_viewManager->setPlaySelectionMode(!m_viewManager->getPlaySelectionMode());
|
Chris@45
|
740 }
|
Chris@45
|
741 }
|
Chris@45
|
742
|
Chris@45
|
743 void
|
Chris@45
|
744 MainWindowBase::playSoloToggled()
|
Chris@45
|
745 {
|
Chris@45
|
746 QAction *action = dynamic_cast<QAction *>(sender());
|
Chris@45
|
747
|
Chris@45
|
748 if (action) {
|
Chris@45
|
749 m_viewManager->setPlaySoloMode(action->isChecked());
|
Chris@45
|
750 } else {
|
Chris@45
|
751 m_viewManager->setPlaySoloMode(!m_viewManager->getPlaySoloMode());
|
Chris@45
|
752 }
|
Chris@45
|
753
|
Chris@45
|
754 if (m_viewManager->getPlaySoloMode()) {
|
Chris@45
|
755 currentPaneChanged(m_paneStack->getCurrentPane());
|
Chris@45
|
756 } else {
|
Chris@45
|
757 m_viewManager->setPlaybackModel(0);
|
Chris@45
|
758 if (m_playSource) {
|
Chris@45
|
759 m_playSource->clearSoloModelSet();
|
Chris@45
|
760 }
|
Chris@45
|
761 }
|
Chris@45
|
762 }
|
Chris@45
|
763
|
Chris@45
|
764 void
|
Chris@45
|
765 MainWindowBase::currentPaneChanged(Pane *p)
|
Chris@45
|
766 {
|
Chris@45
|
767 updateMenuStates();
|
Chris@45
|
768 updateVisibleRangeDisplay(p);
|
Chris@45
|
769
|
Chris@45
|
770 if (!p) return;
|
Chris@45
|
771
|
Chris@45
|
772 if (!(m_viewManager &&
|
Chris@45
|
773 m_playSource &&
|
Chris@45
|
774 m_viewManager->getPlaySoloMode())) {
|
Chris@45
|
775 if (m_viewManager) m_viewManager->setPlaybackModel(0);
|
Chris@45
|
776 return;
|
Chris@45
|
777 }
|
Chris@45
|
778
|
Chris@45
|
779 Model *prevPlaybackModel = m_viewManager->getPlaybackModel();
|
Chris@60
|
780
|
Chris@93
|
781 // What we want here is not the currently playing frame (unless we
|
Chris@93
|
782 // are about to clear out the audio playback buffers -- which may
|
Chris@93
|
783 // or may not be possible, depending on the audio driver). What
|
Chris@93
|
784 // we want is the frame that was last committed to the soundcard
|
Chris@93
|
785 // buffers, as the audio driver will continue playing up to that
|
Chris@93
|
786 // frame before switching to whichever one we decide we want to
|
Chris@93
|
787 // switch to, regardless of our efforts.
|
Chris@93
|
788
|
Chris@435
|
789 sv_frame_t frame = m_playSource->getCurrentBufferedFrame();
|
Chris@93
|
790
|
Chris@388
|
791 cerr << "currentPaneChanged: current frame (in ref model) = " << frame << endl;
|
Chris@45
|
792
|
Chris@45
|
793 View::ModelSet soloModels = p->getModels();
|
Chris@45
|
794
|
Chris@57
|
795 View::ModelSet sources;
|
Chris@57
|
796 for (View::ModelSet::iterator mi = soloModels.begin();
|
Chris@57
|
797 mi != soloModels.end(); ++mi) {
|
Chris@190
|
798 // If a model in this pane is derived from something else,
|
Chris@190
|
799 // then we want to play that model as well -- if the model
|
Chris@190
|
800 // that's derived from it is not something that is itself
|
Chris@190
|
801 // individually playable (e.g. a waveform)
|
Chris@190
|
802 if (*mi &&
|
Chris@190
|
803 !dynamic_cast<RangeSummarisableTimeValueModel *>(*mi) &&
|
Chris@190
|
804 (*mi)->getSourceModel()) {
|
Chris@57
|
805 sources.insert((*mi)->getSourceModel());
|
Chris@57
|
806 }
|
Chris@57
|
807 }
|
Chris@57
|
808 for (View::ModelSet::iterator mi = sources.begin();
|
Chris@57
|
809 mi != sources.end(); ++mi) {
|
Chris@57
|
810 soloModels.insert(*mi);
|
Chris@57
|
811 }
|
Chris@57
|
812
|
Chris@60
|
813 //!!! Need an "atomic" way of telling the play source that the
|
Chris@60
|
814 //playback model has changed, and changing it on ViewManager --
|
Chris@60
|
815 //the play source should be making the setPlaybackModel call to
|
Chris@60
|
816 //ViewManager
|
Chris@60
|
817
|
Chris@45
|
818 for (View::ModelSet::iterator mi = soloModels.begin();
|
Chris@45
|
819 mi != soloModels.end(); ++mi) {
|
Chris@45
|
820 if (dynamic_cast<RangeSummarisableTimeValueModel *>(*mi)) {
|
Chris@45
|
821 m_viewManager->setPlaybackModel(*mi);
|
Chris@45
|
822 }
|
Chris@45
|
823 }
|
Chris@45
|
824
|
Chris@45
|
825 RangeSummarisableTimeValueModel *a =
|
Chris@45
|
826 dynamic_cast<RangeSummarisableTimeValueModel *>(prevPlaybackModel);
|
Chris@45
|
827 RangeSummarisableTimeValueModel *b =
|
Chris@45
|
828 dynamic_cast<RangeSummarisableTimeValueModel *>(m_viewManager->
|
Chris@45
|
829 getPlaybackModel());
|
Chris@45
|
830
|
Chris@45
|
831 m_playSource->setSoloModelSet(soloModels);
|
Chris@45
|
832
|
Chris@45
|
833 if (a && b && (a != b)) {
|
Chris@60
|
834 if (m_playSource->isPlaying()) m_playSource->play(frame);
|
Chris@45
|
835 }
|
Chris@45
|
836 }
|
Chris@45
|
837
|
Chris@45
|
838 void
|
Chris@45
|
839 MainWindowBase::currentLayerChanged(Pane *p, Layer *)
|
Chris@45
|
840 {
|
Chris@45
|
841 updateMenuStates();
|
Chris@45
|
842 updateVisibleRangeDisplay(p);
|
Chris@45
|
843 }
|
Chris@45
|
844
|
Chris@45
|
845 void
|
Chris@45
|
846 MainWindowBase::selectAll()
|
Chris@45
|
847 {
|
Chris@45
|
848 if (!getMainModel()) return;
|
Chris@45
|
849 m_viewManager->setSelection(Selection(getMainModel()->getStartFrame(),
|
Chris@45
|
850 getMainModel()->getEndFrame()));
|
Chris@45
|
851 }
|
Chris@45
|
852
|
Chris@45
|
853 void
|
Chris@45
|
854 MainWindowBase::selectToStart()
|
Chris@45
|
855 {
|
Chris@45
|
856 if (!getMainModel()) return;
|
Chris@45
|
857 m_viewManager->setSelection(Selection(getMainModel()->getStartFrame(),
|
Chris@45
|
858 m_viewManager->getGlobalCentreFrame()));
|
Chris@45
|
859 }
|
Chris@45
|
860
|
Chris@45
|
861 void
|
Chris@45
|
862 MainWindowBase::selectToEnd()
|
Chris@45
|
863 {
|
Chris@45
|
864 if (!getMainModel()) return;
|
Chris@45
|
865 m_viewManager->setSelection(Selection(m_viewManager->getGlobalCentreFrame(),
|
Chris@45
|
866 getMainModel()->getEndFrame()));
|
Chris@45
|
867 }
|
Chris@45
|
868
|
Chris@45
|
869 void
|
Chris@45
|
870 MainWindowBase::selectVisible()
|
Chris@45
|
871 {
|
Chris@45
|
872 Model *model = getMainModel();
|
Chris@45
|
873 if (!model) return;
|
Chris@45
|
874
|
Chris@45
|
875 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@45
|
876 if (!currentPane) return;
|
Chris@45
|
877
|
Chris@435
|
878 sv_frame_t startFrame, endFrame;
|
Chris@45
|
879
|
Chris@45
|
880 if (currentPane->getStartFrame() < 0) startFrame = 0;
|
Chris@45
|
881 else startFrame = currentPane->getStartFrame();
|
Chris@45
|
882
|
Chris@45
|
883 if (currentPane->getEndFrame() > model->getEndFrame()) endFrame = model->getEndFrame();
|
Chris@45
|
884 else endFrame = currentPane->getEndFrame();
|
Chris@45
|
885
|
Chris@45
|
886 m_viewManager->setSelection(Selection(startFrame, endFrame));
|
Chris@45
|
887 }
|
Chris@45
|
888
|
Chris@45
|
889 void
|
Chris@45
|
890 MainWindowBase::clearSelection()
|
Chris@45
|
891 {
|
Chris@45
|
892 m_viewManager->clearSelections();
|
Chris@45
|
893 }
|
Chris@45
|
894
|
Chris@45
|
895 void
|
Chris@45
|
896 MainWindowBase::cut()
|
Chris@45
|
897 {
|
Chris@45
|
898 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@45
|
899 if (!currentPane) return;
|
Chris@45
|
900
|
Chris@45
|
901 Layer *layer = currentPane->getSelectedLayer();
|
Chris@45
|
902 if (!layer) return;
|
Chris@45
|
903
|
Chris@45
|
904 Clipboard &clipboard = m_viewManager->getClipboard();
|
Chris@45
|
905 clipboard.clear();
|
Chris@45
|
906
|
Chris@45
|
907 MultiSelection::SelectionList selections = m_viewManager->getSelections();
|
Chris@45
|
908
|
Chris@45
|
909 CommandHistory::getInstance()->startCompoundOperation(tr("Cut"), true);
|
Chris@45
|
910
|
Chris@45
|
911 for (MultiSelection::SelectionList::iterator i = selections.begin();
|
Chris@45
|
912 i != selections.end(); ++i) {
|
Chris@86
|
913 layer->copy(currentPane, *i, clipboard);
|
Chris@45
|
914 layer->deleteSelection(*i);
|
Chris@45
|
915 }
|
Chris@45
|
916
|
Chris@45
|
917 CommandHistory::getInstance()->endCompoundOperation();
|
Chris@45
|
918 }
|
Chris@45
|
919
|
Chris@45
|
920 void
|
Chris@45
|
921 MainWindowBase::copy()
|
Chris@45
|
922 {
|
Chris@45
|
923 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@45
|
924 if (!currentPane) return;
|
Chris@45
|
925
|
Chris@45
|
926 Layer *layer = currentPane->getSelectedLayer();
|
Chris@45
|
927 if (!layer) return;
|
Chris@45
|
928
|
Chris@45
|
929 Clipboard &clipboard = m_viewManager->getClipboard();
|
Chris@45
|
930 clipboard.clear();
|
Chris@45
|
931
|
Chris@45
|
932 MultiSelection::SelectionList selections = m_viewManager->getSelections();
|
Chris@45
|
933
|
Chris@45
|
934 for (MultiSelection::SelectionList::iterator i = selections.begin();
|
Chris@45
|
935 i != selections.end(); ++i) {
|
Chris@86
|
936 layer->copy(currentPane, *i, clipboard);
|
Chris@45
|
937 }
|
Chris@45
|
938 }
|
Chris@45
|
939
|
Chris@45
|
940 void
|
Chris@45
|
941 MainWindowBase::paste()
|
Chris@45
|
942 {
|
Chris@215
|
943 pasteRelative(0);
|
Chris@215
|
944 }
|
Chris@215
|
945
|
Chris@215
|
946 void
|
Chris@215
|
947 MainWindowBase::pasteAtPlaybackPosition()
|
Chris@215
|
948 {
|
Chris@435
|
949 sv_frame_t pos = getFrame();
|
Chris@215
|
950 Clipboard &clipboard = m_viewManager->getClipboard();
|
Chris@215
|
951 if (!clipboard.empty()) {
|
Chris@435
|
952 sv_frame_t firstEventFrame = clipboard.getPoints()[0].getFrame();
|
Chris@435
|
953 sv_frame_t offset = 0;
|
Chris@215
|
954 if (firstEventFrame < 0) {
|
Chris@366
|
955 offset = pos - firstEventFrame;
|
Chris@354
|
956 } else if (firstEventFrame < pos) {
|
Chris@366
|
957 offset = pos - firstEventFrame;
|
Chris@215
|
958 } else {
|
Chris@366
|
959 offset = -(firstEventFrame - pos);
|
Chris@215
|
960 }
|
Chris@215
|
961 pasteRelative(offset);
|
Chris@215
|
962 }
|
Chris@215
|
963 }
|
Chris@215
|
964
|
Chris@215
|
965 void
|
Chris@435
|
966 MainWindowBase::pasteRelative(sv_frame_t offset)
|
Chris@215
|
967 {
|
Chris@45
|
968 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@45
|
969 if (!currentPane) return;
|
Chris@45
|
970
|
Chris@45
|
971 Layer *layer = currentPane->getSelectedLayer();
|
Chris@45
|
972
|
Chris@45
|
973 Clipboard &clipboard = m_viewManager->getClipboard();
|
Chris@87
|
974
|
Chris@98
|
975 bool inCompound = false;
|
Chris@87
|
976
|
Chris@87
|
977 if (!layer || !layer->isLayerEditable()) {
|
Chris@87
|
978
|
Chris@87
|
979 CommandHistory::getInstance()->startCompoundOperation
|
Chris@87
|
980 (tr("Paste"), true);
|
Chris@87
|
981
|
Chris@87
|
982 // no suitable current layer: create one of the most
|
Chris@87
|
983 // appropriate sort
|
Chris@87
|
984 LayerFactory::LayerType type =
|
Chris@87
|
985 LayerFactory::getInstance()->getLayerTypeForClipboardContents(clipboard);
|
Chris@87
|
986 layer = m_document->createEmptyLayer(type);
|
Chris@87
|
987
|
Chris@87
|
988 if (!layer) {
|
Chris@87
|
989 CommandHistory::getInstance()->endCompoundOperation();
|
Chris@87
|
990 return;
|
Chris@45
|
991 }
|
Chris@87
|
992
|
Chris@87
|
993 m_document->addLayerToView(currentPane, layer);
|
Chris@87
|
994 m_paneStack->setCurrentLayer(currentPane, layer);
|
Chris@87
|
995
|
Chris@87
|
996 inCompound = true;
|
Chris@45
|
997 }
|
Chris@45
|
998
|
Chris@215
|
999 layer->paste(currentPane, clipboard, offset, true);
|
Chris@45
|
1000
|
Chris@87
|
1001 if (inCompound) CommandHistory::getInstance()->endCompoundOperation();
|
Chris@45
|
1002 }
|
Chris@45
|
1003
|
Chris@45
|
1004 void
|
Chris@45
|
1005 MainWindowBase::deleteSelected()
|
Chris@45
|
1006 {
|
Chris@45
|
1007 if (m_paneStack->getCurrentPane() &&
|
Chris@45
|
1008 m_paneStack->getCurrentPane()->getSelectedLayer()) {
|
Chris@45
|
1009
|
Chris@45
|
1010 Layer *layer = m_paneStack->getCurrentPane()->getSelectedLayer();
|
Chris@45
|
1011
|
Chris@409
|
1012 if (m_viewManager) {
|
Chris@409
|
1013
|
Chris@409
|
1014 if (m_viewManager->getToolMode() == ViewManager::MeasureMode) {
|
Chris@409
|
1015
|
Chris@409
|
1016 layer->deleteCurrentMeasureRect();
|
Chris@45
|
1017
|
Chris@409
|
1018 } else {
|
Chris@409
|
1019
|
Chris@409
|
1020 MultiSelection::SelectionList selections =
|
Chris@409
|
1021 m_viewManager->getSelections();
|
Chris@409
|
1022
|
Chris@409
|
1023 for (MultiSelection::SelectionList::iterator i = selections.begin();
|
Chris@409
|
1024 i != selections.end(); ++i) {
|
Chris@409
|
1025 layer->deleteSelection(*i);
|
Chris@409
|
1026 }
|
Chris@45
|
1027 }
|
Chris@45
|
1028 }
|
Chris@45
|
1029 }
|
Chris@45
|
1030 }
|
Chris@45
|
1031
|
Chris@161
|
1032 // FrameTimer method
|
Chris@161
|
1033
|
Chris@435
|
1034 sv_frame_t
|
Chris@161
|
1035 MainWindowBase::getFrame() const
|
Chris@161
|
1036 {
|
Chris@161
|
1037 if (m_playSource && m_playSource->isPlaying()) {
|
Chris@161
|
1038 return m_playSource->getCurrentPlayingFrame();
|
Chris@161
|
1039 } else {
|
Chris@161
|
1040 return m_viewManager->getPlaybackFrame();
|
Chris@161
|
1041 }
|
Chris@161
|
1042 }
|
Chris@161
|
1043
|
Chris@45
|
1044 void
|
Chris@45
|
1045 MainWindowBase::insertInstant()
|
Chris@45
|
1046 {
|
Chris@161
|
1047 insertInstantAt(getFrame());
|
Chris@45
|
1048 }
|
Chris@45
|
1049
|
Chris@45
|
1050 void
|
Chris@45
|
1051 MainWindowBase::insertInstantsAtBoundaries()
|
Chris@45
|
1052 {
|
Chris@45
|
1053 MultiSelection::SelectionList selections = m_viewManager->getSelections();
|
Chris@45
|
1054 for (MultiSelection::SelectionList::iterator i = selections.begin();
|
Chris@45
|
1055 i != selections.end(); ++i) {
|
Chris@435
|
1056 sv_frame_t start = i->getStartFrame();
|
Chris@435
|
1057 sv_frame_t end = i->getEndFrame();
|
Chris@45
|
1058 if (start != end) {
|
Chris@184
|
1059 insertInstantAt(start);
|
Chris@184
|
1060 insertInstantAt(end);
|
Chris@45
|
1061 }
|
Chris@45
|
1062 }
|
Chris@45
|
1063 }
|
Chris@45
|
1064
|
Chris@45
|
1065 void
|
Chris@435
|
1066 MainWindowBase::insertInstantAt(sv_frame_t frame)
|
Chris@45
|
1067 {
|
Chris@45
|
1068 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@45
|
1069 if (!pane) {
|
Chris@45
|
1070 return;
|
Chris@45
|
1071 }
|
Chris@45
|
1072
|
Chris@74
|
1073 frame = pane->alignFromReference(frame);
|
Chris@74
|
1074
|
Chris@45
|
1075 Layer *layer = dynamic_cast<TimeInstantLayer *>
|
Chris@45
|
1076 (pane->getSelectedLayer());
|
Chris@45
|
1077
|
Chris@45
|
1078 if (!layer) {
|
Chris@45
|
1079 for (int i = pane->getLayerCount(); i > 0; --i) {
|
Chris@45
|
1080 layer = dynamic_cast<TimeInstantLayer *>(pane->getLayer(i - 1));
|
Chris@45
|
1081 if (layer) break;
|
Chris@45
|
1082 }
|
Chris@45
|
1083
|
Chris@45
|
1084 if (!layer) {
|
Chris@45
|
1085 CommandHistory::getInstance()->startCompoundOperation
|
Chris@45
|
1086 (tr("Add Point"), true);
|
Chris@45
|
1087 layer = m_document->createEmptyLayer(LayerFactory::TimeInstants);
|
Chris@45
|
1088 if (layer) {
|
Chris@45
|
1089 m_document->addLayerToView(pane, layer);
|
Chris@45
|
1090 m_paneStack->setCurrentLayer(pane, layer);
|
Chris@45
|
1091 }
|
Chris@45
|
1092 CommandHistory::getInstance()->endCompoundOperation();
|
Chris@45
|
1093 }
|
Chris@45
|
1094 }
|
Chris@45
|
1095
|
Chris@45
|
1096 if (layer) {
|
Chris@45
|
1097
|
Chris@45
|
1098 Model *model = layer->getModel();
|
Chris@45
|
1099 SparseOneDimensionalModel *sodm = dynamic_cast<SparseOneDimensionalModel *>
|
Chris@45
|
1100 (model);
|
Chris@45
|
1101
|
Chris@45
|
1102 if (sodm) {
|
Chris@45
|
1103 SparseOneDimensionalModel::Point point(frame, "");
|
Chris@45
|
1104
|
Chris@45
|
1105 SparseOneDimensionalModel::Point prevPoint(0);
|
Chris@45
|
1106 bool havePrevPoint = false;
|
Chris@45
|
1107
|
Chris@45
|
1108 SparseOneDimensionalModel::EditCommand *command =
|
Chris@45
|
1109 new SparseOneDimensionalModel::EditCommand(sodm, tr("Add Point"));
|
Chris@45
|
1110
|
Chris@409
|
1111 if (m_labeller) {
|
Chris@409
|
1112
|
Chris@409
|
1113 if (m_labeller->requiresPrevPoint()) {
|
Chris@409
|
1114
|
Chris@409
|
1115 SparseOneDimensionalModel::PointList prevPoints =
|
Chris@409
|
1116 sodm->getPreviousPoints(frame);
|
Chris@409
|
1117
|
Chris@409
|
1118 if (!prevPoints.empty()) {
|
Chris@409
|
1119 prevPoint = *prevPoints.begin();
|
Chris@409
|
1120 havePrevPoint = true;
|
Chris@409
|
1121 }
|
Chris@45
|
1122 }
|
Chris@45
|
1123
|
Chris@45
|
1124 m_labeller->setSampleRate(sodm->getSampleRate());
|
Chris@45
|
1125
|
Chris@352
|
1126 if (m_labeller->actingOnPrevPoint() && havePrevPoint) {
|
Chris@45
|
1127 command->deletePoint(prevPoint);
|
Chris@45
|
1128 }
|
Chris@45
|
1129
|
Chris@45
|
1130 m_labeller->label<SparseOneDimensionalModel::Point>
|
Chris@45
|
1131 (point, havePrevPoint ? &prevPoint : 0);
|
Chris@45
|
1132
|
Chris@352
|
1133 if (m_labeller->actingOnPrevPoint() && havePrevPoint) {
|
Chris@45
|
1134 command->addPoint(prevPoint);
|
Chris@45
|
1135 }
|
Chris@45
|
1136 }
|
Chris@45
|
1137
|
Chris@45
|
1138 command->addPoint(point);
|
Chris@45
|
1139
|
Chris@45
|
1140 command->setName(tr("Add Point at %1 s")
|
Chris@45
|
1141 .arg(RealTime::frame2RealTime
|
Chris@45
|
1142 (frame,
|
Chris@45
|
1143 sodm->getSampleRate())
|
Chris@45
|
1144 .toText(false).c_str()));
|
Chris@45
|
1145
|
Chris@108
|
1146 Command *c = command->finish();
|
Chris@108
|
1147 if (c) CommandHistory::getInstance()->addCommand(c, false);
|
Chris@45
|
1148 }
|
Chris@45
|
1149 }
|
Chris@45
|
1150 }
|
Chris@45
|
1151
|
Chris@45
|
1152 void
|
Chris@184
|
1153 MainWindowBase::insertItemAtSelection()
|
Chris@184
|
1154 {
|
Chris@184
|
1155 MultiSelection::SelectionList selections = m_viewManager->getSelections();
|
Chris@184
|
1156 for (MultiSelection::SelectionList::iterator i = selections.begin();
|
Chris@184
|
1157 i != selections.end(); ++i) {
|
Chris@435
|
1158 sv_frame_t start = i->getStartFrame();
|
Chris@435
|
1159 sv_frame_t end = i->getEndFrame();
|
Chris@184
|
1160 if (start < end) {
|
Chris@184
|
1161 insertItemAt(start, end - start);
|
Chris@184
|
1162 }
|
Chris@184
|
1163 }
|
Chris@184
|
1164 }
|
Chris@184
|
1165
|
Chris@184
|
1166 void
|
Chris@435
|
1167 MainWindowBase::insertItemAt(sv_frame_t frame, sv_frame_t duration)
|
Chris@184
|
1168 {
|
Chris@184
|
1169 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@184
|
1170 if (!pane) {
|
Chris@184
|
1171 return;
|
Chris@184
|
1172 }
|
Chris@184
|
1173
|
Chris@184
|
1174 // ugh!
|
Chris@184
|
1175
|
Chris@435
|
1176 sv_frame_t alignedStart = pane->alignFromReference(frame);
|
Chris@435
|
1177 sv_frame_t alignedEnd = pane->alignFromReference(frame + duration);
|
Chris@184
|
1178 if (alignedStart >= alignedEnd) return;
|
Chris@435
|
1179 sv_frame_t alignedDuration = alignedEnd - alignedStart;
|
Chris@184
|
1180
|
Chris@184
|
1181 Command *c = 0;
|
Chris@184
|
1182
|
Chris@184
|
1183 QString name = tr("Add Item at %1 s")
|
Chris@184
|
1184 .arg(RealTime::frame2RealTime
|
Chris@184
|
1185 (alignedStart,
|
Chris@184
|
1186 getMainModel()->getSampleRate())
|
Chris@184
|
1187 .toText(false).c_str());
|
Chris@184
|
1188
|
Chris@184
|
1189 Layer *layer = pane->getSelectedLayer();
|
Chris@184
|
1190 if (!layer) return;
|
Chris@184
|
1191
|
Chris@184
|
1192 RegionModel *rm = dynamic_cast<RegionModel *>(layer->getModel());
|
Chris@184
|
1193 if (rm) {
|
Chris@184
|
1194 RegionModel::Point point(alignedStart,
|
Chris@185
|
1195 rm->getValueMaximum() + 1,
|
Chris@184
|
1196 alignedDuration,
|
Chris@184
|
1197 "");
|
Chris@184
|
1198 RegionModel::EditCommand *command =
|
Chris@184
|
1199 new RegionModel::EditCommand(rm, tr("Add Point"));
|
Chris@184
|
1200 command->addPoint(point);
|
Chris@184
|
1201 command->setName(name);
|
Chris@184
|
1202 c = command->finish();
|
Chris@184
|
1203 }
|
Chris@184
|
1204
|
Chris@184
|
1205 if (c) {
|
Chris@184
|
1206 CommandHistory::getInstance()->addCommand(c, false);
|
Chris@184
|
1207 return;
|
Chris@184
|
1208 }
|
Chris@184
|
1209
|
Chris@184
|
1210 NoteModel *nm = dynamic_cast<NoteModel *>(layer->getModel());
|
Chris@184
|
1211 if (nm) {
|
Chris@184
|
1212 NoteModel::Point point(alignedStart,
|
Chris@409
|
1213 nm->getValueMinimum(),
|
Chris@184
|
1214 alignedDuration,
|
Chris@184
|
1215 1.f,
|
Chris@184
|
1216 "");
|
Chris@184
|
1217 NoteModel::EditCommand *command =
|
Chris@184
|
1218 new NoteModel::EditCommand(nm, tr("Add Point"));
|
Chris@184
|
1219 command->addPoint(point);
|
Chris@184
|
1220 command->setName(name);
|
Chris@184
|
1221 c = command->finish();
|
Chris@184
|
1222 }
|
Chris@184
|
1223
|
Chris@184
|
1224 if (c) {
|
Chris@184
|
1225 CommandHistory::getInstance()->addCommand(c, false);
|
Chris@184
|
1226 return;
|
Chris@184
|
1227 }
|
matthiasm@267
|
1228
|
matthiasm@268
|
1229 FlexiNoteModel *fnm = dynamic_cast<FlexiNoteModel *>(layer->getModel());
|
matthiasm@268
|
1230 if (fnm) {
|
matthiasm@267
|
1231 FlexiNoteModel::Point point(alignedStart,
|
Chris@409
|
1232 fnm->getValueMinimum(),
|
Chris@409
|
1233 alignedDuration,
|
Chris@409
|
1234 1.f,
|
Chris@409
|
1235 "");
|
matthiasm@267
|
1236 FlexiNoteModel::EditCommand *command =
|
matthiasm@268
|
1237 new FlexiNoteModel::EditCommand(fnm, tr("Add Point"));
|
matthiasm@267
|
1238 command->addPoint(point);
|
matthiasm@267
|
1239 command->setName(name);
|
matthiasm@267
|
1240 c = command->finish();
|
matthiasm@267
|
1241 }
|
Chris@409
|
1242
|
matthiasm@267
|
1243 if (c) {
|
matthiasm@267
|
1244 CommandHistory::getInstance()->addCommand(c, false);
|
matthiasm@267
|
1245 return;
|
matthiasm@267
|
1246 }
|
Chris@184
|
1247 }
|
Chris@184
|
1248
|
Chris@184
|
1249 void
|
Chris@45
|
1250 MainWindowBase::renumberInstants()
|
Chris@45
|
1251 {
|
Chris@45
|
1252 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@45
|
1253 if (!pane) return;
|
Chris@45
|
1254
|
Chris@45
|
1255 Layer *layer = dynamic_cast<TimeInstantLayer *>(pane->getSelectedLayer());
|
Chris@45
|
1256 if (!layer) return;
|
Chris@45
|
1257
|
Chris@45
|
1258 MultiSelection ms(m_viewManager->getSelection());
|
Chris@45
|
1259
|
Chris@45
|
1260 Model *model = layer->getModel();
|
Chris@45
|
1261 SparseOneDimensionalModel *sodm = dynamic_cast<SparseOneDimensionalModel *>
|
Chris@45
|
1262 (model);
|
Chris@45
|
1263 if (!sodm) return;
|
Chris@45
|
1264
|
Chris@45
|
1265 if (!m_labeller) return;
|
Chris@45
|
1266
|
Chris@45
|
1267 Labeller labeller(*m_labeller);
|
Chris@45
|
1268 labeller.setSampleRate(sodm->getSampleRate());
|
Chris@45
|
1269
|
Chris@537
|
1270 Command *c = labeller.labelAll<SparseOneDimensionalModel::Point>(*sodm, &ms);
|
Chris@537
|
1271 if (c) CommandHistory::getInstance()->addCommand(c, false);
|
Chris@537
|
1272 }
|
Chris@537
|
1273
|
Chris@537
|
1274 void
|
Chris@537
|
1275 MainWindowBase::subdivideInstantsBy(int n)
|
Chris@537
|
1276 {
|
Chris@537
|
1277 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@537
|
1278 if (!pane) return;
|
Chris@537
|
1279
|
Chris@537
|
1280 Layer *layer = dynamic_cast<TimeInstantLayer *>(pane->getSelectedLayer());
|
Chris@537
|
1281 if (!layer) return;
|
Chris@537
|
1282
|
Chris@537
|
1283 MultiSelection ms(m_viewManager->getSelection());
|
Chris@537
|
1284
|
Chris@537
|
1285 Model *model = layer->getModel();
|
Chris@537
|
1286 SparseOneDimensionalModel *sodm =
|
Chris@537
|
1287 dynamic_cast<SparseOneDimensionalModel *>(model);
|
Chris@537
|
1288 if (!sodm) return;
|
Chris@537
|
1289
|
Chris@537
|
1290 if (!m_labeller) return;
|
Chris@537
|
1291
|
Chris@537
|
1292 Labeller labeller(*m_labeller);
|
Chris@537
|
1293 labeller.setSampleRate(sodm->getSampleRate());
|
Chris@537
|
1294
|
Chris@537
|
1295 Command *c = labeller.subdivide<SparseOneDimensionalModel::Point>
|
Chris@537
|
1296 (*sodm, &ms, n);
|
Chris@537
|
1297 if (c) CommandHistory::getInstance()->addCommand(c, false);
|
Chris@45
|
1298 }
|
Chris@45
|
1299
|
Chris@538
|
1300 void
|
Chris@538
|
1301 MainWindowBase::winnowInstantsBy(int n)
|
Chris@538
|
1302 {
|
Chris@538
|
1303 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@538
|
1304 if (!pane) return;
|
Chris@538
|
1305
|
Chris@538
|
1306 Layer *layer = dynamic_cast<TimeInstantLayer *>(pane->getSelectedLayer());
|
Chris@538
|
1307 if (!layer) return;
|
Chris@538
|
1308
|
Chris@538
|
1309 MultiSelection ms(m_viewManager->getSelection());
|
Chris@538
|
1310
|
Chris@538
|
1311 Model *model = layer->getModel();
|
Chris@538
|
1312 SparseOneDimensionalModel *sodm =
|
Chris@538
|
1313 dynamic_cast<SparseOneDimensionalModel *>(model);
|
Chris@538
|
1314 if (!sodm) return;
|
Chris@538
|
1315
|
Chris@538
|
1316 if (!m_labeller) return;
|
Chris@538
|
1317
|
Chris@538
|
1318 Labeller labeller(*m_labeller);
|
Chris@538
|
1319 labeller.setSampleRate(sodm->getSampleRate());
|
Chris@538
|
1320
|
Chris@538
|
1321 Command *c = labeller.winnow<SparseOneDimensionalModel::Point>
|
Chris@538
|
1322 (*sodm, &ms, n);
|
Chris@538
|
1323 if (c) CommandHistory::getInstance()->addCommand(c, false);
|
Chris@538
|
1324 }
|
Chris@538
|
1325
|
Chris@45
|
1326 MainWindowBase::FileOpenStatus
|
Chris@373
|
1327 MainWindowBase::openPath(QString fileOrUrl, AudioFileOpenMode mode)
|
Chris@45
|
1328 {
|
Chris@134
|
1329 ProgressDialog dialog(tr("Opening file or URL..."), true, 2000, this);
|
Chris@134
|
1330 connect(&dialog, SIGNAL(showing()), this, SIGNAL(hideSplash()));
|
Chris@109
|
1331 return open(FileSource(fileOrUrl, &dialog), mode);
|
Chris@45
|
1332 }
|
Chris@45
|
1333
|
Chris@45
|
1334 MainWindowBase::FileOpenStatus
|
Chris@45
|
1335 MainWindowBase::open(FileSource source, AudioFileOpenMode mode)
|
Chris@45
|
1336 {
|
Chris@45
|
1337 FileOpenStatus status;
|
Chris@45
|
1338
|
Chris@45
|
1339 if (!source.isAvailable()) return FileOpenFailed;
|
Chris@45
|
1340 source.waitForData();
|
Chris@45
|
1341
|
Chris@45
|
1342 bool canImportLayer = (getMainModel() != 0 &&
|
Chris@45
|
1343 m_paneStack != 0 &&
|
Chris@45
|
1344 m_paneStack->getCurrentPane() != 0);
|
Chris@45
|
1345
|
Chris@152
|
1346 bool rdf = (source.getExtension().toLower() == "rdf" ||
|
Chris@152
|
1347 source.getExtension().toLower() == "n3" ||
|
Chris@152
|
1348 source.getExtension().toLower() == "ttl");
|
Chris@152
|
1349
|
Chris@152
|
1350 bool audio = AudioFileReaderFactory::getKnownExtensions().contains
|
Chris@152
|
1351 (source.getExtension().toLower());
|
Chris@145
|
1352
|
Chris@145
|
1353 bool rdfSession = false;
|
Chris@145
|
1354 if (rdf) {
|
Chris@145
|
1355 RDFImporter::RDFDocumentType rdfType =
|
Chris@145
|
1356 RDFImporter::identifyDocumentType
|
Chris@145
|
1357 (QUrl::fromLocalFile(source.getLocalFilename()).toString());
|
Chris@145
|
1358 if (rdfType == RDFImporter::AudioRefAndAnnotations ||
|
Chris@145
|
1359 rdfType == RDFImporter::AudioRef) {
|
Chris@145
|
1360 rdfSession = true;
|
Chris@145
|
1361 } else if (rdfType == RDFImporter::NotRDF) {
|
Chris@145
|
1362 rdf = false;
|
Chris@145
|
1363 }
|
Chris@145
|
1364 }
|
Chris@145
|
1365
|
Chris@579
|
1366 try {
|
Chris@579
|
1367 if (rdf) {
|
Chris@579
|
1368 if (rdfSession) {
|
Chris@579
|
1369 bool cancel = false;
|
Chris@579
|
1370 if (!canImportLayer || shouldCreateNewSessionForRDFAudio(&cancel)) {
|
Chris@579
|
1371 return openSession(source);
|
Chris@579
|
1372 } else if (cancel) {
|
Chris@579
|
1373 return FileOpenCancelled;
|
Chris@579
|
1374 } else {
|
Chris@579
|
1375 return openLayer(source);
|
Chris@579
|
1376 }
|
Chris@145
|
1377 } else {
|
Chris@579
|
1378 if ((status = openSession(source)) != FileOpenFailed) {
|
Chris@579
|
1379 return status;
|
Chris@579
|
1380 } else if (!canImportLayer) {
|
Chris@579
|
1381 return FileOpenWrongMode;
|
Chris@579
|
1382 } else if ((status = openLayer(source)) != FileOpenFailed) {
|
Chris@579
|
1383 return status;
|
Chris@579
|
1384 } else {
|
Chris@579
|
1385 return FileOpenFailed;
|
Chris@579
|
1386 }
|
Chris@145
|
1387 }
|
Chris@145
|
1388 }
|
Chris@579
|
1389
|
Chris@579
|
1390 if (audio && (status = openAudio(source, mode)) != FileOpenFailed) {
|
Chris@579
|
1391 return status;
|
Chris@579
|
1392 } else if ((status = openSession(source)) != FileOpenFailed) {
|
Chris@579
|
1393 return status;
|
Chris@579
|
1394 } else if ((status = openPlaylist(source, mode)) != FileOpenFailed) {
|
Chris@579
|
1395 return status;
|
Chris@579
|
1396 } else if (!canImportLayer) {
|
Chris@579
|
1397 return FileOpenWrongMode;
|
Chris@579
|
1398 } else if ((status = openImage(source)) != FileOpenFailed) {
|
Chris@579
|
1399 return status;
|
Chris@579
|
1400 } else if ((status = openLayer(source)) != FileOpenFailed) {
|
Chris@579
|
1401 return status;
|
Chris@579
|
1402 } else {
|
Chris@579
|
1403 return FileOpenFailed;
|
Chris@579
|
1404 }
|
Chris@579
|
1405 } catch (const InsufficientDiscSpace &e) {
|
Chris@579
|
1406 emit hideSplash();
|
Chris@579
|
1407 m_openingAudioFile = false;
|
Chris@594
|
1408 SVCERR << "MainWindowBase: Caught InsufficientDiscSpace in file open" << endl;
|
Chris@579
|
1409 QMessageBox::critical
|
Chris@579
|
1410 (this, tr("Not enough disc space"),
|
Chris@579
|
1411 tr("<b>Not enough disc space</b><p>There doesn't appear to be enough spare disc space to accommodate any necessary temporary files.</p><p>Please clear some space and try again.</p>").arg(e.what()));
|
Chris@579
|
1412 return FileOpenFailed;
|
Chris@592
|
1413 } catch (const std::bad_alloc &e) { // reader may have rethrown this after cleaning up
|
Chris@592
|
1414 emit hideSplash();
|
Chris@592
|
1415 m_openingAudioFile = false;
|
Chris@594
|
1416 SVCERR << "MainWindowBase: Caught bad_alloc in file open" << endl;
|
Chris@592
|
1417 QMessageBox::critical
|
Chris@592
|
1418 (this, tr("Not enough memory"),
|
Chris@592
|
1419 tr("<b>Not enough memory</b><p>There doesn't appear to be enough memory to accommodate any necessary temporary data.</p>"));
|
Chris@592
|
1420 return FileOpenFailed;
|
Chris@45
|
1421 }
|
Chris@45
|
1422 }
|
Chris@45
|
1423
|
Chris@45
|
1424 MainWindowBase::FileOpenStatus
|
Chris@227
|
1425 MainWindowBase::openAudio(FileSource source, AudioFileOpenMode mode,
|
Chris@227
|
1426 QString templateName)
|
Chris@45
|
1427 {
|
Chris@386
|
1428 SVDEBUG << "MainWindowBase::openAudio(" << source.getLocation() << ") with mode " << mode << " and template " << templateName << endl;
|
Chris@45
|
1429
|
Chris@222
|
1430 if (templateName == "") {
|
Chris@231
|
1431 templateName = getDefaultSessionTemplate();
|
Chris@577
|
1432 SVDEBUG << "(Default template is: \"" << templateName << "\")" << endl;
|
Chris@222
|
1433 }
|
Chris@220
|
1434
|
Chris@374
|
1435 // cerr << "template is: \"" << templateName << "\"" << endl;
|
Chris@223
|
1436
|
Chris@413
|
1437 if (!source.isAvailable()) {
|
Chris@413
|
1438 if (source.wasCancelled()) {
|
Chris@413
|
1439 return FileOpenCancelled;
|
Chris@413
|
1440 } else {
|
Chris@413
|
1441 return FileOpenFailed;
|
Chris@413
|
1442 }
|
Chris@413
|
1443 }
|
Chris@413
|
1444
|
Chris@45
|
1445 source.waitForData();
|
Chris@45
|
1446
|
Chris@45
|
1447 m_openingAudioFile = true;
|
Chris@45
|
1448
|
Chris@435
|
1449 sv_samplerate_t rate = 0;
|
Chris@45
|
1450
|
Chris@360
|
1451 if (Preferences::getInstance()->getFixedSampleRate() != 0) {
|
Chris@360
|
1452 rate = Preferences::getInstance()->getFixedSampleRate();
|
Chris@360
|
1453 } else if (Preferences::getInstance()->getResampleOnLoad()) {
|
Chris@552
|
1454 if (getMainModel()) {
|
Chris@552
|
1455 rate = getMainModel()->getSampleRate();
|
Chris@552
|
1456 }
|
Chris@45
|
1457 }
|
Chris@45
|
1458
|
Chris@479
|
1459 ReadOnlyWaveFileModel *newModel = new ReadOnlyWaveFileModel(source, rate);
|
Chris@45
|
1460
|
Chris@45
|
1461 if (!newModel->isOK()) {
|
Chris@45
|
1462 delete newModel;
|
Chris@45
|
1463 m_openingAudioFile = false;
|
Chris@413
|
1464 if (source.wasCancelled()) {
|
Chris@413
|
1465 return FileOpenCancelled;
|
Chris@413
|
1466 } else {
|
Chris@413
|
1467 return FileOpenFailed;
|
Chris@413
|
1468 }
|
Chris@45
|
1469 }
|
Chris@45
|
1470
|
Chris@293
|
1471 // cerr << "mode = " << mode << endl;
|
Chris@45
|
1472
|
Chris@45
|
1473 if (mode == AskUser) {
|
Chris@45
|
1474 if (getMainModel()) {
|
Chris@45
|
1475
|
Chris@147
|
1476 QSettings settings;
|
Chris@147
|
1477 settings.beginGroup("MainWindow");
|
Chris@221
|
1478 int lastMode = settings.value("lastaudioopenmode", 0).toBool();
|
Chris@147
|
1479 settings.endGroup();
|
Chris@221
|
1480 int imode = 0;
|
Chris@45
|
1481
|
Chris@45
|
1482 QStringList items;
|
Chris@221
|
1483 items << tr("Close the current session and start a new one")
|
Chris@221
|
1484 << tr("Replace the main audio file in this session")
|
Chris@221
|
1485 << tr("Add the audio file to this session");
|
Chris@45
|
1486
|
Chris@45
|
1487 bool ok = false;
|
Chris@45
|
1488 QString item = ListInputDialog::getItem
|
Chris@45
|
1489 (this, tr("Select target for import"),
|
Chris@221
|
1490 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
|
1491 items, lastMode, &ok);
|
Chris@45
|
1492
|
Chris@45
|
1493 if (!ok || item.isEmpty()) {
|
Chris@45
|
1494 delete newModel;
|
Chris@45
|
1495 m_openingAudioFile = false;
|
Chris@45
|
1496 return FileOpenCancelled;
|
Chris@45
|
1497 }
|
Chris@45
|
1498
|
Chris@221
|
1499 for (int i = 0; i < items.size(); ++i) {
|
Chris@221
|
1500 if (item == items[i]) imode = i;
|
Chris@221
|
1501 }
|
Chris@221
|
1502
|
Chris@147
|
1503 settings.beginGroup("MainWindow");
|
Chris@221
|
1504 settings.setValue("lastaudioopenmode", imode);
|
Chris@147
|
1505 settings.endGroup();
|
Chris@45
|
1506
|
Chris@221
|
1507 mode = (AudioFileOpenMode)imode;
|
Chris@45
|
1508
|
Chris@45
|
1509 } else {
|
Chris@221
|
1510 // no main model: make a new session
|
Chris@221
|
1511 mode = ReplaceSession;
|
Chris@45
|
1512 }
|
Chris@45
|
1513 }
|
Chris@45
|
1514
|
Chris@45
|
1515 if (mode == ReplaceCurrentPane) {
|
Chris@45
|
1516
|
Chris@45
|
1517 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@45
|
1518 if (pane) {
|
Chris@45
|
1519 if (getMainModel()) {
|
Chris@45
|
1520 View::ModelSet models(pane->getModels());
|
Chris@45
|
1521 if (models.find(getMainModel()) != models.end()) {
|
Chris@221
|
1522 // Current pane contains main model: replace that
|
Chris@45
|
1523 mode = ReplaceMainModel;
|
Chris@45
|
1524 }
|
Chris@221
|
1525 // Otherwise the current pane has a non-default model,
|
Chris@221
|
1526 // which we will deal with later
|
Chris@45
|
1527 } else {
|
Chris@221
|
1528 // We have no main model, so start a new session with
|
Chris@221
|
1529 // optional template
|
Chris@221
|
1530 mode = ReplaceSession;
|
Chris@45
|
1531 }
|
Chris@45
|
1532 } else {
|
Chris@221
|
1533 // We seem to have no current pane! Oh well
|
Chris@45
|
1534 mode = CreateAdditionalModel;
|
Chris@45
|
1535 }
|
Chris@45
|
1536 }
|
Chris@45
|
1537
|
Chris@45
|
1538 if (mode == CreateAdditionalModel && !getMainModel()) {
|
Chris@386
|
1539 SVDEBUG << "Mode is CreateAdditionalModel but we have no main model, switching to ReplaceSession mode" << endl;
|
Chris@221
|
1540 mode = ReplaceSession;
|
Chris@221
|
1541 }
|
Chris@221
|
1542
|
Chris@221
|
1543 bool loadedTemplate = false;
|
Chris@221
|
1544
|
Chris@221
|
1545 if (mode == ReplaceSession) {
|
Chris@258
|
1546
|
Chris@258
|
1547 if (!checkSaveModified()) return FileOpenCancelled;
|
Chris@258
|
1548
|
Chris@386
|
1549 SVDEBUG << "SV looking for template " << templateName << endl;
|
Chris@230
|
1550 if (templateName != "") {
|
Chris@230
|
1551 FileOpenStatus tplStatus = openSessionTemplate(templateName);
|
Chris@258
|
1552 if (tplStatus == FileOpenCancelled) {
|
Chris@577
|
1553 SVDEBUG << "Template load cancelled" << endl;
|
Chris@258
|
1554 return FileOpenCancelled;
|
Chris@258
|
1555 }
|
Chris@230
|
1556 if (tplStatus != FileOpenFailed) {
|
Chris@577
|
1557 SVDEBUG << "Template load succeeded" << endl;
|
Chris@230
|
1558 loadedTemplate = true;
|
Chris@221
|
1559 }
|
Chris@221
|
1560 }
|
Chris@221
|
1561
|
Chris@221
|
1562 if (!loadedTemplate) {
|
Chris@386
|
1563 SVDEBUG << "No template found: closing session, creating new empty document" << endl;
|
Chris@221
|
1564 closeSession();
|
Chris@221
|
1565 createDocument();
|
Chris@221
|
1566 }
|
Chris@221
|
1567
|
Chris@386
|
1568 SVDEBUG << "Now switching to ReplaceMainModel mode" << endl;
|
Chris@45
|
1569 mode = ReplaceMainModel;
|
Chris@45
|
1570 }
|
Chris@45
|
1571
|
Chris@164
|
1572 emit activity(tr("Import audio file \"%1\"").arg(source.getLocation()));
|
Chris@164
|
1573
|
Chris@45
|
1574 if (mode == ReplaceMainModel) {
|
Chris@45
|
1575
|
Chris@45
|
1576 Model *prevMain = getMainModel();
|
Chris@45
|
1577 if (prevMain) {
|
Chris@45
|
1578 m_playSource->removeModel(prevMain);
|
Chris@108
|
1579 PlayParameterRepository::getInstance()->removePlayable(prevMain);
|
Chris@45
|
1580 }
|
Chris@108
|
1581 PlayParameterRepository::getInstance()->addPlayable(newModel);
|
Chris@45
|
1582
|
Chris@248
|
1583 SVDEBUG << "SV about to call setMainModel(" << newModel << "): prevMain is " << prevMain << endl;
|
Chris@248
|
1584
|
Chris@45
|
1585 m_document->setMainModel(newModel);
|
Chris@45
|
1586
|
Chris@45
|
1587 setupMenus();
|
Chris@45
|
1588
|
dan@210
|
1589 if (loadedTemplate || (m_sessionFile == "")) {
|
Chris@45
|
1590 //!!! shouldn't be dealing directly with title from here -- call a method
|
Chris@57
|
1591 setWindowTitle(tr("%1: %2")
|
Chris@57
|
1592 .arg(QApplication::applicationName())
|
Chris@45
|
1593 .arg(source.getLocation()));
|
Chris@45
|
1594 CommandHistory::getInstance()->clear();
|
Chris@45
|
1595 CommandHistory::getInstance()->documentSaved();
|
Chris@45
|
1596 m_documentModified = false;
|
Chris@45
|
1597 } else {
|
Chris@57
|
1598 setWindowTitle(tr("%1: %2 [%3]")
|
Chris@57
|
1599 .arg(QApplication::applicationName())
|
Chris@45
|
1600 .arg(QFileInfo(m_sessionFile).fileName())
|
Chris@45
|
1601 .arg(source.getLocation()));
|
Chris@45
|
1602 if (m_documentModified) {
|
Chris@45
|
1603 m_documentModified = false;
|
Chris@45
|
1604 documentModified(); // so as to restore "(modified)" window title
|
Chris@45
|
1605 }
|
Chris@45
|
1606 }
|
Chris@45
|
1607
|
Chris@45
|
1608 if (!source.isRemote()) m_audioFile = source.getLocalFilename();
|
Chris@45
|
1609
|
Chris@45
|
1610 } else if (mode == CreateAdditionalModel) {
|
Chris@45
|
1611
|
Chris@577
|
1612 SVCERR << "Mode is CreateAdditionalModel" << endl;
|
Chris@577
|
1613
|
Chris@45
|
1614 CommandHistory::getInstance()->startCompoundOperation
|
Chris@219
|
1615 (tr("Import \"%1\"").arg(source.getBasename()), true);
|
Chris@45
|
1616
|
Chris@45
|
1617 m_document->addImportedModel(newModel);
|
Chris@45
|
1618
|
Chris@45
|
1619 AddPaneCommand *command = new AddPaneCommand(this);
|
Chris@45
|
1620 CommandHistory::getInstance()->addCommand(command);
|
Chris@45
|
1621
|
Chris@45
|
1622 Pane *pane = command->getPane();
|
Chris@45
|
1623
|
Chris@47
|
1624 if (m_timeRulerLayer) {
|
Chris@577
|
1625 SVCERR << "Have time ruler, adding it" << endl;
|
Chris@47
|
1626 m_document->addLayerToView(pane, m_timeRulerLayer);
|
Chris@577
|
1627 } else {
|
Chris@577
|
1628 SVCERR << "Do not have time ruler" << endl;
|
Chris@47
|
1629 }
|
Chris@45
|
1630
|
Chris@45
|
1631 Layer *newLayer = m_document->createImportedLayer(newModel);
|
Chris@45
|
1632
|
Chris@45
|
1633 if (newLayer) {
|
Chris@45
|
1634 m_document->addLayerToView(pane, newLayer);
|
Chris@45
|
1635 }
|
Chris@45
|
1636
|
Chris@45
|
1637 CommandHistory::getInstance()->endCompoundOperation();
|
Chris@45
|
1638
|
Chris@45
|
1639 } else if (mode == ReplaceCurrentPane) {
|
Chris@45
|
1640
|
Chris@45
|
1641 // We know there is a current pane, otherwise we would have
|
Chris@45
|
1642 // reset the mode to CreateAdditionalModel above; and we know
|
Chris@45
|
1643 // the current pane does not contain the main model, otherwise
|
Chris@45
|
1644 // we would have reset it to ReplaceMainModel. But we don't
|
Chris@45
|
1645 // know whether the pane contains a waveform model at all.
|
Chris@45
|
1646
|
Chris@45
|
1647 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@45
|
1648 Layer *replace = 0;
|
Chris@45
|
1649
|
Chris@45
|
1650 for (int i = 0; i < pane->getLayerCount(); ++i) {
|
Chris@45
|
1651 Layer *layer = pane->getLayer(i);
|
Chris@45
|
1652 if (dynamic_cast<WaveformLayer *>(layer)) {
|
Chris@45
|
1653 replace = layer;
|
Chris@45
|
1654 break;
|
Chris@45
|
1655 }
|
Chris@45
|
1656 }
|
Chris@45
|
1657
|
Chris@45
|
1658 CommandHistory::getInstance()->startCompoundOperation
|
Chris@219
|
1659 (tr("Import \"%1\"").arg(source.getBasename()), true);
|
Chris@45
|
1660
|
Chris@45
|
1661 m_document->addImportedModel(newModel);
|
Chris@45
|
1662
|
Chris@45
|
1663 if (replace) {
|
Chris@45
|
1664 m_document->removeLayerFromView(pane, replace);
|
Chris@45
|
1665 }
|
Chris@45
|
1666
|
Chris@45
|
1667 Layer *newLayer = m_document->createImportedLayer(newModel);
|
Chris@45
|
1668
|
Chris@45
|
1669 if (newLayer) {
|
Chris@45
|
1670 m_document->addLayerToView(pane, newLayer);
|
Chris@45
|
1671 }
|
Chris@45
|
1672
|
Chris@45
|
1673 CommandHistory::getInstance()->endCompoundOperation();
|
Chris@45
|
1674 }
|
Chris@45
|
1675
|
Chris@45
|
1676 updateMenuStates();
|
Chris@45
|
1677 m_recentFiles.addFile(source.getLocation());
|
Chris@45
|
1678 if (!source.isRemote()) {
|
Chris@45
|
1679 // for file dialog
|
Chris@45
|
1680 registerLastOpenedFilePath(FileFinder::AudioFile,
|
Chris@45
|
1681 source.getLocalFilename());
|
Chris@45
|
1682 }
|
Chris@45
|
1683 m_openingAudioFile = false;
|
Chris@45
|
1684
|
Chris@45
|
1685 currentPaneChanged(m_paneStack->getCurrentPane());
|
Chris@45
|
1686
|
Chris@342
|
1687 emit audioFileLoaded();
|
Chris@342
|
1688
|
Chris@45
|
1689 return FileOpenSucceeded;
|
Chris@45
|
1690 }
|
Chris@45
|
1691
|
Chris@45
|
1692 MainWindowBase::FileOpenStatus
|
Chris@45
|
1693 MainWindowBase::openPlaylist(FileSource source, AudioFileOpenMode mode)
|
Chris@45
|
1694 {
|
Chris@233
|
1695 SVDEBUG << "MainWindowBase::openPlaylist(" << source.getLocation() << ")" << endl;
|
Chris@135
|
1696
|
Chris@45
|
1697 std::set<QString> extensions;
|
Chris@45
|
1698 PlaylistFileReader::getSupportedExtensions(extensions);
|
Chris@152
|
1699 QString extension = source.getExtension().toLower();
|
Chris@45
|
1700 if (extensions.find(extension) == extensions.end()) return FileOpenFailed;
|
Chris@45
|
1701
|
Chris@45
|
1702 if (!source.isAvailable()) return FileOpenFailed;
|
Chris@45
|
1703 source.waitForData();
|
Chris@45
|
1704
|
Chris@45
|
1705 PlaylistFileReader reader(source.getLocalFilename());
|
Chris@45
|
1706 if (!reader.isOK()) return FileOpenFailed;
|
Chris@45
|
1707
|
Chris@45
|
1708 PlaylistFileReader::Playlist playlist = reader.load();
|
Chris@45
|
1709
|
Chris@45
|
1710 bool someSuccess = false;
|
Chris@45
|
1711
|
Chris@45
|
1712 for (PlaylistFileReader::Playlist::const_iterator i = playlist.begin();
|
Chris@45
|
1713 i != playlist.end(); ++i) {
|
Chris@45
|
1714
|
Chris@134
|
1715 ProgressDialog dialog(tr("Opening playlist..."), true, 2000, this);
|
Chris@134
|
1716 connect(&dialog, SIGNAL(showing()), this, SIGNAL(hideSplash()));
|
Chris@109
|
1717 FileOpenStatus status = openAudio(FileSource(*i, &dialog), mode);
|
Chris@45
|
1718
|
Chris@45
|
1719 if (status == FileOpenCancelled) {
|
Chris@45
|
1720 return FileOpenCancelled;
|
Chris@45
|
1721 }
|
Chris@45
|
1722
|
Chris@45
|
1723 if (status == FileOpenSucceeded) {
|
Chris@45
|
1724 someSuccess = true;
|
Chris@45
|
1725 mode = CreateAdditionalModel;
|
Chris@45
|
1726 }
|
Chris@45
|
1727 }
|
Chris@45
|
1728
|
Chris@45
|
1729 if (someSuccess) return FileOpenSucceeded;
|
Chris@45
|
1730 else return FileOpenFailed;
|
Chris@45
|
1731 }
|
Chris@45
|
1732
|
Chris@45
|
1733 MainWindowBase::FileOpenStatus
|
Chris@45
|
1734 MainWindowBase::openLayer(FileSource source)
|
Chris@45
|
1735 {
|
Chris@233
|
1736 SVDEBUG << "MainWindowBase::openLayer(" << source.getLocation() << ")" << endl;
|
Chris@135
|
1737
|
Chris@45
|
1738 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@45
|
1739
|
Chris@45
|
1740 if (!pane) {
|
Chris@45
|
1741 // shouldn't happen, as the menu action should have been disabled
|
Chris@293
|
1742 cerr << "WARNING: MainWindowBase::openLayer: no current pane" << endl;
|
Chris@45
|
1743 return FileOpenWrongMode;
|
Chris@45
|
1744 }
|
Chris@45
|
1745
|
Chris@45
|
1746 if (!getMainModel()) {
|
Chris@45
|
1747 // shouldn't happen, as the menu action should have been disabled
|
Chris@293
|
1748 cerr << "WARNING: MainWindowBase::openLayer: No main model -- hence no default sample rate available" << endl;
|
Chris@45
|
1749 return FileOpenWrongMode;
|
Chris@45
|
1750 }
|
Chris@45
|
1751
|
Chris@45
|
1752 if (!source.isAvailable()) return FileOpenFailed;
|
Chris@45
|
1753 source.waitForData();
|
Chris@45
|
1754
|
Chris@45
|
1755 QString path = source.getLocalFilename();
|
Chris@45
|
1756
|
Chris@145
|
1757 RDFImporter::RDFDocumentType rdfType =
|
Chris@145
|
1758 RDFImporter::identifyDocumentType(QUrl::fromLocalFile(path).toString());
|
Chris@145
|
1759
|
Chris@293
|
1760 // cerr << "RDF type: (in layer) " << (int) rdfType << endl;
|
Chris@148
|
1761
|
Chris@145
|
1762 if (rdfType != RDFImporter::NotRDF) {
|
Chris@145
|
1763
|
Chris@145
|
1764 return openLayersFromRDF(source);
|
Chris@134
|
1765
|
Chris@152
|
1766 } else if (source.getExtension().toLower() == "svl" ||
|
Chris@152
|
1767 (source.getExtension().toLower() == "xml" &&
|
Chris@140
|
1768 (SVFileReader::identifyXmlFile(source.getLocalFilename())
|
Chris@140
|
1769 == SVFileReader::SVLayerFile))) {
|
Chris@45
|
1770
|
Chris@45
|
1771 PaneCallback callback(this);
|
Chris@45
|
1772 QFile file(path);
|
Chris@45
|
1773
|
Chris@45
|
1774 if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
Chris@293
|
1775 cerr << "ERROR: MainWindowBase::openLayer("
|
Chris@294
|
1776 << source.getLocation()
|
Chris@293
|
1777 << "): Failed to open file for reading" << endl;
|
Chris@45
|
1778 return FileOpenFailed;
|
Chris@45
|
1779 }
|
Chris@45
|
1780
|
Chris@45
|
1781 SVFileReader reader(m_document, callback, source.getLocation());
|
Chris@79
|
1782 connect
|
Chris@79
|
1783 (&reader, SIGNAL(modelRegenerationFailed(QString, QString, QString)),
|
Chris@79
|
1784 this, SLOT(modelRegenerationFailed(QString, QString, QString)));
|
Chris@79
|
1785 connect
|
Chris@79
|
1786 (&reader, SIGNAL(modelRegenerationWarning(QString, QString, QString)),
|
Chris@79
|
1787 this, SLOT(modelRegenerationWarning(QString, QString, QString)));
|
Chris@45
|
1788 reader.setCurrentPane(pane);
|
Chris@45
|
1789
|
Chris@45
|
1790 QXmlInputSource inputSource(&file);
|
Chris@45
|
1791 reader.parse(inputSource);
|
Chris@45
|
1792
|
Chris@45
|
1793 if (!reader.isOK()) {
|
Chris@293
|
1794 cerr << "ERROR: MainWindowBase::openLayer("
|
Chris@294
|
1795 << source.getLocation()
|
Chris@45
|
1796 << "): Failed to read XML file: "
|
Chris@293
|
1797 << reader.getErrorString() << endl;
|
Chris@45
|
1798 return FileOpenFailed;
|
Chris@45
|
1799 }
|
Chris@45
|
1800
|
Chris@164
|
1801 emit activity(tr("Import layer XML file \"%1\"").arg(source.getLocation()));
|
Chris@164
|
1802
|
Chris@45
|
1803 m_recentFiles.addFile(source.getLocation());
|
Chris@45
|
1804
|
Chris@45
|
1805 if (!source.isRemote()) {
|
Chris@45
|
1806 registerLastOpenedFilePath(FileFinder::LayerFile, path); // for file dialog
|
Chris@45
|
1807 }
|
Chris@45
|
1808
|
Chris@75
|
1809 return FileOpenSucceeded;
|
Chris@75
|
1810
|
Chris@45
|
1811 } else {
|
Chris@45
|
1812
|
Chris@45
|
1813 try {
|
Chris@45
|
1814
|
Chris@109
|
1815 MIDIFileImportDialog midiDlg(this);
|
Chris@109
|
1816
|
Chris@109
|
1817 Model *model = DataFileReaderFactory::loadNonCSV
|
Chris@109
|
1818 (path, &midiDlg, getMainModel()->getSampleRate());
|
Chris@45
|
1819
|
Chris@109
|
1820 if (!model) {
|
Chris@196
|
1821 CSVFormat format(path);
|
Chris@196
|
1822 format.setSampleRate(getMainModel()->getSampleRate());
|
Chris@196
|
1823 CSVFormatDialog *dialog = new CSVFormatDialog(this, format);
|
Chris@109
|
1824 if (dialog->exec() == QDialog::Accepted) {
|
Chris@109
|
1825 model = DataFileReaderFactory::loadCSV
|
Chris@109
|
1826 (path, dialog->getFormat(),
|
Chris@109
|
1827 getMainModel()->getSampleRate());
|
Chris@109
|
1828 }
|
Chris@109
|
1829 }
|
Chris@109
|
1830
|
Chris@45
|
1831 if (model) {
|
Chris@45
|
1832
|
Chris@233
|
1833 SVDEBUG << "MainWindowBase::openLayer: Have model" << endl;
|
Chris@45
|
1834
|
Chris@164
|
1835 emit activity(tr("Import MIDI file \"%1\"").arg(source.getLocation()));
|
Chris@164
|
1836
|
Chris@45
|
1837 Layer *newLayer = m_document->createImportedLayer(model);
|
Chris@45
|
1838
|
Chris@45
|
1839 if (newLayer) {
|
Chris@45
|
1840
|
Chris@45
|
1841 m_document->addLayerToView(pane, newLayer);
|
Chris@88
|
1842 m_paneStack->setCurrentLayer(pane, newLayer);
|
Chris@88
|
1843
|
Chris@45
|
1844 m_recentFiles.addFile(source.getLocation());
|
Chris@45
|
1845
|
Chris@45
|
1846 if (!source.isRemote()) {
|
Chris@45
|
1847 registerLastOpenedFilePath
|
Chris@45
|
1848 (FileFinder::LayerFile,
|
Chris@45
|
1849 path); // for file dialog
|
Chris@45
|
1850 }
|
Chris@88
|
1851
|
Chris@45
|
1852 return FileOpenSucceeded;
|
Chris@45
|
1853 }
|
Chris@45
|
1854 }
|
Chris@45
|
1855 } catch (DataFileReaderFactory::Exception e) {
|
Chris@45
|
1856 if (e == DataFileReaderFactory::ImportCancelled) {
|
Chris@45
|
1857 return FileOpenCancelled;
|
Chris@45
|
1858 }
|
Chris@45
|
1859 }
|
Chris@45
|
1860 }
|
Chris@45
|
1861
|
Chris@45
|
1862 return FileOpenFailed;
|
Chris@45
|
1863 }
|
Chris@45
|
1864
|
Chris@45
|
1865 MainWindowBase::FileOpenStatus
|
Chris@45
|
1866 MainWindowBase::openImage(FileSource source)
|
Chris@45
|
1867 {
|
Chris@233
|
1868 SVDEBUG << "MainWindowBase::openImage(" << source.getLocation() << ")" << endl;
|
Chris@135
|
1869
|
Chris@45
|
1870 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@45
|
1871
|
Chris@45
|
1872 if (!pane) {
|
Chris@45
|
1873 // shouldn't happen, as the menu action should have been disabled
|
Chris@293
|
1874 cerr << "WARNING: MainWindowBase::openImage: no current pane" << endl;
|
Chris@45
|
1875 return FileOpenWrongMode;
|
Chris@45
|
1876 }
|
Chris@45
|
1877
|
Chris@45
|
1878 if (!m_document->getMainModel()) {
|
Chris@45
|
1879 return FileOpenWrongMode;
|
Chris@45
|
1880 }
|
Chris@45
|
1881
|
Chris@45
|
1882 bool newLayer = false;
|
Chris@45
|
1883
|
Chris@45
|
1884 ImageLayer *il = dynamic_cast<ImageLayer *>(pane->getSelectedLayer());
|
Chris@45
|
1885 if (!il) {
|
Chris@45
|
1886 for (int i = pane->getLayerCount()-1; i >= 0; --i) {
|
Chris@45
|
1887 il = dynamic_cast<ImageLayer *>(pane->getLayer(i));
|
Chris@45
|
1888 if (il) break;
|
Chris@45
|
1889 }
|
Chris@45
|
1890 }
|
Chris@45
|
1891 if (!il) {
|
Chris@45
|
1892 il = dynamic_cast<ImageLayer *>
|
Chris@45
|
1893 (m_document->createEmptyLayer(LayerFactory::Image));
|
Chris@45
|
1894 if (!il) return FileOpenFailed;
|
Chris@45
|
1895 newLayer = true;
|
Chris@45
|
1896 }
|
Chris@45
|
1897
|
Chris@45
|
1898 // We don't put the image file in Recent Files
|
Chris@45
|
1899
|
Chris@293
|
1900 cerr << "openImage: trying location \"" << source.getLocation() << "\" in image layer" << endl;
|
Chris@45
|
1901
|
Chris@45
|
1902 if (!il->addImage(m_viewManager->getGlobalCentreFrame(), source.getLocation())) {
|
Chris@45
|
1903 if (newLayer) {
|
Chris@52
|
1904 m_document->deleteLayer(il); // also releases its model
|
Chris@45
|
1905 }
|
Chris@45
|
1906 return FileOpenFailed;
|
Chris@45
|
1907 } else {
|
Chris@45
|
1908 if (newLayer) {
|
Chris@45
|
1909 m_document->addLayerToView(pane, il);
|
Chris@45
|
1910 }
|
Chris@45
|
1911 m_paneStack->setCurrentLayer(pane, il);
|
Chris@45
|
1912 }
|
Chris@45
|
1913
|
Chris@45
|
1914 return FileOpenSucceeded;
|
Chris@45
|
1915 }
|
Chris@45
|
1916
|
Chris@45
|
1917 MainWindowBase::FileOpenStatus
|
Chris@427
|
1918 MainWindowBase::openDirOfAudio(QString dirPath)
|
Chris@427
|
1919 {
|
Chris@427
|
1920 QDir dir(dirPath);
|
Chris@427
|
1921 QStringList files = dir.entryList(QDir::Files | QDir::Readable);
|
Chris@427
|
1922 files.sort();
|
Chris@427
|
1923
|
Chris@427
|
1924 FileOpenStatus status = FileOpenFailed;
|
Chris@427
|
1925 bool first = true;
|
Chris@427
|
1926 bool cancelled = false;
|
Chris@427
|
1927
|
Chris@427
|
1928 foreach (QString file, files) {
|
Chris@427
|
1929
|
Chris@427
|
1930 FileSource source(dir.filePath(file));
|
Chris@427
|
1931 if (!source.isAvailable()) {
|
Chris@427
|
1932 continue;
|
Chris@427
|
1933 }
|
Chris@427
|
1934
|
Chris@427
|
1935 if (AudioFileReaderFactory::getKnownExtensions().contains
|
Chris@427
|
1936 (source.getExtension().toLower())) {
|
Chris@427
|
1937
|
Chris@427
|
1938 AudioFileOpenMode mode = CreateAdditionalModel;
|
Chris@427
|
1939 if (first) mode = ReplaceSession;
|
Chris@427
|
1940
|
Chris@427
|
1941 switch (openAudio(source, mode)) {
|
Chris@427
|
1942 case FileOpenSucceeded:
|
Chris@427
|
1943 status = FileOpenSucceeded;
|
Chris@427
|
1944 first = false;
|
Chris@427
|
1945 break;
|
Chris@427
|
1946 case FileOpenFailed:
|
Chris@427
|
1947 break;
|
Chris@427
|
1948 case FileOpenCancelled:
|
Chris@427
|
1949 cancelled = true;
|
Chris@427
|
1950 break;
|
Chris@427
|
1951 case FileOpenWrongMode:
|
Chris@427
|
1952 break;
|
Chris@427
|
1953 }
|
Chris@427
|
1954 }
|
Chris@427
|
1955
|
Chris@427
|
1956 if (cancelled) break;
|
Chris@427
|
1957 }
|
Chris@427
|
1958
|
Chris@427
|
1959 return status;
|
Chris@427
|
1960 }
|
Chris@427
|
1961
|
Chris@427
|
1962 MainWindowBase::FileOpenStatus
|
Chris@373
|
1963 MainWindowBase::openSessionPath(QString fileOrUrl)
|
Chris@45
|
1964 {
|
Chris@134
|
1965 ProgressDialog dialog(tr("Opening session..."), true, 2000, this);
|
Chris@134
|
1966 connect(&dialog, SIGNAL(showing()), this, SIGNAL(hideSplash()));
|
Chris@109
|
1967 return openSession(FileSource(fileOrUrl, &dialog));
|
Chris@45
|
1968 }
|
Chris@45
|
1969
|
Chris@45
|
1970 MainWindowBase::FileOpenStatus
|
Chris@45
|
1971 MainWindowBase::openSession(FileSource source)
|
Chris@45
|
1972 {
|
Chris@233
|
1973 SVDEBUG << "MainWindowBase::openSession(" << source.getLocation() << ")" << endl;
|
Chris@135
|
1974
|
Chris@45
|
1975 if (!source.isAvailable()) return FileOpenFailed;
|
Chris@145
|
1976 source.waitForData();
|
Chris@141
|
1977
|
Chris@341
|
1978 QString sessionExt =
|
Chris@341
|
1979 InteractiveFileFinder::getInstance()->getApplicationSessionExtension();
|
Chris@341
|
1980
|
Chris@341
|
1981 if (source.getExtension().toLower() != sessionExt) {
|
Chris@145
|
1982
|
Chris@145
|
1983 RDFImporter::RDFDocumentType rdfType =
|
Chris@145
|
1984 RDFImporter::identifyDocumentType
|
Chris@145
|
1985 (QUrl::fromLocalFile(source.getLocalFilename()).toString());
|
Chris@145
|
1986
|
Chris@293
|
1987 // cerr << "RDF type: " << (int)rdfType << endl;
|
Chris@148
|
1988
|
Chris@145
|
1989 if (rdfType == RDFImporter::AudioRefAndAnnotations ||
|
Chris@145
|
1990 rdfType == RDFImporter::AudioRef) {
|
Chris@145
|
1991 return openSessionFromRDF(source);
|
Chris@145
|
1992 } else if (rdfType != RDFImporter::NotRDF) {
|
Chris@145
|
1993 return FileOpenFailed;
|
Chris@145
|
1994 }
|
Chris@145
|
1995
|
Chris@152
|
1996 if (source.getExtension().toLower() == "xml") {
|
Chris@140
|
1997 if (SVFileReader::identifyXmlFile(source.getLocalFilename()) ==
|
Chris@140
|
1998 SVFileReader::SVSessionFile) {
|
Chris@293
|
1999 cerr << "This XML file looks like a session file, attempting to open it as a session" << endl;
|
Chris@140
|
2000 } else {
|
Chris@140
|
2001 return FileOpenFailed;
|
Chris@140
|
2002 }
|
Chris@140
|
2003 } else {
|
Chris@140
|
2004 return FileOpenFailed;
|
Chris@140
|
2005 }
|
Chris@140
|
2006 }
|
Chris@45
|
2007
|
Chris@140
|
2008 QXmlInputSource *inputSource = 0;
|
Chris@140
|
2009 BZipFileDevice *bzFile = 0;
|
Chris@140
|
2010 QFile *rawFile = 0;
|
Chris@140
|
2011
|
Chris@341
|
2012 if (source.getExtension().toLower() == sessionExt) {
|
Chris@140
|
2013 bzFile = new BZipFileDevice(source.getLocalFilename());
|
Chris@140
|
2014 if (!bzFile->open(QIODevice::ReadOnly)) {
|
Chris@140
|
2015 delete bzFile;
|
Chris@140
|
2016 return FileOpenFailed;
|
Chris@140
|
2017 }
|
Chris@140
|
2018 inputSource = new QXmlInputSource(bzFile);
|
Chris@140
|
2019 } else {
|
Chris@140
|
2020 rawFile = new QFile(source.getLocalFilename());
|
Chris@140
|
2021 inputSource = new QXmlInputSource(rawFile);
|
Chris@140
|
2022 }
|
Chris@140
|
2023
|
Chris@140
|
2024 if (!checkSaveModified()) {
|
Chris@140
|
2025 if (bzFile) bzFile->close();
|
Chris@140
|
2026 delete inputSource;
|
Chris@140
|
2027 delete bzFile;
|
Chris@140
|
2028 delete rawFile;
|
Chris@140
|
2029 return FileOpenCancelled;
|
Chris@140
|
2030 }
|
Chris@45
|
2031
|
Chris@45
|
2032 QString error;
|
Chris@45
|
2033 closeSession();
|
Chris@45
|
2034 createDocument();
|
Chris@45
|
2035
|
Chris@45
|
2036 PaneCallback callback(this);
|
Chris@45
|
2037 m_viewManager->clearSelections();
|
Chris@45
|
2038
|
Chris@45
|
2039 SVFileReader reader(m_document, callback, source.getLocation());
|
Chris@79
|
2040 connect
|
Chris@79
|
2041 (&reader, SIGNAL(modelRegenerationFailed(QString, QString, QString)),
|
Chris@79
|
2042 this, SLOT(modelRegenerationFailed(QString, QString, QString)));
|
Chris@79
|
2043 connect
|
Chris@79
|
2044 (&reader, SIGNAL(modelRegenerationWarning(QString, QString, QString)),
|
Chris@79
|
2045 this, SLOT(modelRegenerationWarning(QString, QString, QString)));
|
Chris@140
|
2046
|
Chris@140
|
2047 reader.parse(*inputSource);
|
Chris@45
|
2048
|
Chris@45
|
2049 if (!reader.isOK()) {
|
Chris@45
|
2050 error = tr("SV XML file read error:\n%1").arg(reader.getErrorString());
|
Chris@45
|
2051 }
|
Chris@45
|
2052
|
Chris@140
|
2053 if (bzFile) bzFile->close();
|
Chris@140
|
2054
|
Chris@140
|
2055 delete inputSource;
|
Chris@140
|
2056 delete bzFile;
|
Chris@140
|
2057 delete rawFile;
|
Chris@45
|
2058
|
Chris@45
|
2059 bool ok = (error == "");
|
Chris@45
|
2060
|
Chris@45
|
2061 if (ok) {
|
Chris@45
|
2062
|
Chris@164
|
2063 emit activity(tr("Import session file \"%1\"").arg(source.getLocation()));
|
Chris@164
|
2064
|
Chris@57
|
2065 setWindowTitle(tr("%1: %2")
|
Chris@57
|
2066 .arg(QApplication::applicationName())
|
Chris@45
|
2067 .arg(source.getLocation()));
|
Chris@45
|
2068
|
Chris@45
|
2069 if (!source.isRemote()) m_sessionFile = source.getLocalFilename();
|
Chris@45
|
2070
|
Chris@45
|
2071 setupMenus();
|
Chris@577
|
2072 findTimeRulerLayer();
|
Chris@45
|
2073
|
Chris@45
|
2074 CommandHistory::getInstance()->clear();
|
Chris@45
|
2075 CommandHistory::getInstance()->documentSaved();
|
Chris@45
|
2076 m_documentModified = false;
|
Chris@45
|
2077 updateMenuStates();
|
Chris@45
|
2078
|
Chris@227
|
2079 m_recentFiles.addFile(source.getLocation());
|
Chris@45
|
2080
|
Chris@45
|
2081 if (!source.isRemote()) {
|
Chris@45
|
2082 // for file dialog
|
Chris@45
|
2083 registerLastOpenedFilePath(FileFinder::SessionFile,
|
Chris@227
|
2084 source.getLocalFilename());
|
Chris@45
|
2085 }
|
Chris@45
|
2086
|
Chris@342
|
2087 emit sessionLoaded();
|
Chris@342
|
2088
|
Chris@45
|
2089 } else {
|
Chris@57
|
2090 setWindowTitle(QApplication::applicationName());
|
Chris@45
|
2091 }
|
Chris@45
|
2092
|
Chris@45
|
2093 return ok ? FileOpenSucceeded : FileOpenFailed;
|
Chris@45
|
2094 }
|
Chris@45
|
2095
|
Chris@141
|
2096 MainWindowBase::FileOpenStatus
|
Chris@230
|
2097 MainWindowBase::openSessionTemplate(QString templateName)
|
Chris@230
|
2098 {
|
Chris@230
|
2099 // Template in the user's template directory takes
|
Chris@230
|
2100 // priority over a bundled one; we don't unbundle, but
|
Chris@230
|
2101 // open directly from the bundled file (where applicable)
|
Chris@230
|
2102 ResourceFinder rf;
|
Chris@230
|
2103 QString tfile = rf.getResourcePath("templates", templateName + ".svt");
|
Chris@230
|
2104 if (tfile != "") {
|
Chris@294
|
2105 cerr << "SV loading template file " << tfile << endl;
|
Chris@230
|
2106 return openSessionTemplate(FileSource("file:" + tfile));
|
Chris@230
|
2107 } else {
|
Chris@230
|
2108 return FileOpenFailed;
|
Chris@230
|
2109 }
|
Chris@230
|
2110 }
|
Chris@230
|
2111
|
Chris@230
|
2112 MainWindowBase::FileOpenStatus
|
Chris@227
|
2113 MainWindowBase::openSessionTemplate(FileSource source)
|
Chris@227
|
2114 {
|
Chris@294
|
2115 cerr << "MainWindowBase::openSessionTemplate(" << source.getLocation() << ")" << endl;
|
Chris@227
|
2116
|
Chris@227
|
2117 if (!source.isAvailable()) return FileOpenFailed;
|
Chris@227
|
2118 source.waitForData();
|
Chris@227
|
2119
|
Chris@227
|
2120 QXmlInputSource *inputSource = 0;
|
Chris@227
|
2121 QFile *file = 0;
|
Chris@227
|
2122
|
Chris@227
|
2123 file = new QFile(source.getLocalFilename());
|
Chris@227
|
2124 inputSource = new QXmlInputSource(file);
|
Chris@227
|
2125
|
Chris@227
|
2126 if (!checkSaveModified()) {
|
Chris@227
|
2127 delete inputSource;
|
Chris@227
|
2128 delete file;
|
Chris@227
|
2129 return FileOpenCancelled;
|
Chris@227
|
2130 }
|
Chris@227
|
2131
|
Chris@227
|
2132 QString error;
|
Chris@227
|
2133 closeSession();
|
Chris@227
|
2134 createDocument();
|
Chris@227
|
2135
|
Chris@227
|
2136 PaneCallback callback(this);
|
Chris@227
|
2137 m_viewManager->clearSelections();
|
Chris@227
|
2138
|
Chris@227
|
2139 SVFileReader reader(m_document, callback, source.getLocation());
|
Chris@227
|
2140 connect
|
Chris@227
|
2141 (&reader, SIGNAL(modelRegenerationFailed(QString, QString, QString)),
|
Chris@227
|
2142 this, SLOT(modelRegenerationFailed(QString, QString, QString)));
|
Chris@227
|
2143 connect
|
Chris@227
|
2144 (&reader, SIGNAL(modelRegenerationWarning(QString, QString, QString)),
|
Chris@227
|
2145 this, SLOT(modelRegenerationWarning(QString, QString, QString)));
|
Chris@227
|
2146
|
Chris@227
|
2147 reader.parse(*inputSource);
|
Chris@227
|
2148
|
Chris@227
|
2149 if (!reader.isOK()) {
|
Chris@227
|
2150 error = tr("SV XML file read error:\n%1").arg(reader.getErrorString());
|
Chris@227
|
2151 }
|
Chris@227
|
2152
|
Chris@227
|
2153 delete inputSource;
|
Chris@227
|
2154 delete file;
|
Chris@227
|
2155
|
Chris@227
|
2156 bool ok = (error == "");
|
Chris@227
|
2157
|
Chris@227
|
2158 setWindowTitle(QApplication::applicationName());
|
Chris@227
|
2159
|
Chris@227
|
2160 if (ok) {
|
Chris@227
|
2161
|
Chris@227
|
2162 emit activity(tr("Open session template \"%1\"").arg(source.getLocation()));
|
Chris@227
|
2163
|
Chris@227
|
2164 setupMenus();
|
Chris@577
|
2165 findTimeRulerLayer();
|
Chris@227
|
2166
|
Chris@227
|
2167 CommandHistory::getInstance()->clear();
|
Chris@227
|
2168 CommandHistory::getInstance()->documentSaved();
|
Chris@227
|
2169 m_documentModified = false;
|
Chris@227
|
2170 updateMenuStates();
|
Chris@342
|
2171
|
Chris@342
|
2172 emit sessionLoaded();
|
Chris@227
|
2173 }
|
Chris@227
|
2174
|
Chris@227
|
2175 return ok ? FileOpenSucceeded : FileOpenFailed;
|
Chris@227
|
2176 }
|
Chris@227
|
2177
|
Chris@227
|
2178 MainWindowBase::FileOpenStatus
|
Chris@141
|
2179 MainWindowBase::openSessionFromRDF(FileSource source)
|
Chris@141
|
2180 {
|
Chris@233
|
2181 SVDEBUG << "MainWindowBase::openSessionFromRDF(" << source.getLocation() << ")" << endl;
|
Chris@141
|
2182
|
Chris@141
|
2183 if (!source.isAvailable()) return FileOpenFailed;
|
Chris@141
|
2184 source.waitForData();
|
Chris@141
|
2185
|
Chris@145
|
2186 if (!checkSaveModified()) {
|
Chris@145
|
2187 return FileOpenCancelled;
|
Chris@141
|
2188 }
|
Chris@143
|
2189
|
Chris@145
|
2190 closeSession();
|
Chris@145
|
2191 createDocument();
|
Chris@145
|
2192
|
Chris@145
|
2193 FileOpenStatus status = openLayersFromRDF(source);
|
Chris@141
|
2194
|
Chris@141
|
2195 setupMenus();
|
Chris@577
|
2196 findTimeRulerLayer();
|
Chris@141
|
2197
|
Chris@141
|
2198 setWindowTitle(tr("%1: %2")
|
Chris@141
|
2199 .arg(QApplication::applicationName())
|
Chris@141
|
2200 .arg(source.getLocation()));
|
Chris@141
|
2201 CommandHistory::getInstance()->clear();
|
Chris@141
|
2202 CommandHistory::getInstance()->documentSaved();
|
Chris@141
|
2203 m_documentModified = false;
|
Chris@145
|
2204
|
Chris@342
|
2205 emit sessionLoaded();
|
Chris@342
|
2206
|
Chris@145
|
2207 return status;
|
Chris@145
|
2208 }
|
Chris@145
|
2209
|
Chris@145
|
2210 MainWindowBase::FileOpenStatus
|
Chris@145
|
2211 MainWindowBase::openLayersFromRDF(FileSource source)
|
Chris@145
|
2212 {
|
Chris@435
|
2213 sv_samplerate_t rate = 0;
|
Chris@145
|
2214
|
Chris@233
|
2215 SVDEBUG << "MainWindowBase::openLayersFromRDF" << endl;
|
Chris@186
|
2216
|
Chris@145
|
2217 ProgressDialog dialog(tr("Importing from RDF..."), true, 2000, this);
|
Chris@145
|
2218 connect(&dialog, SIGNAL(showing()), this, SIGNAL(hideSplash()));
|
Chris@145
|
2219
|
Chris@145
|
2220 if (getMainModel()) {
|
Chris@145
|
2221 rate = getMainModel()->getSampleRate();
|
Chris@145
|
2222 } else if (Preferences::getInstance()->getResampleOnLoad()) {
|
Chris@552
|
2223 if (getMainModel()) {
|
Chris@552
|
2224 rate = getMainModel()->getSampleRate();
|
Chris@552
|
2225 }
|
Chris@145
|
2226 }
|
Chris@145
|
2227
|
Chris@145
|
2228 RDFImporter importer
|
Chris@145
|
2229 (QUrl::fromLocalFile(source.getLocalFilename()).toString(), rate);
|
Chris@145
|
2230
|
Chris@145
|
2231 if (!importer.isOK()) {
|
Chris@147
|
2232 if (importer.getErrorString() != "") {
|
Chris@147
|
2233 QMessageBox::critical
|
Chris@147
|
2234 (this, tr("Failed to import RDF"),
|
Chris@147
|
2235 tr("<b>Failed to import RDF</b><p>Importing data from RDF document at \"%1\" failed: %2</p>")
|
Chris@147
|
2236 .arg(source.getLocation()).arg(importer.getErrorString()));
|
Chris@147
|
2237 }
|
Chris@145
|
2238 return FileOpenFailed;
|
Chris@145
|
2239 }
|
Chris@145
|
2240
|
Chris@145
|
2241 std::vector<Model *> models = importer.getDataModels(&dialog);
|
Chris@145
|
2242
|
Chris@145
|
2243 dialog.setMessage(tr("Importing from RDF..."));
|
Chris@145
|
2244
|
Chris@145
|
2245 if (models.empty()) {
|
Chris@186
|
2246 QMessageBox::critical
|
Chris@186
|
2247 (this, tr("Failed to import RDF"),
|
Chris@186
|
2248 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
|
2249 return FileOpenFailed;
|
Chris@145
|
2250 }
|
Chris@145
|
2251
|
Chris@164
|
2252 emit activity(tr("Import RDF document \"%1\"").arg(source.getLocation()));
|
Chris@164
|
2253
|
Chris@145
|
2254 std::set<Model *> added;
|
Chris@145
|
2255
|
Chris@221
|
2256 for (int i = 0; i < (int)models.size(); ++i) {
|
Chris@145
|
2257
|
Chris@145
|
2258 Model *m = models[i];
|
Chris@145
|
2259 WaveFileModel *w = dynamic_cast<WaveFileModel *>(m);
|
Chris@145
|
2260
|
Chris@145
|
2261 if (w) {
|
Chris@145
|
2262
|
Chris@145
|
2263 Pane *pane = addPaneToStack();
|
Chris@145
|
2264 Layer *layer = 0;
|
Chris@145
|
2265
|
Chris@145
|
2266 if (m_timeRulerLayer) {
|
Chris@145
|
2267 m_document->addLayerToView(pane, m_timeRulerLayer);
|
Chris@145
|
2268 }
|
Chris@145
|
2269
|
Chris@145
|
2270 if (!getMainModel()) {
|
Chris@145
|
2271 m_document->setMainModel(w);
|
Chris@145
|
2272 layer = m_document->createMainModelLayer(LayerFactory::Waveform);
|
Chris@145
|
2273 } else {
|
Chris@145
|
2274 layer = m_document->createImportedLayer(w);
|
Chris@145
|
2275 }
|
Chris@145
|
2276
|
Chris@145
|
2277 m_document->addLayerToView(pane, layer);
|
Chris@145
|
2278
|
Chris@145
|
2279 added.insert(w);
|
Chris@145
|
2280
|
Chris@221
|
2281 for (int j = 0; j < (int)models.size(); ++j) {
|
Chris@145
|
2282
|
Chris@145
|
2283 Model *dm = models[j];
|
Chris@145
|
2284
|
Chris@145
|
2285 if (dm == m) continue;
|
Chris@145
|
2286 if (dm->getSourceModel() != m) continue;
|
Chris@145
|
2287
|
Chris@145
|
2288 layer = m_document->createImportedLayer(dm);
|
Chris@145
|
2289
|
Chris@145
|
2290 if (layer->isLayerOpaque() ||
|
Chris@145
|
2291 dynamic_cast<Colour3DPlotLayer *>(layer)) {
|
Chris@145
|
2292
|
Chris@156
|
2293 // these always go in a new pane, with nothing
|
Chris@156
|
2294 // else going in the same pane
|
Chris@156
|
2295
|
Chris@145
|
2296 Pane *singleLayerPane = addPaneToStack();
|
Chris@145
|
2297 if (m_timeRulerLayer) {
|
Chris@145
|
2298 m_document->addLayerToView(singleLayerPane, m_timeRulerLayer);
|
Chris@145
|
2299 }
|
Chris@145
|
2300 m_document->addLayerToView(singleLayerPane, layer);
|
Chris@145
|
2301
|
Chris@156
|
2302 } else if (layer->getLayerColourSignificance() ==
|
Chris@156
|
2303 Layer::ColourHasMeaningfulValue) {
|
Chris@156
|
2304
|
Chris@156
|
2305 // these can go in a pane with something else, but
|
Chris@156
|
2306 // only if none of the something elses also have
|
Chris@156
|
2307 // this quality
|
Chris@156
|
2308
|
Chris@156
|
2309 bool needNewPane = false;
|
Chris@156
|
2310 for (int i = 0; i < pane->getLayerCount(); ++i) {
|
Chris@156
|
2311 Layer *otherLayer = pane->getLayer(i);
|
Chris@156
|
2312 if (otherLayer &&
|
Chris@156
|
2313 (otherLayer->getLayerColourSignificance() ==
|
Chris@156
|
2314 Layer::ColourHasMeaningfulValue)) {
|
Chris@156
|
2315 needNewPane = true;
|
Chris@156
|
2316 break;
|
Chris@156
|
2317 }
|
Chris@156
|
2318 }
|
Chris@156
|
2319 if (needNewPane) {
|
Chris@156
|
2320 pane = addPaneToStack();
|
Chris@156
|
2321 }
|
Chris@156
|
2322
|
Chris@156
|
2323 m_document->addLayerToView(pane, layer);
|
Chris@156
|
2324
|
Chris@145
|
2325 } else {
|
Chris@145
|
2326
|
Chris@145
|
2327 if (pane->getLayerCount() > 4) {
|
Chris@145
|
2328 pane = addPaneToStack();
|
Chris@145
|
2329 }
|
Chris@145
|
2330
|
Chris@145
|
2331 m_document->addLayerToView(pane, layer);
|
Chris@145
|
2332 }
|
Chris@145
|
2333
|
Chris@145
|
2334 added.insert(dm);
|
Chris@145
|
2335 }
|
Chris@145
|
2336 }
|
Chris@145
|
2337 }
|
Chris@145
|
2338
|
Chris@221
|
2339 for (int i = 0; i < (int)models.size(); ++i) {
|
Chris@145
|
2340
|
Chris@145
|
2341 Model *m = models[i];
|
Chris@145
|
2342
|
Chris@145
|
2343 if (added.find(m) == added.end()) {
|
Chris@145
|
2344
|
Chris@145
|
2345 Layer *layer = m_document->createImportedLayer(m);
|
Chris@145
|
2346 if (!layer) return FileOpenFailed;
|
Chris@145
|
2347
|
Chris@145
|
2348 Pane *singleLayerPane = addPaneToStack();
|
Chris@145
|
2349 if (m_timeRulerLayer) {
|
Chris@145
|
2350 m_document->addLayerToView(singleLayerPane, m_timeRulerLayer);
|
Chris@145
|
2351 }
|
Chris@145
|
2352 m_document->addLayerToView(singleLayerPane, layer);
|
Chris@145
|
2353 }
|
Chris@145
|
2354 }
|
Chris@145
|
2355
|
Chris@145
|
2356 m_recentFiles.addFile(source.getLocation());
|
Chris@145
|
2357 return FileOpenSucceeded;
|
Chris@141
|
2358 }
|
Chris@141
|
2359
|
Chris@584
|
2360 class AudioLogCallback : public breakfastquay::AudioFactory::LogCallback
|
Chris@584
|
2361 {
|
Chris@584
|
2362 public:
|
Chris@584
|
2363 void log(std::string message) const override {
|
Chris@584
|
2364 SVDEBUG << message << endl;
|
Chris@584
|
2365 }
|
Chris@584
|
2366 };
|
Chris@584
|
2367
|
Chris@45
|
2368 void
|
Chris@475
|
2369 MainWindowBase::createAudioIO()
|
Chris@45
|
2370 {
|
Chris@475
|
2371 if (m_playTarget || m_audioIO) return;
|
Chris@475
|
2372
|
Chris@584
|
2373 static AudioLogCallback audioLogCallback;
|
Chris@584
|
2374 breakfastquay::AudioFactory::setLogCallback(&audioLogCallback);
|
Chris@584
|
2375
|
Chris@475
|
2376 if (!(m_soundOptions & WithAudioOutput)) return;
|
Chris@45
|
2377
|
Chris@126
|
2378 QSettings settings;
|
Chris@126
|
2379 settings.beginGroup("Preferences");
|
Chris@547
|
2380 QString implementation = settings.value
|
Chris@547
|
2381 ("audio-target", "").toString();
|
Chris@547
|
2382 QString suffix;
|
Chris@547
|
2383 if (implementation != "") suffix = "-" + implementation;
|
Chris@547
|
2384 QString recordDevice = settings.value
|
Chris@547
|
2385 ("audio-record-device" + suffix, "").toString();
|
Chris@547
|
2386 QString playbackDevice = settings.value
|
Chris@547
|
2387 ("audio-playback-device" + suffix, "").toString();
|
Chris@126
|
2388 settings.endGroup();
|
Chris@547
|
2389
|
Chris@547
|
2390 if (implementation == "auto") {
|
Chris@547
|
2391 implementation = "";
|
Chris@547
|
2392 }
|
Chris@468
|
2393
|
Chris@547
|
2394 breakfastquay::AudioFactory::Preference preference;
|
Chris@547
|
2395 preference.implementation = implementation.toStdString();
|
Chris@547
|
2396 preference.recordDevice = recordDevice.toStdString();
|
Chris@547
|
2397 preference.playbackDevice = playbackDevice.toStdString();
|
Chris@547
|
2398
|
Chris@547
|
2399 SVCERR << "createAudioIO: Preferred implementation = \""
|
Chris@547
|
2400 << preference.implementation << "\"" << endl;
|
Chris@547
|
2401 SVCERR << "createAudioIO: Preferred playback device = \""
|
Chris@547
|
2402 << preference.playbackDevice << "\"" << endl;
|
Chris@547
|
2403 SVCERR << "createAudioIO: Preferred record device = \""
|
Chris@547
|
2404 << preference.recordDevice << "\"" << endl;
|
Chris@475
|
2405
|
Chris@551
|
2406 if (!m_resamplerWrapper) {
|
Chris@551
|
2407 m_resamplerWrapper = new breakfastquay::ResamplerWrapper(m_playSource);
|
Chris@551
|
2408 m_playSource->setResamplerWrapper(m_resamplerWrapper);
|
Chris@551
|
2409 }
|
Chris@569
|
2410
|
Chris@569
|
2411 std::string errorString;
|
Chris@551
|
2412
|
Chris@475
|
2413 if (m_soundOptions & WithAudioInput) {
|
Chris@475
|
2414 m_audioIO = breakfastquay::AudioFactory::
|
Chris@569
|
2415 createCallbackIO(m_recordTarget, m_resamplerWrapper,
|
Chris@569
|
2416 preference, errorString);
|
Chris@525
|
2417 if (m_audioIO) {
|
Chris@525
|
2418 m_audioIO->suspend(); // start in suspended state
|
Chris@525
|
2419 m_playSource->setSystemPlaybackTarget(m_audioIO);
|
Chris@586
|
2420 } else {
|
Chris@586
|
2421 // Failed to create audio I/O; this may just mean there is
|
Chris@586
|
2422 // no record device, so fall through to see what happens
|
Chris@586
|
2423 // next. We only report complete failure if we end up with
|
Chris@586
|
2424 // neither m_audioIO nor m_playTarget.
|
Chris@525
|
2425 }
|
Chris@586
|
2426 }
|
Chris@586
|
2427
|
Chris@586
|
2428 if (!m_audioIO) {
|
Chris@475
|
2429 m_playTarget = breakfastquay::AudioFactory::
|
Chris@569
|
2430 createCallbackPlayTarget(m_resamplerWrapper,
|
Chris@569
|
2431 preference, errorString);
|
Chris@525
|
2432 if (m_playTarget) {
|
Chris@525
|
2433 m_playTarget->suspend(); // start in suspended state
|
Chris@525
|
2434 m_playSource->setSystemPlaybackTarget(m_playTarget);
|
Chris@525
|
2435 }
|
Chris@475
|
2436 }
|
Chris@475
|
2437
|
Chris@475
|
2438 if (!m_playTarget && !m_audioIO) {
|
Chris@104
|
2439 emit hideSplash();
|
Chris@569
|
2440 QString message;
|
Chris@569
|
2441 QString error = errorString.c_str();
|
Chris@569
|
2442 QString firstBit, secondBit;
|
Chris@547
|
2443 if (implementation == "") {
|
Chris@569
|
2444 if (error == "") {
|
Chris@569
|
2445 firstBit = tr("<b>No audio available</b><p>Could not open an audio device.</p>");
|
Chris@569
|
2446 } else {
|
Chris@569
|
2447 firstBit = tr("<b>No audio available</b><p>Could not open audio device: %1</p>").arg(error);
|
Chris@569
|
2448 }
|
Chris@569
|
2449 if (m_soundOptions & WithAudioInput) {
|
Chris@569
|
2450 secondBit = tr("<p>Automatic audio device detection failed. Audio playback and recording will not be available during this session.</p>");
|
Chris@569
|
2451 } else {
|
Chris@569
|
2452 secondBit = tr("<p>Automatic audio device detection failed. Audio playback will not be available during this session.</p>");
|
Chris@569
|
2453 }
|
Chris@126
|
2454 } else {
|
Chris@569
|
2455 QString driverName = breakfastquay::AudioFactory::
|
Chris@569
|
2456 getImplementationDescription(implementation.toStdString())
|
Chris@569
|
2457 .c_str();
|
Chris@569
|
2458 if (error == "") {
|
Chris@569
|
2459 firstBit = tr("<b>No audio available</b><p>Failed to open your preferred audio driver (\"%1\").</p>").arg(driverName);
|
Chris@569
|
2460 } else {
|
Chris@569
|
2461 firstBit = tr("<b>No audio available</b><p>Failed to open your preferred audio driver (\"%1\"): %2.</p>").arg(driverName).arg(error);
|
Chris@569
|
2462 }
|
Chris@569
|
2463 if (m_soundOptions & WithAudioInput) {
|
Chris@569
|
2464 secondBit = tr("<p>Audio playback and recording will not be available during this session.</p>");
|
Chris@569
|
2465 } else {
|
Chris@569
|
2466 secondBit = tr("<p>Audio playback will not be available during this session.</p>");
|
Chris@569
|
2467 }
|
Chris@126
|
2468 }
|
Chris@570
|
2469 SVDEBUG << "createAudioIO: ERROR: Failed to open audio device \""
|
Chris@570
|
2470 << implementation << "\": error is: " << error << endl;
|
Chris@569
|
2471 QMessageBox::warning(this, tr("Couldn't open audio device"),
|
Chris@569
|
2472 firstBit + secondBit, QMessageBox::Ok);
|
Chris@45
|
2473 }
|
Chris@45
|
2474 }
|
Chris@45
|
2475
|
Chris@556
|
2476 void
|
Chris@556
|
2477 MainWindowBase::deleteAudioIO()
|
Chris@556
|
2478 {
|
Chris@556
|
2479 // First prevent this trying to call target.
|
Chris@559
|
2480 if (m_playSource) {
|
Chris@559
|
2481 m_playSource->setSystemPlaybackTarget(0);
|
Chris@559
|
2482 m_playSource->setResamplerWrapper(0);
|
Chris@559
|
2483 }
|
Chris@556
|
2484
|
Chris@556
|
2485 // Then delete the breakfastquay::System object.
|
Chris@556
|
2486 // Only one of these two exists!
|
Chris@556
|
2487 delete m_audioIO;
|
Chris@556
|
2488 delete m_playTarget;
|
Chris@556
|
2489
|
Chris@559
|
2490 // And the breakfastquay resampler wrapper. We need to
|
Chris@559
|
2491 // delete/recreate this if the channel count changes, which is one
|
Chris@559
|
2492 // of the use cases for recreateAudioIO() calling this
|
Chris@559
|
2493 delete m_resamplerWrapper;
|
Chris@559
|
2494
|
Chris@556
|
2495 m_audioIO = 0;
|
Chris@556
|
2496 m_playTarget = 0;
|
Chris@559
|
2497 m_resamplerWrapper = 0;
|
Chris@556
|
2498 }
|
Chris@556
|
2499
|
Chris@556
|
2500 void
|
Chris@556
|
2501 MainWindowBase::recreateAudioIO()
|
Chris@556
|
2502 {
|
Chris@556
|
2503 deleteAudioIO();
|
Chris@556
|
2504 createAudioIO();
|
Chris@556
|
2505 }
|
Chris@556
|
2506
|
Chris@570
|
2507 void
|
Chris@570
|
2508 MainWindowBase::audioChannelCountIncreased(int)
|
Chris@570
|
2509 {
|
Chris@570
|
2510 recreateAudioIO();
|
Chris@570
|
2511 }
|
Chris@570
|
2512
|
Chris@45
|
2513 WaveFileModel *
|
Chris@45
|
2514 MainWindowBase::getMainModel()
|
Chris@45
|
2515 {
|
Chris@45
|
2516 if (!m_document) return 0;
|
Chris@45
|
2517 return m_document->getMainModel();
|
Chris@45
|
2518 }
|
Chris@45
|
2519
|
Chris@45
|
2520 const WaveFileModel *
|
Chris@45
|
2521 MainWindowBase::getMainModel() const
|
Chris@45
|
2522 {
|
Chris@45
|
2523 if (!m_document) return 0;
|
Chris@45
|
2524 return m_document->getMainModel();
|
Chris@45
|
2525 }
|
Chris@45
|
2526
|
Chris@45
|
2527 void
|
Chris@45
|
2528 MainWindowBase::createDocument()
|
Chris@45
|
2529 {
|
Chris@45
|
2530 m_document = new Document;
|
Chris@45
|
2531
|
Chris@45
|
2532 connect(m_document, SIGNAL(layerAdded(Layer *)),
|
Chris@45
|
2533 this, SLOT(layerAdded(Layer *)));
|
Chris@45
|
2534 connect(m_document, SIGNAL(layerRemoved(Layer *)),
|
Chris@45
|
2535 this, SLOT(layerRemoved(Layer *)));
|
Chris@45
|
2536 connect(m_document, SIGNAL(layerAboutToBeDeleted(Layer *)),
|
Chris@45
|
2537 this, SLOT(layerAboutToBeDeleted(Layer *)));
|
Chris@45
|
2538 connect(m_document, SIGNAL(layerInAView(Layer *, bool)),
|
Chris@45
|
2539 this, SLOT(layerInAView(Layer *, bool)));
|
Chris@45
|
2540
|
Chris@45
|
2541 connect(m_document, SIGNAL(modelAdded(Model *)),
|
Chris@45
|
2542 this, SLOT(modelAdded(Model *)));
|
Chris@45
|
2543 connect(m_document, SIGNAL(mainModelChanged(WaveFileModel *)),
|
Chris@45
|
2544 this, SLOT(mainModelChanged(WaveFileModel *)));
|
Chris@45
|
2545 connect(m_document, SIGNAL(modelAboutToBeDeleted(Model *)),
|
Chris@45
|
2546 this, SLOT(modelAboutToBeDeleted(Model *)));
|
Chris@45
|
2547
|
Chris@78
|
2548 connect(m_document, SIGNAL(modelGenerationFailed(QString, QString)),
|
Chris@78
|
2549 this, SLOT(modelGenerationFailed(QString, QString)));
|
Chris@78
|
2550 connect(m_document, SIGNAL(modelRegenerationWarning(QString, QString, QString)),
|
Chris@78
|
2551 this, SLOT(modelRegenerationWarning(QString, QString, QString)));
|
Chris@429
|
2552 connect(m_document, SIGNAL(alignmentComplete(AlignmentModel *)),
|
Chris@429
|
2553 this, SLOT(alignmentComplete(AlignmentModel *)));
|
Chris@423
|
2554 connect(m_document, SIGNAL(alignmentFailed(QString)),
|
Chris@423
|
2555 this, SLOT(alignmentFailed(QString)));
|
Chris@160
|
2556
|
Chris@160
|
2557 emit replacedDocument();
|
Chris@45
|
2558 }
|
Chris@45
|
2559
|
Chris@45
|
2560 bool
|
Chris@45
|
2561 MainWindowBase::saveSessionFile(QString path)
|
Chris@45
|
2562 {
|
Chris@217
|
2563 try {
|
Chris@217
|
2564
|
Chris@217
|
2565 TempWriteFile temp(path);
|
Chris@217
|
2566
|
Chris@217
|
2567 BZipFileDevice bzFile(temp.getTemporaryFilename());
|
Chris@217
|
2568 if (!bzFile.open(QIODevice::WriteOnly)) {
|
Chris@293
|
2569 cerr << "Failed to open session file \""
|
Chris@294
|
2570 << temp.getTemporaryFilename()
|
Chris@217
|
2571 << "\" for writing: "
|
Chris@293
|
2572 << bzFile.errorString() << endl;
|
Chris@217
|
2573 return false;
|
Chris@217
|
2574 }
|
Chris@217
|
2575
|
Chris@217
|
2576 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
|
Chris@217
|
2577
|
Chris@217
|
2578 QTextStream out(&bzFile);
|
Chris@432
|
2579 out.setCodec(QTextCodec::codecForName("UTF-8"));
|
Chris@226
|
2580 toXml(out, false);
|
Chris@217
|
2581 out.flush();
|
Chris@217
|
2582
|
Chris@217
|
2583 QApplication::restoreOverrideCursor();
|
Chris@217
|
2584
|
Chris@217
|
2585 if (!bzFile.isOK()) {
|
Chris@217
|
2586 QMessageBox::critical(this, tr("Failed to write file"),
|
Chris@217
|
2587 tr("<b>Save failed</b><p>Failed to write to file \"%1\": %2")
|
Chris@217
|
2588 .arg(path).arg(bzFile.errorString()));
|
Chris@217
|
2589 bzFile.close();
|
Chris@217
|
2590 return false;
|
Chris@217
|
2591 }
|
Chris@217
|
2592
|
Chris@217
|
2593 bzFile.close();
|
Chris@217
|
2594 temp.moveToTarget();
|
Chris@217
|
2595 return true;
|
Chris@217
|
2596
|
Chris@217
|
2597 } catch (FileOperationFailed &f) {
|
Chris@217
|
2598
|
Chris@217
|
2599 QMessageBox::critical(this, tr("Failed to write file"),
|
Chris@217
|
2600 tr("<b>Save failed</b><p>Failed to write to file \"%1\": %2")
|
Chris@217
|
2601 .arg(path).arg(f.what()));
|
Chris@45
|
2602 return false;
|
Chris@45
|
2603 }
|
Chris@45
|
2604 }
|
Chris@45
|
2605
|
Chris@224
|
2606 bool
|
Chris@224
|
2607 MainWindowBase::saveSessionTemplate(QString path)
|
Chris@224
|
2608 {
|
Chris@224
|
2609 try {
|
Chris@224
|
2610
|
Chris@224
|
2611 TempWriteFile temp(path);
|
Chris@224
|
2612
|
Chris@224
|
2613 QFile file(temp.getTemporaryFilename());
|
Chris@224
|
2614 if (!file.open(QIODevice::WriteOnly)) {
|
Chris@293
|
2615 cerr << "Failed to open session template file \""
|
Chris@294
|
2616 << temp.getTemporaryFilename()
|
Chris@224
|
2617 << "\" for writing: "
|
Chris@294
|
2618 << file.errorString() << endl;
|
Chris@224
|
2619 return false;
|
Chris@224
|
2620 }
|
Chris@224
|
2621
|
Chris@224
|
2622 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
|
Chris@224
|
2623
|
Chris@224
|
2624 QTextStream out(&file);
|
Chris@432
|
2625 out.setCodec(QTextCodec::codecForName("UTF-8"));
|
Chris@226
|
2626 toXml(out, true);
|
Chris@224
|
2627 out.flush();
|
Chris@224
|
2628
|
Chris@224
|
2629 QApplication::restoreOverrideCursor();
|
Chris@224
|
2630
|
Chris@224
|
2631 file.close();
|
Chris@224
|
2632 temp.moveToTarget();
|
Chris@224
|
2633 return true;
|
Chris@224
|
2634
|
Chris@224
|
2635 } catch (FileOperationFailed &f) {
|
Chris@224
|
2636
|
Chris@224
|
2637 QMessageBox::critical(this, tr("Failed to write file"),
|
Chris@224
|
2638 tr("<b>Save failed</b><p>Failed to write to file \"%1\": %2")
|
Chris@224
|
2639 .arg(path).arg(f.what()));
|
Chris@224
|
2640 return false;
|
Chris@224
|
2641 }
|
Chris@224
|
2642 }
|
Chris@224
|
2643
|
Chris@45
|
2644 void
|
Chris@226
|
2645 MainWindowBase::toXml(QTextStream &out, bool asTemplate)
|
Chris@45
|
2646 {
|
Chris@45
|
2647 QString indent(" ");
|
Chris@45
|
2648
|
Chris@45
|
2649 out << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
|
Chris@45
|
2650 out << "<!DOCTYPE sonic-visualiser>\n";
|
Chris@45
|
2651 out << "<sv>\n";
|
Chris@45
|
2652
|
Chris@226
|
2653 if (asTemplate) {
|
Chris@226
|
2654 m_document->toXmlAsTemplate(out, "", "");
|
Chris@226
|
2655 } else {
|
Chris@226
|
2656 m_document->toXml(out, "", "");
|
Chris@226
|
2657 }
|
Chris@45
|
2658
|
Chris@45
|
2659 out << "<display>\n";
|
Chris@45
|
2660
|
Chris@45
|
2661 out << QString(" <window width=\"%1\" height=\"%2\"/>\n")
|
Chris@45
|
2662 .arg(width()).arg(height());
|
Chris@45
|
2663
|
Chris@45
|
2664 for (int i = 0; i < m_paneStack->getPaneCount(); ++i) {
|
Chris@45
|
2665
|
Chris@45
|
2666 Pane *pane = m_paneStack->getPane(i);
|
Chris@45
|
2667
|
Chris@45
|
2668 if (pane) {
|
Chris@45
|
2669 pane->toXml(out, indent);
|
Chris@45
|
2670 }
|
Chris@45
|
2671 }
|
Chris@45
|
2672
|
Chris@45
|
2673 out << "</display>\n";
|
Chris@45
|
2674
|
Chris@45
|
2675 m_viewManager->getSelection().toXml(out);
|
Chris@45
|
2676
|
Chris@45
|
2677 out << "</sv>\n";
|
Chris@45
|
2678 }
|
Chris@45
|
2679
|
Chris@45
|
2680 Pane *
|
Chris@45
|
2681 MainWindowBase::addPaneToStack()
|
Chris@45
|
2682 {
|
Chris@342
|
2683 cerr << "MainWindowBase::addPaneToStack()" << endl;
|
Chris@45
|
2684 AddPaneCommand *command = new AddPaneCommand(this);
|
Chris@45
|
2685 CommandHistory::getInstance()->addCommand(command);
|
Chris@57
|
2686 Pane *pane = command->getPane();
|
Chris@57
|
2687 return pane;
|
Chris@45
|
2688 }
|
Chris@45
|
2689
|
Chris@45
|
2690 void
|
Chris@45
|
2691 MainWindowBase::zoomIn()
|
Chris@45
|
2692 {
|
Chris@45
|
2693 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@45
|
2694 if (currentPane) currentPane->zoom(true);
|
Chris@45
|
2695 }
|
Chris@45
|
2696
|
Chris@45
|
2697 void
|
Chris@45
|
2698 MainWindowBase::zoomOut()
|
Chris@45
|
2699 {
|
Chris@45
|
2700 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@45
|
2701 if (currentPane) currentPane->zoom(false);
|
Chris@45
|
2702 }
|
Chris@45
|
2703
|
Chris@45
|
2704 void
|
Chris@45
|
2705 MainWindowBase::zoomToFit()
|
Chris@45
|
2706 {
|
Chris@45
|
2707 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@45
|
2708 if (!currentPane) return;
|
Chris@45
|
2709
|
Chris@45
|
2710 Model *model = getMainModel();
|
Chris@45
|
2711 if (!model) return;
|
Chris@45
|
2712
|
Chris@434
|
2713 sv_frame_t start = model->getStartFrame();
|
Chris@434
|
2714 sv_frame_t end = model->getEndFrame();
|
Chris@60
|
2715 if (m_playSource) end = std::max(end, m_playSource->getPlayEndFrame());
|
Chris@366
|
2716 int pixels = currentPane->width();
|
Chris@366
|
2717
|
Chris@366
|
2718 int sw = currentPane->getVerticalScaleWidth();
|
Chris@45
|
2719 if (pixels > sw * 2) pixels -= sw * 2;
|
Chris@45
|
2720 else pixels = 1;
|
Chris@45
|
2721 if (pixels > 4) pixels -= 4;
|
Chris@45
|
2722
|
Chris@436
|
2723 int zoomLevel = int((end - start) / pixels);
|
Chris@150
|
2724 if (zoomLevel < 1) zoomLevel = 1;
|
Chris@45
|
2725
|
Chris@45
|
2726 currentPane->setZoomLevel(zoomLevel);
|
Chris@45
|
2727 currentPane->setCentreFrame((start + end) / 2);
|
Chris@45
|
2728 }
|
Chris@45
|
2729
|
Chris@45
|
2730 void
|
Chris@45
|
2731 MainWindowBase::zoomDefault()
|
Chris@45
|
2732 {
|
Chris@45
|
2733 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@302
|
2734 QSettings settings;
|
Chris@302
|
2735 settings.beginGroup("MainWindow");
|
Chris@302
|
2736 int zoom = settings.value("zoom-default", 1024).toInt();
|
Chris@302
|
2737 settings.endGroup();
|
Chris@302
|
2738 if (currentPane) currentPane->setZoomLevel(zoom);
|
Chris@45
|
2739 }
|
Chris@45
|
2740
|
Chris@45
|
2741 void
|
Chris@45
|
2742 MainWindowBase::scrollLeft()
|
Chris@45
|
2743 {
|
Chris@45
|
2744 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@45
|
2745 if (currentPane) currentPane->scroll(false, false);
|
Chris@45
|
2746 }
|
Chris@45
|
2747
|
Chris@45
|
2748 void
|
Chris@45
|
2749 MainWindowBase::jumpLeft()
|
Chris@45
|
2750 {
|
Chris@45
|
2751 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@45
|
2752 if (currentPane) currentPane->scroll(false, true);
|
Chris@45
|
2753 }
|
Chris@45
|
2754
|
Chris@45
|
2755 void
|
Chris@162
|
2756 MainWindowBase::peekLeft()
|
Chris@162
|
2757 {
|
Chris@162
|
2758 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@162
|
2759 if (currentPane) currentPane->scroll(false, false, false);
|
Chris@162
|
2760 }
|
Chris@162
|
2761
|
Chris@162
|
2762 void
|
Chris@45
|
2763 MainWindowBase::scrollRight()
|
Chris@45
|
2764 {
|
Chris@45
|
2765 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@45
|
2766 if (currentPane) currentPane->scroll(true, false);
|
Chris@45
|
2767 }
|
Chris@45
|
2768
|
Chris@45
|
2769 void
|
Chris@45
|
2770 MainWindowBase::jumpRight()
|
Chris@45
|
2771 {
|
Chris@45
|
2772 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@45
|
2773 if (currentPane) currentPane->scroll(true, true);
|
Chris@45
|
2774 }
|
Chris@45
|
2775
|
Chris@45
|
2776 void
|
Chris@162
|
2777 MainWindowBase::peekRight()
|
Chris@162
|
2778 {
|
Chris@162
|
2779 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@162
|
2780 if (currentPane) currentPane->scroll(true, false, false);
|
Chris@162
|
2781 }
|
Chris@162
|
2782
|
Chris@162
|
2783 void
|
Chris@45
|
2784 MainWindowBase::showNoOverlays()
|
Chris@45
|
2785 {
|
Chris@45
|
2786 m_viewManager->setOverlayMode(ViewManager::NoOverlays);
|
Chris@45
|
2787 }
|
Chris@45
|
2788
|
Chris@45
|
2789 void
|
Chris@45
|
2790 MainWindowBase::showMinimalOverlays()
|
Chris@45
|
2791 {
|
Chris@335
|
2792 m_viewManager->setOverlayMode(ViewManager::StandardOverlays);
|
Chris@45
|
2793 }
|
Chris@45
|
2794
|
Chris@45
|
2795 void
|
Chris@45
|
2796 MainWindowBase::showAllOverlays()
|
Chris@45
|
2797 {
|
Chris@45
|
2798 m_viewManager->setOverlayMode(ViewManager::AllOverlays);
|
Chris@45
|
2799 }
|
Chris@45
|
2800
|
Chris@45
|
2801 void
|
Chris@577
|
2802 MainWindowBase::findTimeRulerLayer()
|
Chris@577
|
2803 {
|
Chris@577
|
2804 for (int i = 0; i < m_paneStack->getPaneCount(); ++i) {
|
Chris@577
|
2805 Pane *pane = m_paneStack->getPane(i);
|
Chris@577
|
2806 if (!pane) continue;
|
Chris@577
|
2807 for (int j = 0; j < pane->getLayerCount(); ++j) {
|
Chris@577
|
2808 Layer *layer = pane->getLayer(j);
|
Chris@577
|
2809 if (!dynamic_cast<TimeRulerLayer *>(layer)) continue;
|
Chris@577
|
2810 m_timeRulerLayer = layer;
|
Chris@577
|
2811 return;
|
Chris@577
|
2812 }
|
Chris@577
|
2813 }
|
Chris@577
|
2814 if (m_timeRulerLayer) {
|
Chris@577
|
2815 SVCERR << "WARNING: Time ruler layer was not reset to 0 before session template loaded?" << endl;
|
Chris@577
|
2816 delete m_timeRulerLayer;
|
Chris@577
|
2817 m_timeRulerLayer = 0;
|
Chris@577
|
2818 }
|
Chris@577
|
2819 }
|
Chris@577
|
2820
|
Chris@577
|
2821 void
|
Chris@211
|
2822 MainWindowBase::toggleTimeRulers()
|
Chris@211
|
2823 {
|
Chris@211
|
2824 bool haveRulers = false;
|
Chris@211
|
2825 bool someHidden = false;
|
Chris@211
|
2826
|
Chris@211
|
2827 for (int i = 0; i < m_paneStack->getPaneCount(); ++i) {
|
Chris@211
|
2828
|
Chris@211
|
2829 Pane *pane = m_paneStack->getPane(i);
|
Chris@211
|
2830 if (!pane) continue;
|
Chris@211
|
2831
|
Chris@211
|
2832 for (int j = 0; j < pane->getLayerCount(); ++j) {
|
Chris@211
|
2833
|
Chris@211
|
2834 Layer *layer = pane->getLayer(j);
|
Chris@211
|
2835 if (!dynamic_cast<TimeRulerLayer *>(layer)) continue;
|
Chris@211
|
2836
|
Chris@211
|
2837 haveRulers = true;
|
Chris@211
|
2838 if (layer->isLayerDormant(pane)) someHidden = true;
|
Chris@211
|
2839 }
|
Chris@211
|
2840 }
|
Chris@211
|
2841
|
Chris@211
|
2842 if (haveRulers) {
|
Chris@211
|
2843
|
Chris@211
|
2844 bool show = someHidden;
|
Chris@211
|
2845
|
Chris@211
|
2846 for (int i = 0; i < m_paneStack->getPaneCount(); ++i) {
|
Chris@211
|
2847
|
Chris@211
|
2848 Pane *pane = m_paneStack->getPane(i);
|
Chris@211
|
2849 if (!pane) continue;
|
Chris@211
|
2850
|
Chris@211
|
2851 for (int j = 0; j < pane->getLayerCount(); ++j) {
|
Chris@211
|
2852
|
Chris@211
|
2853 Layer *layer = pane->getLayer(j);
|
Chris@211
|
2854 if (!dynamic_cast<TimeRulerLayer *>(layer)) continue;
|
Chris@211
|
2855
|
Chris@211
|
2856 layer->showLayer(pane, show);
|
Chris@211
|
2857 }
|
Chris@211
|
2858 }
|
Chris@211
|
2859 }
|
Chris@211
|
2860 }
|
Chris@211
|
2861
|
Chris@211
|
2862 void
|
Chris@45
|
2863 MainWindowBase::toggleZoomWheels()
|
Chris@45
|
2864 {
|
Chris@45
|
2865 if (m_viewManager->getZoomWheelsEnabled()) {
|
Chris@45
|
2866 m_viewManager->setZoomWheelsEnabled(false);
|
Chris@45
|
2867 } else {
|
Chris@45
|
2868 m_viewManager->setZoomWheelsEnabled(true);
|
Chris@45
|
2869 }
|
Chris@45
|
2870 }
|
Chris@45
|
2871
|
Chris@45
|
2872 void
|
Chris@45
|
2873 MainWindowBase::togglePropertyBoxes()
|
Chris@45
|
2874 {
|
Chris@45
|
2875 if (m_paneStack->getLayoutStyle() == PaneStack::NoPropertyStacks) {
|
Chris@45
|
2876 if (Preferences::getInstance()->getPropertyBoxLayout() ==
|
Chris@45
|
2877 Preferences::VerticallyStacked) {
|
Chris@45
|
2878 m_paneStack->setLayoutStyle(PaneStack::PropertyStackPerPaneLayout);
|
Chris@45
|
2879 } else {
|
Chris@45
|
2880 m_paneStack->setLayoutStyle(PaneStack::SinglePropertyStackLayout);
|
Chris@45
|
2881 }
|
Chris@45
|
2882 } else {
|
Chris@45
|
2883 m_paneStack->setLayoutStyle(PaneStack::NoPropertyStacks);
|
Chris@45
|
2884 }
|
Chris@45
|
2885 }
|
Chris@45
|
2886
|
Chris@378
|
2887 QLabel *
|
Chris@378
|
2888 MainWindowBase::getStatusLabel() const
|
Chris@378
|
2889 {
|
Chris@378
|
2890 if (!m_statusLabel) {
|
Chris@378
|
2891 m_statusLabel = new QLabel();
|
Chris@378
|
2892 statusBar()->addWidget(m_statusLabel, 1);
|
Chris@378
|
2893 }
|
Chris@379
|
2894
|
Chris@379
|
2895 QList<QFrame *> frames = statusBar()->findChildren<QFrame *>();
|
Chris@379
|
2896 foreach (QFrame *f, frames) {
|
Chris@379
|
2897 f->setFrameStyle(QFrame::NoFrame);
|
Chris@379
|
2898 }
|
Chris@379
|
2899
|
Chris@378
|
2900 return m_statusLabel;
|
Chris@378
|
2901 }
|
Chris@378
|
2902
|
Chris@45
|
2903 void
|
Chris@45
|
2904 MainWindowBase::toggleStatusBar()
|
Chris@45
|
2905 {
|
Chris@45
|
2906 QSettings settings;
|
Chris@45
|
2907 settings.beginGroup("MainWindow");
|
Chris@45
|
2908 bool sb = settings.value("showstatusbar", true).toBool();
|
Chris@45
|
2909
|
Chris@45
|
2910 if (sb) {
|
Chris@45
|
2911 statusBar()->hide();
|
Chris@45
|
2912 } else {
|
Chris@45
|
2913 statusBar()->show();
|
Chris@45
|
2914 }
|
Chris@45
|
2915
|
Chris@45
|
2916 settings.setValue("showstatusbar", !sb);
|
Chris@45
|
2917
|
Chris@45
|
2918 settings.endGroup();
|
Chris@45
|
2919 }
|
Chris@45
|
2920
|
Chris@45
|
2921 void
|
Chris@256
|
2922 MainWindowBase::toggleCentreLine()
|
Chris@256
|
2923 {
|
Chris@256
|
2924 if (m_viewManager->shouldShowCentreLine()) {
|
Chris@256
|
2925 m_viewManager->setShowCentreLine(false);
|
Chris@256
|
2926 } else {
|
Chris@256
|
2927 m_viewManager->setShowCentreLine(true);
|
Chris@256
|
2928 }
|
Chris@256
|
2929 }
|
Chris@256
|
2930
|
Chris@256
|
2931 void
|
Chris@45
|
2932 MainWindowBase::preferenceChanged(PropertyContainer::PropertyName name)
|
Chris@45
|
2933 {
|
Chris@45
|
2934 if (name == "Property Box Layout") {
|
Chris@45
|
2935 if (m_paneStack->getLayoutStyle() != PaneStack::NoPropertyStacks) {
|
Chris@45
|
2936 if (Preferences::getInstance()->getPropertyBoxLayout() ==
|
Chris@45
|
2937 Preferences::VerticallyStacked) {
|
Chris@45
|
2938 m_paneStack->setLayoutStyle(PaneStack::PropertyStackPerPaneLayout);
|
Chris@45
|
2939 } else {
|
Chris@45
|
2940 m_paneStack->setLayoutStyle(PaneStack::SinglePropertyStackLayout);
|
Chris@45
|
2941 }
|
Chris@45
|
2942 }
|
Chris@45
|
2943 } else if (name == "Background Mode" && m_viewManager) {
|
Chris@45
|
2944 Preferences::BackgroundMode mode =
|
Chris@45
|
2945 Preferences::getInstance()->getBackgroundMode();
|
Chris@45
|
2946 if (mode == Preferences::BackgroundFromTheme) {
|
Chris@45
|
2947 m_viewManager->setGlobalDarkBackground(m_initialDarkBackground);
|
Chris@45
|
2948 } else if (mode == Preferences::DarkBackground) {
|
Chris@45
|
2949 m_viewManager->setGlobalDarkBackground(true);
|
Chris@45
|
2950 } else {
|
Chris@45
|
2951 m_viewManager->setGlobalDarkBackground(false);
|
Chris@45
|
2952 }
|
Chris@45
|
2953 }
|
Chris@45
|
2954 }
|
Chris@45
|
2955
|
Chris@45
|
2956 void
|
Chris@45
|
2957 MainWindowBase::play()
|
Chris@45
|
2958 {
|
Chris@516
|
2959 if ((m_recordTarget && m_recordTarget->isRecording()) ||
|
Chris@516
|
2960 (m_playSource && m_playSource->isPlaying())) {
|
Chris@45
|
2961 stop();
|
Chris@479
|
2962 QAction *action = qobject_cast<QAction *>(sender());
|
Chris@479
|
2963 if (action) action->setChecked(false);
|
Chris@45
|
2964 } else {
|
Chris@487
|
2965 if (m_audioIO) m_audioIO->resume();
|
Chris@509
|
2966 else if (m_playTarget) m_playTarget->resume();
|
Chris@45
|
2967 playbackFrameChanged(m_viewManager->getPlaybackFrame());
|
Chris@45
|
2968 m_playSource->play(m_viewManager->getPlaybackFrame());
|
Chris@45
|
2969 }
|
Chris@45
|
2970 }
|
Chris@45
|
2971
|
Chris@45
|
2972 void
|
Chris@477
|
2973 MainWindowBase::record()
|
Chris@477
|
2974 {
|
Chris@586
|
2975 QAction *action = qobject_cast<QAction *>(sender());
|
Chris@586
|
2976
|
Chris@478
|
2977 if (!(m_soundOptions & WithAudioInput)) {
|
Chris@586
|
2978 if (action) action->setChecked(false);
|
Chris@478
|
2979 return;
|
Chris@478
|
2980 }
|
Chris@478
|
2981
|
Chris@477
|
2982 if (!m_recordTarget) {
|
Chris@586
|
2983 if (action) action->setChecked(false);
|
Chris@477
|
2984 return;
|
Chris@477
|
2985 }
|
Chris@477
|
2986
|
Chris@478
|
2987 if (!m_audioIO) {
|
Chris@570
|
2988 cerr << "MainWindowBase::record: about to create audio IO" << endl;
|
Chris@478
|
2989 createAudioIO();
|
Chris@478
|
2990 }
|
Chris@492
|
2991
|
Chris@492
|
2992 if (!m_audioIO) {
|
Chris@586
|
2993 if (!m_playTarget) {
|
Chris@586
|
2994 // Don't need to report this, createAudioIO should have
|
Chris@586
|
2995 if (action) action->setChecked(false);
|
Chris@586
|
2996 return;
|
Chris@586
|
2997 } else {
|
Chris@586
|
2998 // Need to report this: if the play target exists instead
|
Chris@586
|
2999 // of the audio IO, then that means we failed to open a
|
Chris@586
|
3000 // capture device. The record control should be disabled
|
Chris@586
|
3001 // in that situation, so if it happens here, that must
|
Chris@586
|
3002 // mean this is the first time we ever tried to open the
|
Chris@586
|
3003 // audio device, hence the need to report the problem here
|
Chris@586
|
3004 QMessageBox::critical
|
Chris@586
|
3005 (this, tr("No record device available"),
|
Chris@586
|
3006 tr("<b>No record device available</b><p>Failed to find or open an audio device for recording. Only playback will be available.</p>"));
|
Chris@586
|
3007 if (action) action->setChecked(false);
|
Chris@586
|
3008 updateMenuStates();
|
Chris@586
|
3009 return;
|
Chris@586
|
3010 }
|
Chris@492
|
3011 }
|
Chris@478
|
3012
|
Chris@477
|
3013 if (m_recordTarget->isRecording()) {
|
Chris@492
|
3014 stop();
|
Chris@477
|
3015 return;
|
Chris@477
|
3016 }
|
Chris@490
|
3017
|
Chris@483
|
3018 if (m_audioRecordMode == RecordReplaceSession) {
|
Chris@490
|
3019 if (!checkSaveModified()) {
|
Chris@490
|
3020 if (action) action->setChecked(false);
|
Chris@490
|
3021 return;
|
Chris@490
|
3022 }
|
Chris@483
|
3023 }
|
Chris@487
|
3024
|
Chris@557
|
3025 if (m_viewManager) m_viewManager->setGlobalCentreFrame(0);
|
Chris@557
|
3026
|
Chris@586
|
3027 SVDEBUG << "MainWindowBase::record: about to resume" << endl;
|
Chris@492
|
3028 m_audioIO->resume();
|
Chris@509
|
3029
|
Chris@477
|
3030 WritableWaveFileModel *model = m_recordTarget->startRecording();
|
Chris@477
|
3031 if (!model) {
|
Chris@586
|
3032 SVCERR << "ERROR: MainWindowBase::record: Recording failed" << endl;
|
Chris@586
|
3033 QMessageBox::critical
|
Chris@586
|
3034 (this, tr("Recording failed"),
|
Chris@586
|
3035 tr("<b>Recording failed</b><p>Failed to switch to record mode (some internal problem?)</p>"));
|
Chris@490
|
3036 if (action) action->setChecked(false);
|
Chris@477
|
3037 return;
|
Chris@477
|
3038 }
|
Chris@477
|
3039
|
Chris@477
|
3040 if (!model->isOK()) {
|
Chris@477
|
3041 m_recordTarget->stopRecording();
|
Chris@492
|
3042 m_audioIO->suspend();
|
Chris@586
|
3043 if (action) action->setChecked(false);
|
Chris@477
|
3044 delete model;
|
Chris@477
|
3045 return;
|
Chris@477
|
3046 }
|
Chris@487
|
3047
|
Chris@478
|
3048 PlayParameterRepository::getInstance()->addPlayable(model);
|
Chris@483
|
3049
|
Chris@483
|
3050 if (m_audioRecordMode == RecordReplaceSession || !getMainModel()) {
|
Chris@478
|
3051
|
Chris@479
|
3052 //!!! duplication with openAudio here
|
Chris@479
|
3053
|
Chris@479
|
3054 QString templateName = getDefaultSessionTemplate();
|
Chris@479
|
3055 bool loadedTemplate = false;
|
Chris@479
|
3056
|
Chris@479
|
3057 if (templateName != "") {
|
Chris@479
|
3058 FileOpenStatus tplStatus = openSessionTemplate(templateName);
|
Chris@479
|
3059 if (tplStatus == FileOpenCancelled) {
|
Chris@490
|
3060 m_recordTarget->stopRecording();
|
Chris@492
|
3061 m_audioIO->suspend();
|
Chris@490
|
3062 PlayParameterRepository::getInstance()->removePlayable(model);
|
Chris@479
|
3063 return;
|
Chris@479
|
3064 }
|
Chris@479
|
3065 if (tplStatus != FileOpenFailed) {
|
Chris@479
|
3066 loadedTemplate = true;
|
Chris@479
|
3067 }
|
Chris@479
|
3068 }
|
Chris@479
|
3069
|
Chris@479
|
3070 if (!loadedTemplate) {
|
Chris@479
|
3071 closeSession();
|
Chris@479
|
3072 createDocument();
|
Chris@479
|
3073 }
|
Chris@479
|
3074
|
Chris@479
|
3075 Model *prevMain = getMainModel();
|
Chris@479
|
3076 if (prevMain) {
|
Chris@479
|
3077 m_playSource->removeModel(prevMain);
|
Chris@479
|
3078 PlayParameterRepository::getInstance()->removePlayable(prevMain);
|
Chris@479
|
3079 }
|
Chris@479
|
3080
|
Chris@478
|
3081 m_document->setMainModel(model);
|
Chris@478
|
3082 setupMenus();
|
Chris@577
|
3083 findTimeRulerLayer();
|
Chris@478
|
3084
|
Chris@479
|
3085 if (loadedTemplate || (m_sessionFile == "")) {
|
Chris@479
|
3086 //!!! shouldn't be dealing directly with title from here -- call a method
|
Chris@479
|
3087 setWindowTitle(tr("%1: %2")
|
Chris@479
|
3088 .arg(QApplication::applicationName())
|
Chris@479
|
3089 .arg(model->getLocation()));
|
Chris@479
|
3090 CommandHistory::getInstance()->clear();
|
Chris@479
|
3091 CommandHistory::getInstance()->documentSaved();
|
Chris@479
|
3092 m_documentModified = false;
|
Chris@479
|
3093 } else {
|
Chris@479
|
3094 setWindowTitle(tr("%1: %2 [%3]")
|
Chris@479
|
3095 .arg(QApplication::applicationName())
|
Chris@479
|
3096 .arg(QFileInfo(m_sessionFile).fileName())
|
Chris@479
|
3097 .arg(model->getLocation()));
|
Chris@479
|
3098 if (m_documentModified) {
|
Chris@479
|
3099 m_documentModified = false;
|
Chris@479
|
3100 documentModified(); // so as to restore "(modified)" window title
|
Chris@479
|
3101 }
|
Chris@479
|
3102 }
|
Chris@479
|
3103
|
Chris@478
|
3104 } else {
|
Chris@478
|
3105
|
Chris@478
|
3106 CommandHistory::getInstance()->startCompoundOperation
|
Chris@478
|
3107 (tr("Import Recorded Audio"), true);
|
Chris@478
|
3108
|
Chris@478
|
3109 m_document->addImportedModel(model);
|
Chris@478
|
3110
|
Chris@478
|
3111 AddPaneCommand *command = new AddPaneCommand(this);
|
Chris@478
|
3112 CommandHistory::getInstance()->addCommand(command);
|
Chris@478
|
3113
|
Chris@478
|
3114 Pane *pane = command->getPane();
|
Chris@478
|
3115
|
Chris@478
|
3116 if (m_timeRulerLayer) {
|
Chris@478
|
3117 m_document->addLayerToView(pane, m_timeRulerLayer);
|
Chris@478
|
3118 }
|
Chris@478
|
3119
|
Chris@478
|
3120 Layer *newLayer = m_document->createImportedLayer(model);
|
Chris@478
|
3121
|
Chris@478
|
3122 if (newLayer) {
|
Chris@478
|
3123 m_document->addLayerToView(pane, newLayer);
|
Chris@478
|
3124 }
|
Chris@478
|
3125
|
Chris@478
|
3126 CommandHistory::getInstance()->endCompoundOperation();
|
Chris@477
|
3127 }
|
Chris@479
|
3128
|
Chris@479
|
3129 updateMenuStates();
|
Chris@479
|
3130 m_recentFiles.addFile(model->getLocation());
|
Chris@479
|
3131 currentPaneChanged(m_paneStack->getCurrentPane());
|
Chris@496
|
3132
|
Chris@496
|
3133 emit audioFileLoaded();
|
Chris@477
|
3134 }
|
Chris@477
|
3135
|
Chris@477
|
3136 void
|
Chris@45
|
3137 MainWindowBase::ffwd()
|
Chris@45
|
3138 {
|
Chris@45
|
3139 if (!getMainModel()) return;
|
Chris@45
|
3140
|
Chris@435
|
3141 sv_frame_t frame = m_viewManager->getPlaybackFrame();
|
Chris@45
|
3142 ++frame;
|
Chris@45
|
3143
|
Chris@85
|
3144 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@45
|
3145 Layer *layer = getSnapLayer();
|
Chris@435
|
3146 sv_samplerate_t sr = getMainModel()->getSampleRate();
|
Chris@45
|
3147
|
Chris@45
|
3148 if (!layer) {
|
Chris@45
|
3149
|
Chris@45
|
3150 frame = RealTime::realTime2Frame
|
Chris@357
|
3151 (RealTime::frame2RealTime(frame, sr) + m_defaultFfwdRwdStep, sr);
|
Chris@435
|
3152 if (frame > getMainModel()->getEndFrame()) {
|
Chris@45
|
3153 frame = getMainModel()->getEndFrame();
|
Chris@45
|
3154 }
|
Chris@45
|
3155
|
Chris@45
|
3156 } else {
|
Chris@45
|
3157
|
Chris@366
|
3158 int resolution = 0;
|
Chris@166
|
3159 if (pane) frame = pane->alignFromReference(frame);
|
Chris@85
|
3160 if (layer->snapToFeatureFrame(m_paneStack->getCurrentPane(),
|
Chris@85
|
3161 frame, resolution, Layer::SnapRight)) {
|
Chris@85
|
3162 if (pane) frame = pane->alignToReference(frame);
|
Chris@85
|
3163 } else {
|
Chris@45
|
3164 frame = getMainModel()->getEndFrame();
|
Chris@45
|
3165 }
|
Chris@45
|
3166 }
|
Chris@45
|
3167
|
Chris@45
|
3168 if (frame < 0) frame = 0;
|
Chris@45
|
3169
|
Chris@45
|
3170 if (m_viewManager->getPlaySelectionMode()) {
|
Chris@435
|
3171 frame = m_viewManager->constrainFrameToSelection(frame);
|
Chris@45
|
3172 }
|
Chris@45
|
3173
|
Chris@45
|
3174 m_viewManager->setPlaybackFrame(frame);
|
Chris@166
|
3175
|
Chris@435
|
3176 if (frame == getMainModel()->getEndFrame() &&
|
Chris@166
|
3177 m_playSource &&
|
Chris@166
|
3178 m_playSource->isPlaying() &&
|
Chris@166
|
3179 !m_viewManager->getPlayLoopMode()) {
|
Chris@166
|
3180 stop();
|
Chris@166
|
3181 }
|
Chris@45
|
3182 }
|
Chris@45
|
3183
|
Chris@45
|
3184 void
|
Chris@45
|
3185 MainWindowBase::ffwdEnd()
|
Chris@45
|
3186 {
|
Chris@45
|
3187 if (!getMainModel()) return;
|
Chris@45
|
3188
|
Chris@139
|
3189 if (m_playSource &&
|
Chris@139
|
3190 m_playSource->isPlaying() &&
|
Chris@139
|
3191 !m_viewManager->getPlayLoopMode()) {
|
Chris@139
|
3192 stop();
|
Chris@139
|
3193 }
|
Chris@139
|
3194
|
Chris@435
|
3195 sv_frame_t frame = getMainModel()->getEndFrame();
|
Chris@45
|
3196
|
Chris@45
|
3197 if (m_viewManager->getPlaySelectionMode()) {
|
Chris@45
|
3198 frame = m_viewManager->constrainFrameToSelection(frame);
|
Chris@45
|
3199 }
|
Chris@45
|
3200
|
Chris@45
|
3201 m_viewManager->setPlaybackFrame(frame);
|
Chris@45
|
3202 }
|
Chris@45
|
3203
|
Chris@45
|
3204 void
|
Chris@166
|
3205 MainWindowBase::ffwdSimilar()
|
Chris@166
|
3206 {
|
Chris@166
|
3207 if (!getMainModel()) return;
|
Chris@166
|
3208
|
Chris@166
|
3209 Layer *layer = getSnapLayer();
|
Chris@166
|
3210 if (!layer) { ffwd(); return; }
|
Chris@166
|
3211
|
Chris@166
|
3212 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@435
|
3213 sv_frame_t frame = m_viewManager->getPlaybackFrame();
|
Chris@166
|
3214
|
Chris@366
|
3215 int resolution = 0;
|
Chris@166
|
3216 if (pane) frame = pane->alignFromReference(frame);
|
Chris@166
|
3217 if (layer->snapToSimilarFeature(m_paneStack->getCurrentPane(),
|
Chris@166
|
3218 frame, resolution, Layer::SnapRight)) {
|
Chris@166
|
3219 if (pane) frame = pane->alignToReference(frame);
|
Chris@166
|
3220 } else {
|
Chris@166
|
3221 frame = getMainModel()->getEndFrame();
|
Chris@166
|
3222 }
|
Chris@166
|
3223
|
Chris@166
|
3224 if (frame < 0) frame = 0;
|
Chris@166
|
3225
|
Chris@166
|
3226 if (m_viewManager->getPlaySelectionMode()) {
|
Chris@435
|
3227 frame = m_viewManager->constrainFrameToSelection(frame);
|
Chris@166
|
3228 }
|
Chris@166
|
3229
|
Chris@166
|
3230 m_viewManager->setPlaybackFrame(frame);
|
Chris@166
|
3231
|
Chris@435
|
3232 if (frame == getMainModel()->getEndFrame() &&
|
Chris@166
|
3233 m_playSource &&
|
Chris@166
|
3234 m_playSource->isPlaying() &&
|
Chris@166
|
3235 !m_viewManager->getPlayLoopMode()) {
|
Chris@166
|
3236 stop();
|
Chris@166
|
3237 }
|
Chris@166
|
3238 }
|
Chris@166
|
3239
|
Chris@166
|
3240 void
|
Chris@45
|
3241 MainWindowBase::rewind()
|
Chris@45
|
3242 {
|
Chris@45
|
3243 if (!getMainModel()) return;
|
Chris@45
|
3244
|
Chris@435
|
3245 sv_frame_t frame = m_viewManager->getPlaybackFrame();
|
Chris@45
|
3246 if (frame > 0) --frame;
|
Chris@45
|
3247
|
Chris@85
|
3248 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@45
|
3249 Layer *layer = getSnapLayer();
|
Chris@435
|
3250 sv_samplerate_t sr = getMainModel()->getSampleRate();
|
Chris@45
|
3251
|
Chris@45
|
3252 // when rewinding during playback, we want to allow a period
|
Chris@45
|
3253 // following a rewind target point at which the rewind will go to
|
Chris@45
|
3254 // the prior point instead of the immediately neighbouring one
|
Chris@45
|
3255 if (m_playSource && m_playSource->isPlaying()) {
|
Chris@45
|
3256 RealTime ct = RealTime::frame2RealTime(frame, sr);
|
Chris@357
|
3257 ct = ct - RealTime::fromSeconds(0.15);
|
Chris@45
|
3258 if (ct < RealTime::zeroTime) ct = RealTime::zeroTime;
|
Chris@45
|
3259 frame = RealTime::realTime2Frame(ct, sr);
|
Chris@45
|
3260 }
|
Chris@45
|
3261
|
Chris@45
|
3262 if (!layer) {
|
Chris@45
|
3263
|
Chris@45
|
3264 frame = RealTime::realTime2Frame
|
Chris@357
|
3265 (RealTime::frame2RealTime(frame, sr) - m_defaultFfwdRwdStep, sr);
|
Chris@435
|
3266 if (frame < getMainModel()->getStartFrame()) {
|
Chris@45
|
3267 frame = getMainModel()->getStartFrame();
|
Chris@45
|
3268 }
|
Chris@45
|
3269
|
Chris@45
|
3270 } else {
|
Chris@45
|
3271
|
Chris@366
|
3272 int resolution = 0;
|
Chris@166
|
3273 if (pane) frame = pane->alignFromReference(frame);
|
Chris@85
|
3274 if (layer->snapToFeatureFrame(m_paneStack->getCurrentPane(),
|
Chris@85
|
3275 frame, resolution, Layer::SnapLeft)) {
|
Chris@85
|
3276 if (pane) frame = pane->alignToReference(frame);
|
Chris@85
|
3277 } else {
|
Chris@45
|
3278 frame = getMainModel()->getStartFrame();
|
Chris@45
|
3279 }
|
Chris@45
|
3280 }
|
Chris@45
|
3281
|
Chris@45
|
3282 if (frame < 0) frame = 0;
|
Chris@45
|
3283
|
Chris@45
|
3284 if (m_viewManager->getPlaySelectionMode()) {
|
Chris@435
|
3285 frame = m_viewManager->constrainFrameToSelection(frame);
|
Chris@45
|
3286 }
|
Chris@45
|
3287
|
Chris@45
|
3288 m_viewManager->setPlaybackFrame(frame);
|
Chris@45
|
3289 }
|
Chris@45
|
3290
|
Chris@45
|
3291 void
|
Chris@45
|
3292 MainWindowBase::rewindStart()
|
Chris@45
|
3293 {
|
Chris@45
|
3294 if (!getMainModel()) return;
|
Chris@45
|
3295
|
Chris@435
|
3296 sv_frame_t frame = getMainModel()->getStartFrame();
|
Chris@45
|
3297
|
Chris@45
|
3298 if (m_viewManager->getPlaySelectionMode()) {
|
Chris@45
|
3299 frame = m_viewManager->constrainFrameToSelection(frame);
|
Chris@45
|
3300 }
|
Chris@45
|
3301
|
Chris@45
|
3302 m_viewManager->setPlaybackFrame(frame);
|
Chris@45
|
3303 }
|
Chris@45
|
3304
|
Chris@166
|
3305 void
|
Chris@166
|
3306 MainWindowBase::rewindSimilar()
|
Chris@166
|
3307 {
|
Chris@166
|
3308 if (!getMainModel()) return;
|
Chris@166
|
3309
|
Chris@166
|
3310 Layer *layer = getSnapLayer();
|
Chris@166
|
3311 if (!layer) { rewind(); return; }
|
Chris@166
|
3312
|
Chris@166
|
3313 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@435
|
3314 sv_frame_t frame = m_viewManager->getPlaybackFrame();
|
Chris@166
|
3315
|
Chris@366
|
3316 int resolution = 0;
|
Chris@166
|
3317 if (pane) frame = pane->alignFromReference(frame);
|
Chris@166
|
3318 if (layer->snapToSimilarFeature(m_paneStack->getCurrentPane(),
|
Chris@166
|
3319 frame, resolution, Layer::SnapLeft)) {
|
Chris@166
|
3320 if (pane) frame = pane->alignToReference(frame);
|
Chris@166
|
3321 } else {
|
Chris@166
|
3322 frame = getMainModel()->getStartFrame();
|
Chris@166
|
3323 }
|
Chris@166
|
3324
|
Chris@166
|
3325 if (frame < 0) frame = 0;
|
Chris@166
|
3326
|
Chris@166
|
3327 if (m_viewManager->getPlaySelectionMode()) {
|
Chris@435
|
3328 frame = m_viewManager->constrainFrameToSelection(frame);
|
Chris@166
|
3329 }
|
Chris@166
|
3330
|
Chris@166
|
3331 m_viewManager->setPlaybackFrame(frame);
|
Chris@166
|
3332 }
|
Chris@166
|
3333
|
Chris@45
|
3334 Layer *
|
Chris@45
|
3335 MainWindowBase::getSnapLayer() const
|
Chris@45
|
3336 {
|
Chris@45
|
3337 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@45
|
3338 if (!pane) return 0;
|
Chris@45
|
3339
|
Chris@45
|
3340 Layer *layer = pane->getSelectedLayer();
|
Chris@45
|
3341
|
Chris@45
|
3342 if (!dynamic_cast<TimeInstantLayer *>(layer) &&
|
Chris@45
|
3343 !dynamic_cast<TimeValueLayer *>(layer) &&
|
Chris@194
|
3344 !dynamic_cast<RegionLayer *>(layer) &&
|
Chris@45
|
3345 !dynamic_cast<TimeRulerLayer *>(layer)) {
|
Chris@45
|
3346
|
Chris@45
|
3347 layer = 0;
|
Chris@45
|
3348
|
Chris@45
|
3349 for (int i = pane->getLayerCount(); i > 0; --i) {
|
Chris@45
|
3350 Layer *l = pane->getLayer(i-1);
|
Chris@45
|
3351 if (dynamic_cast<TimeRulerLayer *>(l)) {
|
Chris@45
|
3352 layer = l;
|
Chris@45
|
3353 break;
|
Chris@45
|
3354 }
|
Chris@45
|
3355 }
|
Chris@45
|
3356 }
|
Chris@45
|
3357
|
Chris@45
|
3358 return layer;
|
Chris@45
|
3359 }
|
Chris@45
|
3360
|
Chris@45
|
3361 void
|
Chris@45
|
3362 MainWindowBase::stop()
|
Chris@45
|
3363 {
|
Chris@516
|
3364 if (m_recordTarget &&
|
Chris@516
|
3365 m_recordTarget->isRecording()) {
|
Chris@477
|
3366 m_recordTarget->stopRecording();
|
Chris@477
|
3367 }
|
Chris@516
|
3368
|
Chris@516
|
3369 if (!m_playSource) return;
|
Chris@516
|
3370
|
Chris@45
|
3371 m_playSource->stop();
|
Chris@45
|
3372
|
Chris@487
|
3373 if (m_audioIO) m_audioIO->suspend();
|
Chris@509
|
3374 else if (m_playTarget) m_playTarget->suspend();
|
Chris@487
|
3375
|
Chris@45
|
3376 if (m_paneStack && m_paneStack->getCurrentPane()) {
|
Chris@45
|
3377 updateVisibleRangeDisplay(m_paneStack->getCurrentPane());
|
Chris@45
|
3378 } else {
|
Chris@45
|
3379 m_myStatusMessage = "";
|
Chris@378
|
3380 getStatusLabel()->setText("");
|
Chris@45
|
3381 }
|
Chris@45
|
3382 }
|
Chris@45
|
3383
|
Chris@45
|
3384 MainWindowBase::AddPaneCommand::AddPaneCommand(MainWindowBase *mw) :
|
Chris@45
|
3385 m_mw(mw),
|
Chris@45
|
3386 m_pane(0),
|
Chris@45
|
3387 m_prevCurrentPane(0),
|
Chris@45
|
3388 m_added(false)
|
Chris@45
|
3389 {
|
Chris@45
|
3390 }
|
Chris@45
|
3391
|
Chris@45
|
3392 MainWindowBase::AddPaneCommand::~AddPaneCommand()
|
Chris@45
|
3393 {
|
Chris@45
|
3394 if (m_pane && !m_added) {
|
Chris@45
|
3395 m_mw->m_paneStack->deletePane(m_pane);
|
Chris@45
|
3396 }
|
Chris@45
|
3397 }
|
Chris@45
|
3398
|
Chris@45
|
3399 QString
|
Chris@45
|
3400 MainWindowBase::AddPaneCommand::getName() const
|
Chris@45
|
3401 {
|
Chris@45
|
3402 return tr("Add Pane");
|
Chris@45
|
3403 }
|
Chris@45
|
3404
|
Chris@45
|
3405 void
|
Chris@45
|
3406 MainWindowBase::AddPaneCommand::execute()
|
Chris@45
|
3407 {
|
Chris@45
|
3408 if (!m_pane) {
|
Chris@45
|
3409 m_prevCurrentPane = m_mw->m_paneStack->getCurrentPane();
|
Chris@45
|
3410 m_pane = m_mw->m_paneStack->addPane();
|
Chris@45
|
3411
|
Chris@45
|
3412 connect(m_pane, SIGNAL(contextHelpChanged(const QString &)),
|
Chris@45
|
3413 m_mw, SLOT(contextHelpChanged(const QString &)));
|
Chris@45
|
3414 } else {
|
Chris@45
|
3415 m_mw->m_paneStack->showPane(m_pane);
|
Chris@45
|
3416 }
|
Chris@45
|
3417
|
Chris@45
|
3418 m_mw->m_paneStack->setCurrentPane(m_pane);
|
Chris@45
|
3419 m_added = true;
|
Chris@45
|
3420 }
|
Chris@45
|
3421
|
Chris@45
|
3422 void
|
Chris@45
|
3423 MainWindowBase::AddPaneCommand::unexecute()
|
Chris@45
|
3424 {
|
Chris@45
|
3425 m_mw->m_paneStack->hidePane(m_pane);
|
Chris@45
|
3426 m_mw->m_paneStack->setCurrentPane(m_prevCurrentPane);
|
Chris@45
|
3427 m_added = false;
|
Chris@45
|
3428 }
|
Chris@45
|
3429
|
Chris@45
|
3430 MainWindowBase::RemovePaneCommand::RemovePaneCommand(MainWindowBase *mw, Pane *pane) :
|
Chris@45
|
3431 m_mw(mw),
|
Chris@45
|
3432 m_pane(pane),
|
Chris@409
|
3433 m_prevCurrentPane(0),
|
Chris@45
|
3434 m_added(true)
|
Chris@45
|
3435 {
|
Chris@45
|
3436 }
|
Chris@45
|
3437
|
Chris@45
|
3438 MainWindowBase::RemovePaneCommand::~RemovePaneCommand()
|
Chris@45
|
3439 {
|
Chris@45
|
3440 if (m_pane && !m_added) {
|
Chris@45
|
3441 m_mw->m_paneStack->deletePane(m_pane);
|
Chris@45
|
3442 }
|
Chris@45
|
3443 }
|
Chris@45
|
3444
|
Chris@45
|
3445 QString
|
Chris@45
|
3446 MainWindowBase::RemovePaneCommand::getName() const
|
Chris@45
|
3447 {
|
Chris@45
|
3448 return tr("Remove Pane");
|
Chris@45
|
3449 }
|
Chris@45
|
3450
|
Chris@45
|
3451 void
|
Chris@45
|
3452 MainWindowBase::RemovePaneCommand::execute()
|
Chris@45
|
3453 {
|
Chris@45
|
3454 m_prevCurrentPane = m_mw->m_paneStack->getCurrentPane();
|
Chris@45
|
3455 m_mw->m_paneStack->hidePane(m_pane);
|
Chris@45
|
3456 m_added = false;
|
Chris@45
|
3457 }
|
Chris@45
|
3458
|
Chris@45
|
3459 void
|
Chris@45
|
3460 MainWindowBase::RemovePaneCommand::unexecute()
|
Chris@45
|
3461 {
|
Chris@45
|
3462 m_mw->m_paneStack->showPane(m_pane);
|
Chris@45
|
3463 m_mw->m_paneStack->setCurrentPane(m_prevCurrentPane);
|
Chris@45
|
3464 m_added = true;
|
Chris@45
|
3465 }
|
Chris@45
|
3466
|
Chris@45
|
3467 void
|
Chris@45
|
3468 MainWindowBase::deleteCurrentPane()
|
Chris@45
|
3469 {
|
Chris@45
|
3470 CommandHistory::getInstance()->startCompoundOperation
|
Chris@45
|
3471 (tr("Delete Pane"), true);
|
Chris@45
|
3472
|
Chris@45
|
3473 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@45
|
3474 if (pane) {
|
Chris@45
|
3475 while (pane->getLayerCount() > 0) {
|
Chris@45
|
3476 Layer *layer = pane->getLayer(0);
|
Chris@45
|
3477 if (layer) {
|
Chris@45
|
3478 m_document->removeLayerFromView(pane, layer);
|
Chris@45
|
3479 } else {
|
Chris@45
|
3480 break;
|
Chris@45
|
3481 }
|
Chris@45
|
3482 }
|
Chris@45
|
3483
|
Chris@45
|
3484 RemovePaneCommand *command = new RemovePaneCommand(this, pane);
|
Chris@45
|
3485 CommandHistory::getInstance()->addCommand(command);
|
Chris@45
|
3486 }
|
Chris@45
|
3487
|
Chris@45
|
3488 CommandHistory::getInstance()->endCompoundOperation();
|
Chris@45
|
3489
|
Chris@45
|
3490 updateMenuStates();
|
Chris@45
|
3491 }
|
Chris@45
|
3492
|
Chris@45
|
3493 void
|
Chris@45
|
3494 MainWindowBase::deleteCurrentLayer()
|
Chris@45
|
3495 {
|
Chris@45
|
3496 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@45
|
3497 if (pane) {
|
Chris@45
|
3498 Layer *layer = pane->getSelectedLayer();
|
Chris@45
|
3499 if (layer) {
|
Chris@45
|
3500 m_document->removeLayerFromView(pane, layer);
|
Chris@45
|
3501 }
|
Chris@45
|
3502 }
|
Chris@45
|
3503 updateMenuStates();
|
Chris@45
|
3504 }
|
Chris@45
|
3505
|
Chris@45
|
3506 void
|
Chris@123
|
3507 MainWindowBase::editCurrentLayer()
|
Chris@123
|
3508 {
|
Chris@123
|
3509 Layer *layer = 0;
|
Chris@123
|
3510 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@123
|
3511 if (pane) layer = pane->getSelectedLayer();
|
Chris@123
|
3512 if (!layer) return;
|
Chris@123
|
3513
|
Chris@123
|
3514 Model *model = layer->getModel();
|
Chris@123
|
3515 if (!model) return;
|
Chris@123
|
3516
|
Chris@124
|
3517 TabularModel *tabular = dynamic_cast<TabularModel *>(model);
|
Chris@124
|
3518 if (!tabular) {
|
Chris@124
|
3519 //!!! how to prevent this function from being active if not
|
Chris@124
|
3520 //appropriate model type? or will we ultimately support
|
Chris@124
|
3521 //tabular display for all editable models?
|
Chris@233
|
3522 SVDEBUG << "NOTE: Not a tabular model" << endl;
|
Chris@124
|
3523 return;
|
Chris@124
|
3524 }
|
Chris@124
|
3525
|
Chris@123
|
3526 if (m_layerDataDialogMap.find(layer) != m_layerDataDialogMap.end()) {
|
Chris@126
|
3527 if (!m_layerDataDialogMap[layer].isNull()) {
|
Chris@126
|
3528 m_layerDataDialogMap[layer]->show();
|
Chris@126
|
3529 m_layerDataDialogMap[layer]->raise();
|
Chris@126
|
3530 return;
|
Chris@126
|
3531 }
|
Chris@123
|
3532 }
|
Chris@123
|
3533
|
Chris@125
|
3534 QString title = layer->getLayerPresentationName();
|
Chris@125
|
3535
|
Chris@125
|
3536 ModelDataTableDialog *dialog = new ModelDataTableDialog(tabular, title, this);
|
Chris@128
|
3537 dialog->setAttribute(Qt::WA_DeleteOnClose);
|
Chris@128
|
3538
|
Chris@128
|
3539 connectLayerEditDialog(dialog);
|
Chris@123
|
3540
|
Chris@128
|
3541 m_layerDataDialogMap[layer] = dialog;
|
Chris@128
|
3542 m_viewDataDialogMap[pane].insert(dialog);
|
Chris@128
|
3543
|
Chris@128
|
3544 dialog->show();
|
Chris@128
|
3545 }
|
Chris@128
|
3546
|
Chris@128
|
3547 void
|
Chris@128
|
3548 MainWindowBase::connectLayerEditDialog(ModelDataTableDialog *dialog)
|
Chris@128
|
3549 {
|
Chris@123
|
3550 connect(m_viewManager,
|
Chris@435
|
3551 SIGNAL(globalCentreFrameChanged(sv_frame_t)),
|
Chris@123
|
3552 dialog,
|
Chris@435
|
3553 SLOT(userScrolledToFrame(sv_frame_t)));
|
Chris@127
|
3554
|
Chris@127
|
3555 connect(m_viewManager,
|
Chris@435
|
3556 SIGNAL(playbackFrameChanged(sv_frame_t)),
|
Chris@127
|
3557 dialog,
|
Chris@435
|
3558 SLOT(playbackScrolledToFrame(sv_frame_t)));
|
Chris@127
|
3559
|
Chris@123
|
3560 connect(dialog,
|
Chris@435
|
3561 SIGNAL(scrollToFrame(sv_frame_t)),
|
Chris@123
|
3562 m_viewManager,
|
Chris@435
|
3563 SLOT(setGlobalCentreFrame(sv_frame_t)));
|
Chris@129
|
3564
|
Chris@129
|
3565 connect(dialog,
|
Chris@435
|
3566 SIGNAL(scrollToFrame(sv_frame_t)),
|
Chris@129
|
3567 m_viewManager,
|
Chris@435
|
3568 SLOT(setPlaybackFrame(sv_frame_t)));
|
Chris@128
|
3569 }
|
Chris@123
|
3570
|
Chris@123
|
3571 void
|
Chris@73
|
3572 MainWindowBase::previousPane()
|
Chris@73
|
3573 {
|
Chris@73
|
3574 if (!m_paneStack) return;
|
Chris@73
|
3575
|
Chris@73
|
3576 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@73
|
3577 if (!currentPane) return;
|
Chris@73
|
3578
|
Chris@73
|
3579 for (int i = 0; i < m_paneStack->getPaneCount(); ++i) {
|
Chris@73
|
3580 if (m_paneStack->getPane(i) == currentPane) {
|
Chris@73
|
3581 if (i == 0) return;
|
Chris@73
|
3582 m_paneStack->setCurrentPane(m_paneStack->getPane(i-1));
|
Chris@73
|
3583 updateMenuStates();
|
Chris@73
|
3584 return;
|
Chris@73
|
3585 }
|
Chris@73
|
3586 }
|
Chris@73
|
3587 }
|
Chris@73
|
3588
|
Chris@73
|
3589 void
|
Chris@73
|
3590 MainWindowBase::nextPane()
|
Chris@73
|
3591 {
|
Chris@73
|
3592 if (!m_paneStack) return;
|
Chris@73
|
3593
|
Chris@73
|
3594 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@73
|
3595 if (!currentPane) return;
|
Chris@73
|
3596
|
Chris@73
|
3597 for (int i = 0; i < m_paneStack->getPaneCount(); ++i) {
|
Chris@73
|
3598 if (m_paneStack->getPane(i) == currentPane) {
|
Chris@73
|
3599 if (i == m_paneStack->getPaneCount()-1) return;
|
Chris@73
|
3600 m_paneStack->setCurrentPane(m_paneStack->getPane(i+1));
|
Chris@73
|
3601 updateMenuStates();
|
Chris@73
|
3602 return;
|
Chris@73
|
3603 }
|
Chris@73
|
3604 }
|
Chris@73
|
3605 }
|
Chris@73
|
3606
|
Chris@73
|
3607 void
|
Chris@73
|
3608 MainWindowBase::previousLayer()
|
Chris@73
|
3609 {
|
Chris@73
|
3610 if (!m_paneStack) return;
|
Chris@73
|
3611
|
Chris@73
|
3612 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@73
|
3613 if (!currentPane) return;
|
Chris@73
|
3614
|
Chris@403
|
3615 int count = currentPane->getLayerCount();
|
Chris@403
|
3616 if (count == 0) return;
|
Chris@403
|
3617
|
Chris@73
|
3618 Layer *currentLayer = currentPane->getSelectedLayer();
|
Chris@403
|
3619
|
Chris@403
|
3620 if (!currentLayer) {
|
Chris@403
|
3621 // The pane itself is current
|
Chris@403
|
3622 m_paneStack->setCurrentLayer
|
Chris@403
|
3623 (currentPane, currentPane->getFixedOrderLayer(count-1));
|
Chris@403
|
3624 } else {
|
Chris@403
|
3625 for (int i = 0; i < count; ++i) {
|
Chris@403
|
3626 if (currentPane->getFixedOrderLayer(i) == currentLayer) {
|
Chris@403
|
3627 if (i == 0) {
|
Chris@403
|
3628 m_paneStack->setCurrentLayer
|
Chris@403
|
3629 (currentPane, 0); // pane
|
Chris@403
|
3630 } else {
|
Chris@403
|
3631 m_paneStack->setCurrentLayer
|
Chris@403
|
3632 (currentPane, currentPane->getFixedOrderLayer(i-1));
|
Chris@403
|
3633 }
|
Chris@403
|
3634 break;
|
Chris@403
|
3635 }
|
Chris@73
|
3636 }
|
Chris@73
|
3637 }
|
Chris@403
|
3638
|
Chris@403
|
3639 updateMenuStates();
|
Chris@73
|
3640 }
|
Chris@73
|
3641
|
Chris@73
|
3642 void
|
Chris@73
|
3643 MainWindowBase::nextLayer()
|
Chris@73
|
3644 {
|
Chris@73
|
3645 if (!m_paneStack) return;
|
Chris@73
|
3646
|
Chris@73
|
3647 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@73
|
3648 if (!currentPane) return;
|
Chris@73
|
3649
|
Chris@403
|
3650 int count = currentPane->getLayerCount();
|
Chris@403
|
3651 if (count == 0) return;
|
Chris@403
|
3652
|
Chris@73
|
3653 Layer *currentLayer = currentPane->getSelectedLayer();
|
Chris@403
|
3654
|
Chris@403
|
3655 if (!currentLayer) {
|
Chris@403
|
3656 // The pane itself is current
|
Chris@403
|
3657 m_paneStack->setCurrentLayer
|
Chris@403
|
3658 (currentPane, currentPane->getFixedOrderLayer(0));
|
Chris@403
|
3659 } else {
|
Chris@403
|
3660 for (int i = 0; i < count; ++i) {
|
Chris@403
|
3661 if (currentPane->getFixedOrderLayer(i) == currentLayer) {
|
Chris@403
|
3662 if (i == currentPane->getLayerCount()-1) {
|
Chris@403
|
3663 m_paneStack->setCurrentLayer
|
Chris@403
|
3664 (currentPane, 0); // pane
|
Chris@403
|
3665 } else {
|
Chris@403
|
3666 m_paneStack->setCurrentLayer
|
Chris@403
|
3667 (currentPane, currentPane->getFixedOrderLayer(i+1));
|
Chris@403
|
3668 }
|
Chris@403
|
3669 break;
|
Chris@403
|
3670 }
|
Chris@73
|
3671 }
|
Chris@73
|
3672 }
|
Chris@403
|
3673
|
Chris@403
|
3674 updateMenuStates();
|
Chris@73
|
3675 }
|
Chris@73
|
3676
|
Chris@73
|
3677 void
|
Chris@435
|
3678 MainWindowBase::playbackFrameChanged(sv_frame_t frame)
|
Chris@45
|
3679 {
|
Chris@45
|
3680 if (!(m_playSource && m_playSource->isPlaying()) || !getMainModel()) return;
|
Chris@45
|
3681
|
Chris@187
|
3682 updatePositionStatusDisplays();
|
Chris@187
|
3683
|
Chris@45
|
3684 RealTime now = RealTime::frame2RealTime
|
Chris@45
|
3685 (frame, getMainModel()->getSampleRate());
|
Chris@45
|
3686
|
Chris@45
|
3687 if (now.sec == m_lastPlayStatusSec) return;
|
Chris@45
|
3688
|
Chris@45
|
3689 RealTime then = RealTime::frame2RealTime
|
Chris@45
|
3690 (m_playSource->getPlayEndFrame(), getMainModel()->getSampleRate());
|
Chris@45
|
3691
|
Chris@45
|
3692 QString nowStr;
|
Chris@45
|
3693 QString thenStr;
|
Chris@45
|
3694 QString remainingStr;
|
Chris@45
|
3695
|
Chris@45
|
3696 if (then.sec > 10) {
|
Chris@45
|
3697 nowStr = now.toSecText().c_str();
|
Chris@45
|
3698 thenStr = then.toSecText().c_str();
|
Chris@45
|
3699 remainingStr = (then - now).toSecText().c_str();
|
Chris@45
|
3700 m_lastPlayStatusSec = now.sec;
|
Chris@45
|
3701 } else {
|
Chris@45
|
3702 nowStr = now.toText(true).c_str();
|
Chris@45
|
3703 thenStr = then.toText(true).c_str();
|
Chris@45
|
3704 remainingStr = (then - now).toText(true).c_str();
|
Chris@45
|
3705 }
|
Chris@45
|
3706
|
Chris@45
|
3707 m_myStatusMessage = tr("Playing: %1 of %2 (%3 remaining)")
|
Chris@45
|
3708 .arg(nowStr).arg(thenStr).arg(remainingStr);
|
Chris@45
|
3709
|
Chris@378
|
3710 getStatusLabel()->setText(m_myStatusMessage);
|
Chris@45
|
3711 }
|
Chris@45
|
3712
|
Chris@45
|
3713 void
|
Chris@486
|
3714 MainWindowBase::recordDurationChanged(sv_frame_t frame, sv_samplerate_t rate)
|
Chris@486
|
3715 {
|
Chris@486
|
3716 RealTime duration = RealTime::frame2RealTime(frame, rate);
|
Chris@486
|
3717 QString durStr = duration.toSecText().c_str();
|
Chris@486
|
3718
|
Chris@486
|
3719 m_myStatusMessage = tr("Recording: %1").arg(durStr);
|
Chris@486
|
3720
|
Chris@486
|
3721 getStatusLabel()->setText(m_myStatusMessage);
|
Chris@486
|
3722 }
|
Chris@486
|
3723
|
Chris@486
|
3724 void
|
Chris@435
|
3725 MainWindowBase::globalCentreFrameChanged(sv_frame_t )
|
Chris@45
|
3726 {
|
Chris@45
|
3727 if ((m_playSource && m_playSource->isPlaying()) || !getMainModel()) return;
|
Chris@45
|
3728 Pane *p = 0;
|
Chris@45
|
3729 if (!m_paneStack || !(p = m_paneStack->getCurrentPane())) return;
|
Chris@45
|
3730 if (!p->getFollowGlobalPan()) return;
|
Chris@45
|
3731 updateVisibleRangeDisplay(p);
|
Chris@45
|
3732 }
|
Chris@45
|
3733
|
Chris@45
|
3734 void
|
Chris@435
|
3735 MainWindowBase::viewCentreFrameChanged(View *v, sv_frame_t frame)
|
Chris@45
|
3736 {
|
Chris@233
|
3737 // SVDEBUG << "MainWindowBase::viewCentreFrameChanged(" << v << "," << frame << ")" << endl;
|
Chris@123
|
3738
|
Chris@123
|
3739 if (m_viewDataDialogMap.find(v) != m_viewDataDialogMap.end()) {
|
Chris@123
|
3740 for (DataDialogSet::iterator i = m_viewDataDialogMap[v].begin();
|
Chris@123
|
3741 i != m_viewDataDialogMap[v].end(); ++i) {
|
Chris@127
|
3742 (*i)->userScrolledToFrame(frame);
|
Chris@123
|
3743 }
|
Chris@123
|
3744 }
|
Chris@45
|
3745 if ((m_playSource && m_playSource->isPlaying()) || !getMainModel()) return;
|
Chris@45
|
3746 Pane *p = 0;
|
Chris@45
|
3747 if (!m_paneStack || !(p = m_paneStack->getCurrentPane())) return;
|
Chris@45
|
3748 if (v == p) updateVisibleRangeDisplay(p);
|
Chris@45
|
3749 }
|
Chris@45
|
3750
|
Chris@45
|
3751 void
|
Chris@366
|
3752 MainWindowBase::viewZoomLevelChanged(View *v, int , bool )
|
Chris@45
|
3753 {
|
Chris@45
|
3754 if ((m_playSource && m_playSource->isPlaying()) || !getMainModel()) return;
|
Chris@45
|
3755 Pane *p = 0;
|
Chris@45
|
3756 if (!m_paneStack || !(p = m_paneStack->getCurrentPane())) return;
|
Chris@45
|
3757 if (v == p) updateVisibleRangeDisplay(p);
|
Chris@45
|
3758 }
|
Chris@45
|
3759
|
Chris@45
|
3760 void
|
Chris@45
|
3761 MainWindowBase::layerAdded(Layer *)
|
Chris@45
|
3762 {
|
Chris@233
|
3763 // SVDEBUG << "MainWindowBase::layerAdded(" << layer << ")" << endl;
|
Chris@45
|
3764 updateMenuStates();
|
Chris@45
|
3765 }
|
Chris@45
|
3766
|
Chris@45
|
3767 void
|
Chris@45
|
3768 MainWindowBase::layerRemoved(Layer *)
|
Chris@45
|
3769 {
|
Chris@233
|
3770 // SVDEBUG << "MainWindowBase::layerRemoved(" << layer << ")" << endl;
|
Chris@45
|
3771 updateMenuStates();
|
Chris@45
|
3772 }
|
Chris@45
|
3773
|
Chris@45
|
3774 void
|
Chris@45
|
3775 MainWindowBase::layerAboutToBeDeleted(Layer *layer)
|
Chris@45
|
3776 {
|
Chris@233
|
3777 // SVDEBUG << "MainWindowBase::layerAboutToBeDeleted(" << layer << ")" << endl;
|
Chris@123
|
3778
|
Chris@128
|
3779 removeLayerEditDialog(layer);
|
Chris@123
|
3780
|
Chris@47
|
3781 if (m_timeRulerLayer && (layer == m_timeRulerLayer)) {
|
Chris@293
|
3782 // cerr << "(this is the time ruler layer)" << endl;
|
Chris@45
|
3783 m_timeRulerLayer = 0;
|
Chris@45
|
3784 }
|
Chris@45
|
3785 }
|
Chris@45
|
3786
|
Chris@45
|
3787 void
|
Chris@45
|
3788 MainWindowBase::layerInAView(Layer *layer, bool inAView)
|
Chris@45
|
3789 {
|
Chris@233
|
3790 // SVDEBUG << "MainWindowBase::layerInAView(" << layer << "," << inAView << ")" << endl;
|
Chris@128
|
3791
|
Chris@128
|
3792 if (!inAView) removeLayerEditDialog(layer);
|
Chris@45
|
3793
|
Chris@45
|
3794 // Check whether we need to add or remove model from play source
|
Chris@45
|
3795 Model *model = layer->getModel();
|
Chris@45
|
3796 if (model) {
|
Chris@45
|
3797 if (inAView) {
|
Chris@45
|
3798 m_playSource->addModel(model);
|
Chris@45
|
3799 } else {
|
Chris@45
|
3800 bool found = false;
|
Chris@45
|
3801 for (int i = 0; i < m_paneStack->getPaneCount(); ++i) {
|
Chris@45
|
3802 Pane *pane = m_paneStack->getPane(i);
|
Chris@45
|
3803 if (!pane) continue;
|
Chris@45
|
3804 for (int j = 0; j < pane->getLayerCount(); ++j) {
|
Chris@45
|
3805 Layer *pl = pane->getLayer(j);
|
Chris@183
|
3806 if (pl &&
|
Chris@183
|
3807 !dynamic_cast<TimeRulerLayer *>(pl) &&
|
Chris@183
|
3808 (pl->getModel() == model)) {
|
Chris@45
|
3809 found = true;
|
Chris@45
|
3810 break;
|
Chris@45
|
3811 }
|
Chris@45
|
3812 }
|
Chris@45
|
3813 if (found) break;
|
Chris@45
|
3814 }
|
Chris@173
|
3815 if (!found) {
|
Chris@173
|
3816 m_playSource->removeModel(model);
|
Chris@173
|
3817 }
|
Chris@45
|
3818 }
|
Chris@45
|
3819 }
|
Chris@45
|
3820
|
Chris@45
|
3821 updateMenuStates();
|
Chris@45
|
3822 }
|
Chris@45
|
3823
|
Chris@45
|
3824 void
|
Chris@128
|
3825 MainWindowBase::removeLayerEditDialog(Layer *layer)
|
Chris@128
|
3826 {
|
Chris@128
|
3827 if (m_layerDataDialogMap.find(layer) != m_layerDataDialogMap.end()) {
|
Chris@128
|
3828
|
Chris@128
|
3829 ModelDataTableDialog *dialog = m_layerDataDialogMap[layer];
|
Chris@128
|
3830
|
Chris@128
|
3831 for (ViewDataDialogMap::iterator vi = m_viewDataDialogMap.begin();
|
Chris@128
|
3832 vi != m_viewDataDialogMap.end(); ++vi) {
|
Chris@128
|
3833 vi->second.erase(dialog);
|
Chris@128
|
3834 }
|
Chris@128
|
3835
|
Chris@128
|
3836 m_layerDataDialogMap.erase(layer);
|
Chris@128
|
3837 delete dialog;
|
Chris@128
|
3838 }
|
Chris@128
|
3839 }
|
Chris@128
|
3840
|
Chris@128
|
3841 void
|
Chris@45
|
3842 MainWindowBase::modelAdded(Model *model)
|
Chris@45
|
3843 {
|
Chris@233
|
3844 // SVDEBUG << "MainWindowBase::modelAdded(" << model << ")" << endl;
|
gyorgyf@273
|
3845 std::cerr << "\nAdding model " << model->getTypeName() << " to playsource " << std::endl;
|
Chris@45
|
3846 m_playSource->addModel(model);
|
Chris@45
|
3847 }
|
Chris@45
|
3848
|
Chris@45
|
3849 void
|
Chris@45
|
3850 MainWindowBase::mainModelChanged(WaveFileModel *model)
|
Chris@45
|
3851 {
|
Chris@233
|
3852 // SVDEBUG << "MainWindowBase::mainModelChanged(" << model << ")" << endl;
|
Chris@45
|
3853 updateDescriptionLabel();
|
Chris@45
|
3854 if (model) m_viewManager->setMainModelSampleRate(model->getSampleRate());
|
Chris@475
|
3855 if (model && !(m_playTarget || m_audioIO) &&
|
Chris@475
|
3856 (m_soundOptions & WithAudioOutput)) {
|
Chris@475
|
3857 createAudioIO();
|
Chris@360
|
3858 }
|
Chris@45
|
3859 }
|
Chris@45
|
3860
|
Chris@45
|
3861 void
|
Chris@45
|
3862 MainWindowBase::modelAboutToBeDeleted(Model *model)
|
Chris@45
|
3863 {
|
Chris@233
|
3864 // SVDEBUG << "MainWindowBase::modelAboutToBeDeleted(" << model << ")" << endl;
|
Chris@45
|
3865 if (model == m_viewManager->getPlaybackModel()) {
|
Chris@45
|
3866 m_viewManager->setPlaybackModel(0);
|
Chris@45
|
3867 }
|
Chris@45
|
3868 m_playSource->removeModel(model);
|
Chris@45
|
3869 }
|
Chris@45
|
3870
|
Chris@45
|
3871 void
|
Chris@55
|
3872 MainWindowBase::paneDeleteButtonClicked(Pane *pane)
|
Chris@55
|
3873 {
|
Chris@55
|
3874 bool found = false;
|
Chris@55
|
3875 for (int i = 0; i < m_paneStack->getPaneCount(); ++i) {
|
Chris@55
|
3876 if (m_paneStack->getPane(i) == pane) {
|
Chris@55
|
3877 found = true;
|
Chris@55
|
3878 break;
|
Chris@55
|
3879 }
|
Chris@55
|
3880 }
|
Chris@55
|
3881 if (!found) {
|
Chris@233
|
3882 SVDEBUG << "MainWindowBase::paneDeleteButtonClicked: Unknown pane "
|
Chris@229
|
3883 << pane << endl;
|
Chris@55
|
3884 return;
|
Chris@55
|
3885 }
|
Chris@55
|
3886
|
Chris@55
|
3887 CommandHistory::getInstance()->startCompoundOperation
|
Chris@55
|
3888 (tr("Delete Pane"), true);
|
Chris@55
|
3889
|
Chris@55
|
3890 while (pane->getLayerCount() > 0) {
|
Chris@55
|
3891 Layer *layer = pane->getLayer(0);
|
Chris@55
|
3892 if (layer) {
|
Chris@55
|
3893 m_document->removeLayerFromView(pane, layer);
|
Chris@55
|
3894 } else {
|
Chris@55
|
3895 break;
|
Chris@55
|
3896 }
|
Chris@55
|
3897 }
|
Chris@55
|
3898
|
Chris@55
|
3899 RemovePaneCommand *command = new RemovePaneCommand(this, pane);
|
Chris@55
|
3900 CommandHistory::getInstance()->addCommand(command);
|
Chris@55
|
3901
|
Chris@55
|
3902 CommandHistory::getInstance()->endCompoundOperation();
|
Chris@55
|
3903
|
Chris@55
|
3904 updateMenuStates();
|
Chris@55
|
3905 }
|
Chris@55
|
3906
|
Chris@55
|
3907 void
|
Chris@429
|
3908 MainWindowBase::alignmentComplete(AlignmentModel *model)
|
Chris@429
|
3909 {
|
Chris@429
|
3910 cerr << "MainWindowBase::alignmentComplete(" << model << ")" << endl;
|
Chris@429
|
3911 }
|
Chris@429
|
3912
|
Chris@429
|
3913 void
|
Chris@45
|
3914 MainWindowBase::pollOSC()
|
Chris@45
|
3915 {
|
Chris@45
|
3916 if (!m_oscQueue || m_oscQueue->isEmpty()) return;
|
Chris@233
|
3917 SVDEBUG << "MainWindowBase::pollOSC: have " << m_oscQueue->getMessagesAvailable() << " messages" << endl;
|
Chris@45
|
3918
|
Chris@45
|
3919 if (m_openingAudioFile) return;
|
Chris@45
|
3920
|
Chris@45
|
3921 OSCMessage message = m_oscQueue->readMessage();
|
Chris@45
|
3922
|
Chris@45
|
3923 if (message.getTarget() != 0) {
|
Chris@45
|
3924 return; //!!! for now -- this class is target 0, others not handled yet
|
Chris@45
|
3925 }
|
Chris@45
|
3926
|
Chris@45
|
3927 handleOSCMessage(message);
|
Chris@45
|
3928 }
|
Chris@45
|
3929
|
Chris@45
|
3930 void
|
Chris@45
|
3931 MainWindowBase::inProgressSelectionChanged()
|
Chris@45
|
3932 {
|
Chris@45
|
3933 Pane *currentPane = 0;
|
Chris@45
|
3934 if (m_paneStack) currentPane = m_paneStack->getCurrentPane();
|
justin@331
|
3935 if (currentPane) {
|
justin@331
|
3936 //cerr << "JTEST: mouse event on selection pane" << endl;
|
justin@331
|
3937 updateVisibleRangeDisplay(currentPane);
|
justin@331
|
3938 }
|
Chris@45
|
3939 }
|
Chris@45
|
3940
|
Chris@45
|
3941 void
|
Chris@45
|
3942 MainWindowBase::contextHelpChanged(const QString &s)
|
Chris@45
|
3943 {
|
Chris@378
|
3944 QLabel *lab = getStatusLabel();
|
Chris@375
|
3945
|
Chris@45
|
3946 if (s == "" && m_myStatusMessage != "") {
|
Chris@378
|
3947 if (lab->text() != m_myStatusMessage) {
|
Chris@378
|
3948 lab->setText(m_myStatusMessage);
|
Chris@375
|
3949 }
|
Chris@45
|
3950 return;
|
Chris@45
|
3951 }
|
Chris@375
|
3952
|
Chris@378
|
3953 lab->setText(s);
|
Chris@45
|
3954 }
|
Chris@45
|
3955
|
Chris@45
|
3956 void
|
Chris@45
|
3957 MainWindowBase::openHelpUrl(QString url)
|
Chris@45
|
3958 {
|
Chris@45
|
3959 // This method mostly lifted from Qt Assistant source code
|
Chris@45
|
3960
|
Chris@45
|
3961 QProcess *process = new QProcess(this);
|
Chris@45
|
3962 connect(process, SIGNAL(finished(int)), process, SLOT(deleteLater()));
|
Chris@45
|
3963
|
Chris@45
|
3964 QStringList args;
|
Chris@45
|
3965
|
Chris@45
|
3966 #ifdef Q_OS_MAC
|
Chris@45
|
3967 args.append(url);
|
Chris@45
|
3968 process->start("open", args);
|
Chris@45
|
3969 #else
|
Chris@45
|
3970 #ifdef Q_OS_WIN32
|
Chris@358
|
3971 QString pf(getenv("ProgramFiles"));
|
Chris@358
|
3972 QString command = pf + QString("\\Internet Explorer\\IEXPLORE.EXE");
|
Chris@358
|
3973
|
Chris@358
|
3974 args.append(url);
|
Chris@358
|
3975 process->start(command, args);
|
Chris@45
|
3976 #else
|
Chris@45
|
3977 if (!qgetenv("KDE_FULL_SESSION").isEmpty()) {
|
Chris@45
|
3978 args.append("exec");
|
Chris@45
|
3979 args.append(url);
|
Chris@45
|
3980 process->start("kfmclient", args);
|
Chris@45
|
3981 } else if (!qgetenv("BROWSER").isEmpty()) {
|
Chris@45
|
3982 args.append(url);
|
Chris@45
|
3983 process->start(qgetenv("BROWSER"), args);
|
Chris@45
|
3984 } else {
|
Chris@45
|
3985 args.append(url);
|
Chris@45
|
3986 process->start("firefox", args);
|
Chris@45
|
3987 }
|
Chris@45
|
3988 #endif
|
Chris@45
|
3989 #endif
|
Chris@45
|
3990 }
|
Chris@45
|
3991
|
Chris@483
|
3992 void
|
Chris@483
|
3993 MainWindowBase::openLocalFolder(QString path)
|
Chris@483
|
3994 {
|
Chris@483
|
3995 QDir d(path);
|
Chris@483
|
3996 if (d.exists()) {
|
Chris@483
|
3997 QStringList args;
|
Chris@483
|
3998 QString path = d.canonicalPath();
|
Chris@483
|
3999 #if defined Q_OS_WIN32
|
Chris@483
|
4000 // Although the Win32 API is quite happy to have
|
Chris@483
|
4001 // forward slashes as directory separators, Windows
|
Chris@483
|
4002 // Explorer is not
|
Chris@483
|
4003 path = path.replace('/', '\\');
|
Chris@483
|
4004 args << path;
|
Chris@483
|
4005 QProcess::execute("c:/windows/explorer.exe", args);
|
Chris@483
|
4006 #else
|
Chris@483
|
4007 args << path;
|
Chris@483
|
4008 QProcess::execute(
|
Chris@483
|
4009 #if defined Q_OS_MAC
|
Chris@483
|
4010 "/usr/bin/open",
|
Chris@483
|
4011 #else
|
Chris@483
|
4012 "/usr/bin/xdg-open",
|
Chris@483
|
4013 #endif
|
Chris@483
|
4014 args);
|
Chris@483
|
4015 #endif
|
Chris@483
|
4016 }
|
Chris@483
|
4017 }
|
Chris@483
|
4018
|