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