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