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