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