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