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