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