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