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