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