Chris@0
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@0
|
2
|
Chris@0
|
3 /*
|
Chris@0
|
4 Sonic Visualiser
|
Chris@0
|
5 An audio file viewer and annotation editor.
|
Chris@0
|
6 Centre for Digital Music, Queen Mary, University of London.
|
Chris@0
|
7 This file copyright 2006 Chris Cannam.
|
Chris@0
|
8
|
Chris@0
|
9 This program is free software; you can redistribute it and/or
|
Chris@0
|
10 modify it under the terms of the GNU General Public License as
|
Chris@0
|
11 published by the Free Software Foundation; either version 2 of the
|
Chris@0
|
12 License, or (at your option) any later version. See the file
|
Chris@0
|
13 COPYING included with this distribution for more information.
|
Chris@0
|
14 */
|
Chris@0
|
15
|
Chris@1
|
16 #include "version.h"
|
Chris@0
|
17
|
Chris@0
|
18 #include "MainWindow.h"
|
Chris@1
|
19 #include "document/Document.h"
|
Chris@0
|
20 #include "PreferencesDialog.h"
|
Chris@0
|
21
|
Chris@1
|
22 #include "view/Pane.h"
|
Chris@1
|
23 #include "view/PaneStack.h"
|
Chris@1
|
24 #include "data/model/WaveFileModel.h"
|
Chris@1
|
25 #include "data/model/SparseOneDimensionalModel.h"
|
Chris@1
|
26 #include "view/ViewManager.h"
|
Chris@0
|
27 #include "base/Preferences.h"
|
Chris@0
|
28 #include "layer/WaveformLayer.h"
|
Chris@0
|
29 #include "layer/TimeRulerLayer.h"
|
Chris@0
|
30 #include "layer/TimeInstantLayer.h"
|
Chris@0
|
31 #include "layer/TimeValueLayer.h"
|
Chris@0
|
32 #include "layer/Colour3DPlotLayer.h"
|
Chris@0
|
33 #include "widgets/Fader.h"
|
Chris@65
|
34 #include "view/Overview.h"
|
Chris@0
|
35 #include "widgets/PropertyBox.h"
|
Chris@0
|
36 #include "widgets/PropertyStack.h"
|
Chris@0
|
37 #include "widgets/AudioDial.h"
|
Chris@0
|
38 #include "widgets/LayerTree.h"
|
Chris@0
|
39 #include "widgets/ListInputDialog.h"
|
Chris@36
|
40 #include "widgets/SubdividingMenu.h"
|
Chris@0
|
41 #include "audioio/AudioCallbackPlaySource.h"
|
Chris@0
|
42 #include "audioio/AudioCallbackPlayTarget.h"
|
Chris@0
|
43 #include "audioio/AudioTargetFactory.h"
|
Chris@59
|
44 #include "audioio/PlaySpeedRangeMapper.h"
|
Chris@1
|
45 #include "data/fileio/AudioFileReaderFactory.h"
|
Chris@1
|
46 #include "data/fileio/DataFileReaderFactory.h"
|
Chris@1
|
47 #include "data/fileio/WavFileWriter.h"
|
Chris@1
|
48 #include "data/fileio/CSVFileWriter.h"
|
Chris@1
|
49 #include "data/fileio/BZipFileDevice.h"
|
Chris@1
|
50 #include "base/RecentFiles.h"
|
Chris@0
|
51 #include "transform/TransformFactory.h"
|
Chris@0
|
52 #include "base/PlayParameterRepository.h"
|
Chris@0
|
53 #include "base/XmlExportable.h"
|
Chris@0
|
54 #include "base/CommandHistory.h"
|
Chris@0
|
55 #include "base/Profiler.h"
|
Chris@0
|
56 #include "base/Clipboard.h"
|
Chris@69
|
57 #include "osc/OSCQueue.h"
|
Chris@0
|
58
|
Chris@0
|
59 // For version information
|
Chris@0
|
60 #include "vamp/vamp.h"
|
Chris@0
|
61 #include "vamp-sdk/PluginBase.h"
|
Chris@0
|
62 #include "plugin/api/ladspa.h"
|
Chris@0
|
63 #include "plugin/api/dssi.h"
|
Chris@0
|
64
|
Chris@0
|
65 #include <QApplication>
|
Chris@0
|
66 #include <QPushButton>
|
Chris@0
|
67 #include <QFileDialog>
|
Chris@0
|
68 #include <QMessageBox>
|
Chris@0
|
69 #include <QGridLayout>
|
Chris@0
|
70 #include <QLabel>
|
Chris@0
|
71 #include <QAction>
|
Chris@0
|
72 #include <QMenuBar>
|
Chris@0
|
73 #include <QToolBar>
|
Chris@0
|
74 #include <QInputDialog>
|
Chris@0
|
75 #include <QStatusBar>
|
Chris@0
|
76 #include <QTreeView>
|
Chris@0
|
77 #include <QFile>
|
Chris@0
|
78 #include <QTextStream>
|
Chris@0
|
79 #include <QProcess>
|
Chris@7
|
80 #include <QShortcut>
|
Chris@5
|
81 #include <QSettings>
|
Chris@11
|
82 #include <QDateTime>
|
Chris@11
|
83 #include <QProcess>
|
Chris@16
|
84 #include <QCheckBox>
|
Chris@55
|
85 #include <QRegExp>
|
Chris@0
|
86
|
Chris@0
|
87 #include <iostream>
|
Chris@0
|
88 #include <cstdio>
|
Chris@0
|
89 #include <errno.h>
|
Chris@0
|
90
|
Chris@0
|
91 using std::cerr;
|
Chris@0
|
92 using std::endl;
|
Chris@0
|
93
|
Chris@33
|
94 using std::vector;
|
Chris@33
|
95 using std::map;
|
Chris@33
|
96 using std::set;
|
Chris@33
|
97
|
Chris@0
|
98
|
Chris@70
|
99 MainWindow::MainWindow(bool withAudioOutput, bool withOSCSupport) :
|
Chris@0
|
100 m_document(0),
|
Chris@0
|
101 m_paneStack(0),
|
Chris@0
|
102 m_viewManager(0),
|
Chris@65
|
103 m_overview(0),
|
Chris@0
|
104 m_timeRulerLayer(0),
|
Chris@46
|
105 m_audioOutput(withAudioOutput),
|
Chris@0
|
106 m_playSource(0),
|
Chris@0
|
107 m_playTarget(0),
|
Chris@70
|
108 m_oscQueue(withOSCSupport ? new OSCQueue() : 0),
|
Chris@34
|
109 m_recentFiles("RecentFiles"),
|
Chris@49
|
110 m_recentTransforms("RecentTransforms", 20),
|
Chris@0
|
111 m_mainMenusCreated(false),
|
Chris@0
|
112 m_paneMenu(0),
|
Chris@0
|
113 m_layerMenu(0),
|
Chris@34
|
114 m_transformsMenu(0),
|
Chris@0
|
115 m_existingLayersMenu(0),
|
Chris@34
|
116 m_recentFilesMenu(0),
|
Chris@34
|
117 m_recentTransformsMenu(0),
|
Chris@0
|
118 m_rightButtonMenu(0),
|
Chris@0
|
119 m_rightButtonLayerMenu(0),
|
Chris@34
|
120 m_rightButtonTransformsMenu(0),
|
Chris@0
|
121 m_documentModified(false),
|
Chris@70
|
122 m_openingAudioFile(false),
|
Chris@70
|
123 m_abandoning(false),
|
Chris@0
|
124 m_preferencesDialog(0)
|
Chris@0
|
125 {
|
Chris@0
|
126 setWindowTitle(tr("Sonic Visualiser"));
|
Chris@0
|
127
|
Chris@0
|
128 UnitDatabase::getInstance()->registerUnit("Hz");
|
Chris@0
|
129 UnitDatabase::getInstance()->registerUnit("dB");
|
Chris@0
|
130
|
Chris@0
|
131 connect(CommandHistory::getInstance(), SIGNAL(commandExecuted()),
|
Chris@0
|
132 this, SLOT(documentModified()));
|
Chris@0
|
133 connect(CommandHistory::getInstance(), SIGNAL(documentRestored()),
|
Chris@0
|
134 this, SLOT(documentRestored()));
|
Chris@0
|
135
|
Chris@0
|
136 QFrame *frame = new QFrame;
|
Chris@0
|
137 setCentralWidget(frame);
|
Chris@0
|
138
|
Chris@0
|
139 QGridLayout *layout = new QGridLayout;
|
Chris@0
|
140
|
Chris@0
|
141 m_viewManager = new ViewManager();
|
Chris@0
|
142 connect(m_viewManager, SIGNAL(selectionChanged()),
|
Chris@0
|
143 this, SLOT(updateMenuStates()));
|
Chris@0
|
144
|
Chris@0
|
145 m_descriptionLabel = new QLabel;
|
Chris@0
|
146
|
Chris@0
|
147 m_paneStack = new PaneStack(frame, m_viewManager);
|
Chris@0
|
148 connect(m_paneStack, SIGNAL(currentPaneChanged(Pane *)),
|
Chris@0
|
149 this, SLOT(currentPaneChanged(Pane *)));
|
Chris@0
|
150 connect(m_paneStack, SIGNAL(currentLayerChanged(Pane *, Layer *)),
|
Chris@0
|
151 this, SLOT(currentLayerChanged(Pane *, Layer *)));
|
Chris@0
|
152 connect(m_paneStack, SIGNAL(rightButtonMenuRequested(Pane *, QPoint)),
|
Chris@0
|
153 this, SLOT(rightButtonMenuRequested(Pane *, QPoint)));
|
Chris@0
|
154
|
Chris@65
|
155 m_overview = new Overview(frame);
|
Chris@65
|
156 m_overview->setViewManager(m_viewManager);
|
Chris@65
|
157 m_overview->setFixedHeight(40);
|
Chris@0
|
158
|
Chris@0
|
159 m_panLayer = new WaveformLayer;
|
Chris@0
|
160 m_panLayer->setChannelMode(WaveformLayer::MergeChannels);
|
Chris@0
|
161 // m_panLayer->setScale(WaveformLayer::MeterScale);
|
Chris@39
|
162 // m_panLayer->setAutoNormalize(true);
|
Chris@0
|
163 m_panLayer->setBaseColour(Qt::darkGreen);
|
Chris@0
|
164 m_panLayer->setAggressiveCacheing(true);
|
Chris@65
|
165 m_overview->addLayer(m_panLayer);
|
Chris@0
|
166
|
Chris@0
|
167 m_playSource = new AudioCallbackPlaySource(m_viewManager);
|
Chris@0
|
168
|
Chris@0
|
169 connect(m_playSource, SIGNAL(sampleRateMismatch(size_t, size_t, bool)),
|
Chris@0
|
170 this, SLOT(sampleRateMismatch(size_t, size_t, bool)));
|
Chris@42
|
171 connect(m_playSource, SIGNAL(audioOverloadPluginDisabled()),
|
Chris@42
|
172 this, SLOT(audioOverloadPluginDisabled()));
|
Chris@0
|
173
|
Chris@0
|
174 m_fader = new Fader(frame, false);
|
Chris@0
|
175
|
Chris@0
|
176 m_playSpeed = new AudioDial(frame);
|
Chris@12
|
177 m_playSpeed->setMinimum(0);
|
Chris@48
|
178 m_playSpeed->setMaximum(200);
|
Chris@25
|
179 m_playSpeed->setValue(100);
|
Chris@0
|
180 m_playSpeed->setFixedWidth(24);
|
Chris@0
|
181 m_playSpeed->setFixedHeight(24);
|
Chris@0
|
182 m_playSpeed->setNotchesVisible(true);
|
Chris@25
|
183 m_playSpeed->setPageStep(10);
|
Chris@60
|
184 m_playSpeed->setObjectName(tr("Playback Speedup"));
|
Chris@25
|
185 m_playSpeed->setDefaultValue(100);
|
Chris@59
|
186 m_playSpeed->setRangeMapper(new PlaySpeedRangeMapper(0, 200));
|
Chris@60
|
187 m_playSpeed->setShowToolTip(true);
|
Chris@0
|
188 connect(m_playSpeed, SIGNAL(valueChanged(int)),
|
Chris@0
|
189 this, SLOT(playSpeedChanged(int)));
|
Chris@0
|
190
|
Chris@26
|
191 m_playSharpen = new QPushButton(frame);
|
Chris@17
|
192 m_playSharpen->setToolTip(tr("Sharpen percussive transients"));
|
Chris@26
|
193 m_playSharpen->setFixedSize(20, 20);
|
Chris@26
|
194 // m_playSharpen->setFlat(true);
|
Chris@16
|
195 m_playSharpen->setEnabled(false);
|
Chris@26
|
196 m_playSharpen->setCheckable(true);
|
Chris@26
|
197 m_playSharpen->setChecked(false);
|
Chris@26
|
198 m_playSharpen->setIcon(QIcon(":icons/sharpen.png"));
|
Chris@26
|
199 connect(m_playSharpen, SIGNAL(clicked()), this, SLOT(playSharpenToggled()));
|
Chris@26
|
200
|
Chris@26
|
201 m_playMono = new QPushButton(frame);
|
Chris@26
|
202 m_playMono->setToolTip(tr("Run time stretcher in mono only"));
|
Chris@26
|
203 m_playMono->setFixedSize(20, 20);
|
Chris@26
|
204 // m_playMono->setFlat(true);
|
Chris@26
|
205 m_playMono->setEnabled(false);
|
Chris@26
|
206 m_playMono->setCheckable(true);
|
Chris@26
|
207 m_playMono->setChecked(false);
|
Chris@26
|
208 m_playMono->setIcon(QIcon(":icons/mono.png"));
|
Chris@26
|
209 connect(m_playMono, SIGNAL(clicked()), this, SLOT(playMonoToggled()));
|
Chris@21
|
210
|
Chris@21
|
211 QSettings settings;
|
Chris@21
|
212 settings.beginGroup("MainWindow");
|
Chris@24
|
213 m_playSharpen->setChecked(settings.value("playsharpen", true).toBool());
|
Chris@26
|
214 m_playMono->setChecked(settings.value("playmono", false).toBool());
|
Chris@21
|
215 settings.endGroup();
|
Chris@21
|
216
|
Chris@26
|
217 layout->addWidget(m_paneStack, 0, 0, 1, 5);
|
Chris@65
|
218 layout->addWidget(m_overview, 1, 0);
|
Chris@0
|
219 layout->addWidget(m_fader, 1, 1);
|
Chris@0
|
220 layout->addWidget(m_playSpeed, 1, 2);
|
Chris@16
|
221 layout->addWidget(m_playSharpen, 1, 3);
|
Chris@26
|
222 layout->addWidget(m_playMono, 1, 4);
|
Chris@16
|
223
|
Chris@16
|
224 layout->setColumnStretch(0, 10);
|
Chris@16
|
225
|
Chris@0
|
226 frame->setLayout(layout);
|
Chris@0
|
227
|
Chris@0
|
228 connect(m_viewManager, SIGNAL(outputLevelsChanged(float, float)),
|
Chris@0
|
229 this, SLOT(outputLevelsChanged(float, float)));
|
Chris@0
|
230
|
Chris@0
|
231 connect(Preferences::getInstance(),
|
Chris@0
|
232 SIGNAL(propertyChanged(PropertyContainer::PropertyName)),
|
Chris@0
|
233 this,
|
Chris@0
|
234 SLOT(preferenceChanged(PropertyContainer::PropertyName)));
|
Chris@0
|
235
|
Chris@70
|
236 if (m_oscQueue && m_oscQueue->isOK()) {
|
Chris@69
|
237 connect(m_oscQueue, SIGNAL(messagesAvailable()), this, SLOT(pollOSC()));
|
Chris@69
|
238 QTimer *oscTimer = new QTimer(this);
|
Chris@69
|
239 connect(oscTimer, SIGNAL(timeout()), this, SLOT(pollOSC()));
|
Chris@69
|
240 oscTimer->start(1000);
|
Chris@69
|
241 }
|
Chris@69
|
242
|
Chris@0
|
243 setupMenus();
|
Chris@0
|
244 setupToolbars();
|
Chris@0
|
245
|
Chris@47
|
246 // statusBar()->addWidget(m_descriptionLabel);
|
Chris@0
|
247
|
Chris@0
|
248 newSession();
|
Chris@0
|
249 }
|
Chris@0
|
250
|
Chris@0
|
251 MainWindow::~MainWindow()
|
Chris@0
|
252 {
|
Chris@70
|
253 if (!m_abandoning) {
|
Chris@70
|
254 closeSession();
|
Chris@70
|
255 }
|
Chris@0
|
256 delete m_playTarget;
|
Chris@0
|
257 delete m_playSource;
|
Chris@0
|
258 delete m_viewManager;
|
Chris@69
|
259 delete m_oscQueue;
|
Chris@0
|
260 Profiles::getInstance()->dump();
|
Chris@0
|
261 }
|
Chris@0
|
262
|
Chris@0
|
263 void
|
Chris@0
|
264 MainWindow::setupMenus()
|
Chris@0
|
265 {
|
Chris@0
|
266 if (!m_mainMenusCreated) {
|
Chris@0
|
267 m_rightButtonMenu = new QMenu();
|
Chris@0
|
268 }
|
Chris@0
|
269
|
Chris@0
|
270 if (m_rightButtonLayerMenu) {
|
Chris@0
|
271 m_rightButtonLayerMenu->clear();
|
Chris@0
|
272 } else {
|
Chris@0
|
273 m_rightButtonLayerMenu = m_rightButtonMenu->addMenu(tr("&Layer"));
|
Chris@0
|
274 m_rightButtonMenu->addSeparator();
|
Chris@0
|
275 }
|
Chris@0
|
276
|
Chris@34
|
277 if (m_rightButtonTransformsMenu) {
|
Chris@34
|
278 m_rightButtonTransformsMenu->clear();
|
Chris@34
|
279 } else {
|
Chris@34
|
280 m_rightButtonTransformsMenu = m_rightButtonMenu->addMenu(tr("&Transform"));
|
Chris@34
|
281 m_rightButtonMenu->addSeparator();
|
Chris@34
|
282 }
|
Chris@34
|
283
|
Chris@0
|
284 if (!m_mainMenusCreated) {
|
Chris@0
|
285 CommandHistory::getInstance()->registerMenu(m_rightButtonMenu);
|
Chris@0
|
286 m_rightButtonMenu->addSeparator();
|
Chris@66
|
287 }
|
Chris@66
|
288
|
Chris@66
|
289 setupFileMenu();
|
Chris@66
|
290 setupEditMenu();
|
Chris@66
|
291 setupViewMenu();
|
Chris@66
|
292 setupPaneAndLayerMenus();
|
Chris@66
|
293 setupTransformsMenu();
|
Chris@66
|
294 setupHelpMenu();
|
Chris@66
|
295
|
Chris@66
|
296 m_mainMenusCreated = true;
|
Chris@66
|
297 }
|
Chris@66
|
298
|
Chris@66
|
299 void
|
Chris@66
|
300 MainWindow::setupFileMenu()
|
Chris@66
|
301 {
|
Chris@66
|
302 if (m_mainMenusCreated) return;
|
Chris@66
|
303
|
Chris@66
|
304 QMenu *menu = menuBar()->addMenu(tr("&File"));
|
Chris@66
|
305 QToolBar *toolbar = addToolBar(tr("File Toolbar"));
|
Chris@66
|
306
|
Chris@66
|
307 QIcon icon(":icons/filenew.png");
|
Chris@66
|
308 icon.addFile(":icons/filenew-22.png");
|
Chris@66
|
309 QAction *action = new QAction(icon, tr("&New Session"), this);
|
Chris@66
|
310 action->setShortcut(tr("Ctrl+N"));
|
Chris@66
|
311 action->setStatusTip(tr("Clear the current Sonic Visualiser session and start a new one"));
|
Chris@66
|
312 connect(action, SIGNAL(triggered()), this, SLOT(newSession()));
|
Chris@66
|
313 menu->addAction(action);
|
Chris@66
|
314 toolbar->addAction(action);
|
Chris@0
|
315
|
Chris@66
|
316 icon = QIcon(":icons/fileopen.png");
|
Chris@66
|
317 icon.addFile(":icons/fileopen-22.png");
|
Chris@66
|
318
|
Chris@66
|
319 action = new QAction(icon, tr("&Open Session..."), this);
|
Chris@66
|
320 action->setShortcut(tr("Ctrl+O"));
|
Chris@66
|
321 action->setStatusTip(tr("Open a previously saved Sonic Visualiser session file"));
|
Chris@66
|
322 connect(action, SIGNAL(triggered()), this, SLOT(openSession()));
|
Chris@66
|
323 menu->addAction(action);
|
Chris@66
|
324
|
Chris@66
|
325 action = new QAction(icon, tr("&Open..."), this);
|
Chris@66
|
326 action->setStatusTip(tr("Open a session file, audio file, or layer"));
|
Chris@66
|
327 connect(action, SIGNAL(triggered()), this, SLOT(openSomething()));
|
Chris@66
|
328 toolbar->addAction(action);
|
Chris@66
|
329
|
Chris@66
|
330 icon = QIcon(":icons/filesave.png");
|
Chris@66
|
331 icon.addFile(":icons/filesave-22.png");
|
Chris@66
|
332 action = new QAction(icon, tr("&Save Session"), this);
|
Chris@66
|
333 action->setShortcut(tr("Ctrl+S"));
|
Chris@66
|
334 action->setStatusTip(tr("Save the current session into a Sonic Visualiser session file"));
|
Chris@66
|
335 connect(action, SIGNAL(triggered()), this, SLOT(saveSession()));
|
Chris@66
|
336 connect(this, SIGNAL(canSave(bool)), action, SLOT(setEnabled(bool)));
|
Chris@66
|
337 menu->addAction(action);
|
Chris@66
|
338 toolbar->addAction(action);
|
Chris@0
|
339
|
Chris@66
|
340 icon = QIcon(":icons/filesaveas.png");
|
Chris@66
|
341 icon.addFile(":icons/filesaveas-22.png");
|
Chris@66
|
342 action = new QAction(icon, tr("Save Session &As..."), this);
|
Chris@66
|
343 action->setStatusTip(tr("Save the current session into a new Sonic Visualiser session file"));
|
Chris@66
|
344 connect(action, SIGNAL(triggered()), this, SLOT(saveSessionAs()));
|
Chris@66
|
345 menu->addAction(action);
|
Chris@66
|
346 toolbar->addAction(action);
|
Chris@66
|
347
|
Chris@66
|
348 menu->addSeparator();
|
Chris@66
|
349
|
Chris@66
|
350 action = new QAction(tr("&Import Audio File..."), this);
|
Chris@66
|
351 action->setShortcut(tr("Ctrl+I"));
|
Chris@66
|
352 action->setStatusTip(tr("Import an existing audio file"));
|
Chris@66
|
353 connect(action, SIGNAL(triggered()), this, SLOT(importAudio()));
|
Chris@66
|
354 menu->addAction(action);
|
Chris@66
|
355
|
Chris@66
|
356 action = new QAction(tr("Import Secondary Audio File..."), this);
|
Chris@66
|
357 action->setShortcut(tr("Ctrl+Shift+I"));
|
Chris@66
|
358 action->setStatusTip(tr("Import an extra audio file as a separate layer"));
|
Chris@66
|
359 connect(action, SIGNAL(triggered()), this, SLOT(importMoreAudio()));
|
Chris@66
|
360 connect(this, SIGNAL(canImportMoreAudio(bool)), action, SLOT(setEnabled(bool)));
|
Chris@66
|
361 menu->addAction(action);
|
Chris@66
|
362
|
Chris@66
|
363 action = new QAction(tr("&Export Audio File..."), this);
|
Chris@66
|
364 action->setStatusTip(tr("Export selection as an audio file"));
|
Chris@66
|
365 connect(action, SIGNAL(triggered()), this, SLOT(exportAudio()));
|
Chris@66
|
366 connect(this, SIGNAL(canExportAudio(bool)), action, SLOT(setEnabled(bool)));
|
Chris@66
|
367 menu->addAction(action);
|
Chris@66
|
368
|
Chris@66
|
369 menu->addSeparator();
|
Chris@66
|
370
|
Chris@66
|
371 action = new QAction(tr("Import Annotation &Layer..."), this);
|
Chris@66
|
372 action->setShortcut(tr("Ctrl+L"));
|
Chris@66
|
373 action->setStatusTip(tr("Import layer data from an existing file"));
|
Chris@66
|
374 connect(action, SIGNAL(triggered()), this, SLOT(importLayer()));
|
Chris@66
|
375 connect(this, SIGNAL(canImportLayer(bool)), action, SLOT(setEnabled(bool)));
|
Chris@66
|
376 menu->addAction(action);
|
Chris@66
|
377
|
Chris@66
|
378 action = new QAction(tr("Export Annotation Layer..."), this);
|
Chris@66
|
379 action->setStatusTip(tr("Export layer data to a file"));
|
Chris@66
|
380 connect(action, SIGNAL(triggered()), this, SLOT(exportLayer()));
|
Chris@66
|
381 connect(this, SIGNAL(canExportLayer(bool)), action, SLOT(setEnabled(bool)));
|
Chris@66
|
382 menu->addAction(action);
|
Chris@66
|
383
|
Chris@66
|
384 menu->addSeparator();
|
Chris@66
|
385 m_recentFilesMenu = menu->addMenu(tr("&Recent Files"));
|
Chris@66
|
386 setupRecentFilesMenu();
|
Chris@66
|
387 connect(&m_recentFiles, SIGNAL(recentChanged()),
|
Chris@66
|
388 this, SLOT(setupRecentFilesMenu()));
|
Chris@66
|
389
|
Chris@66
|
390 menu->addSeparator();
|
Chris@66
|
391 action = new QAction(tr("&Preferences..."), this);
|
Chris@66
|
392 action->setStatusTip(tr("Adjust the application preferences"));
|
Chris@66
|
393 connect(action, SIGNAL(triggered()), this, SLOT(preferences()));
|
Chris@66
|
394 menu->addAction(action);
|
Chris@0
|
395
|
Chris@66
|
396 /*!!!
|
Chris@66
|
397 menu->addSeparator();
|
Chris@0
|
398
|
Chris@66
|
399 action = new QAction(tr("Play / Pause"), this);
|
Chris@66
|
400 action->setShortcut(tr("Space"));
|
Chris@66
|
401 action->setStatusTip(tr("Start or stop playback from the current position"));
|
Chris@66
|
402 connect(action, SIGNAL(triggered()), this, SLOT(play()));
|
Chris@66
|
403 menu->addAction(action);
|
Chris@66
|
404 */
|
Chris@66
|
405
|
Chris@66
|
406 menu->addSeparator();
|
Chris@66
|
407 action = new QAction(QIcon(":/icons/exit.png"),
|
Chris@66
|
408 tr("&Quit"), this);
|
Chris@66
|
409 action->setShortcut(tr("Ctrl+Q"));
|
Chris@66
|
410 connect(action, SIGNAL(triggered()), this, SLOT(close()));
|
Chris@66
|
411 menu->addAction(action);
|
Chris@66
|
412 }
|
Chris@66
|
413
|
Chris@66
|
414 void
|
Chris@66
|
415 MainWindow::setupEditMenu()
|
Chris@66
|
416 {
|
Chris@66
|
417 if (m_mainMenusCreated) return;
|
Chris@66
|
418
|
Chris@66
|
419 QMenu *menu = menuBar()->addMenu(tr("&Edit"));
|
Chris@66
|
420 CommandHistory::getInstance()->registerMenu(menu);
|
Chris@66
|
421
|
Chris@66
|
422 menu->addSeparator();
|
Chris@66
|
423
|
Chris@66
|
424 QAction *action = new QAction(QIcon(":/icons/editcut.png"),
|
Chris@66
|
425 tr("Cu&t"), this);
|
Chris@66
|
426 action->setShortcut(tr("Ctrl+X"));
|
Chris@66
|
427 connect(action, SIGNAL(triggered()), this, SLOT(cut()));
|
Chris@66
|
428 connect(this, SIGNAL(canEditSelection(bool)), action, SLOT(setEnabled(bool)));
|
Chris@66
|
429 menu->addAction(action);
|
Chris@66
|
430 m_rightButtonMenu->addAction(action);
|
Chris@66
|
431
|
Chris@66
|
432 action = new QAction(QIcon(":/icons/editcopy.png"),
|
Chris@66
|
433 tr("&Copy"), this);
|
Chris@66
|
434 action->setShortcut(tr("Ctrl+C"));
|
Chris@66
|
435 connect(action, SIGNAL(triggered()), this, SLOT(copy()));
|
Chris@66
|
436 connect(this, SIGNAL(canEditSelection(bool)), action, SLOT(setEnabled(bool)));
|
Chris@66
|
437 menu->addAction(action);
|
Chris@66
|
438 m_rightButtonMenu->addAction(action);
|
Chris@66
|
439
|
Chris@66
|
440 action = new QAction(QIcon(":/icons/editpaste.png"),
|
Chris@66
|
441 tr("&Paste"), this);
|
Chris@66
|
442 action->setShortcut(tr("Ctrl+V"));
|
Chris@66
|
443 connect(action, SIGNAL(triggered()), this, SLOT(paste()));
|
Chris@66
|
444 connect(this, SIGNAL(canPaste(bool)), action, SLOT(setEnabled(bool)));
|
Chris@66
|
445 menu->addAction(action);
|
Chris@66
|
446 m_rightButtonMenu->addAction(action);
|
Chris@66
|
447
|
Chris@66
|
448 action = new QAction(tr("&Delete Selected Items"), this);
|
Chris@66
|
449 action->setShortcut(tr("Del"));
|
Chris@66
|
450 connect(action, SIGNAL(triggered()), this, SLOT(deleteSelected()));
|
Chris@66
|
451 connect(this, SIGNAL(canEditSelection(bool)), action, SLOT(setEnabled(bool)));
|
Chris@66
|
452 menu->addAction(action);
|
Chris@66
|
453 m_rightButtonMenu->addAction(action);
|
Chris@66
|
454
|
Chris@66
|
455 menu->addSeparator();
|
Chris@66
|
456 m_rightButtonMenu->addSeparator();
|
Chris@0
|
457
|
Chris@66
|
458 action = new QAction(tr("Select &All"), this);
|
Chris@66
|
459 action->setShortcut(tr("Ctrl+A"));
|
Chris@66
|
460 connect(action, SIGNAL(triggered()), this, SLOT(selectAll()));
|
Chris@66
|
461 connect(this, SIGNAL(canSelect(bool)), action, SLOT(setEnabled(bool)));
|
Chris@66
|
462 menu->addAction(action);
|
Chris@66
|
463 m_rightButtonMenu->addAction(action);
|
Chris@0
|
464
|
Chris@66
|
465 action = new QAction(tr("Select &Visible Range"), this);
|
Chris@66
|
466 action->setShortcut(tr("Ctrl+Shift+A"));
|
Chris@66
|
467 connect(action, SIGNAL(triggered()), this, SLOT(selectVisible()));
|
Chris@66
|
468 connect(this, SIGNAL(canSelect(bool)), action, SLOT(setEnabled(bool)));
|
Chris@66
|
469 menu->addAction(action);
|
Chris@0
|
470
|
Chris@66
|
471 action = new QAction(tr("Select to &Start"), this);
|
Chris@66
|
472 action->setShortcut(tr("Shift+Left"));
|
Chris@66
|
473 connect(action, SIGNAL(triggered()), this, SLOT(selectToStart()));
|
Chris@66
|
474 connect(this, SIGNAL(canSelect(bool)), action, SLOT(setEnabled(bool)));
|
Chris@66
|
475 menu->addAction(action);
|
Chris@0
|
476
|
Chris@66
|
477 action = new QAction(tr("Select to &End"), this);
|
Chris@66
|
478 action->setShortcut(tr("Shift+Right"));
|
Chris@66
|
479 connect(action, SIGNAL(triggered()), this, SLOT(selectToEnd()));
|
Chris@66
|
480 connect(this, SIGNAL(canSelect(bool)), action, SLOT(setEnabled(bool)));
|
Chris@66
|
481 menu->addAction(action);
|
Chris@66
|
482
|
Chris@66
|
483 action = new QAction(tr("C&lear Selection"), this);
|
Chris@66
|
484 action->setShortcut(tr("Esc"));
|
Chris@66
|
485 connect(action, SIGNAL(triggered()), this, SLOT(clearSelection()));
|
Chris@66
|
486 connect(this, SIGNAL(canClearSelection(bool)), action, SLOT(setEnabled(bool)));
|
Chris@66
|
487 menu->addAction(action);
|
Chris@66
|
488 m_rightButtonMenu->addAction(action);
|
Chris@66
|
489
|
Chris@66
|
490 menu->addSeparator();
|
Chris@66
|
491
|
Chris@66
|
492 action = new QAction(tr("&Insert Instant at Playback Position"), this);
|
Chris@66
|
493 action->setShortcut(tr("Enter"));
|
Chris@66
|
494 connect(action, SIGNAL(triggered()), this, SLOT(insertInstant()));
|
Chris@66
|
495 connect(this, SIGNAL(canInsertInstant(bool)), action, SLOT(setEnabled(bool)));
|
Chris@66
|
496 menu->addAction(action);
|
Chris@66
|
497
|
Chris@66
|
498 // Laptop shortcut (no keypad Enter key)
|
Chris@66
|
499 connect(new QShortcut(tr(";"), this), SIGNAL(activated()),
|
Chris@66
|
500 this, SLOT(insertInstant()));
|
Chris@66
|
501 }
|
Chris@66
|
502
|
Chris@66
|
503 void
|
Chris@66
|
504 MainWindow::setupViewMenu()
|
Chris@66
|
505 {
|
Chris@66
|
506 if (m_mainMenusCreated) return;
|
Chris@66
|
507
|
Chris@66
|
508 QMenu *menu = menuBar()->addMenu(tr("&View"));
|
Chris@66
|
509
|
Chris@66
|
510 QActionGroup *overlayGroup = new QActionGroup(this);
|
Chris@0
|
511
|
Chris@66
|
512 QAction *action = new QAction(tr("&No Text Overlays"), this);
|
Chris@66
|
513 action->setShortcut(tr("0"));
|
Chris@66
|
514 action->setStatusTip(tr("Show no texts for frame times, layer names etc"));
|
Chris@66
|
515 connect(action, SIGNAL(triggered()), this, SLOT(showNoOverlays()));
|
Chris@66
|
516 action->setCheckable(true);
|
Chris@66
|
517 action->setChecked(false);
|
Chris@66
|
518 overlayGroup->addAction(action);
|
Chris@66
|
519 menu->addAction(action);
|
Chris@0
|
520
|
Chris@66
|
521 action = new QAction(tr("Basic &Text Overlays"), this);
|
Chris@66
|
522 action->setShortcut(tr("9"));
|
Chris@66
|
523 action->setStatusTip(tr("Show texts for frame times etc, but not layer names etc"));
|
Chris@66
|
524 connect(action, SIGNAL(triggered()), this, SLOT(showBasicOverlays()));
|
Chris@66
|
525 action->setCheckable(true);
|
Chris@66
|
526 action->setChecked(true);
|
Chris@66
|
527 overlayGroup->addAction(action);
|
Chris@66
|
528 menu->addAction(action);
|
Chris@0
|
529
|
Chris@66
|
530 action = new QAction(tr("&All Text Overlays"), this);
|
Chris@66
|
531 action->setShortcut(tr("8"));
|
Chris@66
|
532 action->setStatusTip(tr("Show texts for frame times, layer names etc"));
|
Chris@66
|
533 connect(action, SIGNAL(triggered()), this, SLOT(showAllTextOverlays()));
|
Chris@66
|
534 action->setCheckable(true);
|
Chris@66
|
535 action->setChecked(false);
|
Chris@66
|
536 overlayGroup->addAction(action);
|
Chris@66
|
537 menu->addAction(action);
|
Chris@66
|
538
|
Chris@66
|
539 menu->addSeparator();
|
Chris@0
|
540
|
Chris@66
|
541 action = new QAction(tr("Scroll &Left"), this);
|
Chris@66
|
542 action->setShortcut(tr("Left"));
|
Chris@66
|
543 action->setStatusTip(tr("Scroll the current pane to the left"));
|
Chris@66
|
544 connect(action, SIGNAL(triggered()), this, SLOT(scrollLeft()));
|
Chris@66
|
545 connect(this, SIGNAL(canScroll(bool)), action, SLOT(setEnabled(bool)));
|
Chris@66
|
546 menu->addAction(action);
|
Chris@0
|
547
|
Chris@66
|
548 action = new QAction(tr("Scroll &Right"), this);
|
Chris@66
|
549 action->setShortcut(tr("Right"));
|
Chris@66
|
550 action->setStatusTip(tr("Scroll the current pane to the right"));
|
Chris@66
|
551 connect(action, SIGNAL(triggered()), this, SLOT(scrollRight()));
|
Chris@66
|
552 connect(this, SIGNAL(canScroll(bool)), action, SLOT(setEnabled(bool)));
|
Chris@66
|
553 menu->addAction(action);
|
Chris@0
|
554
|
Chris@66
|
555 action = new QAction(tr("Jump Left"), this);
|
Chris@66
|
556 action->setShortcut(tr("Ctrl+Left"));
|
Chris@66
|
557 action->setStatusTip(tr("Scroll the current pane a big step to the left"));
|
Chris@66
|
558 connect(action, SIGNAL(triggered()), this, SLOT(jumpLeft()));
|
Chris@66
|
559 connect(this, SIGNAL(canScroll(bool)), action, SLOT(setEnabled(bool)));
|
Chris@66
|
560 menu->addAction(action);
|
Chris@0
|
561
|
Chris@66
|
562 action = new QAction(tr("Jump Right"), this);
|
Chris@66
|
563 action->setShortcut(tr("Ctrl+Right"));
|
Chris@66
|
564 action->setStatusTip(tr("Scroll the current pane a big step to the right"));
|
Chris@66
|
565 connect(action, SIGNAL(triggered()), this, SLOT(jumpRight()));
|
Chris@66
|
566 connect(this, SIGNAL(canScroll(bool)), action, SLOT(setEnabled(bool)));
|
Chris@66
|
567 menu->addAction(action);
|
Chris@66
|
568
|
Chris@66
|
569 menu->addSeparator();
|
Chris@66
|
570
|
Chris@66
|
571 action = new QAction(QIcon(":/icons/zoom-in.png"),
|
Chris@66
|
572 tr("Zoom &In"), this);
|
Chris@66
|
573 action->setShortcut(tr("Up"));
|
Chris@66
|
574 action->setStatusTip(tr("Increase the zoom level"));
|
Chris@66
|
575 connect(action, SIGNAL(triggered()), this, SLOT(zoomIn()));
|
Chris@66
|
576 connect(this, SIGNAL(canZoom(bool)), action, SLOT(setEnabled(bool)));
|
Chris@66
|
577 menu->addAction(action);
|
Chris@0
|
578
|
Chris@66
|
579 action = new QAction(QIcon(":/icons/zoom-out.png"),
|
Chris@66
|
580 tr("Zoom &Out"), this);
|
Chris@66
|
581 action->setShortcut(tr("Down"));
|
Chris@66
|
582 action->setStatusTip(tr("Decrease the zoom level"));
|
Chris@66
|
583 connect(action, SIGNAL(triggered()), this, SLOT(zoomOut()));
|
Chris@66
|
584 connect(this, SIGNAL(canZoom(bool)), action, SLOT(setEnabled(bool)));
|
Chris@66
|
585 menu->addAction(action);
|
Chris@0
|
586
|
Chris@66
|
587 action = new QAction(tr("Restore &Default Zoom"), this);
|
Chris@66
|
588 connect(action, SIGNAL(triggered()), this, SLOT(zoomDefault()));
|
Chris@66
|
589 connect(this, SIGNAL(canZoom(bool)), action, SLOT(setEnabled(bool)));
|
Chris@66
|
590 menu->addAction(action);
|
Chris@66
|
591
|
Chris@66
|
592 action = new QAction(tr("Zoom to &Fit"), this);
|
Chris@66
|
593 action->setStatusTip(tr("Zoom to show the whole file"));
|
Chris@66
|
594 connect(action, SIGNAL(triggered()), this, SLOT(zoomToFit()));
|
Chris@66
|
595 connect(this, SIGNAL(canZoom(bool)), action, SLOT(setEnabled(bool)));
|
Chris@66
|
596 menu->addAction(action);
|
Chris@7
|
597
|
Chris@66
|
598 action = new QAction(tr("Show &Zoom Wheels"), this);
|
Chris@66
|
599 action->setShortcut(tr("Z"));
|
Chris@66
|
600 action->setStatusTip(tr("Show thumbwheels for zooming horizontally and vertically"));
|
Chris@66
|
601 connect(action, SIGNAL(triggered()), this, SLOT(toggleZoomWheels()));
|
Chris@66
|
602 action->setCheckable(true);
|
Chris@66
|
603 action->setChecked(m_viewManager->getZoomWheelsEnabled());
|
Chris@66
|
604 menu->addAction(action);
|
Chris@0
|
605
|
Chris@0
|
606 /*!!! This one doesn't work properly yet
|
Chris@62
|
607 */
|
Chris@66
|
608 menu->addSeparator();
|
Chris@66
|
609
|
Chris@66
|
610 action = new QAction(tr("Show &Layer Hierarchy"), this);
|
Chris@66
|
611 action->setShortcut(tr("Alt+L"));
|
Chris@66
|
612 connect(action, SIGNAL(triggered()), this, SLOT(showLayerTree()));
|
Chris@66
|
613 menu->addAction(action);
|
Chris@62
|
614 /* */
|
Chris@66
|
615 }
|
Chris@66
|
616
|
Chris@66
|
617 void
|
Chris@66
|
618 MainWindow::setupPaneAndLayerMenus()
|
Chris@66
|
619 {
|
Chris@0
|
620 if (m_paneMenu) {
|
Chris@0
|
621 m_paneActions.clear();
|
Chris@0
|
622 m_paneMenu->clear();
|
Chris@0
|
623 } else {
|
Chris@0
|
624 m_paneMenu = menuBar()->addMenu(tr("&Pane"));
|
Chris@0
|
625 }
|
Chris@0
|
626
|
Chris@0
|
627 if (m_layerMenu) {
|
Chris@0
|
628 m_layerActions.clear();
|
Chris@0
|
629 m_layerMenu->clear();
|
Chris@0
|
630 } else {
|
Chris@0
|
631 m_layerMenu = menuBar()->addMenu(tr("&Layer"));
|
Chris@0
|
632 }
|
Chris@0
|
633
|
Chris@66
|
634 QMenu *menu = m_paneMenu;
|
Chris@66
|
635
|
Chris@66
|
636 QAction *action = new QAction(QIcon(":/icons/pane.png"), tr("Add &New Pane"), this);
|
Chris@66
|
637 action->setShortcut(tr("Alt+N"));
|
Chris@66
|
638 action->setStatusTip(tr("Add a new pane containing only a time ruler"));
|
Chris@66
|
639 connect(action, SIGNAL(triggered()), this, SLOT(addPane()));
|
Chris@66
|
640 connect(this, SIGNAL(canAddPane(bool)), action, SLOT(setEnabled(bool)));
|
Chris@66
|
641 m_paneActions[action] = PaneConfiguration(LayerFactory::TimeRuler);
|
Chris@66
|
642 menu->addAction(action);
|
Chris@66
|
643
|
Chris@66
|
644 menu->addSeparator();
|
Chris@66
|
645
|
Chris@66
|
646 menu = m_layerMenu;
|
Chris@66
|
647
|
Chris@66
|
648 // menu->addSeparator();
|
Chris@66
|
649
|
Chris@66
|
650 LayerFactory::LayerTypeSet emptyLayerTypes =
|
Chris@66
|
651 LayerFactory::getInstance()->getValidEmptyLayerTypes();
|
Chris@66
|
652
|
Chris@66
|
653 for (LayerFactory::LayerTypeSet::iterator i = emptyLayerTypes.begin();
|
Chris@66
|
654 i != emptyLayerTypes.end(); ++i) {
|
Chris@66
|
655
|
Chris@66
|
656 QIcon icon;
|
Chris@66
|
657 QString mainText, tipText, channelText;
|
Chris@66
|
658 LayerFactory::LayerType type = *i;
|
Chris@66
|
659 QString name = LayerFactory::getInstance()->getLayerPresentationName(type);
|
Chris@66
|
660
|
Chris@66
|
661 icon = QIcon(QString(":/icons/%1.png")
|
Chris@66
|
662 .arg(LayerFactory::getInstance()->getLayerIconName(type)));
|
Chris@66
|
663
|
Chris@66
|
664 mainText = tr("Add New %1 Layer").arg(name);
|
Chris@66
|
665 tipText = tr("Add a new empty layer of type %1").arg(name);
|
Chris@66
|
666
|
Chris@66
|
667 action = new QAction(icon, mainText, this);
|
Chris@66
|
668 action->setStatusTip(tipText);
|
Chris@66
|
669
|
Chris@66
|
670 if (type == LayerFactory::Text) {
|
Chris@66
|
671 action->setShortcut(tr("Alt+T"));
|
Chris@66
|
672 }
|
Chris@66
|
673
|
Chris@66
|
674 connect(action, SIGNAL(triggered()), this, SLOT(addLayer()));
|
Chris@66
|
675 connect(this, SIGNAL(canAddLayer(bool)), action, SLOT(setEnabled(bool)));
|
Chris@66
|
676 m_layerActions[action] = type;
|
Chris@66
|
677 menu->addAction(action);
|
Chris@66
|
678 m_rightButtonLayerMenu->addAction(action);
|
Chris@66
|
679 }
|
Chris@66
|
680
|
Chris@66
|
681 m_rightButtonLayerMenu->addSeparator();
|
Chris@66
|
682 menu->addSeparator();
|
Chris@66
|
683
|
Chris@66
|
684 LayerFactory::LayerType backgroundTypes[] = {
|
Chris@66
|
685 LayerFactory::Waveform,
|
Chris@66
|
686 LayerFactory::Spectrogram,
|
Chris@66
|
687 LayerFactory::MelodicRangeSpectrogram,
|
Chris@66
|
688 LayerFactory::PeakFrequencySpectrogram,
|
Chris@66
|
689 LayerFactory::Spectrum
|
Chris@66
|
690 };
|
Chris@66
|
691
|
Chris@66
|
692 std::vector<Model *> models;
|
Chris@66
|
693 if (m_document) models = m_document->getTransformInputModels(); //!!! not well named for this!
|
Chris@66
|
694 bool plural = (models.size() > 1);
|
Chris@66
|
695 if (models.empty()) {
|
Chris@67
|
696 models.push_back(getMainModel()); // probably 0
|
Chris@66
|
697 }
|
Chris@66
|
698
|
Chris@66
|
699 for (unsigned int i = 0;
|
Chris@66
|
700 i < sizeof(backgroundTypes)/sizeof(backgroundTypes[0]); ++i) {
|
Chris@66
|
701
|
Chris@66
|
702 for (int menuType = 0; menuType <= 1; ++menuType) { // pane, layer
|
Chris@66
|
703
|
Chris@66
|
704 if (menuType == 0) menu = m_paneMenu;
|
Chris@66
|
705 else menu = m_layerMenu;
|
Chris@66
|
706
|
Chris@66
|
707 QMenu *submenu = 0;
|
Chris@66
|
708
|
Chris@66
|
709 QIcon icon;
|
Chris@66
|
710 QString mainText, shortcutText, tipText, channelText;
|
Chris@66
|
711 LayerFactory::LayerType type = backgroundTypes[i];
|
Chris@66
|
712 bool mono = true;
|
Chris@66
|
713
|
Chris@66
|
714 switch (type) {
|
Chris@66
|
715
|
Chris@66
|
716 case LayerFactory::Waveform:
|
Chris@66
|
717 icon = QIcon(":/icons/waveform.png");
|
Chris@66
|
718 mainText = tr("Add &Waveform");
|
Chris@66
|
719 if (menuType == 0) {
|
Chris@66
|
720 shortcutText = tr("Alt+W");
|
Chris@66
|
721 tipText = tr("Add a new pane showing a waveform view");
|
Chris@66
|
722 } else {
|
Chris@66
|
723 tipText = tr("Add a new layer showing a waveform view");
|
Chris@66
|
724 }
|
Chris@66
|
725 mono = false;
|
Chris@66
|
726 break;
|
Chris@66
|
727
|
Chris@66
|
728 case LayerFactory::Spectrogram:
|
Chris@67
|
729 icon = QIcon(":/icons/spectrogram.png");
|
Chris@66
|
730 mainText = tr("Add &Spectrogram");
|
Chris@66
|
731 if (menuType == 0) {
|
Chris@66
|
732 shortcutText = tr("Alt+S");
|
Chris@66
|
733 tipText = tr("Add a new pane showing a dB spectrogram");
|
Chris@66
|
734 } else {
|
Chris@66
|
735 tipText = tr("Add a new layer showing a dB spectrogram");
|
Chris@66
|
736 }
|
Chris@66
|
737 break;
|
Chris@66
|
738
|
Chris@66
|
739 case LayerFactory::MelodicRangeSpectrogram:
|
Chris@67
|
740 icon = QIcon(":/icons/spectrogram.png");
|
Chris@66
|
741 mainText = tr("Add &Melodic Range Spectrogram");
|
Chris@66
|
742 if (menuType == 0) {
|
Chris@66
|
743 shortcutText = tr("Alt+M");
|
Chris@66
|
744 tipText = tr("Add a new pane showing a spectrogram set up for a pitch overview");
|
Chris@66
|
745 } else {
|
Chris@66
|
746 tipText = tr("Add a new layer showing a spectrogram set up for a pitch overview");
|
Chris@66
|
747 }
|
Chris@66
|
748 break;
|
Chris@66
|
749
|
Chris@66
|
750 case LayerFactory::PeakFrequencySpectrogram:
|
Chris@67
|
751 icon = QIcon(":/icons/spectrogram.png");
|
Chris@66
|
752 mainText = tr("Add &Peak Frequency Spectrogram");
|
Chris@66
|
753 if (menuType == 0) {
|
Chris@66
|
754 shortcutText = tr("Alt+P");
|
Chris@66
|
755 tipText = tr("Add a new pane showing a spectrogram set up for tracking frequencies");
|
Chris@66
|
756 } else {
|
Chris@66
|
757 tipText = tr("Add a new layer showing a spectrogram set up for tracking frequencies");
|
Chris@66
|
758 }
|
Chris@66
|
759 break;
|
Chris@66
|
760
|
Chris@66
|
761 case LayerFactory::Spectrum:
|
Chris@67
|
762 icon = QIcon(":/icons/spectrum.png");
|
Chris@66
|
763 mainText = tr("Add Spectr&um");
|
Chris@66
|
764 if (menuType == 0) {
|
Chris@66
|
765 shortcutText = tr("Alt+U");
|
Chris@66
|
766 tipText = tr("Add a new pane showing a frequency spectrum");
|
Chris@66
|
767 } else {
|
Chris@66
|
768 tipText = tr("Add a new layer showing a frequency spectrum");
|
Chris@66
|
769 }
|
Chris@66
|
770 break;
|
Chris@66
|
771
|
Chris@66
|
772 default: break;
|
Chris@66
|
773 }
|
Chris@66
|
774
|
Chris@66
|
775 std::vector<Model *> candidateModels;
|
Chris@66
|
776 if (menuType == 0) {
|
Chris@66
|
777 candidateModels = models;
|
Chris@66
|
778 } else {
|
Chris@66
|
779 candidateModels.push_back(0);
|
Chris@66
|
780 }
|
Chris@66
|
781
|
Chris@66
|
782 for (std::vector<Model *>::iterator mi =
|
Chris@66
|
783 candidateModels.begin();
|
Chris@66
|
784 mi != candidateModels.end(); ++mi) {
|
Chris@66
|
785
|
Chris@66
|
786 Model *model = *mi;
|
Chris@66
|
787
|
Chris@66
|
788 int channels = 0;
|
Chris@66
|
789 if (model) {
|
Chris@66
|
790 DenseTimeValueModel *dtvm =
|
Chris@66
|
791 dynamic_cast<DenseTimeValueModel *>(model);
|
Chris@66
|
792 if (dtvm) channels = dtvm->getChannelCount();
|
Chris@66
|
793 }
|
Chris@66
|
794 if (channels < 1 && getMainModel()) {
|
Chris@66
|
795 channels = getMainModel()->getChannelCount();
|
Chris@66
|
796 }
|
Chris@66
|
797 if (channels < 1) channels = 1;
|
Chris@66
|
798
|
Chris@66
|
799 for (int c = 0; c <= channels; ++c) {
|
Chris@66
|
800
|
Chris@66
|
801 if (c == 1 && channels == 1) continue;
|
Chris@66
|
802 bool isDefault = (c == 0);
|
Chris@66
|
803 bool isOnly = (isDefault && (channels == 1));
|
Chris@66
|
804
|
Chris@66
|
805 if (menuType == 1) {
|
Chris@66
|
806 if (isDefault) isOnly = true;
|
Chris@66
|
807 else continue;
|
Chris@66
|
808 }
|
Chris@66
|
809
|
Chris@66
|
810 if (isOnly && (!plural || menuType == 1)) {
|
Chris@66
|
811
|
Chris@67
|
812 if (type != LayerFactory::Waveform) {
|
Chris@67
|
813 action = new QAction(mainText, this);
|
Chris@67
|
814 } else {
|
Chris@67
|
815 action = new QAction(icon, mainText, this);
|
Chris@67
|
816 }
|
Chris@67
|
817
|
Chris@66
|
818 action->setShortcut(shortcutText);
|
Chris@66
|
819 action->setStatusTip(tipText);
|
Chris@66
|
820 if (menuType == 0) {
|
Chris@66
|
821 connect(action, SIGNAL(triggered()),
|
Chris@66
|
822 this, SLOT(addPane()));
|
Chris@66
|
823 connect(this, SIGNAL(canAddPane(bool)),
|
Chris@66
|
824 action, SLOT(setEnabled(bool)));
|
Chris@66
|
825 m_paneActions[action] = PaneConfiguration(type);
|
Chris@66
|
826 } else {
|
Chris@66
|
827 connect(action, SIGNAL(triggered()),
|
Chris@66
|
828 this, SLOT(addLayer()));
|
Chris@66
|
829 connect(this, SIGNAL(canAddLayer(bool)),
|
Chris@66
|
830 action, SLOT(setEnabled(bool)));
|
Chris@66
|
831 m_layerActions[action] = type;
|
Chris@66
|
832 }
|
Chris@66
|
833 menu->addAction(action);
|
Chris@66
|
834
|
Chris@66
|
835 } else {
|
Chris@66
|
836
|
Chris@66
|
837 if (!submenu) {
|
Chris@66
|
838 submenu = menu->addMenu(mainText);
|
Chris@67
|
839 } else if (isDefault) {
|
Chris@67
|
840 submenu->addSeparator();
|
Chris@66
|
841 }
|
Chris@66
|
842
|
Chris@66
|
843 QString actionText;
|
Chris@66
|
844 if (c == 0) {
|
Chris@66
|
845 if (mono) {
|
Chris@66
|
846 actionText = tr("&All Channels Mixed");
|
Chris@66
|
847 } else {
|
Chris@66
|
848 actionText = tr("&All Channels");
|
Chris@66
|
849 }
|
Chris@66
|
850 } else {
|
Chris@66
|
851 actionText = tr("Channel &%1").arg(c);
|
Chris@66
|
852 }
|
Chris@66
|
853
|
Chris@66
|
854 if (model) {
|
Chris@66
|
855 actionText = tr("%1: %2")
|
Chris@66
|
856 .arg(model->objectName())
|
Chris@66
|
857 .arg(actionText);
|
Chris@66
|
858 }
|
Chris@67
|
859
|
Chris@67
|
860 if (isDefault) {
|
Chris@67
|
861 action = new QAction(icon, actionText, this);
|
Chris@67
|
862 if (!model || model == getMainModel()) {
|
Chris@67
|
863 action->setShortcut(shortcutText);
|
Chris@67
|
864 }
|
Chris@67
|
865 } else {
|
Chris@67
|
866 action = new QAction(actionText, this);
|
Chris@67
|
867 }
|
Chris@67
|
868
|
Chris@66
|
869 action->setStatusTip(tipText);
|
Chris@66
|
870
|
Chris@66
|
871 if (menuType == 0) {
|
Chris@66
|
872 connect(action, SIGNAL(triggered()),
|
Chris@66
|
873 this, SLOT(addPane()));
|
Chris@66
|
874 connect(this, SIGNAL(canAddPane(bool)),
|
Chris@66
|
875 action, SLOT(setEnabled(bool)));
|
Chris@66
|
876 m_paneActions[action] =
|
Chris@66
|
877 PaneConfiguration(type, model, c - 1);
|
Chris@66
|
878 } else {
|
Chris@66
|
879 connect(action, SIGNAL(triggered()),
|
Chris@66
|
880 this, SLOT(addLayer()));
|
Chris@66
|
881 connect(this, SIGNAL(canAddLayer(bool)),
|
Chris@66
|
882 action, SLOT(setEnabled(bool)));
|
Chris@66
|
883 m_layerActions[action] = type;
|
Chris@66
|
884 }
|
Chris@66
|
885
|
Chris@66
|
886 submenu->addAction(action);
|
Chris@66
|
887 }
|
Chris@66
|
888 }
|
Chris@66
|
889 }
|
Chris@66
|
890 }
|
Chris@66
|
891 }
|
Chris@66
|
892
|
Chris@66
|
893 menu = m_paneMenu;
|
Chris@66
|
894
|
Chris@66
|
895 menu->addSeparator();
|
Chris@66
|
896
|
Chris@66
|
897 action = new QAction(QIcon(":/icons/editdelete.png"), tr("&Delete Pane"), this);
|
Chris@66
|
898 action->setShortcut(tr("Alt+D"));
|
Chris@66
|
899 action->setStatusTip(tr("Delete the currently selected pane"));
|
Chris@66
|
900 connect(action, SIGNAL(triggered()), this, SLOT(deleteCurrentPane()));
|
Chris@66
|
901 connect(this, SIGNAL(canDeleteCurrentPane(bool)), action, SLOT(setEnabled(bool)));
|
Chris@66
|
902 menu->addAction(action);
|
Chris@66
|
903
|
Chris@66
|
904 menu = m_layerMenu;
|
Chris@66
|
905
|
Chris@66
|
906 action = new QAction(QIcon(":/icons/timeruler.png"), tr("Add &Time Ruler"), this);
|
Chris@66
|
907 action->setStatusTip(tr("Add a new layer showing a time ruler"));
|
Chris@66
|
908 connect(action, SIGNAL(triggered()), this, SLOT(addLayer()));
|
Chris@66
|
909 connect(this, SIGNAL(canAddLayer(bool)), action, SLOT(setEnabled(bool)));
|
Chris@66
|
910 m_layerActions[action] = LayerFactory::TimeRuler;
|
Chris@66
|
911 menu->addAction(action);
|
Chris@66
|
912
|
Chris@66
|
913 menu->addSeparator();
|
Chris@66
|
914
|
Chris@66
|
915 m_existingLayersMenu = menu->addMenu(tr("Add &Existing Layer"));
|
Chris@66
|
916 m_rightButtonLayerMenu->addMenu(m_existingLayersMenu);
|
Chris@66
|
917 setupExistingLayersMenu();
|
Chris@66
|
918
|
Chris@66
|
919 m_rightButtonLayerMenu->addSeparator();
|
Chris@66
|
920 menu->addSeparator();
|
Chris@66
|
921
|
Chris@66
|
922 action = new QAction(tr("&Rename Layer..."), this);
|
Chris@66
|
923 action->setShortcut(tr("Alt+R"));
|
Chris@66
|
924 action->setStatusTip(tr("Rename the currently active layer"));
|
Chris@66
|
925 connect(action, SIGNAL(triggered()), this, SLOT(renameCurrentLayer()));
|
Chris@66
|
926 connect(this, SIGNAL(canRenameLayer(bool)), action, SLOT(setEnabled(bool)));
|
Chris@66
|
927 menu->addAction(action);
|
Chris@66
|
928 m_rightButtonLayerMenu->addAction(action);
|
Chris@66
|
929
|
Chris@66
|
930 action = new QAction(QIcon(":/icons/editdelete.png"), tr("&Delete Layer"), this);
|
Chris@66
|
931 action->setShortcut(tr("Alt+Shift+D"));
|
Chris@66
|
932 action->setStatusTip(tr("Delete the currently active layer"));
|
Chris@66
|
933 connect(action, SIGNAL(triggered()), this, SLOT(deleteCurrentLayer()));
|
Chris@66
|
934 connect(this, SIGNAL(canDeleteCurrentLayer(bool)), action, SLOT(setEnabled(bool)));
|
Chris@66
|
935 menu->addAction(action);
|
Chris@66
|
936 m_rightButtonLayerMenu->addAction(action);
|
Chris@66
|
937 }
|
Chris@66
|
938
|
Chris@66
|
939 void
|
Chris@66
|
940 MainWindow::setupTransformsMenu()
|
Chris@66
|
941 {
|
Chris@34
|
942 if (m_transformsMenu) {
|
Chris@34
|
943 m_transformActions.clear();
|
Chris@34
|
944 m_transformActionsReverse.clear();
|
Chris@34
|
945 m_transformsMenu->clear();
|
Chris@34
|
946 } else {
|
Chris@34
|
947 m_transformsMenu = menuBar()->addMenu(tr("&Transform"));
|
Chris@34
|
948 }
|
Chris@34
|
949
|
Chris@0
|
950 TransformFactory::TransformList transforms =
|
Chris@0
|
951 TransformFactory::getInstance()->getAllTransforms();
|
Chris@0
|
952
|
Chris@33
|
953 vector<QString> types =
|
Chris@0
|
954 TransformFactory::getInstance()->getAllTransformTypes();
|
Chris@0
|
955
|
Chris@37
|
956 map<QString, map<QString, SubdividingMenu *> > categoryMenus;
|
Chris@37
|
957 map<QString, map<QString, SubdividingMenu *> > makerMenus;
|
Chris@33
|
958
|
Chris@36
|
959 map<QString, SubdividingMenu *> byPluginNameMenus;
|
Chris@33
|
960 map<QString, map<QString, QMenu *> > pluginNameMenus;
|
Chris@33
|
961
|
Chris@37
|
962 set<SubdividingMenu *> pendingMenus;
|
Chris@37
|
963
|
Chris@34
|
964 m_recentTransformsMenu = m_transformsMenu->addMenu(tr("&Recent Transforms"));
|
Chris@34
|
965 m_rightButtonTransformsMenu->addMenu(m_recentTransformsMenu);
|
Chris@34
|
966 connect(&m_recentTransforms, SIGNAL(recentChanged()),
|
Chris@34
|
967 this, SLOT(setupRecentTransformsMenu()));
|
Chris@34
|
968
|
Chris@34
|
969 m_transformsMenu->addSeparator();
|
Chris@34
|
970 m_rightButtonTransformsMenu->addSeparator();
|
Chris@34
|
971
|
Chris@33
|
972 for (vector<QString>::iterator i = types.begin(); i != types.end(); ++i) {
|
Chris@33
|
973
|
Chris@33
|
974 if (i != types.begin()) {
|
Chris@34
|
975 m_transformsMenu->addSeparator();
|
Chris@34
|
976 m_rightButtonTransformsMenu->addSeparator();
|
Chris@33
|
977 }
|
Chris@33
|
978
|
Chris@33
|
979 QString byCategoryLabel = tr("%1 by Category").arg(*i);
|
Chris@37
|
980 SubdividingMenu *byCategoryMenu = new SubdividingMenu(byCategoryLabel,
|
Chris@37
|
981 20, 40);
|
Chris@37
|
982 m_transformsMenu->addMenu(byCategoryMenu);
|
Chris@34
|
983 m_rightButtonTransformsMenu->addMenu(byCategoryMenu);
|
Chris@37
|
984 pendingMenus.insert(byCategoryMenu);
|
Chris@33
|
985
|
Chris@33
|
986 vector<QString> categories =
|
Chris@33
|
987 TransformFactory::getInstance()->getTransformCategories(*i);
|
Chris@33
|
988
|
Chris@33
|
989 for (vector<QString>::iterator j = categories.begin();
|
Chris@33
|
990 j != categories.end(); ++j) {
|
Chris@33
|
991
|
Chris@33
|
992 QString category = *j;
|
Chris@33
|
993 if (category == "") category = tr("Unclassified");
|
Chris@33
|
994
|
Chris@33
|
995 if (categories.size() < 2) {
|
Chris@33
|
996 categoryMenus[*i][category] = byCategoryMenu;
|
Chris@33
|
997 continue;
|
Chris@33
|
998 }
|
Chris@33
|
999
|
Chris@33
|
1000 QStringList components = category.split(" > ");
|
Chris@33
|
1001 QString key;
|
Chris@33
|
1002
|
Chris@33
|
1003 for (QStringList::iterator k = components.begin();
|
Chris@33
|
1004 k != components.end(); ++k) {
|
Chris@33
|
1005
|
Chris@33
|
1006 QString parentKey = key;
|
Chris@33
|
1007 if (key != "") key += " > ";
|
Chris@33
|
1008 key += *k;
|
Chris@33
|
1009
|
Chris@33
|
1010 if (categoryMenus[*i].find(key) == categoryMenus[*i].end()) {
|
Chris@37
|
1011 SubdividingMenu *m = new SubdividingMenu(*k, 20, 40);
|
Chris@37
|
1012 pendingMenus.insert(m);
|
Chris@37
|
1013 categoryMenus[*i][key] = m;
|
Chris@33
|
1014 if (parentKey == "") {
|
Chris@37
|
1015 byCategoryMenu->addMenu(m);
|
Chris@33
|
1016 } else {
|
Chris@37
|
1017 categoryMenus[*i][parentKey]->addMenu(m);
|
Chris@33
|
1018 }
|
Chris@33
|
1019 }
|
Chris@33
|
1020 }
|
Chris@33
|
1021 }
|
Chris@33
|
1022
|
Chris@34
|
1023 QString byPluginNameLabel = tr("%1 by Plugin Name").arg(*i);
|
Chris@36
|
1024 byPluginNameMenus[*i] = new SubdividingMenu(byPluginNameLabel);
|
Chris@36
|
1025 m_transformsMenu->addMenu(byPluginNameMenus[*i]);
|
Chris@34
|
1026 m_rightButtonTransformsMenu->addMenu(byPluginNameMenus[*i]);
|
Chris@37
|
1027 pendingMenus.insert(byPluginNameMenus[*i]);
|
Chris@34
|
1028
|
Chris@33
|
1029 QString byMakerLabel = tr("%1 by Maker").arg(*i);
|
Chris@37
|
1030 SubdividingMenu *byMakerMenu = new SubdividingMenu(byMakerLabel, 20, 40);
|
Chris@37
|
1031 m_transformsMenu->addMenu(byMakerMenu);
|
Chris@34
|
1032 m_rightButtonTransformsMenu->addMenu(byMakerMenu);
|
Chris@37
|
1033 pendingMenus.insert(byMakerMenu);
|
Chris@33
|
1034
|
Chris@33
|
1035 vector<QString> makers =
|
Chris@33
|
1036 TransformFactory::getInstance()->getTransformMakers(*i);
|
Chris@37
|
1037
|
Chris@33
|
1038 for (vector<QString>::iterator j = makers.begin();
|
Chris@33
|
1039 j != makers.end(); ++j) {
|
Chris@33
|
1040
|
Chris@33
|
1041 QString maker = *j;
|
Chris@33
|
1042 if (maker == "") maker = tr("Unknown");
|
Chris@55
|
1043 maker.replace(QRegExp(tr(" [\\(<].*$")), "");
|
Chris@55
|
1044
|
Chris@37
|
1045 makerMenus[*i][maker] = new SubdividingMenu(maker, 30, 40);
|
Chris@37
|
1046 byMakerMenu->addMenu(makerMenus[*i][maker]);
|
Chris@37
|
1047 pendingMenus.insert(makerMenus[*i][maker]);
|
Chris@33
|
1048 }
|
Chris@0
|
1049 }
|
Chris@0
|
1050
|
Chris@0
|
1051 for (unsigned int i = 0; i < transforms.size(); ++i) {
|
Chris@0
|
1052
|
Chris@0
|
1053 QString description = transforms[i].description;
|
Chris@0
|
1054 if (description == "") description = transforms[i].name;
|
Chris@0
|
1055
|
Chris@33
|
1056 QString type = transforms[i].type;
|
Chris@33
|
1057
|
Chris@33
|
1058 QString category = transforms[i].category;
|
Chris@33
|
1059 if (category == "") category = tr("Unclassified");
|
Chris@33
|
1060
|
Chris@33
|
1061 QString maker = transforms[i].maker;
|
Chris@33
|
1062 if (maker == "") maker = tr("Unknown");
|
Chris@55
|
1063 maker.replace(QRegExp(tr(" [\\(<].*$")), "");
|
Chris@33
|
1064
|
Chris@33
|
1065 QString pluginName = description.section(": ", 0, 0);
|
Chris@33
|
1066 QString output = description.section(": ", 1);
|
Chris@33
|
1067
|
Chris@66
|
1068 QAction *action = new QAction(tr("%1...").arg(description), this);
|
Chris@0
|
1069 connect(action, SIGNAL(triggered()), this, SLOT(addLayer()));
|
Chris@34
|
1070 m_transformActions[action] = transforms[i].name;
|
Chris@34
|
1071 m_transformActionsReverse[transforms[i].name] = action;
|
Chris@0
|
1072 connect(this, SIGNAL(canAddLayer(bool)), action, SLOT(setEnabled(bool)));
|
Chris@33
|
1073
|
Chris@33
|
1074 if (categoryMenus[type].find(category) == categoryMenus[type].end()) {
|
Chris@33
|
1075 std::cerr << "WARNING: MainWindow::setupMenus: Internal error: "
|
Chris@33
|
1076 << "No category menu for transform \""
|
Chris@33
|
1077 << description.toStdString() << "\" (category = \""
|
Chris@33
|
1078 << category.toStdString() << "\")" << std::endl;
|
Chris@33
|
1079 } else {
|
Chris@33
|
1080 categoryMenus[type][category]->addAction(action);
|
Chris@33
|
1081 }
|
Chris@33
|
1082
|
Chris@33
|
1083 if (makerMenus[type].find(maker) == makerMenus[type].end()) {
|
Chris@33
|
1084 std::cerr << "WARNING: MainWindow::setupMenus: Internal error: "
|
Chris@33
|
1085 << "No maker menu for transform \""
|
Chris@33
|
1086 << description.toStdString() << "\" (maker = \""
|
Chris@33
|
1087 << maker.toStdString() << "\")" << std::endl;
|
Chris@33
|
1088 } else {
|
Chris@37
|
1089 makerMenus[type][maker]->addAction(pluginName, action);
|
Chris@33
|
1090 }
|
Chris@33
|
1091
|
Chris@33
|
1092 action = new QAction(tr("%1...").arg(output == "" ? pluginName : output), this);
|
Chris@33
|
1093 connect(action, SIGNAL(triggered()), this, SLOT(addLayer()));
|
Chris@34
|
1094 m_transformActions[action] = transforms[i].name;
|
Chris@33
|
1095 connect(this, SIGNAL(canAddLayer(bool)), action, SLOT(setEnabled(bool)));
|
Chris@33
|
1096
|
Chris@34
|
1097 // cerr << "Transform: \"" << name.toStdString() << "\": plugin name \"" << pluginName.toStdString() << "\"" << endl;
|
Chris@34
|
1098
|
Chris@33
|
1099 if (pluginNameMenus[type].find(pluginName) ==
|
Chris@33
|
1100 pluginNameMenus[type].end()) {
|
Chris@33
|
1101
|
Chris@36
|
1102 SubdividingMenu *parentMenu = byPluginNameMenus[type];
|
Chris@34
|
1103
|
Chris@33
|
1104 if (output == "") {
|
Chris@36
|
1105 parentMenu->addAction(pluginName, action);
|
Chris@33
|
1106 } else {
|
Chris@34
|
1107 pluginNameMenus[type][pluginName] =
|
Chris@34
|
1108 parentMenu->addMenu(pluginName);
|
Chris@33
|
1109 connect(this, SIGNAL(canAddLayer(bool)),
|
Chris@33
|
1110 pluginNameMenus[type][pluginName],
|
Chris@33
|
1111 SLOT(setEnabled(bool)));
|
Chris@33
|
1112 }
|
Chris@33
|
1113 }
|
Chris@33
|
1114
|
Chris@33
|
1115 if (pluginNameMenus[type].find(pluginName) !=
|
Chris@33
|
1116 pluginNameMenus[type].end()) {
|
Chris@33
|
1117 pluginNameMenus[type][pluginName]->addAction(action);
|
Chris@33
|
1118 }
|
Chris@0
|
1119 }
|
Chris@0
|
1120
|
Chris@37
|
1121 for (set<SubdividingMenu *>::iterator i = pendingMenus.begin();
|
Chris@37
|
1122 i != pendingMenus.end(); ++i) {
|
Chris@37
|
1123 (*i)->entriesAdded();
|
Chris@37
|
1124 }
|
Chris@37
|
1125
|
Chris@34
|
1126 setupRecentTransformsMenu();
|
Chris@66
|
1127 }
|
Chris@66
|
1128
|
Chris@66
|
1129 void
|
Chris@66
|
1130 MainWindow::setupHelpMenu()
|
Chris@66
|
1131 {
|
Chris@66
|
1132 if (m_mainMenusCreated) return;
|
Chris@66
|
1133
|
Chris@66
|
1134 QMenu *menu = menuBar()->addMenu(tr("&Help"));
|
Chris@66
|
1135
|
Chris@66
|
1136 QAction *action = new QAction(tr("&Help Reference"), this);
|
Chris@66
|
1137 action->setStatusTip(tr("Open the Sonic Visualiser reference manual"));
|
Chris@66
|
1138 connect(action, SIGNAL(triggered()), this, SLOT(help()));
|
Chris@0
|
1139 menu->addAction(action);
|
Chris@0
|
1140
|
Chris@66
|
1141 action = new QAction(tr("Sonic Visualiser on the &Web"), this);
|
Chris@66
|
1142 action->setStatusTip(tr("Open the Sonic Visualiser website"));
|
Chris@66
|
1143 connect(action, SIGNAL(triggered()), this, SLOT(website()));
|
Chris@0
|
1144 menu->addAction(action);
|
Chris@66
|
1145
|
Chris@66
|
1146 action = new QAction(tr("&About Sonic Visualiser"), this);
|
Chris@66
|
1147 action->setStatusTip(tr("Show information about Sonic Visualiser"));
|
Chris@66
|
1148 connect(action, SIGNAL(triggered()), this, SLOT(about()));
|
Chris@0
|
1149 menu->addAction(action);
|
Chris@0
|
1150 }
|
Chris@0
|
1151
|
Chris@0
|
1152 void
|
Chris@0
|
1153 MainWindow::setupRecentFilesMenu()
|
Chris@0
|
1154 {
|
Chris@0
|
1155 m_recentFilesMenu->clear();
|
Chris@34
|
1156 vector<QString> files = m_recentFiles.getRecent();
|
Chris@0
|
1157 for (size_t i = 0; i < files.size(); ++i) {
|
Chris@0
|
1158 QAction *action = new QAction(files[i], this);
|
Chris@0
|
1159 connect(action, SIGNAL(triggered()), this, SLOT(openRecentFile()));
|
Chris@0
|
1160 m_recentFilesMenu->addAction(action);
|
Chris@0
|
1161 }
|
Chris@0
|
1162 }
|
Chris@0
|
1163
|
Chris@0
|
1164 void
|
Chris@34
|
1165 MainWindow::setupRecentTransformsMenu()
|
Chris@34
|
1166 {
|
Chris@34
|
1167 m_recentTransformsMenu->clear();
|
Chris@34
|
1168 vector<QString> transforms = m_recentTransforms.getRecent();
|
Chris@34
|
1169 for (size_t i = 0; i < transforms.size(); ++i) {
|
Chris@34
|
1170 TransformActionReverseMap::iterator ti =
|
Chris@34
|
1171 m_transformActionsReverse.find(transforms[i]);
|
Chris@34
|
1172 if (ti == m_transformActionsReverse.end()) {
|
Chris@34
|
1173 std::cerr << "WARNING: MainWindow::setupRecentTransformsMenu: "
|
Chris@34
|
1174 << "Unknown transform \"" << transforms[i].toStdString()
|
Chris@34
|
1175 << "\" in recent transforms list" << std::endl;
|
Chris@34
|
1176 continue;
|
Chris@34
|
1177 }
|
Chris@34
|
1178 m_recentTransformsMenu->addAction(ti->second);
|
Chris@34
|
1179 }
|
Chris@34
|
1180 }
|
Chris@34
|
1181
|
Chris@34
|
1182 void
|
Chris@0
|
1183 MainWindow::setupExistingLayersMenu()
|
Chris@0
|
1184 {
|
Chris@0
|
1185 if (!m_existingLayersMenu) return; // should have been created by setupMenus
|
Chris@0
|
1186
|
Chris@0
|
1187 // std::cerr << "MainWindow::setupExistingLayersMenu" << std::endl;
|
Chris@0
|
1188
|
Chris@0
|
1189 m_existingLayersMenu->clear();
|
Chris@0
|
1190 m_existingLayerActions.clear();
|
Chris@0
|
1191
|
Chris@33
|
1192 vector<Layer *> orderedLayers;
|
Chris@33
|
1193 set<Layer *> observedLayers;
|
Chris@0
|
1194
|
Chris@0
|
1195 for (int i = 0; i < m_paneStack->getPaneCount(); ++i) {
|
Chris@0
|
1196
|
Chris@0
|
1197 Pane *pane = m_paneStack->getPane(i);
|
Chris@0
|
1198 if (!pane) continue;
|
Chris@0
|
1199
|
Chris@0
|
1200 for (int j = 0; j < pane->getLayerCount(); ++j) {
|
Chris@0
|
1201
|
Chris@0
|
1202 Layer *layer = pane->getLayer(j);
|
Chris@0
|
1203 if (!layer) continue;
|
Chris@0
|
1204 if (observedLayers.find(layer) != observedLayers.end()) {
|
Chris@0
|
1205 std::cerr << "found duplicate layer " << layer << std::endl;
|
Chris@0
|
1206 continue;
|
Chris@0
|
1207 }
|
Chris@0
|
1208
|
Chris@0
|
1209 // std::cerr << "found new layer " << layer << " (name = "
|
Chris@0
|
1210 // << layer->getLayerPresentationName().toStdString() << ")" << std::endl;
|
Chris@0
|
1211
|
Chris@0
|
1212 orderedLayers.push_back(layer);
|
Chris@0
|
1213 observedLayers.insert(layer);
|
Chris@0
|
1214 }
|
Chris@0
|
1215 }
|
Chris@0
|
1216
|
Chris@33
|
1217 map<QString, int> observedNames;
|
Chris@0
|
1218
|
Chris@0
|
1219 for (int i = 0; i < orderedLayers.size(); ++i) {
|
Chris@0
|
1220
|
Chris@0
|
1221 QString name = orderedLayers[i]->getLayerPresentationName();
|
Chris@0
|
1222 int n = ++observedNames[name];
|
Chris@0
|
1223 if (n > 1) name = QString("%1 <%2>").arg(name).arg(n);
|
Chris@0
|
1224
|
Chris@0
|
1225 QAction *action = new QAction(name, this);
|
Chris@0
|
1226 connect(action, SIGNAL(triggered()), this, SLOT(addLayer()));
|
Chris@0
|
1227 connect(this, SIGNAL(canAddLayer(bool)), action, SLOT(setEnabled(bool)));
|
Chris@0
|
1228 m_existingLayerActions[action] = orderedLayers[i];
|
Chris@0
|
1229
|
Chris@0
|
1230 m_existingLayersMenu->addAction(action);
|
Chris@0
|
1231 }
|
Chris@0
|
1232 }
|
Chris@0
|
1233
|
Chris@0
|
1234 void
|
Chris@0
|
1235 MainWindow::setupToolbars()
|
Chris@0
|
1236 {
|
Chris@0
|
1237 QToolBar *toolbar = addToolBar(tr("Transport Toolbar"));
|
Chris@0
|
1238
|
Chris@0
|
1239 QAction *action = toolbar->addAction(QIcon(":/icons/rewind-start.png"),
|
Chris@0
|
1240 tr("Rewind to Start"));
|
Chris@0
|
1241 action->setShortcut(tr("Home"));
|
Chris@0
|
1242 action->setStatusTip(tr("Rewind to the start"));
|
Chris@0
|
1243 connect(action, SIGNAL(triggered()), this, SLOT(rewindStart()));
|
Chris@0
|
1244 connect(this, SIGNAL(canPlay(bool)), action, SLOT(setEnabled(bool)));
|
Chris@0
|
1245
|
Chris@0
|
1246 action = toolbar->addAction(QIcon(":/icons/rewind.png"),
|
Chris@0
|
1247 tr("Rewind"));
|
Chris@0
|
1248 action->setShortcut(tr("PageUp"));
|
Chris@0
|
1249 action->setStatusTip(tr("Rewind to the previous time instant in the current layer"));
|
Chris@0
|
1250 connect(action, SIGNAL(triggered()), this, SLOT(rewind()));
|
Chris@0
|
1251 connect(this, SIGNAL(canRewind(bool)), action, SLOT(setEnabled(bool)));
|
Chris@0
|
1252
|
Chris@0
|
1253 action = toolbar->addAction(QIcon(":/icons/playpause.png"),
|
Chris@0
|
1254 tr("Play / Pause"));
|
Chris@0
|
1255 action->setCheckable(true);
|
Chris@0
|
1256 action->setShortcut(tr("Space"));
|
Chris@0
|
1257 action->setStatusTip(tr("Start or stop playback from the current position"));
|
Chris@0
|
1258 connect(action, SIGNAL(triggered()), this, SLOT(play()));
|
Chris@0
|
1259 connect(m_playSource, SIGNAL(playStatusChanged(bool)),
|
Chris@0
|
1260 action, SLOT(setChecked(bool)));
|
Chris@0
|
1261 connect(this, SIGNAL(canPlay(bool)), action, SLOT(setEnabled(bool)));
|
Chris@0
|
1262
|
Chris@0
|
1263 action = toolbar->addAction(QIcon(":/icons/ffwd.png"),
|
Chris@0
|
1264 tr("Fast Forward"));
|
Chris@0
|
1265 action->setShortcut(tr("PageDown"));
|
Chris@0
|
1266 action->setStatusTip(tr("Fast forward to the next time instant in the current layer"));
|
Chris@0
|
1267 connect(action, SIGNAL(triggered()), this, SLOT(ffwd()));
|
Chris@0
|
1268 connect(this, SIGNAL(canFfwd(bool)), action, SLOT(setEnabled(bool)));
|
Chris@0
|
1269
|
Chris@0
|
1270 action = toolbar->addAction(QIcon(":/icons/ffwd-end.png"),
|
Chris@0
|
1271 tr("Fast Forward to End"));
|
Chris@0
|
1272 action->setShortcut(tr("End"));
|
Chris@0
|
1273 action->setStatusTip(tr("Fast-forward to the end"));
|
Chris@0
|
1274 connect(action, SIGNAL(triggered()), this, SLOT(ffwdEnd()));
|
Chris@0
|
1275 connect(this, SIGNAL(canPlay(bool)), action, SLOT(setEnabled(bool)));
|
Chris@0
|
1276
|
Chris@0
|
1277 toolbar = addToolBar(tr("Play Mode Toolbar"));
|
Chris@0
|
1278
|
Chris@0
|
1279 action = toolbar->addAction(QIcon(":/icons/playselection.png"),
|
Chris@0
|
1280 tr("Constrain Playback to Selection"));
|
Chris@0
|
1281 action->setCheckable(true);
|
Chris@0
|
1282 action->setChecked(m_viewManager->getPlaySelectionMode());
|
Chris@0
|
1283 action->setShortcut(tr("s"));
|
Chris@0
|
1284 action->setStatusTip(tr("Constrain playback to the selected area"));
|
Chris@69
|
1285 connect(m_viewManager, SIGNAL(playSelectionModeChanged(bool)),
|
Chris@69
|
1286 action, SLOT(setChecked(bool)));
|
Chris@0
|
1287 connect(action, SIGNAL(triggered()), this, SLOT(playSelectionToggled()));
|
Chris@0
|
1288 connect(this, SIGNAL(canPlaySelection(bool)), action, SLOT(setEnabled(bool)));
|
Chris@0
|
1289
|
Chris@0
|
1290 action = toolbar->addAction(QIcon(":/icons/playloop.png"),
|
Chris@0
|
1291 tr("Loop Playback"));
|
Chris@0
|
1292 action->setCheckable(true);
|
Chris@0
|
1293 action->setChecked(m_viewManager->getPlayLoopMode());
|
Chris@0
|
1294 action->setShortcut(tr("l"));
|
Chris@0
|
1295 action->setStatusTip(tr("Loop playback"));
|
Chris@69
|
1296 connect(m_viewManager, SIGNAL(playLoopModeChanged(bool)),
|
Chris@69
|
1297 action, SLOT(setChecked(bool)));
|
Chris@0
|
1298 connect(action, SIGNAL(triggered()), this, SLOT(playLoopToggled()));
|
Chris@0
|
1299 connect(this, SIGNAL(canPlay(bool)), action, SLOT(setEnabled(bool)));
|
Chris@0
|
1300
|
Chris@0
|
1301 toolbar = addToolBar(tr("Edit Toolbar"));
|
Chris@0
|
1302 CommandHistory::getInstance()->registerToolbar(toolbar);
|
Chris@0
|
1303
|
Chris@0
|
1304 toolbar = addToolBar(tr("Tools Toolbar"));
|
Chris@0
|
1305 QActionGroup *group = new QActionGroup(this);
|
Chris@0
|
1306
|
Chris@0
|
1307 action = toolbar->addAction(QIcon(":/icons/navigate.png"),
|
Chris@0
|
1308 tr("Navigate"));
|
Chris@0
|
1309 action->setCheckable(true);
|
Chris@0
|
1310 action->setChecked(true);
|
Chris@0
|
1311 action->setShortcut(tr("1"));
|
Chris@0
|
1312 connect(action, SIGNAL(triggered()), this, SLOT(toolNavigateSelected()));
|
Chris@0
|
1313 group->addAction(action);
|
Chris@0
|
1314 m_toolActions[ViewManager::NavigateMode] = action;
|
Chris@0
|
1315
|
Chris@0
|
1316 action = toolbar->addAction(QIcon(":/icons/select.png"),
|
Chris@0
|
1317 tr("Select"));
|
Chris@0
|
1318 action->setCheckable(true);
|
Chris@0
|
1319 action->setShortcut(tr("2"));
|
Chris@0
|
1320 connect(action, SIGNAL(triggered()), this, SLOT(toolSelectSelected()));
|
Chris@0
|
1321 group->addAction(action);
|
Chris@0
|
1322 m_toolActions[ViewManager::SelectMode] = action;
|
Chris@0
|
1323
|
Chris@0
|
1324 action = toolbar->addAction(QIcon(":/icons/move.png"),
|
Chris@0
|
1325 tr("Edit"));
|
Chris@0
|
1326 action->setCheckable(true);
|
Chris@0
|
1327 action->setShortcut(tr("3"));
|
Chris@0
|
1328 connect(action, SIGNAL(triggered()), this, SLOT(toolEditSelected()));
|
Chris@0
|
1329 connect(this, SIGNAL(canEditLayer(bool)), action, SLOT(setEnabled(bool)));
|
Chris@0
|
1330 group->addAction(action);
|
Chris@0
|
1331 m_toolActions[ViewManager::EditMode] = action;
|
Chris@0
|
1332
|
Chris@0
|
1333 action = toolbar->addAction(QIcon(":/icons/draw.png"),
|
Chris@0
|
1334 tr("Draw"));
|
Chris@0
|
1335 action->setCheckable(true);
|
Chris@0
|
1336 action->setShortcut(tr("4"));
|
Chris@0
|
1337 connect(action, SIGNAL(triggered()), this, SLOT(toolDrawSelected()));
|
Chris@0
|
1338 connect(this, SIGNAL(canEditLayer(bool)), action, SLOT(setEnabled(bool)));
|
Chris@0
|
1339 group->addAction(action);
|
Chris@0
|
1340 m_toolActions[ViewManager::DrawMode] = action;
|
Chris@0
|
1341
|
Chris@0
|
1342 // action = toolbar->addAction(QIcon(":/icons/text.png"),
|
Chris@0
|
1343 // tr("Text"));
|
Chris@0
|
1344 // action->setCheckable(true);
|
Chris@0
|
1345 // action->setShortcut(tr("5"));
|
Chris@0
|
1346 // connect(action, SIGNAL(triggered()), this, SLOT(toolTextSelected()));
|
Chris@0
|
1347 // group->addAction(action);
|
Chris@0
|
1348 // m_toolActions[ViewManager::TextMode] = action;
|
Chris@0
|
1349
|
Chris@0
|
1350 toolNavigateSelected();
|
Chris@0
|
1351 }
|
Chris@0
|
1352
|
Chris@0
|
1353 void
|
Chris@0
|
1354 MainWindow::updateMenuStates()
|
Chris@0
|
1355 {
|
Chris@0
|
1356 bool haveCurrentPane =
|
Chris@0
|
1357 (m_paneStack &&
|
Chris@0
|
1358 (m_paneStack->getCurrentPane() != 0));
|
Chris@0
|
1359 bool haveCurrentLayer =
|
Chris@0
|
1360 (haveCurrentPane &&
|
Chris@0
|
1361 (m_paneStack->getCurrentPane()->getSelectedLayer()));
|
Chris@0
|
1362 bool haveMainModel =
|
Chris@0
|
1363 (getMainModel() != 0);
|
Chris@0
|
1364 bool havePlayTarget =
|
Chris@0
|
1365 (m_playTarget != 0);
|
Chris@0
|
1366 bool haveSelection =
|
Chris@0
|
1367 (m_viewManager &&
|
Chris@0
|
1368 !m_viewManager->getSelections().empty());
|
Chris@0
|
1369 bool haveCurrentEditableLayer =
|
Chris@0
|
1370 (haveCurrentLayer &&
|
Chris@0
|
1371 m_paneStack->getCurrentPane()->getSelectedLayer()->
|
Chris@0
|
1372 isLayerEditable());
|
Chris@0
|
1373 bool haveCurrentTimeInstantsLayer =
|
Chris@0
|
1374 (haveCurrentLayer &&
|
Chris@0
|
1375 dynamic_cast<TimeInstantLayer *>
|
Chris@0
|
1376 (m_paneStack->getCurrentPane()->getSelectedLayer()));
|
Chris@0
|
1377 bool haveCurrentTimeValueLayer =
|
Chris@0
|
1378 (haveCurrentLayer &&
|
Chris@0
|
1379 dynamic_cast<TimeValueLayer *>
|
Chris@0
|
1380 (m_paneStack->getCurrentPane()->getSelectedLayer()));
|
Chris@0
|
1381 bool haveCurrentColour3DPlot =
|
Chris@0
|
1382 (haveCurrentLayer &&
|
Chris@0
|
1383 dynamic_cast<Colour3DPlotLayer *>
|
Chris@0
|
1384 (m_paneStack->getCurrentPane()->getSelectedLayer()));
|
Chris@0
|
1385 bool haveClipboardContents =
|
Chris@0
|
1386 (m_viewManager &&
|
Chris@0
|
1387 !m_viewManager->getClipboard().empty());
|
Chris@0
|
1388
|
Chris@0
|
1389 emit canAddPane(haveMainModel);
|
Chris@0
|
1390 emit canDeleteCurrentPane(haveCurrentPane);
|
Chris@0
|
1391 emit canZoom(haveMainModel && haveCurrentPane);
|
Chris@0
|
1392 emit canScroll(haveMainModel && haveCurrentPane);
|
Chris@0
|
1393 emit canAddLayer(haveMainModel && haveCurrentPane);
|
Chris@0
|
1394 emit canImportMoreAudio(haveMainModel);
|
Chris@0
|
1395 emit canImportLayer(haveMainModel && haveCurrentPane);
|
Chris@0
|
1396 emit canExportAudio(haveMainModel);
|
Chris@0
|
1397 emit canExportLayer(haveMainModel &&
|
Chris@0
|
1398 (haveCurrentEditableLayer || haveCurrentColour3DPlot));
|
Chris@0
|
1399 emit canDeleteCurrentLayer(haveCurrentLayer);
|
Chris@0
|
1400 emit canRenameLayer(haveCurrentLayer);
|
Chris@0
|
1401 emit canEditLayer(haveCurrentEditableLayer);
|
Chris@0
|
1402 emit canSelect(haveMainModel && haveCurrentPane);
|
Chris@0
|
1403 emit canPlay(/*!!! haveMainModel && */ havePlayTarget);
|
Chris@0
|
1404 emit canFfwd(haveCurrentTimeInstantsLayer || haveCurrentTimeValueLayer);
|
Chris@0
|
1405 emit canRewind(haveCurrentTimeInstantsLayer || haveCurrentTimeValueLayer);
|
Chris@0
|
1406 emit canPaste(haveCurrentEditableLayer && haveClipboardContents);
|
Chris@0
|
1407 emit canInsertInstant(haveCurrentPane);
|
Chris@0
|
1408 emit canPlaySelection(haveMainModel && havePlayTarget && haveSelection);
|
Chris@0
|
1409 emit canClearSelection(haveSelection);
|
Chris@0
|
1410 emit canEditSelection(haveSelection && haveCurrentEditableLayer);
|
Chris@0
|
1411 emit canSave(m_sessionFile != "" && m_documentModified);
|
Chris@0
|
1412 }
|
Chris@0
|
1413
|
Chris@0
|
1414 void
|
Chris@0
|
1415 MainWindow::updateDescriptionLabel()
|
Chris@0
|
1416 {
|
Chris@0
|
1417 if (!getMainModel()) {
|
Chris@0
|
1418 m_descriptionLabel->setText(tr("No audio file loaded."));
|
Chris@0
|
1419 return;
|
Chris@0
|
1420 }
|
Chris@0
|
1421
|
Chris@0
|
1422 QString description;
|
Chris@0
|
1423
|
Chris@0
|
1424 size_t ssr = getMainModel()->getSampleRate();
|
Chris@0
|
1425 size_t tsr = ssr;
|
Chris@0
|
1426 if (m_playSource) tsr = m_playSource->getTargetSampleRate();
|
Chris@0
|
1427
|
Chris@0
|
1428 if (ssr != tsr) {
|
Chris@0
|
1429 description = tr("%1Hz (resampling to %2Hz)").arg(ssr).arg(tsr);
|
Chris@0
|
1430 } else {
|
Chris@0
|
1431 description = QString("%1Hz").arg(ssr);
|
Chris@0
|
1432 }
|
Chris@0
|
1433
|
Chris@0
|
1434 description = QString("%1 - %2")
|
Chris@0
|
1435 .arg(RealTime::frame2RealTime(getMainModel()->getEndFrame(), ssr)
|
Chris@0
|
1436 .toText(false).c_str())
|
Chris@0
|
1437 .arg(description);
|
Chris@0
|
1438
|
Chris@0
|
1439 m_descriptionLabel->setText(description);
|
Chris@0
|
1440 }
|
Chris@0
|
1441
|
Chris@0
|
1442 void
|
Chris@0
|
1443 MainWindow::documentModified()
|
Chris@0
|
1444 {
|
Chris@0
|
1445 // std::cerr << "MainWindow::documentModified" << std::endl;
|
Chris@0
|
1446
|
Chris@0
|
1447 if (!m_documentModified) {
|
Chris@0
|
1448 setWindowTitle(tr("%1 (modified)").arg(windowTitle()));
|
Chris@0
|
1449 }
|
Chris@0
|
1450
|
Chris@0
|
1451 m_documentModified = true;
|
Chris@0
|
1452 updateMenuStates();
|
Chris@0
|
1453 }
|
Chris@0
|
1454
|
Chris@0
|
1455 void
|
Chris@0
|
1456 MainWindow::documentRestored()
|
Chris@0
|
1457 {
|
Chris@0
|
1458 // std::cerr << "MainWindow::documentRestored" << std::endl;
|
Chris@0
|
1459
|
Chris@0
|
1460 if (m_documentModified) {
|
Chris@0
|
1461 QString wt(windowTitle());
|
Chris@0
|
1462 wt.replace(tr(" (modified)"), "");
|
Chris@0
|
1463 setWindowTitle(wt);
|
Chris@0
|
1464 }
|
Chris@0
|
1465
|
Chris@0
|
1466 m_documentModified = false;
|
Chris@0
|
1467 updateMenuStates();
|
Chris@0
|
1468 }
|
Chris@0
|
1469
|
Chris@0
|
1470 void
|
Chris@0
|
1471 MainWindow::playLoopToggled()
|
Chris@0
|
1472 {
|
Chris@0
|
1473 QAction *action = dynamic_cast<QAction *>(sender());
|
Chris@0
|
1474
|
Chris@0
|
1475 if (action) {
|
Chris@0
|
1476 m_viewManager->setPlayLoopMode(action->isChecked());
|
Chris@0
|
1477 } else {
|
Chris@0
|
1478 m_viewManager->setPlayLoopMode(!m_viewManager->getPlayLoopMode());
|
Chris@0
|
1479 }
|
Chris@0
|
1480 }
|
Chris@0
|
1481
|
Chris@0
|
1482 void
|
Chris@0
|
1483 MainWindow::playSelectionToggled()
|
Chris@0
|
1484 {
|
Chris@0
|
1485 QAction *action = dynamic_cast<QAction *>(sender());
|
Chris@0
|
1486
|
Chris@0
|
1487 if (action) {
|
Chris@0
|
1488 m_viewManager->setPlaySelectionMode(action->isChecked());
|
Chris@0
|
1489 } else {
|
Chris@0
|
1490 m_viewManager->setPlaySelectionMode(!m_viewManager->getPlaySelectionMode());
|
Chris@0
|
1491 }
|
Chris@0
|
1492 }
|
Chris@0
|
1493
|
Chris@0
|
1494 void
|
Chris@0
|
1495 MainWindow::currentPaneChanged(Pane *)
|
Chris@0
|
1496 {
|
Chris@0
|
1497 updateMenuStates();
|
Chris@0
|
1498 }
|
Chris@0
|
1499
|
Chris@0
|
1500 void
|
Chris@0
|
1501 MainWindow::currentLayerChanged(Pane *, Layer *)
|
Chris@0
|
1502 {
|
Chris@0
|
1503 updateMenuStates();
|
Chris@0
|
1504 }
|
Chris@0
|
1505
|
Chris@0
|
1506 void
|
Chris@0
|
1507 MainWindow::toolNavigateSelected()
|
Chris@0
|
1508 {
|
Chris@0
|
1509 m_viewManager->setToolMode(ViewManager::NavigateMode);
|
Chris@0
|
1510 }
|
Chris@0
|
1511
|
Chris@0
|
1512 void
|
Chris@0
|
1513 MainWindow::toolSelectSelected()
|
Chris@0
|
1514 {
|
Chris@0
|
1515 m_viewManager->setToolMode(ViewManager::SelectMode);
|
Chris@0
|
1516 }
|
Chris@0
|
1517
|
Chris@0
|
1518 void
|
Chris@0
|
1519 MainWindow::toolEditSelected()
|
Chris@0
|
1520 {
|
Chris@0
|
1521 m_viewManager->setToolMode(ViewManager::EditMode);
|
Chris@0
|
1522 }
|
Chris@0
|
1523
|
Chris@0
|
1524 void
|
Chris@0
|
1525 MainWindow::toolDrawSelected()
|
Chris@0
|
1526 {
|
Chris@0
|
1527 m_viewManager->setToolMode(ViewManager::DrawMode);
|
Chris@0
|
1528 }
|
Chris@0
|
1529
|
Chris@0
|
1530 //void
|
Chris@0
|
1531 //MainWindow::toolTextSelected()
|
Chris@0
|
1532 //{
|
Chris@0
|
1533 // m_viewManager->setToolMode(ViewManager::TextMode);
|
Chris@0
|
1534 //}
|
Chris@0
|
1535
|
Chris@0
|
1536 void
|
Chris@0
|
1537 MainWindow::selectAll()
|
Chris@0
|
1538 {
|
Chris@0
|
1539 if (!getMainModel()) return;
|
Chris@0
|
1540 m_viewManager->setSelection(Selection(getMainModel()->getStartFrame(),
|
Chris@0
|
1541 getMainModel()->getEndFrame()));
|
Chris@0
|
1542 }
|
Chris@0
|
1543
|
Chris@0
|
1544 void
|
Chris@0
|
1545 MainWindow::selectToStart()
|
Chris@0
|
1546 {
|
Chris@0
|
1547 if (!getMainModel()) return;
|
Chris@0
|
1548 m_viewManager->setSelection(Selection(getMainModel()->getStartFrame(),
|
Chris@0
|
1549 m_viewManager->getGlobalCentreFrame()));
|
Chris@0
|
1550 }
|
Chris@0
|
1551
|
Chris@0
|
1552 void
|
Chris@0
|
1553 MainWindow::selectToEnd()
|
Chris@0
|
1554 {
|
Chris@0
|
1555 if (!getMainModel()) return;
|
Chris@0
|
1556 m_viewManager->setSelection(Selection(m_viewManager->getGlobalCentreFrame(),
|
Chris@0
|
1557 getMainModel()->getEndFrame()));
|
Chris@0
|
1558 }
|
Chris@0
|
1559
|
Chris@0
|
1560 void
|
Chris@0
|
1561 MainWindow::selectVisible()
|
Chris@0
|
1562 {
|
Chris@0
|
1563 Model *model = getMainModel();
|
Chris@0
|
1564 if (!model) return;
|
Chris@0
|
1565
|
Chris@0
|
1566 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@0
|
1567 if (!currentPane) return;
|
Chris@0
|
1568
|
Chris@0
|
1569 size_t startFrame, endFrame;
|
Chris@0
|
1570
|
Chris@0
|
1571 if (currentPane->getStartFrame() < 0) startFrame = 0;
|
Chris@0
|
1572 else startFrame = currentPane->getStartFrame();
|
Chris@0
|
1573
|
Chris@0
|
1574 if (currentPane->getEndFrame() > model->getEndFrame()) endFrame = model->getEndFrame();
|
Chris@0
|
1575 else endFrame = currentPane->getEndFrame();
|
Chris@0
|
1576
|
Chris@0
|
1577 m_viewManager->setSelection(Selection(startFrame, endFrame));
|
Chris@0
|
1578 }
|
Chris@0
|
1579
|
Chris@0
|
1580 void
|
Chris@0
|
1581 MainWindow::clearSelection()
|
Chris@0
|
1582 {
|
Chris@0
|
1583 m_viewManager->clearSelections();
|
Chris@0
|
1584 }
|
Chris@0
|
1585
|
Chris@0
|
1586 void
|
Chris@0
|
1587 MainWindow::cut()
|
Chris@0
|
1588 {
|
Chris@0
|
1589 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@0
|
1590 if (!currentPane) return;
|
Chris@0
|
1591
|
Chris@0
|
1592 Layer *layer = currentPane->getSelectedLayer();
|
Chris@0
|
1593 if (!layer) return;
|
Chris@0
|
1594
|
Chris@0
|
1595 Clipboard &clipboard = m_viewManager->getClipboard();
|
Chris@0
|
1596 clipboard.clear();
|
Chris@0
|
1597
|
Chris@0
|
1598 MultiSelection::SelectionList selections = m_viewManager->getSelections();
|
Chris@0
|
1599
|
Chris@0
|
1600 CommandHistory::getInstance()->startCompoundOperation(tr("Cut"), true);
|
Chris@0
|
1601
|
Chris@0
|
1602 for (MultiSelection::SelectionList::iterator i = selections.begin();
|
Chris@0
|
1603 i != selections.end(); ++i) {
|
Chris@0
|
1604 layer->copy(*i, clipboard);
|
Chris@0
|
1605 layer->deleteSelection(*i);
|
Chris@0
|
1606 }
|
Chris@0
|
1607
|
Chris@0
|
1608 CommandHistory::getInstance()->endCompoundOperation();
|
Chris@0
|
1609 }
|
Chris@0
|
1610
|
Chris@0
|
1611 void
|
Chris@0
|
1612 MainWindow::copy()
|
Chris@0
|
1613 {
|
Chris@0
|
1614 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@0
|
1615 if (!currentPane) return;
|
Chris@0
|
1616
|
Chris@0
|
1617 Layer *layer = currentPane->getSelectedLayer();
|
Chris@0
|
1618 if (!layer) return;
|
Chris@0
|
1619
|
Chris@0
|
1620 Clipboard &clipboard = m_viewManager->getClipboard();
|
Chris@0
|
1621 clipboard.clear();
|
Chris@0
|
1622
|
Chris@0
|
1623 MultiSelection::SelectionList selections = m_viewManager->getSelections();
|
Chris@0
|
1624
|
Chris@0
|
1625 for (MultiSelection::SelectionList::iterator i = selections.begin();
|
Chris@0
|
1626 i != selections.end(); ++i) {
|
Chris@0
|
1627 layer->copy(*i, clipboard);
|
Chris@0
|
1628 }
|
Chris@0
|
1629 }
|
Chris@0
|
1630
|
Chris@0
|
1631 void
|
Chris@0
|
1632 MainWindow::paste()
|
Chris@0
|
1633 {
|
Chris@0
|
1634 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@0
|
1635 if (!currentPane) return;
|
Chris@0
|
1636
|
Chris@0
|
1637 //!!! if we have no current layer, we should create one of the most
|
Chris@0
|
1638 // appropriate type
|
Chris@0
|
1639
|
Chris@0
|
1640 Layer *layer = currentPane->getSelectedLayer();
|
Chris@0
|
1641 if (!layer) return;
|
Chris@0
|
1642
|
Chris@0
|
1643 Clipboard &clipboard = m_viewManager->getClipboard();
|
Chris@0
|
1644 Clipboard::PointList contents = clipboard.getPoints();
|
Chris@0
|
1645 /*
|
Chris@0
|
1646 long minFrame = 0;
|
Chris@0
|
1647 bool have = false;
|
Chris@0
|
1648 for (int i = 0; i < contents.size(); ++i) {
|
Chris@0
|
1649 if (!contents[i].haveFrame()) continue;
|
Chris@0
|
1650 if (!have || contents[i].getFrame() < minFrame) {
|
Chris@0
|
1651 minFrame = contents[i].getFrame();
|
Chris@0
|
1652 have = true;
|
Chris@0
|
1653 }
|
Chris@0
|
1654 }
|
Chris@0
|
1655
|
Chris@0
|
1656 long frameOffset = long(m_viewManager->getGlobalCentreFrame()) - minFrame;
|
Chris@0
|
1657
|
Chris@0
|
1658 layer->paste(clipboard, frameOffset);
|
Chris@0
|
1659 */
|
Chris@0
|
1660 layer->paste(clipboard, 0, true);
|
Chris@0
|
1661 }
|
Chris@0
|
1662
|
Chris@0
|
1663 void
|
Chris@0
|
1664 MainWindow::deleteSelected()
|
Chris@0
|
1665 {
|
Chris@0
|
1666 if (m_paneStack->getCurrentPane() &&
|
Chris@0
|
1667 m_paneStack->getCurrentPane()->getSelectedLayer()) {
|
Chris@0
|
1668
|
Chris@0
|
1669 MultiSelection::SelectionList selections =
|
Chris@0
|
1670 m_viewManager->getSelections();
|
Chris@0
|
1671
|
Chris@0
|
1672 for (MultiSelection::SelectionList::iterator i = selections.begin();
|
Chris@0
|
1673 i != selections.end(); ++i) {
|
Chris@0
|
1674
|
Chris@0
|
1675 m_paneStack->getCurrentPane()->getSelectedLayer()->deleteSelection(*i);
|
Chris@0
|
1676 }
|
Chris@0
|
1677 }
|
Chris@0
|
1678 }
|
Chris@0
|
1679
|
Chris@0
|
1680 void
|
Chris@0
|
1681 MainWindow::insertInstant()
|
Chris@0
|
1682 {
|
Chris@0
|
1683 int frame = m_viewManager->getPlaybackFrame();
|
Chris@0
|
1684
|
Chris@0
|
1685 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@0
|
1686 if (!pane) {
|
Chris@0
|
1687 return;
|
Chris@0
|
1688 }
|
Chris@0
|
1689
|
Chris@0
|
1690 Layer *layer = dynamic_cast<TimeInstantLayer *>
|
Chris@0
|
1691 (pane->getSelectedLayer());
|
Chris@0
|
1692
|
Chris@0
|
1693 if (!layer) {
|
Chris@0
|
1694 for (int i = pane->getLayerCount(); i > 0; --i) {
|
Chris@0
|
1695 layer = dynamic_cast<TimeInstantLayer *>(pane->getLayer(i - 1));
|
Chris@0
|
1696 if (layer) break;
|
Chris@0
|
1697 }
|
Chris@0
|
1698
|
Chris@0
|
1699 if (!layer) {
|
Chris@0
|
1700 CommandHistory::getInstance()->startCompoundOperation
|
Chris@0
|
1701 (tr("Add Point"), true);
|
Chris@0
|
1702 layer = m_document->createEmptyLayer(LayerFactory::TimeInstants);
|
Chris@0
|
1703 if (layer) {
|
Chris@0
|
1704 m_document->addLayerToView(pane, layer);
|
Chris@0
|
1705 m_paneStack->setCurrentLayer(pane, layer);
|
Chris@0
|
1706 }
|
Chris@0
|
1707 CommandHistory::getInstance()->endCompoundOperation();
|
Chris@0
|
1708 }
|
Chris@0
|
1709 }
|
Chris@0
|
1710
|
Chris@0
|
1711 if (layer) {
|
Chris@0
|
1712
|
Chris@0
|
1713 Model *model = layer->getModel();
|
Chris@0
|
1714 SparseOneDimensionalModel *sodm = dynamic_cast<SparseOneDimensionalModel *>
|
Chris@0
|
1715 (model);
|
Chris@0
|
1716
|
Chris@0
|
1717 if (sodm) {
|
Chris@0
|
1718 SparseOneDimensionalModel::Point point
|
Chris@0
|
1719 (frame, QString("%1").arg(sodm->getPointCount() + 1));
|
Chris@0
|
1720 CommandHistory::getInstance()->addCommand
|
Chris@0
|
1721 (new SparseOneDimensionalModel::AddPointCommand(sodm, point,
|
Chris@0
|
1722 tr("Add Points")),
|
Chris@0
|
1723 true, true); // bundled
|
Chris@0
|
1724 }
|
Chris@0
|
1725 }
|
Chris@0
|
1726 }
|
Chris@0
|
1727
|
Chris@0
|
1728 void
|
Chris@0
|
1729 MainWindow::importAudio()
|
Chris@0
|
1730 {
|
Chris@0
|
1731 QString orig = m_audioFile;
|
Chris@0
|
1732
|
Chris@0
|
1733 // std::cerr << "orig = " << orig.toStdString() << std::endl;
|
Chris@0
|
1734
|
Chris@0
|
1735 if (orig == "") orig = ".";
|
Chris@0
|
1736
|
Chris@0
|
1737 QString path = QFileDialog::getOpenFileName
|
Chris@0
|
1738 (this, tr("Select an audio file"), orig,
|
Chris@0
|
1739 tr("Audio files (%1)\nAll files (*.*)")
|
Chris@0
|
1740 .arg(AudioFileReaderFactory::getKnownExtensions()));
|
Chris@0
|
1741
|
Chris@0
|
1742 if (path != "") {
|
Chris@0
|
1743 if (!openAudioFile(path, ReplaceMainModel)) {
|
Chris@0
|
1744 QMessageBox::critical(this, tr("Failed to open file"),
|
Chris@0
|
1745 tr("Audio file \"%1\" could not be opened").arg(path));
|
Chris@0
|
1746 }
|
Chris@0
|
1747 }
|
Chris@0
|
1748 }
|
Chris@0
|
1749
|
Chris@0
|
1750 void
|
Chris@0
|
1751 MainWindow::importMoreAudio()
|
Chris@0
|
1752 {
|
Chris@0
|
1753 QString orig = m_audioFile;
|
Chris@0
|
1754
|
Chris@0
|
1755 // std::cerr << "orig = " << orig.toStdString() << std::endl;
|
Chris@0
|
1756
|
Chris@0
|
1757 if (orig == "") orig = ".";
|
Chris@0
|
1758
|
Chris@0
|
1759 QString path = QFileDialog::getOpenFileName
|
Chris@0
|
1760 (this, tr("Select an audio file"), orig,
|
Chris@0
|
1761 tr("Audio files (%1)\nAll files (*.*)")
|
Chris@0
|
1762 .arg(AudioFileReaderFactory::getKnownExtensions()));
|
Chris@0
|
1763
|
Chris@0
|
1764 if (path != "") {
|
Chris@0
|
1765 if (!openAudioFile(path, CreateAdditionalModel)) {
|
Chris@0
|
1766 QMessageBox::critical(this, tr("Failed to open file"),
|
Chris@0
|
1767 tr("Audio file \"%1\" could not be opened").arg(path));
|
Chris@0
|
1768 }
|
Chris@0
|
1769 }
|
Chris@0
|
1770 }
|
Chris@0
|
1771
|
Chris@0
|
1772 void
|
Chris@0
|
1773 MainWindow::exportAudio()
|
Chris@0
|
1774 {
|
Chris@0
|
1775 if (!getMainModel()) return;
|
Chris@0
|
1776
|
Chris@0
|
1777 QString path = QFileDialog::getSaveFileName
|
Chris@0
|
1778 (this, tr("Select a file to export to"), ".",
|
Chris@0
|
1779 tr("WAV audio files (*.wav)\nAll files (*.*)"));
|
Chris@0
|
1780
|
Chris@0
|
1781 if (path == "") return;
|
Chris@0
|
1782
|
Chris@0
|
1783 if (!path.endsWith(".wav")) path = path + ".wav";
|
Chris@0
|
1784
|
Chris@0
|
1785 bool ok = false;
|
Chris@0
|
1786 QString error;
|
Chris@0
|
1787
|
Chris@0
|
1788 MultiSelection ms = m_viewManager->getSelection();
|
Chris@0
|
1789 MultiSelection::SelectionList selections = m_viewManager->getSelections();
|
Chris@0
|
1790
|
Chris@0
|
1791 bool multiple = false;
|
Chris@0
|
1792
|
Chris@38
|
1793 MultiSelection *selectionToWrite = 0;
|
Chris@38
|
1794
|
Chris@38
|
1795 if (selections.size() == 1) {
|
Chris@0
|
1796
|
Chris@0
|
1797 QStringList items;
|
Chris@0
|
1798 items << tr("Export the selected region only")
|
Chris@0
|
1799 << tr("Export the whole audio file");
|
Chris@0
|
1800
|
Chris@0
|
1801 bool ok = false;
|
Chris@0
|
1802 QString item = ListInputDialog::getItem
|
Chris@0
|
1803 (this, tr("Select region to export"),
|
Chris@0
|
1804 tr("Which region from the original audio file do you want to export?"),
|
Chris@0
|
1805 items, 0, &ok);
|
Chris@0
|
1806
|
Chris@0
|
1807 if (!ok || item.isEmpty()) return;
|
Chris@0
|
1808
|
Chris@38
|
1809 if (item == items[0]) selectionToWrite = &ms;
|
Chris@38
|
1810
|
Chris@38
|
1811 } else if (selections.size() > 1) {
|
Chris@0
|
1812
|
Chris@0
|
1813 QStringList items;
|
Chris@0
|
1814 items << tr("Export the selected regions into a single audio file")
|
Chris@0
|
1815 << tr("Export the selected regions into separate files")
|
Chris@0
|
1816 << tr("Export the whole audio file");
|
Chris@0
|
1817
|
Chris@0
|
1818 QString item = ListInputDialog::getItem
|
Chris@0
|
1819 (this, tr("Select region to export"),
|
Chris@0
|
1820 tr("Multiple regions of the original audio file are selected.\nWhat do you want to export?"),
|
Chris@0
|
1821 items, 0, &ok);
|
Chris@0
|
1822
|
Chris@0
|
1823 if (!ok || item.isEmpty()) return;
|
Chris@0
|
1824
|
Chris@0
|
1825 if (item == items[0]) {
|
Chris@0
|
1826
|
Chris@38
|
1827 selectionToWrite = &ms;
|
Chris@38
|
1828
|
Chris@38
|
1829 } else if (item == items[1]) {
|
Chris@0
|
1830
|
Chris@0
|
1831 multiple = true;
|
Chris@0
|
1832
|
Chris@0
|
1833 int n = 1;
|
Chris@0
|
1834 QString base = path;
|
Chris@0
|
1835 base.replace(".wav", "");
|
Chris@0
|
1836
|
Chris@0
|
1837 for (MultiSelection::SelectionList::iterator i = selections.begin();
|
Chris@0
|
1838 i != selections.end(); ++i) {
|
Chris@0
|
1839
|
Chris@0
|
1840 MultiSelection subms;
|
Chris@0
|
1841 subms.setSelection(*i);
|
Chris@0
|
1842
|
Chris@0
|
1843 QString subpath = QString("%1.%2.wav").arg(base).arg(n);
|
Chris@0
|
1844 ++n;
|
Chris@0
|
1845
|
Chris@0
|
1846 if (QFileInfo(subpath).exists()) {
|
Chris@0
|
1847 error = tr("Fragment file %1 already exists, aborting").arg(subpath);
|
Chris@0
|
1848 break;
|
Chris@0
|
1849 }
|
Chris@0
|
1850
|
Chris@38
|
1851 WavFileWriter subwriter(subpath,
|
Chris@38
|
1852 getMainModel()->getSampleRate(),
|
Chris@38
|
1853 getMainModel()->getChannelCount());
|
Chris@38
|
1854 subwriter.writeModel(getMainModel(), &subms);
|
Chris@0
|
1855 ok = subwriter.isOK();
|
Chris@0
|
1856
|
Chris@0
|
1857 if (!ok) {
|
Chris@0
|
1858 error = subwriter.getError();
|
Chris@0
|
1859 break;
|
Chris@0
|
1860 }
|
Chris@0
|
1861 }
|
Chris@0
|
1862 }
|
Chris@0
|
1863 }
|
Chris@0
|
1864
|
Chris@38
|
1865 if (!multiple) {
|
Chris@38
|
1866 WavFileWriter writer(path,
|
Chris@38
|
1867 getMainModel()->getSampleRate(),
|
Chris@38
|
1868 getMainModel()->getChannelCount());
|
Chris@38
|
1869 writer.writeModel(getMainModel(), selectionToWrite);
|
Chris@38
|
1870 ok = writer.isOK();
|
Chris@38
|
1871 error = writer.getError();
|
Chris@0
|
1872 }
|
Chris@0
|
1873
|
Chris@0
|
1874 if (ok) {
|
Chris@0
|
1875 if (!multiple) {
|
Chris@34
|
1876 m_recentFiles.addFile(path);
|
Chris@0
|
1877 }
|
Chris@0
|
1878 } else {
|
Chris@0
|
1879 QMessageBox::critical(this, tr("Failed to write file"), error);
|
Chris@0
|
1880 }
|
Chris@0
|
1881 }
|
Chris@0
|
1882
|
Chris@0
|
1883 void
|
Chris@0
|
1884 MainWindow::importLayer()
|
Chris@0
|
1885 {
|
Chris@0
|
1886 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@0
|
1887
|
Chris@0
|
1888 if (!pane) {
|
Chris@0
|
1889 // shouldn't happen, as the menu action should have been disabled
|
Chris@0
|
1890 std::cerr << "WARNING: MainWindow::importLayer: no current pane" << std::endl;
|
Chris@0
|
1891 return;
|
Chris@0
|
1892 }
|
Chris@0
|
1893
|
Chris@0
|
1894 if (!getMainModel()) {
|
Chris@0
|
1895 // shouldn't happen, as the menu action should have been disabled
|
Chris@0
|
1896 std::cerr << "WARNING: MainWindow::importLayer: No main model -- hence no default sample rate available" << std::endl;
|
Chris@0
|
1897 return;
|
Chris@0
|
1898 }
|
Chris@0
|
1899
|
Chris@0
|
1900 QString path = QFileDialog::getOpenFileName
|
Chris@0
|
1901 (this, tr("Select file"), ".",
|
Chris@0
|
1902 tr("All supported files (%1)\nSonic Visualiser Layer XML files (*.svl)\nComma-separated data files (*.csv)\nSpace-separated .lab files (*.lab)\nMIDI files (*.mid)\nText files (*.txt)\nAll files (*.*)").arg(DataFileReaderFactory::getKnownExtensions()));
|
Chris@0
|
1903
|
Chris@0
|
1904 if (path != "") {
|
Chris@0
|
1905
|
Chris@0
|
1906 if (!openLayerFile(path)) {
|
Chris@0
|
1907 QMessageBox::critical(this, tr("Failed to open file"),
|
Chris@0
|
1908 tr("File %1 could not be opened.").arg(path));
|
Chris@0
|
1909 return;
|
Chris@0
|
1910 }
|
Chris@0
|
1911 }
|
Chris@0
|
1912 }
|
Chris@0
|
1913
|
Chris@0
|
1914 bool
|
Chris@0
|
1915 MainWindow::openLayerFile(QString path)
|
Chris@0
|
1916 {
|
Chris@0
|
1917 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@0
|
1918
|
Chris@0
|
1919 if (!pane) {
|
Chris@0
|
1920 // shouldn't happen, as the menu action should have been disabled
|
Chris@0
|
1921 std::cerr << "WARNING: MainWindow::openLayerFile: no current pane" << std::endl;
|
Chris@0
|
1922 return false;
|
Chris@0
|
1923 }
|
Chris@0
|
1924
|
Chris@0
|
1925 if (!getMainModel()) {
|
Chris@0
|
1926 // shouldn't happen, as the menu action should have been disabled
|
Chris@0
|
1927 std::cerr << "WARNING: MainWindow::openLayerFile: No main model -- hence no default sample rate available" << std::endl;
|
Chris@0
|
1928 return false;
|
Chris@0
|
1929 }
|
Chris@0
|
1930
|
Chris@0
|
1931 if (path.endsWith(".svl") || path.endsWith(".xml")) {
|
Chris@0
|
1932
|
Chris@0
|
1933 PaneCallback callback(this);
|
Chris@0
|
1934 QFile file(path);
|
Chris@0
|
1935
|
Chris@0
|
1936 if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
Chris@0
|
1937 std::cerr << "ERROR: MainWindow::openLayerFile("
|
Chris@0
|
1938 << path.toStdString()
|
Chris@0
|
1939 << "): Failed to open file for reading" << std::endl;
|
Chris@0
|
1940 return false;
|
Chris@0
|
1941 }
|
Chris@0
|
1942
|
Chris@0
|
1943 SVFileReader reader(m_document, callback);
|
Chris@0
|
1944 reader.setCurrentPane(pane);
|
Chris@0
|
1945
|
Chris@0
|
1946 QXmlInputSource inputSource(&file);
|
Chris@0
|
1947 reader.parse(inputSource);
|
Chris@0
|
1948
|
Chris@0
|
1949 if (!reader.isOK()) {
|
Chris@0
|
1950 std::cerr << "ERROR: MainWindow::openLayerFile("
|
Chris@0
|
1951 << path.toStdString()
|
Chris@0
|
1952 << "): Failed to read XML file: "
|
Chris@0
|
1953 << reader.getErrorString().toStdString() << std::endl;
|
Chris@0
|
1954 return false;
|
Chris@0
|
1955 }
|
Chris@0
|
1956
|
Chris@34
|
1957 m_recentFiles.addFile(path);
|
Chris@0
|
1958 return true;
|
Chris@0
|
1959
|
Chris@0
|
1960 } else {
|
Chris@0
|
1961
|
Chris@0
|
1962 Model *model = DataFileReaderFactory::load(path, getMainModel()->getSampleRate());
|
Chris@0
|
1963
|
Chris@0
|
1964 if (model) {
|
Chris@0
|
1965 Layer *newLayer = m_document->createImportedLayer(model);
|
Chris@0
|
1966 if (newLayer) {
|
Chris@0
|
1967 m_document->addLayerToView(pane, newLayer);
|
Chris@34
|
1968 m_recentFiles.addFile(path);
|
Chris@0
|
1969 return true;
|
Chris@0
|
1970 }
|
Chris@0
|
1971 }
|
Chris@0
|
1972 }
|
Chris@0
|
1973
|
Chris@0
|
1974 return false;
|
Chris@0
|
1975 }
|
Chris@0
|
1976
|
Chris@0
|
1977 void
|
Chris@0
|
1978 MainWindow::exportLayer()
|
Chris@0
|
1979 {
|
Chris@0
|
1980 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@0
|
1981 if (!pane) return;
|
Chris@0
|
1982
|
Chris@0
|
1983 Layer *layer = pane->getSelectedLayer();
|
Chris@0
|
1984 if (!layer) return;
|
Chris@0
|
1985
|
Chris@0
|
1986 Model *model = layer->getModel();
|
Chris@0
|
1987 if (!model) return;
|
Chris@0
|
1988
|
Chris@0
|
1989 QString path = QFileDialog::getSaveFileName
|
Chris@0
|
1990 (this, tr("Select a file to export to"), ".",
|
Chris@0
|
1991 tr("Sonic Visualiser Layer XML files (*.svl)\nComma-separated data files (*.csv)\nText files (*.txt)\nAll files (*.*)"));
|
Chris@0
|
1992
|
Chris@0
|
1993 if (path == "") return;
|
Chris@0
|
1994
|
Chris@0
|
1995 if (QFileInfo(path).suffix() == "") path += ".svl";
|
Chris@0
|
1996
|
Chris@0
|
1997 QString error;
|
Chris@0
|
1998
|
Chris@0
|
1999 if (path.endsWith(".xml") || path.endsWith(".svl")) {
|
Chris@0
|
2000
|
Chris@0
|
2001 QFile file(path);
|
Chris@0
|
2002 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
Chris@0
|
2003 error = tr("Failed to open file %1 for writing").arg(path);
|
Chris@0
|
2004 } else {
|
Chris@0
|
2005 QTextStream out(&file);
|
Chris@0
|
2006 out << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
|
Chris@0
|
2007 << "<!DOCTYPE sonic-visualiser>\n"
|
Chris@0
|
2008 << "<sv>\n"
|
Chris@0
|
2009 << " <data>\n";
|
Chris@0
|
2010
|
Chris@0
|
2011 model->toXml(out, " ");
|
Chris@0
|
2012
|
Chris@0
|
2013 out << " </data>\n"
|
Chris@0
|
2014 << " <display>\n";
|
Chris@0
|
2015
|
Chris@0
|
2016 layer->toXml(out, " ");
|
Chris@0
|
2017
|
Chris@0
|
2018 out << " </display>\n"
|
Chris@0
|
2019 << "</sv>\n";
|
Chris@0
|
2020 }
|
Chris@0
|
2021
|
Chris@0
|
2022 } else {
|
Chris@0
|
2023
|
Chris@0
|
2024 CSVFileWriter writer(path, model,
|
Chris@0
|
2025 (path.endsWith(".csv") ? "," : "\t"));
|
Chris@0
|
2026 writer.write();
|
Chris@0
|
2027
|
Chris@0
|
2028 if (!writer.isOK()) {
|
Chris@0
|
2029 error = writer.getError();
|
Chris@0
|
2030 }
|
Chris@0
|
2031 }
|
Chris@0
|
2032
|
Chris@0
|
2033 if (error != "") {
|
Chris@0
|
2034 QMessageBox::critical(this, tr("Failed to write file"), error);
|
Chris@0
|
2035 } else {
|
Chris@34
|
2036 m_recentFiles.addFile(path);
|
Chris@0
|
2037 }
|
Chris@0
|
2038 }
|
Chris@0
|
2039
|
Chris@0
|
2040 bool
|
Chris@0
|
2041 MainWindow::openAudioFile(QString path, AudioFileOpenMode mode)
|
Chris@0
|
2042 {
|
Chris@0
|
2043 if (!(QFileInfo(path).exists() &&
|
Chris@0
|
2044 QFileInfo(path).isFile() &&
|
Chris@0
|
2045 QFileInfo(path).isReadable())) {
|
Chris@0
|
2046 return false;
|
Chris@0
|
2047 }
|
Chris@0
|
2048
|
Chris@70
|
2049 m_openingAudioFile = true;
|
Chris@70
|
2050
|
Chris@0
|
2051 WaveFileModel *newModel = new WaveFileModel(path);
|
Chris@0
|
2052
|
Chris@0
|
2053 if (!newModel->isOK()) {
|
Chris@0
|
2054 delete newModel;
|
Chris@70
|
2055 m_openingAudioFile = false;
|
Chris@0
|
2056 return false;
|
Chris@0
|
2057 }
|
Chris@0
|
2058
|
Chris@0
|
2059 bool setAsMain = true;
|
Chris@0
|
2060 static bool prevSetAsMain = true;
|
Chris@0
|
2061
|
Chris@0
|
2062 if (mode == CreateAdditionalModel) setAsMain = false;
|
Chris@0
|
2063 else if (mode == AskUser) {
|
Chris@0
|
2064 if (m_document->getMainModel()) {
|
Chris@0
|
2065
|
Chris@0
|
2066 QStringList items;
|
Chris@0
|
2067 items << tr("Replace the existing main waveform")
|
Chris@0
|
2068 << tr("Load this file into a new waveform pane");
|
Chris@0
|
2069
|
Chris@0
|
2070 bool ok = false;
|
Chris@0
|
2071 QString item = ListInputDialog::getItem
|
Chris@0
|
2072 (this, tr("Select target for import"),
|
Chris@0
|
2073 tr("You already have an audio waveform loaded.\nWhat would you like to do with the new audio file?"),
|
Chris@0
|
2074 items, prevSetAsMain ? 0 : 1, &ok);
|
Chris@0
|
2075
|
Chris@0
|
2076 if (!ok || item.isEmpty()) {
|
Chris@0
|
2077 delete newModel;
|
Chris@70
|
2078 m_openingAudioFile = false;
|
Chris@0
|
2079 return false;
|
Chris@0
|
2080 }
|
Chris@0
|
2081
|
Chris@0
|
2082 setAsMain = (item == items[0]);
|
Chris@0
|
2083 prevSetAsMain = setAsMain;
|
Chris@0
|
2084 }
|
Chris@0
|
2085 }
|
Chris@0
|
2086
|
Chris@0
|
2087 if (setAsMain) {
|
Chris@0
|
2088
|
Chris@0
|
2089 Model *prevMain = getMainModel();
|
Chris@0
|
2090 if (prevMain) m_playSource->removeModel(prevMain);
|
Chris@0
|
2091
|
Chris@0
|
2092 PlayParameterRepository::getInstance()->clear();
|
Chris@0
|
2093
|
Chris@0
|
2094 // The clear() call will have removed the parameters for the
|
Chris@0
|
2095 // main model. Re-add them with the new one.
|
Chris@0
|
2096 PlayParameterRepository::getInstance()->addModel(newModel);
|
Chris@0
|
2097
|
Chris@0
|
2098 m_document->setMainModel(newModel);
|
Chris@0
|
2099 setupMenus();
|
Chris@0
|
2100
|
Chris@0
|
2101 if (m_sessionFile == "") {
|
Chris@0
|
2102 setWindowTitle(tr("Sonic Visualiser: %1")
|
Chris@0
|
2103 .arg(QFileInfo(path).fileName()));
|
Chris@0
|
2104 CommandHistory::getInstance()->clear();
|
Chris@0
|
2105 CommandHistory::getInstance()->documentSaved();
|
Chris@0
|
2106 m_documentModified = false;
|
Chris@0
|
2107 } else {
|
Chris@0
|
2108 setWindowTitle(tr("Sonic Visualiser: %1 [%2]")
|
Chris@0
|
2109 .arg(QFileInfo(m_sessionFile).fileName())
|
Chris@0
|
2110 .arg(QFileInfo(path).fileName()));
|
Chris@0
|
2111 if (m_documentModified) {
|
Chris@0
|
2112 m_documentModified = false;
|
Chris@0
|
2113 documentModified(); // so as to restore "(modified)" window title
|
Chris@0
|
2114 }
|
Chris@0
|
2115 }
|
Chris@0
|
2116
|
Chris@0
|
2117 m_audioFile = path;
|
Chris@0
|
2118
|
Chris@0
|
2119 } else { // !setAsMain
|
Chris@0
|
2120
|
Chris@0
|
2121 CommandHistory::getInstance()->startCompoundOperation
|
Chris@0
|
2122 (tr("Import \"%1\"").arg(QFileInfo(path).fileName()), true);
|
Chris@0
|
2123
|
Chris@0
|
2124 m_document->addImportedModel(newModel);
|
Chris@0
|
2125
|
Chris@0
|
2126 AddPaneCommand *command = new AddPaneCommand(this);
|
Chris@0
|
2127 CommandHistory::getInstance()->addCommand(command);
|
Chris@0
|
2128
|
Chris@0
|
2129 Pane *pane = command->getPane();
|
Chris@0
|
2130
|
Chris@0
|
2131 if (!m_timeRulerLayer) {
|
Chris@0
|
2132 m_timeRulerLayer = m_document->createMainModelLayer
|
Chris@0
|
2133 (LayerFactory::TimeRuler);
|
Chris@0
|
2134 }
|
Chris@0
|
2135
|
Chris@0
|
2136 m_document->addLayerToView(pane, m_timeRulerLayer);
|
Chris@0
|
2137
|
Chris@0
|
2138 Layer *newLayer = m_document->createImportedLayer(newModel);
|
Chris@0
|
2139
|
Chris@0
|
2140 if (newLayer) {
|
Chris@0
|
2141 m_document->addLayerToView(pane, newLayer);
|
Chris@0
|
2142 }
|
Chris@0
|
2143
|
Chris@0
|
2144 CommandHistory::getInstance()->endCompoundOperation();
|
Chris@0
|
2145 }
|
Chris@0
|
2146
|
Chris@0
|
2147 updateMenuStates();
|
Chris@34
|
2148 m_recentFiles.addFile(path);
|
Chris@70
|
2149 m_openingAudioFile = false;
|
Chris@0
|
2150
|
Chris@0
|
2151 return true;
|
Chris@0
|
2152 }
|
Chris@0
|
2153
|
Chris@0
|
2154 void
|
Chris@0
|
2155 MainWindow::createPlayTarget()
|
Chris@0
|
2156 {
|
Chris@0
|
2157 if (m_playTarget) return;
|
Chris@0
|
2158
|
Chris@0
|
2159 m_playTarget = AudioTargetFactory::createCallbackTarget(m_playSource);
|
Chris@0
|
2160 if (!m_playTarget) {
|
Chris@0
|
2161 QMessageBox::warning
|
Chris@0
|
2162 (this, tr("Couldn't open audio device"),
|
Chris@0
|
2163 tr("Could not open an audio device for playback.\nAudio playback will not be available during this session.\n"),
|
Chris@0
|
2164 QMessageBox::Ok, 0);
|
Chris@0
|
2165 }
|
Chris@0
|
2166 connect(m_fader, SIGNAL(valueChanged(float)),
|
Chris@0
|
2167 m_playTarget, SLOT(setOutputGain(float)));
|
Chris@0
|
2168 }
|
Chris@0
|
2169
|
Chris@0
|
2170 WaveFileModel *
|
Chris@0
|
2171 MainWindow::getMainModel()
|
Chris@0
|
2172 {
|
Chris@0
|
2173 if (!m_document) return 0;
|
Chris@0
|
2174 return m_document->getMainModel();
|
Chris@0
|
2175 }
|
Chris@0
|
2176
|
Chris@0
|
2177 void
|
Chris@0
|
2178 MainWindow::newSession()
|
Chris@0
|
2179 {
|
Chris@0
|
2180 if (!checkSaveModified()) return;
|
Chris@0
|
2181
|
Chris@0
|
2182 closeSession();
|
Chris@0
|
2183 createDocument();
|
Chris@0
|
2184
|
Chris@0
|
2185 Pane *pane = m_paneStack->addPane();
|
Chris@0
|
2186
|
Chris@0
|
2187 if (!m_timeRulerLayer) {
|
Chris@0
|
2188 m_timeRulerLayer = m_document->createMainModelLayer
|
Chris@0
|
2189 (LayerFactory::TimeRuler);
|
Chris@0
|
2190 }
|
Chris@0
|
2191
|
Chris@0
|
2192 m_document->addLayerToView(pane, m_timeRulerLayer);
|
Chris@0
|
2193
|
Chris@0
|
2194 Layer *waveform = m_document->createMainModelLayer(LayerFactory::Waveform);
|
Chris@0
|
2195 m_document->addLayerToView(pane, waveform);
|
Chris@0
|
2196
|
Chris@65
|
2197 m_overview->registerView(pane);
|
Chris@0
|
2198
|
Chris@0
|
2199 CommandHistory::getInstance()->clear();
|
Chris@0
|
2200 CommandHistory::getInstance()->documentSaved();
|
Chris@0
|
2201 documentRestored();
|
Chris@0
|
2202 updateMenuStates();
|
Chris@0
|
2203 }
|
Chris@0
|
2204
|
Chris@0
|
2205 void
|
Chris@0
|
2206 MainWindow::createDocument()
|
Chris@0
|
2207 {
|
Chris@0
|
2208 m_document = new Document;
|
Chris@0
|
2209
|
Chris@0
|
2210 connect(m_document, SIGNAL(layerAdded(Layer *)),
|
Chris@0
|
2211 this, SLOT(layerAdded(Layer *)));
|
Chris@0
|
2212 connect(m_document, SIGNAL(layerRemoved(Layer *)),
|
Chris@0
|
2213 this, SLOT(layerRemoved(Layer *)));
|
Chris@0
|
2214 connect(m_document, SIGNAL(layerAboutToBeDeleted(Layer *)),
|
Chris@0
|
2215 this, SLOT(layerAboutToBeDeleted(Layer *)));
|
Chris@0
|
2216 connect(m_document, SIGNAL(layerInAView(Layer *, bool)),
|
Chris@0
|
2217 this, SLOT(layerInAView(Layer *, bool)));
|
Chris@0
|
2218
|
Chris@0
|
2219 connect(m_document, SIGNAL(modelAdded(Model *)),
|
Chris@0
|
2220 this, SLOT(modelAdded(Model *)));
|
Chris@0
|
2221 connect(m_document, SIGNAL(mainModelChanged(WaveFileModel *)),
|
Chris@0
|
2222 this, SLOT(mainModelChanged(WaveFileModel *)));
|
Chris@0
|
2223 connect(m_document, SIGNAL(modelAboutToBeDeleted(Model *)),
|
Chris@0
|
2224 this, SLOT(modelAboutToBeDeleted(Model *)));
|
Chris@0
|
2225
|
Chris@0
|
2226 connect(m_document, SIGNAL(modelGenerationFailed(QString)),
|
Chris@0
|
2227 this, SLOT(modelGenerationFailed(QString)));
|
Chris@63
|
2228 connect(m_document, SIGNAL(modelRegenerationFailed(QString, QString)),
|
Chris@63
|
2229 this, SLOT(modelRegenerationFailed(QString, QString)));
|
Chris@0
|
2230 }
|
Chris@0
|
2231
|
Chris@0
|
2232 void
|
Chris@0
|
2233 MainWindow::closeSession()
|
Chris@0
|
2234 {
|
Chris@0
|
2235 if (!checkSaveModified()) return;
|
Chris@0
|
2236
|
Chris@0
|
2237 while (m_paneStack->getPaneCount() > 0) {
|
Chris@0
|
2238
|
Chris@0
|
2239 Pane *pane = m_paneStack->getPane(m_paneStack->getPaneCount() - 1);
|
Chris@0
|
2240
|
Chris@0
|
2241 while (pane->getLayerCount() > 0) {
|
Chris@0
|
2242 m_document->removeLayerFromView
|
Chris@0
|
2243 (pane, pane->getLayer(pane->getLayerCount() - 1));
|
Chris@0
|
2244 }
|
Chris@0
|
2245
|
Chris@65
|
2246 m_overview->unregisterView(pane);
|
Chris@0
|
2247 m_paneStack->deletePane(pane);
|
Chris@0
|
2248 }
|
Chris@0
|
2249
|
Chris@0
|
2250 while (m_paneStack->getHiddenPaneCount() > 0) {
|
Chris@0
|
2251
|
Chris@0
|
2252 Pane *pane = m_paneStack->getHiddenPane
|
Chris@0
|
2253 (m_paneStack->getHiddenPaneCount() - 1);
|
Chris@0
|
2254
|
Chris@0
|
2255 while (pane->getLayerCount() > 0) {
|
Chris@0
|
2256 m_document->removeLayerFromView
|
Chris@0
|
2257 (pane, pane->getLayer(pane->getLayerCount() - 1));
|
Chris@0
|
2258 }
|
Chris@0
|
2259
|
Chris@65
|
2260 m_overview->unregisterView(pane);
|
Chris@0
|
2261 m_paneStack->deletePane(pane);
|
Chris@0
|
2262 }
|
Chris@0
|
2263
|
Chris@0
|
2264 delete m_document;
|
Chris@0
|
2265 m_document = 0;
|
Chris@0
|
2266 m_viewManager->clearSelections();
|
Chris@0
|
2267 m_timeRulerLayer = 0; // document owned this
|
Chris@0
|
2268
|
Chris@0
|
2269 m_sessionFile = "";
|
Chris@0
|
2270 setWindowTitle(tr("Sonic Visualiser"));
|
Chris@0
|
2271
|
Chris@0
|
2272 CommandHistory::getInstance()->clear();
|
Chris@0
|
2273 CommandHistory::getInstance()->documentSaved();
|
Chris@0
|
2274 documentRestored();
|
Chris@0
|
2275 }
|
Chris@0
|
2276
|
Chris@0
|
2277 void
|
Chris@0
|
2278 MainWindow::openSession()
|
Chris@0
|
2279 {
|
Chris@0
|
2280 if (!checkSaveModified()) return;
|
Chris@0
|
2281
|
Chris@0
|
2282 QString orig = m_audioFile;
|
Chris@0
|
2283 if (orig == "") orig = ".";
|
Chris@0
|
2284 else orig = QFileInfo(orig).absoluteDir().canonicalPath();
|
Chris@0
|
2285
|
Chris@0
|
2286 QString path = QFileDialog::getOpenFileName
|
Chris@0
|
2287 (this, tr("Select a session file"), orig,
|
Chris@0
|
2288 tr("Sonic Visualiser session files (*.sv)\nAll files (*.*)"));
|
Chris@0
|
2289
|
Chris@0
|
2290 if (path.isEmpty()) return;
|
Chris@0
|
2291
|
Chris@0
|
2292 if (!(QFileInfo(path).exists() &&
|
Chris@0
|
2293 QFileInfo(path).isFile() &&
|
Chris@0
|
2294 QFileInfo(path).isReadable())) {
|
Chris@0
|
2295 QMessageBox::critical(this, tr("Failed to open file"),
|
Chris@0
|
2296 tr("File \"%1\" does not exist or is not a readable file").arg(path));
|
Chris@0
|
2297 return;
|
Chris@0
|
2298 }
|
Chris@0
|
2299
|
Chris@0
|
2300 if (!openSessionFile(path)) {
|
Chris@0
|
2301 QMessageBox::critical(this, tr("Failed to open file"),
|
Chris@0
|
2302 tr("Session file \"%1\" could not be opened").arg(path));
|
Chris@0
|
2303 }
|
Chris@0
|
2304 }
|
Chris@0
|
2305
|
Chris@0
|
2306 void
|
Chris@0
|
2307 MainWindow::openSomething()
|
Chris@0
|
2308 {
|
Chris@0
|
2309 QString orig = m_audioFile;
|
Chris@0
|
2310 if (orig == "") orig = ".";
|
Chris@0
|
2311 else orig = QFileInfo(orig).absoluteDir().canonicalPath();
|
Chris@0
|
2312
|
Chris@0
|
2313 bool canImportLayer = (getMainModel() != 0 &&
|
Chris@0
|
2314 m_paneStack != 0 &&
|
Chris@0
|
2315 m_paneStack->getCurrentPane() != 0);
|
Chris@0
|
2316
|
Chris@0
|
2317 QString importSpec;
|
Chris@0
|
2318
|
Chris@0
|
2319 if (canImportLayer) {
|
Chris@0
|
2320 importSpec = tr("All supported files (*.sv %1 %2)\nSonic Visualiser session files (*.sv)\nAudio files (%1)\nLayer files (%2)\nAll files (*.*)")
|
Chris@0
|
2321 .arg(AudioFileReaderFactory::getKnownExtensions())
|
Chris@0
|
2322 .arg(DataFileReaderFactory::getKnownExtensions());
|
Chris@0
|
2323 } else {
|
Chris@0
|
2324 importSpec = tr("All supported files (*.sv %1)\nSonic Visualiser session files (*.sv)\nAudio files (%1)\nAll files (*.*)")
|
Chris@0
|
2325 .arg(AudioFileReaderFactory::getKnownExtensions());
|
Chris@0
|
2326 }
|
Chris@0
|
2327
|
Chris@0
|
2328 QString path = QFileDialog::getOpenFileName
|
Chris@0
|
2329 (this, tr("Select a file to open"), orig, importSpec);
|
Chris@0
|
2330
|
Chris@0
|
2331 if (path.isEmpty()) return;
|
Chris@0
|
2332
|
Chris@0
|
2333 if (!(QFileInfo(path).exists() &&
|
Chris@0
|
2334 QFileInfo(path).isFile() &&
|
Chris@0
|
2335 QFileInfo(path).isReadable())) {
|
Chris@0
|
2336 QMessageBox::critical(this, tr("Failed to open file"),
|
Chris@0
|
2337 tr("File \"%1\" does not exist or is not a readable file").arg(path));
|
Chris@0
|
2338 return;
|
Chris@0
|
2339 }
|
Chris@0
|
2340
|
Chris@0
|
2341 if (path.endsWith(".sv")) {
|
Chris@0
|
2342
|
Chris@0
|
2343 if (!checkSaveModified()) return;
|
Chris@0
|
2344
|
Chris@0
|
2345 if (!openSessionFile(path)) {
|
Chris@0
|
2346 QMessageBox::critical(this, tr("Failed to open file"),
|
Chris@0
|
2347 tr("Session file \"%1\" could not be opened").arg(path));
|
Chris@0
|
2348 }
|
Chris@0
|
2349
|
Chris@0
|
2350 } else {
|
Chris@0
|
2351
|
Chris@0
|
2352 if (!openAudioFile(path, AskUser)) {
|
Chris@0
|
2353
|
Chris@0
|
2354 if (!canImportLayer || !openLayerFile(path)) {
|
Chris@0
|
2355
|
Chris@0
|
2356 QMessageBox::critical(this, tr("Failed to open file"),
|
Chris@0
|
2357 tr("File \"%1\" could not be opened").arg(path));
|
Chris@0
|
2358 }
|
Chris@0
|
2359 }
|
Chris@0
|
2360 }
|
Chris@0
|
2361 }
|
Chris@0
|
2362
|
Chris@0
|
2363 void
|
Chris@0
|
2364 MainWindow::openRecentFile()
|
Chris@0
|
2365 {
|
Chris@0
|
2366 QObject *obj = sender();
|
Chris@0
|
2367 QAction *action = dynamic_cast<QAction *>(obj);
|
Chris@0
|
2368
|
Chris@0
|
2369 if (!action) {
|
Chris@0
|
2370 std::cerr << "WARNING: MainWindow::openRecentFile: sender is not an action"
|
Chris@0
|
2371 << std::endl;
|
Chris@0
|
2372 return;
|
Chris@0
|
2373 }
|
Chris@0
|
2374
|
Chris@0
|
2375 QString path = action->text();
|
Chris@0
|
2376 if (path == "") return;
|
Chris@0
|
2377
|
Chris@0
|
2378 if (path.endsWith("sv")) {
|
Chris@0
|
2379
|
Chris@0
|
2380 if (!checkSaveModified()) return ;
|
Chris@0
|
2381
|
Chris@0
|
2382 if (!openSessionFile(path)) {
|
Chris@0
|
2383 QMessageBox::critical(this, tr("Failed to open file"),
|
Chris@0
|
2384 tr("Session file \"%1\" could not be opened").arg(path));
|
Chris@0
|
2385 }
|
Chris@0
|
2386
|
Chris@0
|
2387 } else {
|
Chris@0
|
2388
|
Chris@0
|
2389 if (!openAudioFile(path, AskUser)) {
|
Chris@0
|
2390
|
Chris@0
|
2391 bool canImportLayer = (getMainModel() != 0 &&
|
Chris@0
|
2392 m_paneStack != 0 &&
|
Chris@0
|
2393 m_paneStack->getCurrentPane() != 0);
|
Chris@0
|
2394
|
Chris@0
|
2395 if (!canImportLayer || !openLayerFile(path)) {
|
Chris@0
|
2396
|
Chris@0
|
2397 QMessageBox::critical(this, tr("Failed to open file"),
|
Chris@0
|
2398 tr("File \"%1\" could not be opened").arg(path));
|
Chris@0
|
2399 }
|
Chris@0
|
2400 }
|
Chris@0
|
2401 }
|
Chris@0
|
2402 }
|
Chris@0
|
2403
|
Chris@0
|
2404 bool
|
Chris@54
|
2405 MainWindow::openSomeFile(QString path, AudioFileOpenMode mode)
|
Chris@0
|
2406 {
|
Chris@54
|
2407 if (openAudioFile(path, mode)) {
|
Chris@0
|
2408 return true;
|
Chris@0
|
2409 } else if (openSessionFile(path)) {
|
Chris@0
|
2410 return true;
|
Chris@0
|
2411 } else {
|
Chris@0
|
2412 return false;
|
Chris@0
|
2413 }
|
Chris@0
|
2414 }
|
Chris@0
|
2415
|
Chris@0
|
2416 bool
|
Chris@0
|
2417 MainWindow::openSessionFile(QString path)
|
Chris@0
|
2418 {
|
Chris@0
|
2419 BZipFileDevice bzFile(path);
|
Chris@0
|
2420 if (!bzFile.open(QIODevice::ReadOnly)) {
|
Chris@0
|
2421 std::cerr << "Failed to open session file \"" << path.toStdString()
|
Chris@0
|
2422 << "\": " << bzFile.errorString().toStdString() << std::endl;
|
Chris@0
|
2423 return false;
|
Chris@0
|
2424 }
|
Chris@0
|
2425
|
Chris@0
|
2426 QString error;
|
Chris@0
|
2427 closeSession();
|
Chris@0
|
2428 createDocument();
|
Chris@0
|
2429
|
Chris@0
|
2430 PaneCallback callback(this);
|
Chris@0
|
2431 m_viewManager->clearSelections();
|
Chris@0
|
2432
|
Chris@0
|
2433 SVFileReader reader(m_document, callback);
|
Chris@0
|
2434 QXmlInputSource inputSource(&bzFile);
|
Chris@0
|
2435 reader.parse(inputSource);
|
Chris@0
|
2436
|
Chris@0
|
2437 if (!reader.isOK()) {
|
Chris@0
|
2438 error = tr("SV XML file read error:\n%1").arg(reader.getErrorString());
|
Chris@0
|
2439 }
|
Chris@0
|
2440
|
Chris@0
|
2441 bzFile.close();
|
Chris@0
|
2442
|
Chris@0
|
2443 bool ok = (error == "");
|
Chris@0
|
2444
|
Chris@0
|
2445 if (ok) {
|
Chris@0
|
2446 setWindowTitle(tr("Sonic Visualiser: %1")
|
Chris@0
|
2447 .arg(QFileInfo(path).fileName()));
|
Chris@0
|
2448 m_sessionFile = path;
|
Chris@0
|
2449 setupMenus();
|
Chris@0
|
2450 CommandHistory::getInstance()->clear();
|
Chris@0
|
2451 CommandHistory::getInstance()->documentSaved();
|
Chris@0
|
2452 m_documentModified = false;
|
Chris@0
|
2453 updateMenuStates();
|
Chris@34
|
2454 m_recentFiles.addFile(path);
|
Chris@0
|
2455 } else {
|
Chris@0
|
2456 setWindowTitle(tr("Sonic Visualiser"));
|
Chris@0
|
2457 }
|
Chris@0
|
2458
|
Chris@0
|
2459 return ok;
|
Chris@0
|
2460 }
|
Chris@0
|
2461
|
Chris@0
|
2462 void
|
Chris@0
|
2463 MainWindow::closeEvent(QCloseEvent *e)
|
Chris@0
|
2464 {
|
Chris@70
|
2465 if (!m_abandoning && !checkSaveModified()) {
|
Chris@0
|
2466 e->ignore();
|
Chris@0
|
2467 return;
|
Chris@0
|
2468 }
|
Chris@0
|
2469
|
Chris@5
|
2470 QSettings settings;
|
Chris@5
|
2471 settings.beginGroup("MainWindow");
|
Chris@5
|
2472 settings.setValue("size", size());
|
Chris@5
|
2473 settings.setValue("position", pos());
|
Chris@5
|
2474 settings.endGroup();
|
Chris@5
|
2475
|
Chris@0
|
2476 e->accept();
|
Chris@0
|
2477 return;
|
Chris@0
|
2478 }
|
Chris@0
|
2479
|
Chris@0
|
2480 bool
|
Chris@11
|
2481 MainWindow::commitData(bool mayAskUser)
|
Chris@11
|
2482 {
|
Chris@11
|
2483 if (mayAskUser) {
|
Chris@11
|
2484 return checkSaveModified();
|
Chris@11
|
2485 } else {
|
Chris@11
|
2486 if (!m_documentModified) return true;
|
Chris@11
|
2487
|
Chris@11
|
2488 // If we can't check with the user first, then we can't save
|
Chris@11
|
2489 // to the original session file (even if we have it) -- have
|
Chris@11
|
2490 // to use a temporary file
|
Chris@11
|
2491
|
Chris@11
|
2492 QString svDirBase = ".sv1";
|
Chris@11
|
2493 QString svDir = QDir::home().filePath(svDirBase);
|
Chris@11
|
2494
|
Chris@11
|
2495 if (!QFileInfo(svDir).exists()) {
|
Chris@11
|
2496 if (!QDir::home().mkdir(svDirBase)) return false;
|
Chris@11
|
2497 } else {
|
Chris@11
|
2498 if (!QFileInfo(svDir).isDir()) return false;
|
Chris@11
|
2499 }
|
Chris@11
|
2500
|
Chris@11
|
2501 // This name doesn't have to be unguessable
|
Chris@11
|
2502
|
Chris@11
|
2503 QString fname = QString("tmp-%1-%2.sv")
|
Chris@11
|
2504 .arg(QDateTime::currentDateTime().toString("yyyyMMddhhmmsszzz"))
|
Chris@11
|
2505 .arg(QProcess().pid());
|
Chris@11
|
2506 QString fpath = QDir(svDir).filePath(fname);
|
Chris@11
|
2507 if (saveSessionFile(fpath)) {
|
Chris@34
|
2508 m_recentFiles.addFile(fpath);
|
Chris@11
|
2509 return true;
|
Chris@11
|
2510 } else {
|
Chris@11
|
2511 return false;
|
Chris@11
|
2512 }
|
Chris@11
|
2513 }
|
Chris@11
|
2514 }
|
Chris@11
|
2515
|
Chris@11
|
2516 bool
|
Chris@0
|
2517 MainWindow::checkSaveModified()
|
Chris@0
|
2518 {
|
Chris@0
|
2519 // Called before some destructive operation (e.g. new session,
|
Chris@0
|
2520 // exit program). Return true if we can safely proceed, false to
|
Chris@0
|
2521 // cancel.
|
Chris@0
|
2522
|
Chris@0
|
2523 if (!m_documentModified) return true;
|
Chris@0
|
2524
|
Chris@0
|
2525 int button =
|
Chris@0
|
2526 QMessageBox::warning(this,
|
Chris@0
|
2527 tr("Session modified"),
|
Chris@0
|
2528 tr("The current session has been modified.\nDo you want to save it?"),
|
Chris@0
|
2529 QMessageBox::Yes,
|
Chris@0
|
2530 QMessageBox::No,
|
Chris@0
|
2531 QMessageBox::Cancel);
|
Chris@0
|
2532
|
Chris@0
|
2533 if (button == QMessageBox::Yes) {
|
Chris@0
|
2534 saveSession();
|
Chris@0
|
2535 if (m_documentModified) { // save failed -- don't proceed!
|
Chris@0
|
2536 return false;
|
Chris@0
|
2537 } else {
|
Chris@0
|
2538 return true; // saved, so it's safe to continue now
|
Chris@0
|
2539 }
|
Chris@0
|
2540 } else if (button == QMessageBox::No) {
|
Chris@0
|
2541 m_documentModified = false; // so we know to abandon it
|
Chris@0
|
2542 return true;
|
Chris@0
|
2543 }
|
Chris@0
|
2544
|
Chris@0
|
2545 // else cancel
|
Chris@0
|
2546 return false;
|
Chris@0
|
2547 }
|
Chris@0
|
2548
|
Chris@0
|
2549 void
|
Chris@0
|
2550 MainWindow::saveSession()
|
Chris@0
|
2551 {
|
Chris@0
|
2552 if (m_sessionFile != "") {
|
Chris@0
|
2553 if (!saveSessionFile(m_sessionFile)) {
|
Chris@0
|
2554 QMessageBox::critical(this, tr("Failed to save file"),
|
Chris@0
|
2555 tr("Session file \"%1\" could not be saved.").arg(m_sessionFile));
|
Chris@0
|
2556 } else {
|
Chris@0
|
2557 CommandHistory::getInstance()->documentSaved();
|
Chris@0
|
2558 documentRestored();
|
Chris@0
|
2559 }
|
Chris@0
|
2560 } else {
|
Chris@0
|
2561 saveSessionAs();
|
Chris@0
|
2562 }
|
Chris@0
|
2563 }
|
Chris@0
|
2564
|
Chris@0
|
2565 void
|
Chris@0
|
2566 MainWindow::saveSessionAs()
|
Chris@0
|
2567 {
|
Chris@0
|
2568 QString orig = m_audioFile;
|
Chris@0
|
2569 if (orig == "") orig = ".";
|
Chris@0
|
2570 else orig = QFileInfo(orig).absoluteDir().canonicalPath();
|
Chris@0
|
2571
|
Chris@0
|
2572 QString path;
|
Chris@0
|
2573 bool good = false;
|
Chris@0
|
2574
|
Chris@0
|
2575 while (!good) {
|
Chris@0
|
2576
|
Chris@0
|
2577 path = QFileDialog::getSaveFileName
|
Chris@0
|
2578 (this, tr("Select a file to save to"), orig,
|
Chris@0
|
2579 tr("Sonic Visualiser session files (*.sv)\nAll files (*.*)"), 0,
|
Chris@0
|
2580 QFileDialog::DontConfirmOverwrite); // we'll do that
|
Chris@0
|
2581
|
Chris@0
|
2582 if (path.isEmpty()) return;
|
Chris@0
|
2583
|
Chris@0
|
2584 if (!path.endsWith(".sv")) path = path + ".sv";
|
Chris@0
|
2585
|
Chris@0
|
2586 QFileInfo fi(path);
|
Chris@0
|
2587
|
Chris@0
|
2588 if (fi.isDir()) {
|
Chris@0
|
2589 QMessageBox::critical(this, tr("Directory selected"),
|
Chris@0
|
2590 tr("File \"%1\" is a directory").arg(path));
|
Chris@0
|
2591 continue;
|
Chris@0
|
2592 }
|
Chris@0
|
2593
|
Chris@0
|
2594 if (fi.exists()) {
|
Chris@0
|
2595 if (QMessageBox::question(this, tr("File exists"),
|
Chris@0
|
2596 tr("The file \"%1\" already exists.\nDo you want to overwrite it?").arg(path),
|
Chris@0
|
2597 QMessageBox::Ok,
|
Chris@0
|
2598 QMessageBox::Cancel) == QMessageBox::Ok) {
|
Chris@0
|
2599 good = true;
|
Chris@0
|
2600 } else {
|
Chris@0
|
2601 continue;
|
Chris@0
|
2602 }
|
Chris@0
|
2603 }
|
Chris@0
|
2604
|
Chris@0
|
2605 good = true;
|
Chris@0
|
2606 }
|
Chris@0
|
2607
|
Chris@0
|
2608 if (!saveSessionFile(path)) {
|
Chris@0
|
2609 QMessageBox::critical(this, tr("Failed to save file"),
|
Chris@0
|
2610 tr("Session file \"%1\" could not be saved.").arg(m_sessionFile));
|
Chris@0
|
2611 } else {
|
Chris@0
|
2612 setWindowTitle(tr("Sonic Visualiser: %1")
|
Chris@0
|
2613 .arg(QFileInfo(path).fileName()));
|
Chris@0
|
2614 m_sessionFile = path;
|
Chris@0
|
2615 CommandHistory::getInstance()->documentSaved();
|
Chris@0
|
2616 documentRestored();
|
Chris@34
|
2617 m_recentFiles.addFile(path);
|
Chris@0
|
2618 }
|
Chris@0
|
2619 }
|
Chris@0
|
2620
|
Chris@0
|
2621 bool
|
Chris@0
|
2622 MainWindow::saveSessionFile(QString path)
|
Chris@0
|
2623 {
|
Chris@0
|
2624 BZipFileDevice bzFile(path);
|
Chris@0
|
2625 if (!bzFile.open(QIODevice::WriteOnly)) {
|
Chris@0
|
2626 std::cerr << "Failed to open session file \"" << path.toStdString()
|
Chris@0
|
2627 << "\" for writing: "
|
Chris@0
|
2628 << bzFile.errorString().toStdString() << std::endl;
|
Chris@0
|
2629 return false;
|
Chris@0
|
2630 }
|
Chris@0
|
2631
|
Chris@0
|
2632 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
|
Chris@0
|
2633
|
Chris@0
|
2634 QTextStream out(&bzFile);
|
Chris@0
|
2635 toXml(out);
|
Chris@0
|
2636 out.flush();
|
Chris@0
|
2637
|
Chris@0
|
2638 QApplication::restoreOverrideCursor();
|
Chris@0
|
2639
|
Chris@0
|
2640 if (bzFile.errorString() != "") {
|
Chris@0
|
2641 QMessageBox::critical(this, tr("Failed to write file"),
|
Chris@0
|
2642 tr("Failed to write to file \"%1\": %2")
|
Chris@0
|
2643 .arg(path).arg(bzFile.errorString()));
|
Chris@0
|
2644 bzFile.close();
|
Chris@0
|
2645 return false;
|
Chris@0
|
2646 }
|
Chris@0
|
2647
|
Chris@0
|
2648 bzFile.close();
|
Chris@0
|
2649 return true;
|
Chris@0
|
2650 }
|
Chris@0
|
2651
|
Chris@0
|
2652 void
|
Chris@0
|
2653 MainWindow::toXml(QTextStream &out)
|
Chris@0
|
2654 {
|
Chris@0
|
2655 QString indent(" ");
|
Chris@0
|
2656
|
Chris@0
|
2657 out << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
|
Chris@0
|
2658 out << "<!DOCTYPE sonic-visualiser>\n";
|
Chris@0
|
2659 out << "<sv>\n";
|
Chris@0
|
2660
|
Chris@0
|
2661 m_document->toXml(out, "", "");
|
Chris@0
|
2662
|
Chris@0
|
2663 out << "<display>\n";
|
Chris@0
|
2664
|
Chris@0
|
2665 out << QString(" <window width=\"%1\" height=\"%2\"/>\n")
|
Chris@0
|
2666 .arg(width()).arg(height());
|
Chris@0
|
2667
|
Chris@0
|
2668 for (int i = 0; i < m_paneStack->getPaneCount(); ++i) {
|
Chris@0
|
2669
|
Chris@0
|
2670 Pane *pane = m_paneStack->getPane(i);
|
Chris@0
|
2671
|
Chris@0
|
2672 if (pane) {
|
Chris@0
|
2673 pane->toXml(out, indent);
|
Chris@0
|
2674 }
|
Chris@0
|
2675 }
|
Chris@0
|
2676
|
Chris@0
|
2677 out << "</display>\n";
|
Chris@0
|
2678
|
Chris@0
|
2679 m_viewManager->getSelection().toXml(out);
|
Chris@0
|
2680
|
Chris@0
|
2681 out << "</sv>\n";
|
Chris@0
|
2682 }
|
Chris@0
|
2683
|
Chris@0
|
2684 Pane *
|
Chris@0
|
2685 MainWindow::addPaneToStack()
|
Chris@0
|
2686 {
|
Chris@0
|
2687 AddPaneCommand *command = new AddPaneCommand(this);
|
Chris@0
|
2688 CommandHistory::getInstance()->addCommand(command);
|
Chris@0
|
2689 return command->getPane();
|
Chris@0
|
2690 }
|
Chris@0
|
2691
|
Chris@0
|
2692 void
|
Chris@0
|
2693 MainWindow::zoomIn()
|
Chris@0
|
2694 {
|
Chris@0
|
2695 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@0
|
2696 if (currentPane) currentPane->zoom(true);
|
Chris@0
|
2697 }
|
Chris@0
|
2698
|
Chris@0
|
2699 void
|
Chris@0
|
2700 MainWindow::zoomOut()
|
Chris@0
|
2701 {
|
Chris@0
|
2702 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@0
|
2703 if (currentPane) currentPane->zoom(false);
|
Chris@0
|
2704 }
|
Chris@0
|
2705
|
Chris@0
|
2706 void
|
Chris@0
|
2707 MainWindow::zoomToFit()
|
Chris@0
|
2708 {
|
Chris@0
|
2709 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@0
|
2710 if (!currentPane) return;
|
Chris@0
|
2711
|
Chris@0
|
2712 Model *model = getMainModel();
|
Chris@0
|
2713 if (!model) return;
|
Chris@0
|
2714
|
Chris@0
|
2715 size_t start = model->getStartFrame();
|
Chris@0
|
2716 size_t end = model->getEndFrame();
|
Chris@0
|
2717 size_t pixels = currentPane->width();
|
Chris@0
|
2718 size_t zoomLevel = (end - start) / pixels;
|
Chris@0
|
2719
|
Chris@0
|
2720 currentPane->setZoomLevel(zoomLevel);
|
Chris@0
|
2721 currentPane->setStartFrame(start);
|
Chris@0
|
2722 }
|
Chris@0
|
2723
|
Chris@0
|
2724 void
|
Chris@0
|
2725 MainWindow::zoomDefault()
|
Chris@0
|
2726 {
|
Chris@0
|
2727 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@0
|
2728 if (currentPane) currentPane->setZoomLevel(1024);
|
Chris@0
|
2729 }
|
Chris@0
|
2730
|
Chris@0
|
2731 void
|
Chris@0
|
2732 MainWindow::scrollLeft()
|
Chris@0
|
2733 {
|
Chris@0
|
2734 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@0
|
2735 if (currentPane) currentPane->scroll(false, false);
|
Chris@0
|
2736 }
|
Chris@0
|
2737
|
Chris@0
|
2738 void
|
Chris@0
|
2739 MainWindow::jumpLeft()
|
Chris@0
|
2740 {
|
Chris@0
|
2741 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@0
|
2742 if (currentPane) currentPane->scroll(false, true);
|
Chris@0
|
2743 }
|
Chris@0
|
2744
|
Chris@0
|
2745 void
|
Chris@0
|
2746 MainWindow::scrollRight()
|
Chris@0
|
2747 {
|
Chris@0
|
2748 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@0
|
2749 if (currentPane) currentPane->scroll(true, false);
|
Chris@0
|
2750 }
|
Chris@0
|
2751
|
Chris@0
|
2752 void
|
Chris@0
|
2753 MainWindow::jumpRight()
|
Chris@0
|
2754 {
|
Chris@0
|
2755 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@0
|
2756 if (currentPane) currentPane->scroll(true, true);
|
Chris@0
|
2757 }
|
Chris@0
|
2758
|
Chris@0
|
2759 void
|
Chris@0
|
2760 MainWindow::showNoOverlays()
|
Chris@0
|
2761 {
|
Chris@0
|
2762 m_viewManager->setOverlayMode(ViewManager::NoOverlays);
|
Chris@0
|
2763 }
|
Chris@0
|
2764
|
Chris@0
|
2765 void
|
Chris@0
|
2766 MainWindow::showBasicOverlays()
|
Chris@0
|
2767 {
|
Chris@0
|
2768 m_viewManager->setOverlayMode(ViewManager::BasicOverlays);
|
Chris@0
|
2769 }
|
Chris@0
|
2770
|
Chris@0
|
2771 void
|
Chris@7
|
2772 MainWindow::showAllTextOverlays()
|
Chris@0
|
2773 {
|
Chris@0
|
2774 m_viewManager->setOverlayMode(ViewManager::AllOverlays);
|
Chris@0
|
2775 }
|
Chris@0
|
2776
|
Chris@0
|
2777 void
|
Chris@7
|
2778 MainWindow::toggleZoomWheels()
|
Chris@7
|
2779 {
|
Chris@7
|
2780 if (m_viewManager->getZoomWheelsEnabled()) {
|
Chris@7
|
2781 m_viewManager->setZoomWheelsEnabled(false);
|
Chris@7
|
2782 } else {
|
Chris@7
|
2783 m_viewManager->setZoomWheelsEnabled(true);
|
Chris@7
|
2784 }
|
Chris@7
|
2785 }
|
Chris@7
|
2786
|
Chris@7
|
2787 void
|
Chris@0
|
2788 MainWindow::play()
|
Chris@0
|
2789 {
|
Chris@0
|
2790 if (m_playSource->isPlaying()) {
|
Chris@0
|
2791 m_playSource->stop();
|
Chris@0
|
2792 } else {
|
Chris@0
|
2793 m_playSource->play(m_viewManager->getPlaybackFrame());
|
Chris@0
|
2794 }
|
Chris@0
|
2795 }
|
Chris@0
|
2796
|
Chris@0
|
2797 void
|
Chris@0
|
2798 MainWindow::ffwd()
|
Chris@0
|
2799 {
|
Chris@0
|
2800 if (!getMainModel()) return;
|
Chris@0
|
2801
|
Chris@0
|
2802 int frame = m_viewManager->getPlaybackFrame();
|
Chris@0
|
2803 ++frame;
|
Chris@0
|
2804
|
Chris@0
|
2805 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@0
|
2806 if (!pane) return;
|
Chris@0
|
2807
|
Chris@0
|
2808 Layer *layer = pane->getSelectedLayer();
|
Chris@0
|
2809
|
Chris@0
|
2810 if (!dynamic_cast<TimeInstantLayer *>(layer) &&
|
Chris@0
|
2811 !dynamic_cast<TimeValueLayer *>(layer)) return;
|
Chris@0
|
2812
|
Chris@0
|
2813 size_t resolution = 0;
|
Chris@0
|
2814 if (!layer->snapToFeatureFrame(pane, frame, resolution, Layer::SnapRight)) {
|
Chris@0
|
2815 frame = getMainModel()->getEndFrame();
|
Chris@0
|
2816 }
|
Chris@0
|
2817
|
Chris@0
|
2818 m_viewManager->setPlaybackFrame(frame);
|
Chris@0
|
2819 }
|
Chris@0
|
2820
|
Chris@0
|
2821 void
|
Chris@0
|
2822 MainWindow::ffwdEnd()
|
Chris@0
|
2823 {
|
Chris@0
|
2824 if (!getMainModel()) return;
|
Chris@0
|
2825 m_viewManager->setPlaybackFrame(getMainModel()->getEndFrame());
|
Chris@0
|
2826 }
|
Chris@0
|
2827
|
Chris@0
|
2828 void
|
Chris@0
|
2829 MainWindow::rewind()
|
Chris@0
|
2830 {
|
Chris@0
|
2831 if (!getMainModel()) return;
|
Chris@0
|
2832
|
Chris@0
|
2833 int frame = m_viewManager->getPlaybackFrame();
|
Chris@0
|
2834 if (frame > 0) --frame;
|
Chris@0
|
2835
|
Chris@0
|
2836 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@0
|
2837 if (!pane) return;
|
Chris@0
|
2838
|
Chris@0
|
2839 Layer *layer = pane->getSelectedLayer();
|
Chris@0
|
2840
|
Chris@0
|
2841 if (!dynamic_cast<TimeInstantLayer *>(layer) &&
|
Chris@0
|
2842 !dynamic_cast<TimeValueLayer *>(layer)) return;
|
Chris@0
|
2843
|
Chris@0
|
2844 size_t resolution = 0;
|
Chris@0
|
2845 if (!layer->snapToFeatureFrame(pane, frame, resolution, Layer::SnapLeft)) {
|
Chris@0
|
2846 frame = getMainModel()->getEndFrame();
|
Chris@0
|
2847 }
|
Chris@0
|
2848
|
Chris@0
|
2849 m_viewManager->setPlaybackFrame(frame);
|
Chris@0
|
2850 }
|
Chris@0
|
2851
|
Chris@0
|
2852 void
|
Chris@0
|
2853 MainWindow::rewindStart()
|
Chris@0
|
2854 {
|
Chris@0
|
2855 if (!getMainModel()) return;
|
Chris@0
|
2856 m_viewManager->setPlaybackFrame(getMainModel()->getStartFrame());
|
Chris@0
|
2857 }
|
Chris@0
|
2858
|
Chris@0
|
2859 void
|
Chris@0
|
2860 MainWindow::stop()
|
Chris@0
|
2861 {
|
Chris@0
|
2862 m_playSource->stop();
|
Chris@0
|
2863 }
|
Chris@0
|
2864
|
Chris@0
|
2865 void
|
Chris@0
|
2866 MainWindow::addPane()
|
Chris@0
|
2867 {
|
Chris@0
|
2868 QObject *s = sender();
|
Chris@0
|
2869 QAction *action = dynamic_cast<QAction *>(s);
|
Chris@0
|
2870
|
Chris@0
|
2871 if (!action) {
|
Chris@0
|
2872 std::cerr << "WARNING: MainWindow::addPane: sender is not an action"
|
Chris@0
|
2873 << std::endl;
|
Chris@0
|
2874 return;
|
Chris@0
|
2875 }
|
Chris@0
|
2876
|
Chris@0
|
2877 PaneActionMap::iterator i = m_paneActions.find(action);
|
Chris@0
|
2878
|
Chris@0
|
2879 if (i == m_paneActions.end()) {
|
Chris@0
|
2880 std::cerr << "WARNING: MainWindow::addPane: unknown action "
|
Chris@0
|
2881 << action->objectName().toStdString() << std::endl;
|
Chris@0
|
2882 return;
|
Chris@0
|
2883 }
|
Chris@0
|
2884
|
Chris@69
|
2885 addPane(i->second, action->text());
|
Chris@69
|
2886 }
|
Chris@69
|
2887
|
Chris@69
|
2888 void
|
Chris@69
|
2889 MainWindow::addPane(const PaneConfiguration &configuration, QString text)
|
Chris@69
|
2890 {
|
Chris@69
|
2891 CommandHistory::getInstance()->startCompoundOperation(text, true);
|
Chris@0
|
2892
|
Chris@0
|
2893 AddPaneCommand *command = new AddPaneCommand(this);
|
Chris@0
|
2894 CommandHistory::getInstance()->addCommand(command);
|
Chris@0
|
2895
|
Chris@0
|
2896 Pane *pane = command->getPane();
|
Chris@0
|
2897
|
Chris@69
|
2898 if (configuration.layer == LayerFactory::Spectrum) {
|
Chris@7
|
2899 pane->setPlaybackFollow(View::PlaybackScrollContinuous);
|
Chris@7
|
2900 }
|
Chris@7
|
2901
|
Chris@69
|
2902 if (configuration.layer != LayerFactory::TimeRuler &&
|
Chris@69
|
2903 configuration.layer != LayerFactory::Spectrum) {
|
Chris@8
|
2904
|
Chris@0
|
2905 if (!m_timeRulerLayer) {
|
Chris@0
|
2906 // std::cerr << "no time ruler layer, creating one" << std::endl;
|
Chris@0
|
2907 m_timeRulerLayer = m_document->createMainModelLayer
|
Chris@0
|
2908 (LayerFactory::TimeRuler);
|
Chris@0
|
2909 }
|
Chris@0
|
2910
|
Chris@0
|
2911 // std::cerr << "adding time ruler layer " << m_timeRulerLayer << std::endl;
|
Chris@0
|
2912
|
Chris@0
|
2913 m_document->addLayerToView(pane, m_timeRulerLayer);
|
Chris@0
|
2914 }
|
Chris@0
|
2915
|
Chris@69
|
2916 Layer *newLayer = m_document->createLayer(configuration.layer);
|
Chris@69
|
2917
|
Chris@69
|
2918 Model *suggestedModel = configuration.sourceModel;
|
Chris@66
|
2919 Model *model = 0;
|
Chris@66
|
2920
|
Chris@66
|
2921 if (suggestedModel) {
|
Chris@66
|
2922
|
Chris@66
|
2923 // check its validity
|
Chris@66
|
2924 std::vector<Model *> inputModels = m_document->getTransformInputModels();
|
Chris@66
|
2925 for (size_t j = 0; j < inputModels.size(); ++j) {
|
Chris@66
|
2926 if (inputModels[j] == suggestedModel) {
|
Chris@66
|
2927 model = suggestedModel;
|
Chris@66
|
2928 break;
|
Chris@66
|
2929 }
|
Chris@66
|
2930 }
|
Chris@66
|
2931
|
Chris@66
|
2932 if (!model) {
|
Chris@66
|
2933 std::cerr << "WARNING: Model " << (void *)suggestedModel
|
Chris@66
|
2934 << " appears in pane action map, but is not reported "
|
Chris@66
|
2935 << "by document as a valid transform source" << std::endl;
|
Chris@66
|
2936 }
|
Chris@66
|
2937 }
|
Chris@66
|
2938
|
Chris@66
|
2939 if (!model) model = m_document->getMainModel();
|
Chris@66
|
2940
|
Chris@66
|
2941 m_document->setModel(newLayer, model);
|
Chris@66
|
2942
|
Chris@69
|
2943 m_document->setChannel(newLayer, configuration.channel);
|
Chris@0
|
2944 m_document->addLayerToView(pane, newLayer);
|
Chris@0
|
2945
|
Chris@0
|
2946 m_paneStack->setCurrentPane(pane);
|
Chris@70
|
2947 m_paneStack->setCurrentLayer(pane, newLayer);
|
Chris@0
|
2948
|
Chris@0
|
2949 CommandHistory::getInstance()->endCompoundOperation();
|
Chris@0
|
2950
|
Chris@0
|
2951 updateMenuStates();
|
Chris@0
|
2952 }
|
Chris@0
|
2953
|
Chris@0
|
2954 MainWindow::AddPaneCommand::AddPaneCommand(MainWindow *mw) :
|
Chris@0
|
2955 m_mw(mw),
|
Chris@0
|
2956 m_pane(0),
|
Chris@0
|
2957 m_prevCurrentPane(0),
|
Chris@0
|
2958 m_added(false)
|
Chris@0
|
2959 {
|
Chris@0
|
2960 }
|
Chris@0
|
2961
|
Chris@0
|
2962 MainWindow::AddPaneCommand::~AddPaneCommand()
|
Chris@0
|
2963 {
|
Chris@0
|
2964 if (m_pane && !m_added) {
|
Chris@0
|
2965 m_mw->m_paneStack->deletePane(m_pane);
|
Chris@0
|
2966 }
|
Chris@0
|
2967 }
|
Chris@0
|
2968
|
Chris@0
|
2969 QString
|
Chris@0
|
2970 MainWindow::AddPaneCommand::getName() const
|
Chris@0
|
2971 {
|
Chris@0
|
2972 return tr("Add Pane");
|
Chris@0
|
2973 }
|
Chris@0
|
2974
|
Chris@0
|
2975 void
|
Chris@0
|
2976 MainWindow::AddPaneCommand::execute()
|
Chris@0
|
2977 {
|
Chris@0
|
2978 if (!m_pane) {
|
Chris@0
|
2979 m_prevCurrentPane = m_mw->m_paneStack->getCurrentPane();
|
Chris@0
|
2980 m_pane = m_mw->m_paneStack->addPane();
|
Chris@0
|
2981 } else {
|
Chris@0
|
2982 m_mw->m_paneStack->showPane(m_pane);
|
Chris@0
|
2983 }
|
Chris@0
|
2984
|
Chris@0
|
2985 m_mw->m_paneStack->setCurrentPane(m_pane);
|
Chris@65
|
2986 m_mw->m_overview->registerView(m_pane);
|
Chris@0
|
2987 m_added = true;
|
Chris@0
|
2988 }
|
Chris@0
|
2989
|
Chris@0
|
2990 void
|
Chris@0
|
2991 MainWindow::AddPaneCommand::unexecute()
|
Chris@0
|
2992 {
|
Chris@0
|
2993 m_mw->m_paneStack->hidePane(m_pane);
|
Chris@0
|
2994 m_mw->m_paneStack->setCurrentPane(m_prevCurrentPane);
|
Chris@65
|
2995 m_mw->m_overview->unregisterView(m_pane);
|
Chris@0
|
2996 m_added = false;
|
Chris@0
|
2997 }
|
Chris@0
|
2998
|
Chris@0
|
2999 MainWindow::RemovePaneCommand::RemovePaneCommand(MainWindow *mw, Pane *pane) :
|
Chris@0
|
3000 m_mw(mw),
|
Chris@0
|
3001 m_pane(pane),
|
Chris@0
|
3002 m_added(true)
|
Chris@0
|
3003 {
|
Chris@0
|
3004 }
|
Chris@0
|
3005
|
Chris@0
|
3006 MainWindow::RemovePaneCommand::~RemovePaneCommand()
|
Chris@0
|
3007 {
|
Chris@0
|
3008 if (m_pane && !m_added) {
|
Chris@0
|
3009 m_mw->m_paneStack->deletePane(m_pane);
|
Chris@0
|
3010 }
|
Chris@0
|
3011 }
|
Chris@0
|
3012
|
Chris@0
|
3013 QString
|
Chris@0
|
3014 MainWindow::RemovePaneCommand::getName() const
|
Chris@0
|
3015 {
|
Chris@0
|
3016 return tr("Remove Pane");
|
Chris@0
|
3017 }
|
Chris@0
|
3018
|
Chris@0
|
3019 void
|
Chris@0
|
3020 MainWindow::RemovePaneCommand::execute()
|
Chris@0
|
3021 {
|
Chris@0
|
3022 m_prevCurrentPane = m_mw->m_paneStack->getCurrentPane();
|
Chris@0
|
3023 m_mw->m_paneStack->hidePane(m_pane);
|
Chris@65
|
3024 m_mw->m_overview->unregisterView(m_pane);
|
Chris@0
|
3025 m_added = false;
|
Chris@0
|
3026 }
|
Chris@0
|
3027
|
Chris@0
|
3028 void
|
Chris@0
|
3029 MainWindow::RemovePaneCommand::unexecute()
|
Chris@0
|
3030 {
|
Chris@0
|
3031 m_mw->m_paneStack->showPane(m_pane);
|
Chris@0
|
3032 m_mw->m_paneStack->setCurrentPane(m_prevCurrentPane);
|
Chris@65
|
3033 m_mw->m_overview->registerView(m_pane);
|
Chris@0
|
3034 m_added = true;
|
Chris@0
|
3035 }
|
Chris@0
|
3036
|
Chris@0
|
3037 void
|
Chris@0
|
3038 MainWindow::addLayer()
|
Chris@0
|
3039 {
|
Chris@0
|
3040 QObject *s = sender();
|
Chris@0
|
3041 QAction *action = dynamic_cast<QAction *>(s);
|
Chris@0
|
3042
|
Chris@0
|
3043 if (!action) {
|
Chris@0
|
3044 std::cerr << "WARNING: MainWindow::addLayer: sender is not an action"
|
Chris@0
|
3045 << std::endl;
|
Chris@0
|
3046 return;
|
Chris@0
|
3047 }
|
Chris@0
|
3048
|
Chris@0
|
3049 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@0
|
3050
|
Chris@0
|
3051 if (!pane) {
|
Chris@0
|
3052 std::cerr << "WARNING: MainWindow::addLayer: no current pane" << std::endl;
|
Chris@0
|
3053 return;
|
Chris@0
|
3054 }
|
Chris@0
|
3055
|
Chris@0
|
3056 ExistingLayerActionMap::iterator ei = m_existingLayerActions.find(action);
|
Chris@0
|
3057
|
Chris@0
|
3058 if (ei != m_existingLayerActions.end()) {
|
Chris@0
|
3059 Layer *newLayer = ei->second;
|
Chris@0
|
3060 m_document->addLayerToView(pane, newLayer);
|
Chris@0
|
3061 m_paneStack->setCurrentLayer(pane, newLayer);
|
Chris@0
|
3062 return;
|
Chris@0
|
3063 }
|
Chris@0
|
3064
|
Chris@34
|
3065 TransformActionMap::iterator i = m_transformActions.find(action);
|
Chris@34
|
3066
|
Chris@34
|
3067 if (i == m_transformActions.end()) {
|
Chris@0
|
3068
|
Chris@0
|
3069 LayerActionMap::iterator i = m_layerActions.find(action);
|
Chris@0
|
3070
|
Chris@0
|
3071 if (i == m_layerActions.end()) {
|
Chris@0
|
3072 std::cerr << "WARNING: MainWindow::addLayer: unknown action "
|
Chris@0
|
3073 << action->objectName().toStdString() << std::endl;
|
Chris@0
|
3074 return;
|
Chris@0
|
3075 }
|
Chris@0
|
3076
|
Chris@0
|
3077 LayerFactory::LayerType type = i->second;
|
Chris@0
|
3078
|
Chris@0
|
3079 LayerFactory::LayerTypeSet emptyTypes =
|
Chris@0
|
3080 LayerFactory::getInstance()->getValidEmptyLayerTypes();
|
Chris@0
|
3081
|
Chris@0
|
3082 Layer *newLayer;
|
Chris@0
|
3083
|
Chris@0
|
3084 if (emptyTypes.find(type) != emptyTypes.end()) {
|
Chris@0
|
3085
|
Chris@0
|
3086 newLayer = m_document->createEmptyLayer(type);
|
Chris@0
|
3087 m_toolActions[ViewManager::DrawMode]->trigger();
|
Chris@0
|
3088
|
Chris@0
|
3089 } else {
|
Chris@0
|
3090
|
Chris@0
|
3091 newLayer = m_document->createMainModelLayer(type);
|
Chris@0
|
3092 }
|
Chris@0
|
3093
|
Chris@0
|
3094 m_document->addLayerToView(pane, newLayer);
|
Chris@0
|
3095 m_paneStack->setCurrentLayer(pane, newLayer);
|
Chris@0
|
3096
|
Chris@0
|
3097 return;
|
Chris@0
|
3098 }
|
Chris@0
|
3099
|
Chris@0
|
3100 TransformName transform = i->second;
|
Chris@0
|
3101 TransformFactory *factory = TransformFactory::getInstance();
|
Chris@0
|
3102
|
Chris@0
|
3103 QString configurationXml;
|
Chris@0
|
3104
|
Chris@0
|
3105 int channel = -1;
|
Chris@0
|
3106 // pick up the default channel from any existing layers on the same pane
|
Chris@0
|
3107 for (int j = 0; j < pane->getLayerCount(); ++j) {
|
Chris@0
|
3108 int c = LayerFactory::getInstance()->getChannel(pane->getLayer(j));
|
Chris@0
|
3109 if (c != -1) {
|
Chris@0
|
3110 channel = c;
|
Chris@0
|
3111 break;
|
Chris@0
|
3112 }
|
Chris@0
|
3113 }
|
Chris@0
|
3114
|
Chris@33
|
3115 // We always ask for configuration, even if the plugin isn't
|
Chris@33
|
3116 // supposed to be configurable, because we need to let the user
|
Chris@33
|
3117 // change the execution context (block size etc).
|
Chris@0
|
3118
|
Chris@27
|
3119 PluginTransform::ExecutionContext context(channel);
|
Chris@27
|
3120
|
Chris@66
|
3121 std::vector<Model *> candidateInputModels =
|
Chris@66
|
3122 m_document->getTransformInputModels();
|
Chris@53
|
3123
|
Chris@54
|
3124 Model *inputModel = factory->getConfigurationForTransform(transform,
|
Chris@54
|
3125 candidateInputModels,
|
Chris@54
|
3126 context,
|
Chris@54
|
3127 configurationXml,
|
Chris@54
|
3128 m_playSource);
|
Chris@54
|
3129 if (!inputModel) return;
|
Chris@54
|
3130
|
Chris@54
|
3131 std::cerr << "Input model is " << inputModel << " \"" << inputModel->objectName().toStdString() << std::endl;
|
Chris@0
|
3132
|
Chris@0
|
3133 Layer *newLayer = m_document->createDerivedLayer(transform,
|
Chris@54
|
3134 inputModel,
|
Chris@27
|
3135 context,
|
Chris@0
|
3136 configurationXml);
|
Chris@0
|
3137
|
Chris@0
|
3138 if (newLayer) {
|
Chris@0
|
3139 m_document->addLayerToView(pane, newLayer);
|
Chris@27
|
3140 m_document->setChannel(newLayer, context.channel);
|
Chris@34
|
3141 m_recentTransforms.add(transform);
|
Chris@70
|
3142 m_paneStack->setCurrentLayer(pane, newLayer);
|
Chris@0
|
3143 }
|
Chris@0
|
3144
|
Chris@0
|
3145 updateMenuStates();
|
Chris@0
|
3146 }
|
Chris@0
|
3147
|
Chris@0
|
3148 void
|
Chris@0
|
3149 MainWindow::deleteCurrentPane()
|
Chris@0
|
3150 {
|
Chris@0
|
3151 CommandHistory::getInstance()->startCompoundOperation
|
Chris@0
|
3152 (tr("Delete Pane"), true);
|
Chris@0
|
3153
|
Chris@0
|
3154 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@0
|
3155 if (pane) {
|
Chris@0
|
3156 while (pane->getLayerCount() > 0) {
|
Chris@0
|
3157 Layer *layer = pane->getLayer(0);
|
Chris@0
|
3158 if (layer) {
|
Chris@0
|
3159 m_document->removeLayerFromView(pane, layer);
|
Chris@0
|
3160 } else {
|
Chris@0
|
3161 break;
|
Chris@0
|
3162 }
|
Chris@0
|
3163 }
|
Chris@0
|
3164
|
Chris@0
|
3165 RemovePaneCommand *command = new RemovePaneCommand(this, pane);
|
Chris@0
|
3166 CommandHistory::getInstance()->addCommand(command);
|
Chris@0
|
3167 }
|
Chris@0
|
3168
|
Chris@0
|
3169 CommandHistory::getInstance()->endCompoundOperation();
|
Chris@0
|
3170
|
Chris@0
|
3171 updateMenuStates();
|
Chris@0
|
3172 }
|
Chris@0
|
3173
|
Chris@0
|
3174 void
|
Chris@0
|
3175 MainWindow::deleteCurrentLayer()
|
Chris@0
|
3176 {
|
Chris@0
|
3177 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@0
|
3178 if (pane) {
|
Chris@0
|
3179 Layer *layer = pane->getSelectedLayer();
|
Chris@0
|
3180 if (layer) {
|
Chris@0
|
3181 m_document->removeLayerFromView(pane, layer);
|
Chris@0
|
3182 }
|
Chris@0
|
3183 }
|
Chris@0
|
3184 updateMenuStates();
|
Chris@0
|
3185 }
|
Chris@0
|
3186
|
Chris@0
|
3187 void
|
Chris@0
|
3188 MainWindow::renameCurrentLayer()
|
Chris@0
|
3189 {
|
Chris@0
|
3190 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@0
|
3191 if (pane) {
|
Chris@0
|
3192 Layer *layer = pane->getSelectedLayer();
|
Chris@0
|
3193 if (layer) {
|
Chris@0
|
3194 bool ok = false;
|
Chris@0
|
3195 QString newName = QInputDialog::getText
|
Chris@0
|
3196 (this, tr("Rename Layer"),
|
Chris@0
|
3197 tr("New name for this layer:"),
|
Chris@0
|
3198 QLineEdit::Normal, layer->objectName(), &ok);
|
Chris@0
|
3199 if (ok) {
|
Chris@0
|
3200 layer->setObjectName(newName);
|
Chris@0
|
3201 setupExistingLayersMenu();
|
Chris@0
|
3202 }
|
Chris@0
|
3203 }
|
Chris@0
|
3204 }
|
Chris@0
|
3205 }
|
Chris@0
|
3206
|
Chris@0
|
3207 void
|
Chris@59
|
3208 MainWindow::playSpeedChanged(int position)
|
Chris@0
|
3209 {
|
Chris@59
|
3210 PlaySpeedRangeMapper mapper(0, 200);
|
Chris@60
|
3211
|
Chris@60
|
3212 float percent = m_playSpeed->mappedValue();
|
Chris@60
|
3213
|
Chris@60
|
3214 float factor = mapper.getFactorForValue(percent);
|
Chris@60
|
3215
|
Chris@60
|
3216 // float factor = mapper.getFactorForPosition(position);
|
Chris@60
|
3217 // float percent = mapper.getValueForPosition(position);
|
Chris@60
|
3218
|
Chris@60
|
3219 std::cerr << "speed = " << position << " percent = " << percent << " factor = " << factor << std::endl;
|
Chris@60
|
3220
|
Chris@60
|
3221 //!!! bool slow = (position < 100);
|
Chris@59
|
3222 bool something = (position != 100);
|
Chris@60
|
3223 /*!!!
|
Chris@59
|
3224 int pc = lrintf(percent);
|
Chris@21
|
3225
|
Chris@21
|
3226 m_playSpeed->setToolTip(tr("Playback speed: %1%2%")
|
Chris@60
|
3227 .arg(!slow ? "+" : "")
|
Chris@21
|
3228 .arg(pc));
|
Chris@60
|
3229 */
|
Chris@25
|
3230 m_playSharpen->setEnabled(something);
|
Chris@26
|
3231 m_playMono->setEnabled(something);
|
Chris@25
|
3232 bool sharpen = (something && m_playSharpen->isChecked());
|
Chris@26
|
3233 bool mono = (something && m_playMono->isChecked());
|
Chris@26
|
3234 m_playSource->setTimeStretch(factor, sharpen, mono);
|
Chris@16
|
3235 }
|
Chris@16
|
3236
|
Chris@16
|
3237 void
|
Chris@16
|
3238 MainWindow::playSharpenToggled()
|
Chris@16
|
3239 {
|
Chris@21
|
3240 QSettings settings;
|
Chris@21
|
3241 settings.beginGroup("MainWindow");
|
Chris@21
|
3242 settings.setValue("playsharpen", m_playSharpen->isChecked());
|
Chris@21
|
3243 settings.endGroup();
|
Chris@21
|
3244
|
Chris@16
|
3245 playSpeedChanged(m_playSpeed->value());
|
Chris@0
|
3246 }
|
Chris@0
|
3247
|
Chris@0
|
3248 void
|
Chris@26
|
3249 MainWindow::playMonoToggled()
|
Chris@26
|
3250 {
|
Chris@26
|
3251 QSettings settings;
|
Chris@26
|
3252 settings.beginGroup("MainWindow");
|
Chris@26
|
3253 settings.setValue("playmono", m_playMono->isChecked());
|
Chris@26
|
3254 settings.endGroup();
|
Chris@26
|
3255
|
Chris@26
|
3256 playSpeedChanged(m_playSpeed->value());
|
Chris@26
|
3257 }
|
Chris@26
|
3258
|
Chris@26
|
3259 void
|
Chris@0
|
3260 MainWindow::outputLevelsChanged(float left, float right)
|
Chris@0
|
3261 {
|
Chris@0
|
3262 m_fader->setPeakLeft(left);
|
Chris@0
|
3263 m_fader->setPeakRight(right);
|
Chris@0
|
3264 }
|
Chris@0
|
3265
|
Chris@0
|
3266 void
|
Chris@0
|
3267 MainWindow::sampleRateMismatch(size_t requested, size_t actual,
|
Chris@0
|
3268 bool willResample)
|
Chris@0
|
3269 {
|
Chris@0
|
3270 if (!willResample) {
|
Chris@0
|
3271 //!!! more helpful message needed
|
Chris@0
|
3272 QMessageBox::information
|
Chris@0
|
3273 (this, tr("Sample rate mismatch"),
|
Chris@0
|
3274 tr("The sample rate of this audio file (%1 Hz) does not match\nthe current playback rate (%2 Hz).\n\nThe file will play at the wrong speed.")
|
Chris@0
|
3275 .arg(requested).arg(actual));
|
Chris@0
|
3276 }
|
Chris@0
|
3277
|
Chris@0
|
3278 /*!!! Let's not do this for now, and see how we go -- now that we're putting
|
Chris@0
|
3279 sample rate information in the status bar
|
Chris@0
|
3280
|
Chris@0
|
3281 QMessageBox::information
|
Chris@0
|
3282 (this, tr("Sample rate mismatch"),
|
Chris@0
|
3283 tr("The sample rate of this audio file (%1 Hz) does not match\nthat of the output audio device (%2 Hz).\n\nThe file will be resampled automatically during playback.")
|
Chris@0
|
3284 .arg(requested).arg(actual));
|
Chris@0
|
3285 */
|
Chris@0
|
3286
|
Chris@0
|
3287 updateDescriptionLabel();
|
Chris@0
|
3288 }
|
Chris@0
|
3289
|
Chris@0
|
3290 void
|
Chris@42
|
3291 MainWindow::audioOverloadPluginDisabled()
|
Chris@42
|
3292 {
|
Chris@42
|
3293 QMessageBox::information
|
Chris@42
|
3294 (this, tr("Audio processing overload"),
|
Chris@42
|
3295 tr("Audio effects plugin auditioning has been disabled\ndue to a processing overload."));
|
Chris@42
|
3296 }
|
Chris@42
|
3297
|
Chris@42
|
3298 void
|
Chris@0
|
3299 MainWindow::layerAdded(Layer *layer)
|
Chris@0
|
3300 {
|
Chris@0
|
3301 // std::cerr << "MainWindow::layerAdded(" << layer << ")" << std::endl;
|
Chris@0
|
3302 // setupExistingLayersMenu();
|
Chris@0
|
3303 updateMenuStates();
|
Chris@0
|
3304 }
|
Chris@0
|
3305
|
Chris@0
|
3306 void
|
Chris@0
|
3307 MainWindow::layerRemoved(Layer *layer)
|
Chris@0
|
3308 {
|
Chris@0
|
3309 // std::cerr << "MainWindow::layerRemoved(" << layer << ")" << std::endl;
|
Chris@0
|
3310 setupExistingLayersMenu();
|
Chris@0
|
3311 updateMenuStates();
|
Chris@0
|
3312 }
|
Chris@0
|
3313
|
Chris@0
|
3314 void
|
Chris@0
|
3315 MainWindow::layerAboutToBeDeleted(Layer *layer)
|
Chris@0
|
3316 {
|
Chris@0
|
3317 // std::cerr << "MainWindow::layerAboutToBeDeleted(" << layer << ")" << std::endl;
|
Chris@0
|
3318 if (layer == m_timeRulerLayer) {
|
Chris@0
|
3319 // std::cerr << "(this is the time ruler layer)" << std::endl;
|
Chris@0
|
3320 m_timeRulerLayer = 0;
|
Chris@0
|
3321 }
|
Chris@0
|
3322 }
|
Chris@0
|
3323
|
Chris@0
|
3324 void
|
Chris@0
|
3325 MainWindow::layerInAView(Layer *layer, bool inAView)
|
Chris@0
|
3326 {
|
Chris@0
|
3327 // std::cerr << "MainWindow::layerInAView(" << layer << "," << inAView << ")" << std::endl;
|
Chris@0
|
3328
|
Chris@0
|
3329 // Check whether we need to add or remove model from play source
|
Chris@0
|
3330 Model *model = layer->getModel();
|
Chris@0
|
3331 if (model) {
|
Chris@0
|
3332 if (inAView) {
|
Chris@0
|
3333 m_playSource->addModel(model);
|
Chris@0
|
3334 } else {
|
Chris@0
|
3335 bool found = false;
|
Chris@0
|
3336 for (int i = 0; i < m_paneStack->getPaneCount(); ++i) {
|
Chris@0
|
3337 Pane *pane = m_paneStack->getPane(i);
|
Chris@0
|
3338 if (!pane) continue;
|
Chris@0
|
3339 for (int j = 0; j < pane->getLayerCount(); ++j) {
|
Chris@0
|
3340 Layer *pl = pane->getLayer(j);
|
Chris@0
|
3341 if (pl && pl->getModel() == model) {
|
Chris@0
|
3342 found = true;
|
Chris@0
|
3343 break;
|
Chris@0
|
3344 }
|
Chris@0
|
3345 }
|
Chris@0
|
3346 if (found) break;
|
Chris@0
|
3347 }
|
Chris@0
|
3348 if (!found) m_playSource->removeModel(model);
|
Chris@0
|
3349 }
|
Chris@0
|
3350 }
|
Chris@0
|
3351
|
Chris@0
|
3352 setupExistingLayersMenu();
|
Chris@0
|
3353 updateMenuStates();
|
Chris@0
|
3354 }
|
Chris@0
|
3355
|
Chris@0
|
3356 void
|
Chris@0
|
3357 MainWindow::modelAdded(Model *model)
|
Chris@0
|
3358 {
|
Chris@0
|
3359 // std::cerr << "MainWindow::modelAdded(" << model << ")" << std::endl;
|
Chris@0
|
3360 m_playSource->addModel(model);
|
Chris@66
|
3361 if (dynamic_cast<DenseTimeValueModel *>(model)) {
|
Chris@66
|
3362 setupPaneAndLayerMenus();
|
Chris@66
|
3363 }
|
Chris@0
|
3364 }
|
Chris@0
|
3365
|
Chris@0
|
3366 void
|
Chris@0
|
3367 MainWindow::mainModelChanged(WaveFileModel *model)
|
Chris@0
|
3368 {
|
Chris@0
|
3369 // std::cerr << "MainWindow::mainModelChanged(" << model << ")" << std::endl;
|
Chris@0
|
3370 updateDescriptionLabel();
|
Chris@0
|
3371 m_panLayer->setModel(model);
|
Chris@0
|
3372 if (model) m_viewManager->setMainModelSampleRate(model->getSampleRate());
|
Chris@46
|
3373 if (model && !m_playTarget && m_audioOutput) createPlayTarget();
|
Chris@0
|
3374 }
|
Chris@0
|
3375
|
Chris@0
|
3376 void
|
Chris@0
|
3377 MainWindow::modelAboutToBeDeleted(Model *model)
|
Chris@0
|
3378 {
|
Chris@0
|
3379 // std::cerr << "MainWindow::modelAboutToBeDeleted(" << model << ")" << std::endl;
|
Chris@0
|
3380 m_playSource->removeModel(model);
|
Chris@0
|
3381 }
|
Chris@0
|
3382
|
Chris@0
|
3383 void
|
Chris@0
|
3384 MainWindow::modelGenerationFailed(QString transformName)
|
Chris@0
|
3385 {
|
Chris@0
|
3386 QMessageBox::warning
|
Chris@0
|
3387 (this,
|
Chris@0
|
3388 tr("Failed to generate layer"),
|
Chris@34
|
3389 tr("Failed to generate a derived layer.\n\nThe layer transform \"%1\" failed.\n\nThis probably means that a plugin failed to initialise, perhaps because it\nrejected the processing block size that was requested.")
|
Chris@0
|
3390 .arg(transformName),
|
Chris@0
|
3391 QMessageBox::Ok, 0);
|
Chris@0
|
3392 }
|
Chris@0
|
3393
|
Chris@0
|
3394 void
|
Chris@0
|
3395 MainWindow::modelRegenerationFailed(QString layerName, QString transformName)
|
Chris@0
|
3396 {
|
Chris@0
|
3397 QMessageBox::warning
|
Chris@0
|
3398 (this,
|
Chris@0
|
3399 tr("Failed to regenerate layer"),
|
Chris@34
|
3400 tr("Failed to regenerate derived layer \"%1\".\n\nThe layer transform \"%2\" failed to run.\n\nThis probably means the layer used a plugin that is not currently available.")
|
Chris@0
|
3401 .arg(layerName).arg(transformName),
|
Chris@0
|
3402 QMessageBox::Ok, 0);
|
Chris@0
|
3403 }
|
Chris@0
|
3404
|
Chris@0
|
3405 void
|
Chris@0
|
3406 MainWindow::rightButtonMenuRequested(Pane *pane, QPoint position)
|
Chris@0
|
3407 {
|
Chris@0
|
3408 // std::cerr << "MainWindow::rightButtonMenuRequested(" << pane << ", " << position.x() << ", " << position.y() << ")" << std::endl;
|
Chris@0
|
3409 m_paneStack->setCurrentPane(pane);
|
Chris@0
|
3410 m_rightButtonMenu->popup(position);
|
Chris@0
|
3411 }
|
Chris@0
|
3412
|
Chris@0
|
3413 void
|
Chris@0
|
3414 MainWindow::showLayerTree()
|
Chris@0
|
3415 {
|
Chris@0
|
3416 QTreeView *view = new QTreeView();
|
Chris@0
|
3417 LayerTreeModel *tree = new LayerTreeModel(m_paneStack);
|
Chris@0
|
3418 view->expand(tree->index(0, 0, QModelIndex()));
|
Chris@0
|
3419 view->setModel(tree);
|
Chris@0
|
3420 view->show();
|
Chris@0
|
3421 }
|
Chris@0
|
3422
|
Chris@0
|
3423 void
|
Chris@69
|
3424 MainWindow::pollOSC()
|
Chris@69
|
3425 {
|
Chris@70
|
3426 if (!m_oscQueue || m_oscQueue->isEmpty()) return;
|
Chris@69
|
3427 std::cerr << "MainWindow::pollOSC: have " << m_oscQueue->getMessagesAvailable() << " messages" << std::endl;
|
Chris@69
|
3428
|
Chris@70
|
3429 if (m_openingAudioFile) return;
|
Chris@70
|
3430
|
Chris@69
|
3431 OSCMessage message = m_oscQueue->readMessage();
|
Chris@69
|
3432
|
Chris@69
|
3433 if (message.getTarget() != 0) {
|
Chris@69
|
3434 return; //!!! for now -- this class is target 0, others not handled yet
|
Chris@69
|
3435 }
|
Chris@69
|
3436
|
Chris@69
|
3437 handleOSCMessage(message);
|
Chris@69
|
3438 }
|
Chris@69
|
3439
|
Chris@69
|
3440 void
|
Chris@69
|
3441 MainWindow::handleOSCMessage(const OSCMessage &message)
|
Chris@69
|
3442 {
|
Chris@70
|
3443 std::cerr << "MainWindow::handleOSCMessage: thread id = "
|
Chris@70
|
3444 << QThread::currentThreadId() << std::endl;
|
Chris@70
|
3445
|
Chris@69
|
3446 // This large function should really be abstracted out.
|
Chris@69
|
3447
|
Chris@69
|
3448 if (message.getMethod() == "open") {
|
Chris@69
|
3449
|
Chris@69
|
3450 if (message.getArgCount() == 1 &&
|
Chris@69
|
3451 message.getArg(0).canConvert(QVariant::String)) {
|
Chris@69
|
3452 QString path = message.getArg(0).toString();
|
Chris@69
|
3453 if (!openSomeFile(path, ReplaceMainModel)) {
|
Chris@69
|
3454 std::cerr << "MainWindow::handleOSCMessage: File open failed for path \""
|
Chris@69
|
3455 << path.toStdString() << "\"" << std::endl;
|
Chris@69
|
3456 }
|
Chris@69
|
3457 //!!! we really need to spin here and not return until the
|
Chris@69
|
3458 // file has been completely decoded...
|
Chris@69
|
3459 }
|
Chris@69
|
3460
|
Chris@69
|
3461 } else if (message.getMethod() == "openadditional") {
|
Chris@69
|
3462
|
Chris@69
|
3463 if (message.getArgCount() == 1 &&
|
Chris@69
|
3464 message.getArg(0).canConvert(QVariant::String)) {
|
Chris@69
|
3465 QString path = message.getArg(0).toString();
|
Chris@69
|
3466 if (!openSomeFile(path, CreateAdditionalModel)) {
|
Chris@69
|
3467 std::cerr << "MainWindow::handleOSCMessage: File open failed for path \""
|
Chris@69
|
3468 << path.toStdString() << "\"" << std::endl;
|
Chris@69
|
3469 }
|
Chris@69
|
3470 }
|
Chris@69
|
3471
|
Chris@69
|
3472 } else if (message.getMethod() == "recent" ||
|
Chris@69
|
3473 message.getMethod() == "last") {
|
Chris@69
|
3474
|
Chris@69
|
3475 int n = 0;
|
Chris@69
|
3476 if (message.getMethod() == "recent" &&
|
Chris@69
|
3477 message.getArgCount() == 1 &&
|
Chris@69
|
3478 message.getArg(0).canConvert(QVariant::Int)) {
|
Chris@69
|
3479 n = message.getArg(0).toInt() - 1;
|
Chris@69
|
3480 }
|
Chris@69
|
3481 std::vector<QString> recent = m_recentFiles.getRecent();
|
Chris@69
|
3482 if (n >= 0 && n < recent.size()) {
|
Chris@69
|
3483 if (!openSomeFile(recent[n], ReplaceMainModel)) {
|
Chris@69
|
3484 std::cerr << "MainWindow::handleOSCMessage: File open failed for path \""
|
Chris@69
|
3485 << recent[n].toStdString() << "\"" << std::endl;
|
Chris@69
|
3486 }
|
Chris@69
|
3487 }
|
Chris@69
|
3488
|
Chris@69
|
3489 } else if (message.getMethod() == "save") {
|
Chris@69
|
3490
|
Chris@69
|
3491 QString path;
|
Chris@69
|
3492 if (message.getArgCount() == 1 &&
|
Chris@69
|
3493 message.getArg(0).canConvert(QVariant::String)) {
|
Chris@69
|
3494 path = message.getArg(0).toString();
|
Chris@69
|
3495 if (QFileInfo(path).exists()) {
|
Chris@69
|
3496 std::cerr << "MainWindow::handleOSCMessage: Refusing to overwrite existing file in save" << std::endl;
|
Chris@69
|
3497 } else {
|
Chris@69
|
3498 saveSessionFile(path);
|
Chris@69
|
3499 }
|
Chris@69
|
3500 }
|
Chris@69
|
3501
|
Chris@69
|
3502 } else if (message.getMethod() == "export") {
|
Chris@69
|
3503
|
Chris@69
|
3504 QString path;
|
Chris@69
|
3505 if (getMainModel()) {
|
Chris@69
|
3506 if (message.getArgCount() == 1 &&
|
Chris@69
|
3507 message.getArg(0).canConvert(QVariant::String)) {
|
Chris@69
|
3508 path = message.getArg(0).toString();
|
Chris@69
|
3509 if (QFileInfo(path).exists()) {
|
Chris@69
|
3510 std::cerr << "MainWindow::handleOSCMessage: Refusing to overwrite existing file in export" << std::endl;
|
Chris@69
|
3511 } else {
|
Chris@69
|
3512 WavFileWriter writer(path,
|
Chris@69
|
3513 getMainModel()->getSampleRate(),
|
Chris@69
|
3514 getMainModel()->getChannelCount());
|
Chris@69
|
3515 MultiSelection ms = m_viewManager->getSelection();
|
Chris@69
|
3516 if (!ms.getSelections().empty()) {
|
Chris@69
|
3517 writer.writeModel(getMainModel(), &ms);
|
Chris@69
|
3518 } else {
|
Chris@69
|
3519 writer.writeModel(getMainModel());
|
Chris@69
|
3520 }
|
Chris@69
|
3521 }
|
Chris@69
|
3522 }
|
Chris@69
|
3523 }
|
Chris@69
|
3524
|
Chris@69
|
3525 } else if (message.getMethod() == "jump" ||
|
Chris@69
|
3526 message.getMethod() == "play") {
|
Chris@69
|
3527
|
Chris@69
|
3528 if (getMainModel()) {
|
Chris@69
|
3529
|
Chris@69
|
3530 unsigned long frame = m_viewManager->getPlaybackFrame();
|
Chris@69
|
3531 bool selection = false;
|
Chris@69
|
3532 bool play = (message.getMethod() == "play");
|
Chris@69
|
3533
|
Chris@69
|
3534 if (message.getArgCount() == 1) {
|
Chris@69
|
3535
|
Chris@69
|
3536 if (message.getArg(0).canConvert(QVariant::String) &&
|
Chris@69
|
3537 message.getArg(0).toString() == "selection") {
|
Chris@69
|
3538
|
Chris@69
|
3539 selection = true;
|
Chris@69
|
3540
|
Chris@69
|
3541 } else if (message.getArg(0).canConvert(QVariant::String) &&
|
Chris@69
|
3542 message.getArg(0).toString() == "end") {
|
Chris@69
|
3543
|
Chris@69
|
3544 frame = getMainModel()->getEndFrame();
|
Chris@69
|
3545
|
Chris@69
|
3546 } else if (message.getArg(0).canConvert(QVariant::Double)) {
|
Chris@69
|
3547
|
Chris@69
|
3548 double time = message.getArg(0).toDouble();
|
Chris@69
|
3549 if (time < 0.0) time = 0.0;
|
Chris@69
|
3550
|
Chris@69
|
3551 frame = lrint(time * getMainModel()->getSampleRate());
|
Chris@69
|
3552 }
|
Chris@69
|
3553 }
|
Chris@69
|
3554
|
Chris@69
|
3555 if (frame > getMainModel()->getEndFrame()) {
|
Chris@69
|
3556 frame = getMainModel()->getEndFrame();
|
Chris@69
|
3557 }
|
Chris@69
|
3558
|
Chris@69
|
3559 if (play) {
|
Chris@69
|
3560 m_viewManager->setPlaySelectionMode(selection);
|
Chris@69
|
3561 }
|
Chris@69
|
3562
|
Chris@69
|
3563 if (selection) {
|
Chris@69
|
3564 MultiSelection::SelectionList sl = m_viewManager->getSelections();
|
Chris@69
|
3565 if (!sl.empty()) {
|
Chris@69
|
3566 frame = sl.begin()->getStartFrame();
|
Chris@69
|
3567 }
|
Chris@69
|
3568 }
|
Chris@69
|
3569
|
Chris@69
|
3570 m_viewManager->setPlaybackFrame(frame);
|
Chris@69
|
3571
|
Chris@69
|
3572 if (play && !m_playSource->isPlaying()) {
|
Chris@69
|
3573 m_playSource->play(frame);
|
Chris@69
|
3574 }
|
Chris@69
|
3575 }
|
Chris@69
|
3576
|
Chris@69
|
3577 } else if (message.getMethod() == "stop") {
|
Chris@69
|
3578
|
Chris@69
|
3579 if (m_playSource->isPlaying()) m_playSource->stop();
|
Chris@69
|
3580
|
Chris@69
|
3581 } else if (message.getMethod() == "loop") {
|
Chris@69
|
3582
|
Chris@69
|
3583 if (message.getArgCount() == 1 &&
|
Chris@69
|
3584 message.getArg(0).canConvert(QVariant::String)) {
|
Chris@69
|
3585
|
Chris@69
|
3586 QString str = message.getArg(0).toString();
|
Chris@69
|
3587 if (str == "on") {
|
Chris@69
|
3588 m_viewManager->setPlayLoopMode(true);
|
Chris@69
|
3589 } else if (str == "off") {
|
Chris@69
|
3590 m_viewManager->setPlayLoopMode(false);
|
Chris@69
|
3591 }
|
Chris@69
|
3592 }
|
Chris@69
|
3593
|
Chris@69
|
3594 } else if (message.getMethod() == "select" ||
|
Chris@69
|
3595 message.getMethod() == "addselect") {
|
Chris@69
|
3596
|
Chris@69
|
3597 if (getMainModel()) {
|
Chris@69
|
3598
|
Chris@69
|
3599 unsigned long f0 = getMainModel()->getStartFrame();
|
Chris@69
|
3600 unsigned long f1 = getMainModel()->getEndFrame();
|
Chris@69
|
3601
|
Chris@69
|
3602 bool done = false;
|
Chris@69
|
3603
|
Chris@69
|
3604 if (message.getArgCount() == 2 &&
|
Chris@69
|
3605 message.getArg(0).canConvert(QVariant::Double) &&
|
Chris@69
|
3606 message.getArg(1).canConvert(QVariant::Double)) {
|
Chris@69
|
3607
|
Chris@69
|
3608 double t0 = message.getArg(0).toDouble();
|
Chris@69
|
3609 double t1 = message.getArg(1).toDouble();
|
Chris@69
|
3610 if (t1 < t0) { double temp = t0; t0 = t1; t1 = temp; }
|
Chris@69
|
3611 if (t0 < 0.0) t0 = 0.0;
|
Chris@69
|
3612 if (t1 < 0.0) t1 = 0.0;
|
Chris@69
|
3613
|
Chris@69
|
3614 f0 = lrint(t0 * getMainModel()->getSampleRate());
|
Chris@69
|
3615 f1 = lrint(t1 * getMainModel()->getSampleRate());
|
Chris@69
|
3616
|
Chris@69
|
3617 } else if (message.getArgCount() == 1 &&
|
Chris@69
|
3618 message.getArg(0).canConvert(QVariant::String)) {
|
Chris@69
|
3619
|
Chris@69
|
3620 QString str = message.getArg(0).toString();
|
Chris@69
|
3621 if (str == "none") {
|
Chris@69
|
3622 m_viewManager->clearSelections();
|
Chris@69
|
3623 done = true;
|
Chris@69
|
3624 }
|
Chris@69
|
3625 }
|
Chris@69
|
3626
|
Chris@69
|
3627 if (!done) {
|
Chris@69
|
3628 if (message.getMethod() == "select") {
|
Chris@69
|
3629 m_viewManager->setSelection(Selection(f0, f1));
|
Chris@69
|
3630 } else {
|
Chris@69
|
3631 m_viewManager->addSelection(Selection(f0, f1));
|
Chris@69
|
3632 }
|
Chris@69
|
3633 }
|
Chris@69
|
3634 }
|
Chris@69
|
3635
|
Chris@69
|
3636 } else if (message.getMethod() == "add") {
|
Chris@69
|
3637
|
Chris@69
|
3638 if (getMainModel()) {
|
Chris@69
|
3639
|
Chris@69
|
3640 if (message.getArgCount() >= 1 &&
|
Chris@69
|
3641 message.getArg(0).canConvert(QVariant::String)) {
|
Chris@69
|
3642
|
Chris@69
|
3643 int channel = -1;
|
Chris@69
|
3644 if (message.getArgCount() == 2 &&
|
Chris@69
|
3645 message.getArg(0).canConvert(QVariant::Int)) {
|
Chris@69
|
3646 channel = message.getArg(0).toInt();
|
Chris@69
|
3647 if (channel < -1 ||
|
Chris@69
|
3648 channel > getMainModel()->getChannelCount()) {
|
Chris@69
|
3649 std::cerr << "WARNING: MainWindow::handleOSCMessage: channel "
|
Chris@69
|
3650 << channel << " out of range" << std::endl;
|
Chris@69
|
3651 channel = -1;
|
Chris@69
|
3652 }
|
Chris@69
|
3653 }
|
Chris@69
|
3654
|
Chris@69
|
3655 QString str = message.getArg(0).toString();
|
Chris@69
|
3656
|
Chris@69
|
3657 LayerFactory::LayerType type =
|
Chris@69
|
3658 LayerFactory::getInstance()->getLayerTypeForName(str);
|
Chris@69
|
3659
|
Chris@69
|
3660 if (type == LayerFactory::UnknownLayer) {
|
Chris@69
|
3661 std::cerr << "WARNING: MainWindow::handleOSCMessage: unknown layer "
|
Chris@69
|
3662 << "type " << str.toStdString() << std::endl;
|
Chris@69
|
3663 } else {
|
Chris@69
|
3664
|
Chris@69
|
3665 PaneConfiguration configuration(type,
|
Chris@69
|
3666 getMainModel(),
|
Chris@69
|
3667 channel);
|
Chris@69
|
3668
|
Chris@69
|
3669 addPane(configuration,
|
Chris@69
|
3670 tr("Add %1 Pane")
|
Chris@69
|
3671 .arg(LayerFactory::getInstance()->
|
Chris@69
|
3672 getLayerPresentationName(type)));
|
Chris@69
|
3673 }
|
Chris@69
|
3674 }
|
Chris@69
|
3675 }
|
Chris@69
|
3676
|
Chris@69
|
3677 } else if (message.getMethod() == "undo") {
|
Chris@69
|
3678
|
Chris@69
|
3679 CommandHistory::getInstance()->undo();
|
Chris@69
|
3680
|
Chris@69
|
3681 } else if (message.getMethod() == "redo") {
|
Chris@69
|
3682
|
Chris@69
|
3683 CommandHistory::getInstance()->redo();
|
Chris@69
|
3684
|
Chris@69
|
3685 } else if (message.getMethod() == "set") {
|
Chris@69
|
3686
|
Chris@70
|
3687 if (message.getArgCount() == 2 &&
|
Chris@69
|
3688 message.getArg(0).canConvert(QVariant::String) &&
|
Chris@69
|
3689 message.getArg(1).canConvert(QVariant::Double)) {
|
Chris@69
|
3690
|
Chris@69
|
3691 QString property = message.getArg(0).toString();
|
Chris@69
|
3692 float value = (float)message.getArg(1).toDouble();
|
Chris@69
|
3693
|
Chris@69
|
3694 if (property == "gain") {
|
Chris@69
|
3695 if (value < 0.0) value = 0.0;
|
Chris@69
|
3696 m_fader->setValue(value);
|
Chris@69
|
3697 if (m_playTarget) m_playTarget->setOutputGain(value);
|
Chris@69
|
3698 } else if (property == "speedup") {
|
Chris@69
|
3699 m_playSpeed->setMappedValue(value);
|
Chris@69
|
3700 } else if (property == "overlays") {
|
Chris@69
|
3701 if (value < 0.5) {
|
Chris@69
|
3702 m_viewManager->setOverlayMode(ViewManager::NoOverlays);
|
Chris@69
|
3703 } else if (value < 1.5) {
|
Chris@69
|
3704 m_viewManager->setOverlayMode(ViewManager::BasicOverlays);
|
Chris@69
|
3705 } else {
|
Chris@69
|
3706 m_viewManager->setOverlayMode(ViewManager::AllOverlays);
|
Chris@69
|
3707 }
|
Chris@70
|
3708 } else if (property == "zoomwheels") {
|
Chris@70
|
3709 m_viewManager->setZoomWheelsEnabled(value > 0.5);
|
Chris@70
|
3710 }
|
Chris@70
|
3711
|
Chris@70
|
3712 } else {
|
Chris@70
|
3713 PropertyContainer *container = 0;
|
Chris@70
|
3714 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@70
|
3715 if (pane &&
|
Chris@70
|
3716 message.getArgCount() == 3 &&
|
Chris@70
|
3717 message.getArg(0).canConvert(QVariant::String) &&
|
Chris@70
|
3718 message.getArg(1).canConvert(QVariant::String) &&
|
Chris@70
|
3719 message.getArg(2).canConvert(QVariant::String)) {
|
Chris@70
|
3720 if (message.getArg(0).toString() == "pane") {
|
Chris@70
|
3721 container = pane->getPropertyContainer(0);
|
Chris@70
|
3722 } else if (message.getArg(0).toString() == "layer") {
|
Chris@70
|
3723 container = pane->getSelectedLayer();
|
Chris@70
|
3724 }
|
Chris@70
|
3725 }
|
Chris@70
|
3726 if (container) {
|
Chris@70
|
3727 QString nameString = message.getArg(1).toString();
|
Chris@70
|
3728 QString valueString = message.getArg(2).toString();
|
Chris@70
|
3729 container->setPropertyWithCommand(nameString, valueString);
|
Chris@69
|
3730 }
|
Chris@69
|
3731 }
|
Chris@69
|
3732
|
Chris@69
|
3733 } else if (message.getMethod() == "setcurrent") {
|
Chris@69
|
3734
|
Chris@69
|
3735 int paneIndex = -1, layerIndex = -1;
|
Chris@69
|
3736 bool wantLayer = false;
|
Chris@69
|
3737
|
Chris@69
|
3738 if (message.getArgCount() >= 1 &&
|
Chris@69
|
3739 message.getArg(0).canConvert(QVariant::Int)) {
|
Chris@69
|
3740
|
Chris@69
|
3741 paneIndex = message.getArg(0).toInt() - 1;
|
Chris@69
|
3742
|
Chris@69
|
3743 if (message.getArgCount() >= 2 &&
|
Chris@69
|
3744 message.getArg(1).canConvert(QVariant::Int)) {
|
Chris@69
|
3745 wantLayer = true;
|
Chris@69
|
3746 layerIndex = message.getArg(1).toInt() - 1;
|
Chris@69
|
3747 }
|
Chris@69
|
3748 }
|
Chris@69
|
3749
|
Chris@69
|
3750 if (paneIndex >= 0 && paneIndex < m_paneStack->getPaneCount()) {
|
Chris@69
|
3751 Pane *pane = m_paneStack->getPane(paneIndex);
|
Chris@70
|
3752 m_paneStack->setCurrentPane(pane);
|
Chris@69
|
3753 if (layerIndex >= 0 && layerIndex < pane->getLayerCount()) {
|
Chris@69
|
3754 Layer *layer = pane->getLayer(layerIndex);
|
Chris@69
|
3755 m_paneStack->setCurrentLayer(pane, layer);
|
Chris@69
|
3756 } else if (wantLayer && layerIndex == -1) {
|
Chris@69
|
3757 m_paneStack->setCurrentLayer(pane, 0);
|
Chris@69
|
3758 }
|
Chris@69
|
3759 }
|
Chris@69
|
3760
|
Chris@69
|
3761 } else if (message.getMethod() == "delete") {
|
Chris@69
|
3762
|
Chris@69
|
3763 if (message.getArgCount() == 1 &&
|
Chris@69
|
3764 message.getArg(0).canConvert(QVariant::String)) {
|
Chris@69
|
3765
|
Chris@69
|
3766 QString target = message.getArg(0).toString();
|
Chris@69
|
3767
|
Chris@69
|
3768 if (target == "pane") {
|
Chris@69
|
3769
|
Chris@69
|
3770 deleteCurrentPane();
|
Chris@69
|
3771
|
Chris@69
|
3772 } else if (target == "layer") {
|
Chris@69
|
3773
|
Chris@69
|
3774 deleteCurrentLayer();
|
Chris@69
|
3775
|
Chris@69
|
3776 } else {
|
Chris@69
|
3777
|
Chris@69
|
3778 std::cerr << "WARNING: MainWindow::handleOSCMessage: Unknown delete target " << target.toStdString() << std::endl;
|
Chris@69
|
3779 }
|
Chris@69
|
3780 }
|
Chris@69
|
3781
|
Chris@69
|
3782 } else if (message.getMethod() == "zoom") {
|
Chris@69
|
3783
|
Chris@69
|
3784 if (message.getArgCount() == 1) {
|
Chris@69
|
3785 if (message.getArg(0).canConvert(QVariant::String) &&
|
Chris@69
|
3786 message.getArg(0).toString() == "in") {
|
Chris@69
|
3787 zoomIn();
|
Chris@69
|
3788 } else if (message.getArg(0).canConvert(QVariant::String) &&
|
Chris@69
|
3789 message.getArg(0).toString() == "out") {
|
Chris@69
|
3790 zoomOut();
|
Chris@69
|
3791 } else if (message.getArg(0).canConvert(QVariant::String) &&
|
Chris@69
|
3792 message.getArg(0).toString() == "default") {
|
Chris@69
|
3793 zoomDefault();
|
Chris@69
|
3794 } else if (message.getArg(0).canConvert(QVariant::Double)) {
|
Chris@69
|
3795 double level = message.getArg(0).toDouble();
|
Chris@69
|
3796 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@69
|
3797 if (level < 1.0) level = 1.0;
|
Chris@69
|
3798 if (currentPane) currentPane->setZoomLevel(lrint(level));
|
Chris@69
|
3799 }
|
Chris@69
|
3800 }
|
Chris@69
|
3801
|
Chris@70
|
3802 } else if (message.getMethod() == "quit") {
|
Chris@70
|
3803
|
Chris@70
|
3804 m_abandoning = true;
|
Chris@70
|
3805 close();
|
Chris@70
|
3806
|
Chris@70
|
3807 } else if (message.getMethod() == "resize") {
|
Chris@70
|
3808
|
Chris@70
|
3809 if (message.getArgCount() == 2) {
|
Chris@70
|
3810
|
Chris@70
|
3811 int width = 0, height = 0;
|
Chris@70
|
3812
|
Chris@70
|
3813 if (message.getArg(1).canConvert(QVariant::Int)) {
|
Chris@70
|
3814
|
Chris@70
|
3815 height = message.getArg(1).toInt();
|
Chris@70
|
3816
|
Chris@70
|
3817 if (message.getArg(0).canConvert(QVariant::String) &&
|
Chris@70
|
3818 message.getArg(0).toString() == "pane") {
|
Chris@70
|
3819
|
Chris@70
|
3820 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@70
|
3821 if (pane) pane->resize(pane->width(), height);
|
Chris@70
|
3822
|
Chris@70
|
3823 } else if (message.getArg(0).canConvert(QVariant::Int)) {
|
Chris@70
|
3824
|
Chris@70
|
3825 width = message.getArg(0).toInt();
|
Chris@70
|
3826 resize(width, height);
|
Chris@70
|
3827 }
|
Chris@70
|
3828 }
|
Chris@70
|
3829 }
|
Chris@70
|
3830
|
Chris@70
|
3831 } else if (message.getMethod() == "transform") {
|
Chris@70
|
3832
|
Chris@70
|
3833 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@70
|
3834
|
Chris@70
|
3835 if (getMainModel() &&
|
Chris@70
|
3836 pane &&
|
Chris@70
|
3837 message.getArgCount() == 1 &&
|
Chris@70
|
3838 message.getArg(0).canConvert(QVariant::String)) {
|
Chris@70
|
3839
|
Chris@70
|
3840 TransformName transform = message.getArg(0).toString();
|
Chris@70
|
3841
|
Chris@70
|
3842 Layer *newLayer = m_document->createDerivedLayer
|
Chris@70
|
3843 (transform,
|
Chris@70
|
3844 getMainModel(),
|
Chris@70
|
3845 PluginTransform::ExecutionContext(),
|
Chris@70
|
3846 "");
|
Chris@70
|
3847
|
Chris@70
|
3848 if (newLayer) {
|
Chris@70
|
3849 m_document->addLayerToView(pane, newLayer);
|
Chris@70
|
3850 m_recentTransforms.add(transform);
|
Chris@70
|
3851 m_paneStack->setCurrentLayer(pane, newLayer);
|
Chris@70
|
3852 }
|
Chris@70
|
3853 }
|
Chris@70
|
3854
|
Chris@69
|
3855 } else {
|
Chris@69
|
3856 std::cerr << "WARNING: MainWindow::handleOSCMessage: Unknown or unsupported "
|
Chris@69
|
3857 << "method \"" << message.getMethod().toStdString()
|
Chris@69
|
3858 << "\"" << std::endl;
|
Chris@69
|
3859 }
|
Chris@69
|
3860
|
Chris@69
|
3861 }
|
Chris@69
|
3862
|
Chris@69
|
3863 void
|
Chris@0
|
3864 MainWindow::preferenceChanged(PropertyContainer::PropertyName name)
|
Chris@0
|
3865 {
|
Chris@0
|
3866 if (name == "Property Box Layout") {
|
Chris@0
|
3867 if (Preferences::getInstance()->getPropertyBoxLayout() ==
|
Chris@0
|
3868 Preferences::VerticallyStacked) {
|
Chris@0
|
3869 m_paneStack->setLayoutStyle(PaneStack::PropertyStackPerPaneLayout);
|
Chris@0
|
3870 } else {
|
Chris@0
|
3871 m_paneStack->setLayoutStyle(PaneStack::SinglePropertyStackLayout);
|
Chris@0
|
3872 }
|
Chris@0
|
3873 }
|
Chris@0
|
3874 }
|
Chris@0
|
3875
|
Chris@0
|
3876 void
|
Chris@0
|
3877 MainWindow::preferences()
|
Chris@0
|
3878 {
|
Chris@0
|
3879 if (!m_preferencesDialog.isNull()) {
|
Chris@0
|
3880 m_preferencesDialog->show();
|
Chris@0
|
3881 m_preferencesDialog->raise();
|
Chris@0
|
3882 return;
|
Chris@0
|
3883 }
|
Chris@0
|
3884
|
Chris@0
|
3885 m_preferencesDialog = new PreferencesDialog(this);
|
Chris@0
|
3886
|
Chris@0
|
3887 // DeleteOnClose is safe here, because m_preferencesDialog is a
|
Chris@0
|
3888 // QPointer that will be zeroed when the dialog is deleted. We
|
Chris@0
|
3889 // use it in preference to leaving the dialog lying around because
|
Chris@0
|
3890 // if you Cancel the dialog, it resets the preferences state
|
Chris@0
|
3891 // without resetting its own widgets, so its state will be
|
Chris@0
|
3892 // incorrect when next shown unless we construct it afresh
|
Chris@0
|
3893 m_preferencesDialog->setAttribute(Qt::WA_DeleteOnClose);
|
Chris@0
|
3894
|
Chris@0
|
3895 m_preferencesDialog->show();
|
Chris@0
|
3896 }
|
Chris@0
|
3897
|
Chris@0
|
3898 void
|
Chris@0
|
3899 MainWindow::website()
|
Chris@0
|
3900 {
|
Chris@0
|
3901 openHelpUrl(tr("http://www.sonicvisualiser.org/"));
|
Chris@0
|
3902 }
|
Chris@0
|
3903
|
Chris@0
|
3904 void
|
Chris@0
|
3905 MainWindow::help()
|
Chris@0
|
3906 {
|
Chris@0
|
3907 openHelpUrl(tr("http://www.sonicvisualiser.org/doc/reference/en/"));
|
Chris@0
|
3908 }
|
Chris@0
|
3909
|
Chris@0
|
3910 void
|
Chris@0
|
3911 MainWindow::openHelpUrl(QString url)
|
Chris@0
|
3912 {
|
Chris@0
|
3913 // This method mostly lifted from Qt Assistant source code
|
Chris@0
|
3914
|
Chris@0
|
3915 QProcess *process = new QProcess(this);
|
Chris@0
|
3916 connect(process, SIGNAL(finished(int)), process, SLOT(deleteLater()));
|
Chris@0
|
3917
|
Chris@0
|
3918 QStringList args;
|
Chris@0
|
3919
|
Chris@0
|
3920 #ifdef Q_OS_MAC
|
Chris@0
|
3921 args.append(url);
|
Chris@0
|
3922 process->start("open", args);
|
Chris@0
|
3923 #else
|
Chris@0
|
3924 #ifdef Q_OS_WIN32
|
Chris@0
|
3925
|
Chris@0
|
3926 QString pf(getenv("ProgramFiles"));
|
Chris@0
|
3927 QString command = pf + QString("\\Internet Explorer\\IEXPLORE.EXE");
|
Chris@0
|
3928
|
Chris@0
|
3929 args.append(url);
|
Chris@0
|
3930 process->start(command, args);
|
Chris@0
|
3931
|
Chris@0
|
3932 #else
|
Chris@0
|
3933 #ifdef Q_WS_X11
|
Chris@0
|
3934 if (!qgetenv("KDE_FULL_SESSION").isEmpty()) {
|
Chris@0
|
3935 args.append("exec");
|
Chris@0
|
3936 args.append(url);
|
Chris@0
|
3937 process->start("kfmclient", args);
|
Chris@0
|
3938 } else if (!qgetenv("BROWSER").isEmpty()) {
|
Chris@0
|
3939 args.append(url);
|
Chris@0
|
3940 process->start(qgetenv("BROWSER"), args);
|
Chris@0
|
3941 } else {
|
Chris@0
|
3942 args.append(url);
|
Chris@0
|
3943 process->start("firefox", args);
|
Chris@0
|
3944 }
|
Chris@0
|
3945 #endif
|
Chris@0
|
3946 #endif
|
Chris@0
|
3947 #endif
|
Chris@0
|
3948 }
|
Chris@0
|
3949
|
Chris@0
|
3950 void
|
Chris@0
|
3951 MainWindow::about()
|
Chris@0
|
3952 {
|
Chris@0
|
3953 bool debug = false;
|
Chris@0
|
3954 QString version = "(unknown version)";
|
Chris@0
|
3955
|
Chris@0
|
3956 #ifdef BUILD_DEBUG
|
Chris@0
|
3957 debug = true;
|
Chris@0
|
3958 #endif
|
Chris@0
|
3959 #ifdef SV_VERSION
|
Chris@0
|
3960 #ifdef SVNREV
|
Chris@0
|
3961 version = tr("Release %1 : Revision %2").arg(SV_VERSION).arg(SVNREV);
|
Chris@0
|
3962 #else
|
Chris@0
|
3963 version = tr("Release %1").arg(SV_VERSION);
|
Chris@0
|
3964 #endif
|
Chris@0
|
3965 #else
|
Chris@0
|
3966 #ifdef SVNREV
|
Chris@0
|
3967 version = tr("Unreleased : Revision %1").arg(SVNREV);
|
Chris@0
|
3968 #endif
|
Chris@0
|
3969 #endif
|
Chris@0
|
3970
|
Chris@0
|
3971 QString aboutText;
|
Chris@0
|
3972
|
Chris@0
|
3973 aboutText += tr("<h3>About Sonic Visualiser</h3>");
|
Chris@0
|
3974 aboutText += tr("<p>Sonic Visualiser is a program for viewing and exploring audio data for semantic music analysis and annotation.</p>");
|
Chris@0
|
3975 aboutText += tr("<p>%1 : %2 build</p>")
|
Chris@0
|
3976 .arg(version)
|
Chris@0
|
3977 .arg(debug ? tr("Debug") : tr("Release"));
|
Chris@0
|
3978
|
Chris@0
|
3979 #ifdef BUILD_STATIC
|
Chris@0
|
3980 aboutText += tr("<p>Statically linked");
|
Chris@0
|
3981 #ifndef QT_SHARED
|
Chris@0
|
3982 aboutText += tr("<br>With Qt (v%1) © Trolltech AS").arg(QT_VERSION_STR);
|
Chris@0
|
3983 #endif
|
Chris@0
|
3984 #ifdef HAVE_JACK
|
Chris@0
|
3985 aboutText += tr("<br>With JACK audio output (v%1) © Paul Davis and Jack O'Quin").arg(JACK_VERSION);
|
Chris@0
|
3986 #endif
|
Chris@0
|
3987 #ifdef HAVE_PORTAUDIO
|
Chris@0
|
3988 aboutText += tr("<br>With PortAudio audio output © Ross Bencina and Phil Burk");
|
Chris@0
|
3989 #endif
|
Chris@0
|
3990 #ifdef HAVE_OGGZ
|
Chris@0
|
3991 aboutText += tr("<br>With Ogg file decoder (oggz v%1, fishsound v%2) © CSIRO Australia").arg(OGGZ_VERSION).arg(FISHSOUND_VERSION);
|
Chris@0
|
3992 #endif
|
Chris@0
|
3993 #ifdef HAVE_MAD
|
Chris@0
|
3994 aboutText += tr("<br>With MAD mp3 decoder (v%1) © Underbit Technologies Inc").arg(MAD_VERSION);
|
Chris@0
|
3995 #endif
|
Chris@0
|
3996 #ifdef HAVE_SAMPLERATE
|
Chris@0
|
3997 aboutText += tr("<br>With libsamplerate (v%1) © Erik de Castro Lopo").arg(SAMPLERATE_VERSION);
|
Chris@0
|
3998 #endif
|
Chris@0
|
3999 #ifdef HAVE_SNDFILE
|
Chris@0
|
4000 aboutText += tr("<br>With libsndfile (v%1) © Erik de Castro Lopo").arg(SNDFILE_VERSION);
|
Chris@0
|
4001 #endif
|
Chris@0
|
4002 #ifdef HAVE_FFTW3
|
Chris@0
|
4003 aboutText += tr("<br>With FFTW3 (v%1) © Matteo Frigo and MIT").arg(FFTW3_VERSION);
|
Chris@0
|
4004 #endif
|
Chris@0
|
4005 #ifdef HAVE_VAMP
|
Chris@0
|
4006 aboutText += tr("<br>With Vamp plugin support (API v%1, SDK v%2) © Chris Cannam").arg(VAMP_API_VERSION).arg(VAMP_SDK_VERSION);
|
Chris@0
|
4007 #endif
|
Chris@0
|
4008 aboutText += tr("<br>With LADSPA plugin support (API v%1) © Richard Furse, Paul Davis, Stefan Westerfeld").arg(LADSPA_VERSION);
|
Chris@0
|
4009 aboutText += tr("<br>With DSSI plugin support (API v%1) © Chris Cannam, Steve Harris, Sean Bolton").arg(DSSI_VERSION);
|
Chris@69
|
4010 #ifdef HAVE_LIBLO
|
Chris@69
|
4011 aboutText += tr("<br>With liblo Lite OSC library (v%1) © Steve Harris").arg(LIBLO_VERSION);
|
Chris@70
|
4012 if (m_oscQueue && m_oscQueue->isOK()) {
|
Chris@69
|
4013 aboutText += tr("<p>The OSC URL for this instance is: \"%1\"").arg(m_oscQueue->getOSCURL());
|
Chris@69
|
4014 }
|
Chris@69
|
4015 #endif
|
Chris@0
|
4016 aboutText += "</p>";
|
Chris@0
|
4017 #endif
|
Chris@0
|
4018
|
Chris@0
|
4019 aboutText +=
|
Chris@0
|
4020 "<p>Sonic Visualiser Copyright © 2005 - 2006 Chris Cannam<br>"
|
Chris@0
|
4021 "Centre for Digital Music, Queen Mary, University of London.</p>"
|
Chris@0
|
4022 "<p>This program is free software; you can redistribute it and/or<br>"
|
Chris@0
|
4023 "modify it under the terms of the GNU General Public License as<br>"
|
Chris@0
|
4024 "published by the Free Software Foundation; either version 2 of the<br>"
|
Chris@0
|
4025 "License, or (at your option) any later version.<br>See the file "
|
Chris@0
|
4026 "COPYING included with this distribution for more information.</p>";
|
Chris@0
|
4027
|
Chris@0
|
4028 QMessageBox::about(this, tr("About Sonic Visualiser"), aboutText);
|
Chris@0
|
4029 }
|
Chris@0
|
4030
|
Chris@0
|
4031
|
Chris@0
|
4032 #ifdef INCLUDE_MOCFILES
|
Chris@0
|
4033 #include "MainWindow.moc.cpp"
|
Chris@0
|
4034 #endif
|