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