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