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