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