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@77
|
7 This file copyright 2006 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@1
|
19 #include "document/Document.h"
|
Chris@0
|
20 #include "PreferencesDialog.h"
|
Chris@0
|
21
|
Chris@1
|
22 #include "view/Pane.h"
|
Chris@1
|
23 #include "view/PaneStack.h"
|
Chris@1
|
24 #include "data/model/WaveFileModel.h"
|
Chris@1
|
25 #include "data/model/SparseOneDimensionalModel.h"
|
Chris@185
|
26 #include "data/model/NoteModel.h"
|
Chris@189
|
27 #include "data/model/Labeller.h"
|
Chris@1
|
28 #include "view/ViewManager.h"
|
Chris@0
|
29 #include "base/Preferences.h"
|
Chris@0
|
30 #include "layer/WaveformLayer.h"
|
Chris@0
|
31 #include "layer/TimeRulerLayer.h"
|
Chris@0
|
32 #include "layer/TimeInstantLayer.h"
|
Chris@0
|
33 #include "layer/TimeValueLayer.h"
|
Chris@0
|
34 #include "layer/Colour3DPlotLayer.h"
|
Chris@95
|
35 #include "layer/SliceLayer.h"
|
Chris@95
|
36 #include "layer/SliceableLayer.h"
|
Chris@193
|
37 #include "layer/ImageLayer.h"
|
Chris@0
|
38 #include "widgets/Fader.h"
|
Chris@65
|
39 #include "view/Overview.h"
|
Chris@0
|
40 #include "widgets/PropertyBox.h"
|
Chris@0
|
41 #include "widgets/PropertyStack.h"
|
Chris@0
|
42 #include "widgets/AudioDial.h"
|
Chris@168
|
43 #include "widgets/IconLoader.h"
|
Chris@0
|
44 #include "widgets/LayerTree.h"
|
Chris@0
|
45 #include "widgets/ListInputDialog.h"
|
Chris@36
|
46 #include "widgets/SubdividingMenu.h"
|
Chris@90
|
47 #include "widgets/NotifyingPushButton.h"
|
Chris@162
|
48 #include "widgets/KeyReference.h"
|
Chris@192
|
49 #include "widgets/LabelCounterInputDialog.h"
|
Chris@0
|
50 #include "audioio/AudioCallbackPlaySource.h"
|
Chris@0
|
51 #include "audioio/AudioCallbackPlayTarget.h"
|
Chris@0
|
52 #include "audioio/AudioTargetFactory.h"
|
Chris@59
|
53 #include "audioio/PlaySpeedRangeMapper.h"
|
Chris@1
|
54 #include "data/fileio/DataFileReaderFactory.h"
|
Chris@180
|
55 #include "data/fileio/PlaylistFileReader.h"
|
Chris@1
|
56 #include "data/fileio/WavFileWriter.h"
|
Chris@1
|
57 #include "data/fileio/CSVFileWriter.h"
|
Chris@185
|
58 #include "data/fileio/MIDIFileWriter.h"
|
Chris@1
|
59 #include "data/fileio/BZipFileDevice.h"
|
Chris@85
|
60 #include "data/fileio/RemoteFile.h"
|
Chris@91
|
61 #include "data/fft/FFTDataServer.h"
|
Chris@1
|
62 #include "base/RecentFiles.h"
|
Chris@0
|
63 #include "transform/TransformFactory.h"
|
Chris@0
|
64 #include "base/PlayParameterRepository.h"
|
Chris@0
|
65 #include "base/XmlExportable.h"
|
Chris@0
|
66 #include "base/CommandHistory.h"
|
Chris@0
|
67 #include "base/Profiler.h"
|
Chris@0
|
68 #include "base/Clipboard.h"
|
Chris@165
|
69 #include "base/UnitDatabase.h"
|
Chris@165
|
70 #include "base/ColourDatabase.h"
|
Chris@69
|
71 #include "osc/OSCQueue.h"
|
Chris@0
|
72
|
Chris@180
|
73 //!!!
|
Chris@180
|
74 #include "data/model/AggregateWaveModel.h"
|
Chris@180
|
75
|
Chris@0
|
76 // For version information
|
Chris@0
|
77 #include "vamp/vamp.h"
|
Chris@0
|
78 #include "vamp-sdk/PluginBase.h"
|
Chris@0
|
79 #include "plugin/api/ladspa.h"
|
Chris@0
|
80 #include "plugin/api/dssi.h"
|
Chris@0
|
81
|
Chris@0
|
82 #include <QApplication>
|
Chris@0
|
83 #include <QMessageBox>
|
Chris@0
|
84 #include <QGridLayout>
|
Chris@0
|
85 #include <QLabel>
|
Chris@0
|
86 #include <QAction>
|
Chris@0
|
87 #include <QMenuBar>
|
Chris@0
|
88 #include <QToolBar>
|
Chris@0
|
89 #include <QInputDialog>
|
Chris@0
|
90 #include <QStatusBar>
|
Chris@0
|
91 #include <QTreeView>
|
Chris@0
|
92 #include <QFile>
|
Chris@88
|
93 #include <QFileInfo>
|
Chris@88
|
94 #include <QDir>
|
Chris@0
|
95 #include <QTextStream>
|
Chris@0
|
96 #include <QProcess>
|
Chris@7
|
97 #include <QShortcut>
|
Chris@5
|
98 #include <QSettings>
|
Chris@11
|
99 #include <QDateTime>
|
Chris@11
|
100 #include <QProcess>
|
Chris@16
|
101 #include <QCheckBox>
|
Chris@55
|
102 #include <QRegExp>
|
Chris@158
|
103 #include <QScrollArea>
|
Chris@0
|
104
|
Chris@0
|
105 #include <iostream>
|
Chris@0
|
106 #include <cstdio>
|
Chris@0
|
107 #include <errno.h>
|
Chris@0
|
108
|
Chris@0
|
109 using std::cerr;
|
Chris@0
|
110 using std::endl;
|
Chris@0
|
111
|
Chris@33
|
112 using std::vector;
|
Chris@33
|
113 using std::map;
|
Chris@33
|
114 using std::set;
|
Chris@33
|
115
|
Chris@0
|
116
|
Chris@70
|
117 MainWindow::MainWindow(bool withAudioOutput, bool withOSCSupport) :
|
Chris@0
|
118 m_document(0),
|
Chris@0
|
119 m_paneStack(0),
|
Chris@0
|
120 m_viewManager(0),
|
Chris@65
|
121 m_overview(0),
|
Chris@0
|
122 m_timeRulerLayer(0),
|
Chris@46
|
123 m_audioOutput(withAudioOutput),
|
Chris@0
|
124 m_playSource(0),
|
Chris@0
|
125 m_playTarget(0),
|
Chris@70
|
126 m_oscQueue(withOSCSupport ? new OSCQueue() : 0),
|
Chris@81
|
127 m_recentFiles("RecentFiles", 20),
|
Chris@49
|
128 m_recentTransforms("RecentTransforms", 20),
|
Chris@0
|
129 m_mainMenusCreated(false),
|
Chris@0
|
130 m_paneMenu(0),
|
Chris@0
|
131 m_layerMenu(0),
|
Chris@34
|
132 m_transformsMenu(0),
|
Chris@155
|
133 m_playbackMenu(0),
|
Chris@0
|
134 m_existingLayersMenu(0),
|
Chris@95
|
135 m_sliceMenu(0),
|
Chris@34
|
136 m_recentFilesMenu(0),
|
Chris@34
|
137 m_recentTransformsMenu(0),
|
Chris@0
|
138 m_rightButtonMenu(0),
|
Chris@0
|
139 m_rightButtonLayerMenu(0),
|
Chris@34
|
140 m_rightButtonTransformsMenu(0),
|
Chris@155
|
141 m_rightButtonPlaybackMenu(0),
|
Chris@155
|
142 m_ffwdAction(0),
|
Chris@155
|
143 m_rwdAction(0),
|
Chris@0
|
144 m_documentModified(false),
|
Chris@70
|
145 m_openingAudioFile(false),
|
Chris@70
|
146 m_abandoning(false),
|
Chris@189
|
147 m_labeller(0),
|
Chris@162
|
148 m_preferencesDialog(0),
|
Chris@177
|
149 m_layerTreeView(0),
|
Chris@162
|
150 m_keyReference(new KeyReference())
|
Chris@0
|
151 {
|
Chris@0
|
152 setWindowTitle(tr("Sonic Visualiser"));
|
Chris@0
|
153
|
Chris@165
|
154 UnitDatabase *udb = UnitDatabase::getInstance();
|
Chris@165
|
155 udb->registerUnit("Hz");
|
Chris@165
|
156 udb->registerUnit("dB");
|
Chris@165
|
157 udb->registerUnit("s");
|
Chris@165
|
158
|
Chris@165
|
159 ColourDatabase *cdb = ColourDatabase::getInstance();
|
Chris@165
|
160 cdb->addColour(Qt::black, tr("Black"));
|
Chris@165
|
161 cdb->addColour(Qt::darkRed, tr("Red"));
|
Chris@165
|
162 cdb->addColour(Qt::darkBlue, tr("Blue"));
|
Chris@165
|
163 cdb->addColour(Qt::darkGreen, tr("Green"));
|
Chris@165
|
164 cdb->addColour(QColor(200, 50, 255), tr("Purple"));
|
Chris@165
|
165 cdb->addColour(QColor(255, 150, 50), tr("Orange"));
|
Chris@166
|
166 cdb->setUseDarkBackground(cdb->addColour(Qt::white, tr("White")), true);
|
Chris@166
|
167 cdb->setUseDarkBackground(cdb->addColour(Qt::red, tr("Bright Red")), true);
|
Chris@166
|
168 cdb->setUseDarkBackground(cdb->addColour(QColor(30, 150, 255), tr("Bright Blue")), true);
|
Chris@166
|
169 cdb->setUseDarkBackground(cdb->addColour(Qt::green, tr("Bright Green")), true);
|
Chris@166
|
170 cdb->setUseDarkBackground(cdb->addColour(QColor(225, 74, 255), tr("Bright Purple")), true);
|
Chris@166
|
171 cdb->setUseDarkBackground(cdb->addColour(QColor(255, 188, 80), tr("Bright Orange")), true);
|
Chris@0
|
172
|
Chris@0
|
173 connect(CommandHistory::getInstance(), SIGNAL(commandExecuted()),
|
Chris@0
|
174 this, SLOT(documentModified()));
|
Chris@0
|
175 connect(CommandHistory::getInstance(), SIGNAL(documentRestored()),
|
Chris@0
|
176 this, SLOT(documentRestored()));
|
Chris@0
|
177
|
Chris@0
|
178 QFrame *frame = new QFrame;
|
Chris@0
|
179 setCentralWidget(frame);
|
Chris@0
|
180
|
Chris@0
|
181 QGridLayout *layout = new QGridLayout;
|
Chris@0
|
182
|
Chris@0
|
183 m_viewManager = new ViewManager();
|
Chris@0
|
184 connect(m_viewManager, SIGNAL(selectionChanged()),
|
Chris@0
|
185 this, SLOT(updateMenuStates()));
|
Chris@117
|
186 connect(m_viewManager, SIGNAL(inProgressSelectionChanged()),
|
Chris@117
|
187 this, SLOT(inProgressSelectionChanged()));
|
Chris@0
|
188
|
Chris@180
|
189 Preferences::BackgroundMode mode =
|
Chris@180
|
190 Preferences::getInstance()->getBackgroundMode();
|
Chris@180
|
191 m_initialDarkBackground = m_viewManager->getGlobalDarkBackground();
|
Chris@180
|
192 if (mode != Preferences::BackgroundFromTheme) {
|
Chris@180
|
193 m_viewManager->setGlobalDarkBackground
|
Chris@180
|
194 (mode == Preferences::DarkBackground);
|
Chris@180
|
195 }
|
Chris@180
|
196
|
Chris@0
|
197 m_descriptionLabel = new QLabel;
|
Chris@0
|
198
|
Chris@158
|
199 QScrollArea *scroll = new QScrollArea(frame);
|
Chris@158
|
200 scroll->setWidgetResizable(true);
|
Chris@158
|
201 scroll->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
Chris@159
|
202 scroll->setFrameShape(QFrame::NoFrame);
|
Chris@159
|
203
|
Chris@159
|
204 m_paneStack = new PaneStack(scroll, m_viewManager);
|
Chris@0
|
205 connect(m_paneStack, SIGNAL(currentPaneChanged(Pane *)),
|
Chris@0
|
206 this, SLOT(currentPaneChanged(Pane *)));
|
Chris@0
|
207 connect(m_paneStack, SIGNAL(currentLayerChanged(Pane *, Layer *)),
|
Chris@0
|
208 this, SLOT(currentLayerChanged(Pane *, Layer *)));
|
Chris@0
|
209 connect(m_paneStack, SIGNAL(rightButtonMenuRequested(Pane *, QPoint)),
|
Chris@0
|
210 this, SLOT(rightButtonMenuRequested(Pane *, QPoint)));
|
Chris@73
|
211 connect(m_paneStack, SIGNAL(propertyStacksResized()),
|
Chris@73
|
212 this, SLOT(propertyStacksResized()));
|
Chris@90
|
213 connect(m_paneStack, SIGNAL(contextHelpChanged(const QString &)),
|
Chris@116
|
214 this, SLOT(contextHelpChanged(const QString &)));
|
Chris@193
|
215 connect(m_paneStack, SIGNAL(dropAccepted(Pane *, QStringList)),
|
Chris@193
|
216 this, SLOT(paneDropAccepted(Pane *, QStringList)));
|
Chris@193
|
217 connect(m_paneStack, SIGNAL(dropAccepted(Pane *, QString)),
|
Chris@193
|
218 this, SLOT(paneDropAccepted(Pane *, QString)));
|
Chris@0
|
219
|
Chris@159
|
220 scroll->setWidget(m_paneStack);
|
Chris@159
|
221
|
Chris@65
|
222 m_overview = new Overview(frame);
|
Chris@65
|
223 m_overview->setViewManager(m_viewManager);
|
Chris@65
|
224 m_overview->setFixedHeight(40);
|
Chris@144
|
225 #ifndef _WIN32
|
Chris@144
|
226 // For some reason, the contents of the overview never appear if we
|
Chris@144
|
227 // make this setting on Windows. I have no inclination at the moment
|
Chris@144
|
228 // to track down the reason why.
|
Chris@129
|
229 m_overview->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
|
Chris@144
|
230 #endif
|
Chris@90
|
231 connect(m_overview, SIGNAL(contextHelpChanged(const QString &)),
|
Chris@116
|
232 this, SLOT(contextHelpChanged(const QString &)));
|
Chris@0
|
233
|
Chris@0
|
234 m_panLayer = new WaveformLayer;
|
Chris@0
|
235 m_panLayer->setChannelMode(WaveformLayer::MergeChannels);
|
Chris@0
|
236 m_panLayer->setAggressiveCacheing(true);
|
Chris@65
|
237 m_overview->addLayer(m_panLayer);
|
Chris@174
|
238
|
Chris@174
|
239 if (m_viewManager->getGlobalDarkBackground()) {
|
Chris@174
|
240 m_panLayer->setBaseColour
|
Chris@174
|
241 (ColourDatabase::getInstance()->getColourIndex(tr("Bright Green")));
|
Chris@174
|
242 } else {
|
Chris@174
|
243 m_panLayer->setBaseColour
|
Chris@174
|
244 (ColourDatabase::getInstance()->getColourIndex(tr("Green")));
|
Chris@174
|
245 }
|
Chris@0
|
246
|
Chris@0
|
247 m_playSource = new AudioCallbackPlaySource(m_viewManager);
|
Chris@0
|
248
|
Chris@0
|
249 connect(m_playSource, SIGNAL(sampleRateMismatch(size_t, size_t, bool)),
|
Chris@0
|
250 this, SLOT(sampleRateMismatch(size_t, size_t, bool)));
|
Chris@42
|
251 connect(m_playSource, SIGNAL(audioOverloadPluginDisabled()),
|
Chris@42
|
252 this, SLOT(audioOverloadPluginDisabled()));
|
Chris@0
|
253
|
Chris@0
|
254 m_fader = new Fader(frame, false);
|
Chris@90
|
255 connect(m_fader, SIGNAL(mouseEntered()), this, SLOT(mouseEnteredWidget()));
|
Chris@90
|
256 connect(m_fader, SIGNAL(mouseLeft()), this, SLOT(mouseLeftWidget()));
|
Chris@0
|
257
|
Chris@0
|
258 m_playSpeed = new AudioDial(frame);
|
Chris@12
|
259 m_playSpeed->setMinimum(0);
|
Chris@48
|
260 m_playSpeed->setMaximum(200);
|
Chris@25
|
261 m_playSpeed->setValue(100);
|
Chris@0
|
262 m_playSpeed->setFixedWidth(24);
|
Chris@0
|
263 m_playSpeed->setFixedHeight(24);
|
Chris@0
|
264 m_playSpeed->setNotchesVisible(true);
|
Chris@25
|
265 m_playSpeed->setPageStep(10);
|
Chris@60
|
266 m_playSpeed->setObjectName(tr("Playback Speedup"));
|
Chris@25
|
267 m_playSpeed->setDefaultValue(100);
|
Chris@59
|
268 m_playSpeed->setRangeMapper(new PlaySpeedRangeMapper(0, 200));
|
Chris@60
|
269 m_playSpeed->setShowToolTip(true);
|
Chris@0
|
270 connect(m_playSpeed, SIGNAL(valueChanged(int)),
|
Chris@0
|
271 this, SLOT(playSpeedChanged(int)));
|
Chris@90
|
272 connect(m_playSpeed, SIGNAL(mouseEntered()), this, SLOT(mouseEnteredWidget()));
|
Chris@90
|
273 connect(m_playSpeed, SIGNAL(mouseLeft()), this, SLOT(mouseLeftWidget()));
|
Chris@90
|
274
|
Chris@168
|
275 IconLoader il;
|
Chris@168
|
276
|
Chris@90
|
277 m_playSharpen = new NotifyingPushButton(frame);
|
Chris@17
|
278 m_playSharpen->setToolTip(tr("Sharpen percussive transients"));
|
Chris@26
|
279 m_playSharpen->setFixedSize(20, 20);
|
Chris@16
|
280 m_playSharpen->setEnabled(false);
|
Chris@26
|
281 m_playSharpen->setCheckable(true);
|
Chris@26
|
282 m_playSharpen->setChecked(false);
|
Chris@168
|
283 m_playSharpen->setIcon(il.load("sharpen"));
|
Chris@26
|
284 connect(m_playSharpen, SIGNAL(clicked()), this, SLOT(playSharpenToggled()));
|
Chris@90
|
285 connect(m_playSharpen, SIGNAL(mouseEntered()), this, SLOT(mouseEnteredWidget()));
|
Chris@90
|
286 connect(m_playSharpen, SIGNAL(mouseLeft()), this, SLOT(mouseLeftWidget()));
|
Chris@90
|
287
|
Chris@90
|
288 m_playMono = new NotifyingPushButton(frame);
|
Chris@26
|
289 m_playMono->setToolTip(tr("Run time stretcher in mono only"));
|
Chris@26
|
290 m_playMono->setFixedSize(20, 20);
|
Chris@26
|
291 m_playMono->setEnabled(false);
|
Chris@26
|
292 m_playMono->setCheckable(true);
|
Chris@26
|
293 m_playMono->setChecked(false);
|
Chris@168
|
294 m_playMono->setIcon(il.load("mono"));
|
Chris@26
|
295 connect(m_playMono, SIGNAL(clicked()), this, SLOT(playMonoToggled()));
|
Chris@90
|
296 connect(m_playMono, SIGNAL(mouseEntered()), this, SLOT(mouseEnteredWidget()));
|
Chris@90
|
297 connect(m_playMono, SIGNAL(mouseLeft()), this, SLOT(mouseLeftWidget()));
|
Chris@21
|
298
|
Chris@21
|
299 QSettings settings;
|
Chris@21
|
300 settings.beginGroup("MainWindow");
|
Chris@24
|
301 m_playSharpen->setChecked(settings.value("playsharpen", true).toBool());
|
Chris@26
|
302 m_playMono->setChecked(settings.value("playmono", false).toBool());
|
Chris@21
|
303 settings.endGroup();
|
Chris@21
|
304
|
Chris@129
|
305 layout->setSpacing(4);
|
Chris@159
|
306 layout->addWidget(scroll, 0, 0, 1, 5);
|
Chris@65
|
307 layout->addWidget(m_overview, 1, 0);
|
Chris@0
|
308 layout->addWidget(m_fader, 1, 1);
|
Chris@0
|
309 layout->addWidget(m_playSpeed, 1, 2);
|
Chris@16
|
310 layout->addWidget(m_playSharpen, 1, 3);
|
Chris@26
|
311 layout->addWidget(m_playMono, 1, 4);
|
Chris@16
|
312
|
Chris@129
|
313 m_paneStack->setPropertyStackMinWidth
|
Chris@129
|
314 (m_fader->width() + m_playSpeed->width() + m_playSharpen->width() +
|
Chris@129
|
315 m_playMono->width() + layout->spacing() * 4);
|
Chris@129
|
316
|
Chris@16
|
317 layout->setColumnStretch(0, 10);
|
Chris@16
|
318
|
Chris@0
|
319 frame->setLayout(layout);
|
Chris@0
|
320
|
Chris@0
|
321 connect(m_viewManager, SIGNAL(outputLevelsChanged(float, float)),
|
Chris@0
|
322 this, SLOT(outputLevelsChanged(float, float)));
|
Chris@0
|
323
|
Chris@116
|
324 connect(m_viewManager, SIGNAL(playbackFrameChanged(unsigned long)),
|
Chris@116
|
325 this, SLOT(playbackFrameChanged(unsigned long)));
|
Chris@116
|
326
|
Chris@116
|
327 connect(m_viewManager, SIGNAL(globalCentreFrameChanged(unsigned long)),
|
Chris@116
|
328 this, SLOT(globalCentreFrameChanged(unsigned long)));
|
Chris@116
|
329
|
Chris@116
|
330 connect(m_viewManager, SIGNAL(viewCentreFrameChanged(View *, unsigned long)),
|
Chris@116
|
331 this, SLOT(viewCentreFrameChanged(View *, unsigned long)));
|
Chris@116
|
332
|
Chris@116
|
333 connect(m_viewManager, SIGNAL(viewZoomLevelChanged(View *, unsigned long, bool)),
|
Chris@116
|
334 this, SLOT(viewZoomLevelChanged(View *, unsigned long, bool)));
|
Chris@116
|
335
|
Chris@0
|
336 connect(Preferences::getInstance(),
|
Chris@0
|
337 SIGNAL(propertyChanged(PropertyContainer::PropertyName)),
|
Chris@0
|
338 this,
|
Chris@0
|
339 SLOT(preferenceChanged(PropertyContainer::PropertyName)));
|
Chris@0
|
340
|
Chris@98
|
341 // preferenceChanged("Property Box Layout");
|
Chris@98
|
342
|
Chris@70
|
343 if (m_oscQueue && m_oscQueue->isOK()) {
|
Chris@69
|
344 connect(m_oscQueue, SIGNAL(messagesAvailable()), this, SLOT(pollOSC()));
|
Chris@69
|
345 QTimer *oscTimer = new QTimer(this);
|
Chris@69
|
346 connect(oscTimer, SIGNAL(timeout()), this, SLOT(pollOSC()));
|
Chris@69
|
347 oscTimer->start(1000);
|
Chris@69
|
348 }
|
Chris@69
|
349
|
Chris@189
|
350 Labeller::ValueType labellerType = Labeller::ValueFromTwoLevelCounter;
|
Chris@189
|
351 settings.beginGroup("MainWindow");
|
Chris@189
|
352 labellerType = (Labeller::ValueType)
|
Chris@189
|
353 settings.value("labellertype", (int)labellerType).toInt();
|
Chris@189
|
354 int cycle = settings.value("labellercycle", 4).toInt();
|
Chris@189
|
355 settings.endGroup();
|
Chris@189
|
356
|
Chris@189
|
357 m_labeller = new Labeller(labellerType);
|
Chris@189
|
358 m_labeller->setCounterCycleSize(cycle);
|
Chris@189
|
359
|
Chris@0
|
360 setupMenus();
|
Chris@0
|
361 setupToolbars();
|
Chris@155
|
362 setupHelpMenu();
|
Chris@0
|
363
|
Chris@90
|
364 statusBar();
|
Chris@0
|
365
|
Chris@0
|
366 newSession();
|
Chris@0
|
367 }
|
Chris@0
|
368
|
Chris@0
|
369 MainWindow::~MainWindow()
|
Chris@0
|
370 {
|
Chris@137
|
371 // std::cerr << "MainWindow::~MainWindow()" << std::endl;
|
Chris@118
|
372
|
Chris@70
|
373 if (!m_abandoning) {
|
Chris@70
|
374 closeSession();
|
Chris@70
|
375 }
|
Chris@0
|
376 delete m_playTarget;
|
Chris@0
|
377 delete m_playSource;
|
Chris@0
|
378 delete m_viewManager;
|
Chris@69
|
379 delete m_oscQueue;
|
Chris@162
|
380 delete m_keyReference;
|
Chris@163
|
381 delete m_preferencesDialog;
|
Chris@177
|
382 delete m_layerTreeView;
|
Chris@0
|
383 Profiles::getInstance()->dump();
|
Chris@0
|
384 }
|
Chris@0
|
385
|
Chris@81
|
386 QString
|
Chris@88
|
387 MainWindow::getOpenFileName(FileFinder::FileType type)
|
Chris@81
|
388 {
|
Chris@88
|
389 FileFinder *ff = FileFinder::getInstance();
|
Chris@81
|
390 switch (type) {
|
Chris@88
|
391 case FileFinder::SessionFile:
|
Chris@88
|
392 return ff->getOpenFileName(type, m_sessionFile);
|
Chris@88
|
393 case FileFinder::AudioFile:
|
Chris@88
|
394 return ff->getOpenFileName(type, m_audioFile);
|
Chris@88
|
395 case FileFinder::LayerFile:
|
Chris@88
|
396 return ff->getOpenFileName(type, m_sessionFile);
|
Chris@185
|
397 case FileFinder::LayerFileNoMidi:
|
Chris@185
|
398 return ff->getOpenFileName(type, m_sessionFile);
|
Chris@88
|
399 case FileFinder::SessionOrAudioFile:
|
Chris@88
|
400 return ff->getOpenFileName(type, m_sessionFile);
|
Chris@121
|
401 case FileFinder::ImageFile:
|
Chris@121
|
402 return ff->getOpenFileName(type, m_sessionFile);
|
Chris@88
|
403 case FileFinder::AnyFile:
|
Chris@88
|
404 if (getMainModel() != 0 &&
|
Chris@88
|
405 m_paneStack != 0 &&
|
Chris@88
|
406 m_paneStack->getCurrentPane() != 0) { // can import a layer
|
Chris@88
|
407 return ff->getOpenFileName(FileFinder::AnyFile, m_sessionFile);
|
Chris@81
|
408 } else {
|
Chris@88
|
409 return ff->getOpenFileName(FileFinder::SessionOrAudioFile,
|
Chris@88
|
410 m_sessionFile);
|
Chris@81
|
411 }
|
Chris@81
|
412 }
|
Chris@88
|
413 return "";
|
Chris@88
|
414 }
|
Chris@88
|
415
|
Chris@88
|
416 QString
|
Chris@88
|
417 MainWindow::getSaveFileName(FileFinder::FileType type)
|
Chris@88
|
418 {
|
Chris@88
|
419 FileFinder *ff = FileFinder::getInstance();
|
Chris@88
|
420 switch (type) {
|
Chris@88
|
421 case FileFinder::SessionFile:
|
Chris@88
|
422 return ff->getSaveFileName(type, m_sessionFile);
|
Chris@88
|
423 case FileFinder::AudioFile:
|
Chris@88
|
424 return ff->getSaveFileName(type, m_audioFile);
|
Chris@88
|
425 case FileFinder::LayerFile:
|
Chris@88
|
426 return ff->getSaveFileName(type, m_sessionFile);
|
Chris@185
|
427 case FileFinder::LayerFileNoMidi:
|
Chris@185
|
428 return ff->getSaveFileName(type, m_sessionFile);
|
Chris@88
|
429 case FileFinder::SessionOrAudioFile:
|
Chris@88
|
430 return ff->getSaveFileName(type, m_sessionFile);
|
Chris@121
|
431 case FileFinder::ImageFile:
|
Chris@121
|
432 return ff->getSaveFileName(type, m_sessionFile);
|
Chris@88
|
433 case FileFinder::AnyFile:
|
Chris@88
|
434 return ff->getSaveFileName(type, m_sessionFile);
|
Chris@81
|
435 }
|
Chris@88
|
436 return "";
|
Chris@81
|
437 }
|
Chris@81
|
438
|
Chris@88
|
439 void
|
Chris@88
|
440 MainWindow::registerLastOpenedFilePath(FileFinder::FileType type, QString path)
|
Chris@81
|
441 {
|
Chris@88
|
442 FileFinder *ff = FileFinder::getInstance();
|
Chris@88
|
443 ff->registerLastOpenedFilePath(type, path);
|
Chris@81
|
444 }
|
Chris@81
|
445
|
Chris@81
|
446 void
|
Chris@0
|
447 MainWindow::setupMenus()
|
Chris@0
|
448 {
|
Chris@0
|
449 if (!m_mainMenusCreated) {
|
Chris@0
|
450 m_rightButtonMenu = new QMenu();
|
Chris@104
|
451
|
Chris@104
|
452 // No -- we don't want tear-off enabled on the right-button
|
Chris@104
|
453 // menu. If it is enabled, then simply right-clicking and
|
Chris@104
|
454 // releasing will pop up the menu, activate the tear-off, and
|
Chris@104
|
455 // leave the torn-off menu window in front of the main window.
|
Chris@104
|
456 // That isn't desirable. I'm not sure it ever would be, in a
|
Chris@104
|
457 // context menu -- perhaps technically a Qt bug?
|
Chris@104
|
458 // m_rightButtonMenu->setTearOffEnabled(true);
|
Chris@0
|
459 }
|
Chris@0
|
460
|
Chris@0
|
461 if (m_rightButtonLayerMenu) {
|
Chris@0
|
462 m_rightButtonLayerMenu->clear();
|
Chris@0
|
463 } else {
|
Chris@0
|
464 m_rightButtonLayerMenu = m_rightButtonMenu->addMenu(tr("&Layer"));
|
Chris@97
|
465 m_rightButtonLayerMenu->setTearOffEnabled(true);
|
Chris@0
|
466 m_rightButtonMenu->addSeparator();
|
Chris@0
|
467 }
|
Chris@0
|
468
|
Chris@34
|
469 if (m_rightButtonTransformsMenu) {
|
Chris@34
|
470 m_rightButtonTransformsMenu->clear();
|
Chris@34
|
471 } else {
|
Chris@34
|
472 m_rightButtonTransformsMenu = m_rightButtonMenu->addMenu(tr("&Transform"));
|
Chris@97
|
473 m_rightButtonTransformsMenu->setTearOffEnabled(true);
|
Chris@34
|
474 m_rightButtonMenu->addSeparator();
|
Chris@34
|
475 }
|
Chris@34
|
476
|
Chris@0
|
477 if (!m_mainMenusCreated) {
|
Chris@0
|
478 CommandHistory::getInstance()->registerMenu(m_rightButtonMenu);
|
Chris@0
|
479 m_rightButtonMenu->addSeparator();
|
Chris@66
|
480 }
|
Chris@66
|
481
|
Chris@66
|
482 setupFileMenu();
|
Chris@66
|
483 setupEditMenu();
|
Chris@66
|
484 setupViewMenu();
|
Chris@66
|
485 setupPaneAndLayerMenus();
|
Chris@66
|
486 setupTransformsMenu();
|
Chris@66
|
487
|
Chris@66
|
488 m_mainMenusCreated = true;
|
Chris@66
|
489 }
|
Chris@66
|
490
|
Chris@66
|
491 void
|
Chris@66
|
492 MainWindow::setupFileMenu()
|
Chris@66
|
493 {
|
Chris@66
|
494 if (m_mainMenusCreated) return;
|
Chris@66
|
495
|
Chris@66
|
496 QMenu *menu = menuBar()->addMenu(tr("&File"));
|
Chris@97
|
497 menu->setTearOffEnabled(true);
|
Chris@66
|
498 QToolBar *toolbar = addToolBar(tr("File Toolbar"));
|
Chris@66
|
499
|
Chris@162
|
500 m_keyReference->setCategory(tr("File and Session Management"));
|
Chris@162
|
501
|
Chris@168
|
502 IconLoader il;
|
Chris@168
|
503
|
Chris@168
|
504 QIcon icon = il.load("filenew");
|
Chris@168
|
505 icon.addPixmap(il.loadPixmap("filenew-22"));
|
Chris@66
|
506 QAction *action = new QAction(icon, tr("&New Session"), this);
|
Chris@66
|
507 action->setShortcut(tr("Ctrl+N"));
|
Chris@90
|
508 action->setStatusTip(tr("Abandon the current Sonic Visualiser session and start a new one"));
|
Chris@66
|
509 connect(action, SIGNAL(triggered()), this, SLOT(newSession()));
|
Chris@162
|
510 m_keyReference->registerShortcut(action);
|
Chris@66
|
511 menu->addAction(action);
|
Chris@66
|
512 toolbar->addAction(action);
|
Chris@138
|
513
|
Chris@168
|
514 icon = il.load("fileopensession");
|
Chris@66
|
515 action = new QAction(icon, tr("&Open Session..."), this);
|
Chris@66
|
516 action->setShortcut(tr("Ctrl+O"));
|
Chris@66
|
517 action->setStatusTip(tr("Open a previously saved Sonic Visualiser session file"));
|
Chris@66
|
518 connect(action, SIGNAL(triggered()), this, SLOT(openSession()));
|
Chris@162
|
519 m_keyReference->registerShortcut(action);
|
Chris@66
|
520 menu->addAction(action);
|
Chris@66
|
521
|
Chris@168
|
522 icon = il.load("fileopen");
|
Chris@168
|
523 icon.addPixmap(il.loadPixmap("fileopen-22"));
|
Chris@138
|
524
|
Chris@66
|
525 action = new QAction(icon, tr("&Open..."), this);
|
Chris@66
|
526 action->setStatusTip(tr("Open a session file, audio file, or layer"));
|
Chris@66
|
527 connect(action, SIGNAL(triggered()), this, SLOT(openSomething()));
|
Chris@66
|
528 toolbar->addAction(action);
|
Chris@66
|
529
|
Chris@168
|
530 icon = il.load("filesave");
|
Chris@168
|
531 icon.addPixmap(il.loadPixmap("filesave-22"));
|
Chris@66
|
532 action = new QAction(icon, tr("&Save Session"), this);
|
Chris@66
|
533 action->setShortcut(tr("Ctrl+S"));
|
Chris@66
|
534 action->setStatusTip(tr("Save the current session into a Sonic Visualiser session file"));
|
Chris@66
|
535 connect(action, SIGNAL(triggered()), this, SLOT(saveSession()));
|
Chris@66
|
536 connect(this, SIGNAL(canSave(bool)), action, SLOT(setEnabled(bool)));
|
Chris@162
|
537 m_keyReference->registerShortcut(action);
|
Chris@66
|
538 menu->addAction(action);
|
Chris@66
|
539 toolbar->addAction(action);
|
Chris@0
|
540
|
Chris@168
|
541 icon = il.load("filesaveas");
|
Chris@168
|
542 icon.addPixmap(il.loadPixmap("filesaveas-22"));
|
Chris@66
|
543 action = new QAction(icon, tr("Save Session &As..."), this);
|
Chris@66
|
544 action->setStatusTip(tr("Save the current session into a new Sonic Visualiser session file"));
|
Chris@66
|
545 connect(action, SIGNAL(triggered()), this, SLOT(saveSessionAs()));
|
Chris@66
|
546 menu->addAction(action);
|
Chris@66
|
547 toolbar->addAction(action);
|
Chris@66
|
548
|
Chris@66
|
549 menu->addSeparator();
|
Chris@66
|
550
|
Chris@168
|
551 icon = il.load("fileopenaudio");
|
Chris@138
|
552 action = new QAction(icon, tr("&Import Audio File..."), this);
|
Chris@66
|
553 action->setShortcut(tr("Ctrl+I"));
|
Chris@66
|
554 action->setStatusTip(tr("Import an existing audio file"));
|
Chris@66
|
555 connect(action, SIGNAL(triggered()), this, SLOT(importAudio()));
|
Chris@162
|
556 m_keyReference->registerShortcut(action);
|
Chris@66
|
557 menu->addAction(action);
|
Chris@66
|
558
|
Chris@66
|
559 action = new QAction(tr("Import Secondary Audio File..."), this);
|
Chris@66
|
560 action->setShortcut(tr("Ctrl+Shift+I"));
|
Chris@66
|
561 action->setStatusTip(tr("Import an extra audio file as a separate layer"));
|
Chris@66
|
562 connect(action, SIGNAL(triggered()), this, SLOT(importMoreAudio()));
|
Chris@66
|
563 connect(this, SIGNAL(canImportMoreAudio(bool)), action, SLOT(setEnabled(bool)));
|
Chris@162
|
564 m_keyReference->registerShortcut(action);
|
Chris@66
|
565 menu->addAction(action);
|
Chris@66
|
566
|
Chris@66
|
567 action = new QAction(tr("&Export Audio File..."), this);
|
Chris@66
|
568 action->setStatusTip(tr("Export selection as an audio file"));
|
Chris@66
|
569 connect(action, SIGNAL(triggered()), this, SLOT(exportAudio()));
|
Chris@66
|
570 connect(this, SIGNAL(canExportAudio(bool)), action, SLOT(setEnabled(bool)));
|
Chris@66
|
571 menu->addAction(action);
|
Chris@66
|
572
|
Chris@66
|
573 menu->addSeparator();
|
Chris@66
|
574
|
Chris@66
|
575 action = new QAction(tr("Import Annotation &Layer..."), this);
|
Chris@66
|
576 action->setShortcut(tr("Ctrl+L"));
|
Chris@66
|
577 action->setStatusTip(tr("Import layer data from an existing file"));
|
Chris@66
|
578 connect(action, SIGNAL(triggered()), this, SLOT(importLayer()));
|
Chris@66
|
579 connect(this, SIGNAL(canImportLayer(bool)), action, SLOT(setEnabled(bool)));
|
Chris@162
|
580 m_keyReference->registerShortcut(action);
|
Chris@66
|
581 menu->addAction(action);
|
Chris@66
|
582
|
Chris@66
|
583 action = new QAction(tr("Export Annotation Layer..."), this);
|
Chris@66
|
584 action->setStatusTip(tr("Export layer data to a file"));
|
Chris@66
|
585 connect(action, SIGNAL(triggered()), this, SLOT(exportLayer()));
|
Chris@66
|
586 connect(this, SIGNAL(canExportLayer(bool)), action, SLOT(setEnabled(bool)));
|
Chris@66
|
587 menu->addAction(action);
|
Chris@66
|
588
|
Chris@66
|
589 menu->addSeparator();
|
Chris@86
|
590
|
Chris@121
|
591 action = new QAction(tr("Export Image File..."), this);
|
Chris@121
|
592 action->setStatusTip(tr("Export a single pane to an image file"));
|
Chris@121
|
593 connect(action, SIGNAL(triggered()), this, SLOT(exportImage()));
|
Chris@121
|
594 connect(this, SIGNAL(canExportImage(bool)), action, SLOT(setEnabled(bool)));
|
Chris@121
|
595 menu->addAction(action);
|
Chris@121
|
596
|
Chris@121
|
597 menu->addSeparator();
|
Chris@121
|
598
|
Chris@86
|
599 action = new QAction(tr("Open Lo&cation..."), this);
|
Chris@86
|
600 action->setShortcut(tr("Ctrl+Shift+O"));
|
Chris@86
|
601 action->setStatusTip(tr("Open or import a file from a remote URL"));
|
Chris@86
|
602 connect(action, SIGNAL(triggered()), this, SLOT(openLocation()));
|
Chris@162
|
603 m_keyReference->registerShortcut(action);
|
Chris@86
|
604 menu->addAction(action);
|
Chris@86
|
605
|
Chris@86
|
606 menu->addSeparator();
|
Chris@86
|
607
|
Chris@66
|
608 m_recentFilesMenu = menu->addMenu(tr("&Recent Files"));
|
Chris@97
|
609 m_recentFilesMenu->setTearOffEnabled(true);
|
Chris@66
|
610 setupRecentFilesMenu();
|
Chris@66
|
611 connect(&m_recentFiles, SIGNAL(recentChanged()),
|
Chris@66
|
612 this, SLOT(setupRecentFilesMenu()));
|
Chris@66
|
613
|
Chris@66
|
614 menu->addSeparator();
|
Chris@66
|
615 action = new QAction(tr("&Preferences..."), this);
|
Chris@66
|
616 action->setStatusTip(tr("Adjust the application preferences"));
|
Chris@66
|
617 connect(action, SIGNAL(triggered()), this, SLOT(preferences()));
|
Chris@66
|
618 menu->addAction(action);
|
Chris@0
|
619
|
Chris@66
|
620 menu->addSeparator();
|
Chris@168
|
621 action = new QAction(il.load("exit"),
|
Chris@66
|
622 tr("&Quit"), this);
|
Chris@66
|
623 action->setShortcut(tr("Ctrl+Q"));
|
Chris@90
|
624 action->setStatusTip(tr("Exit Sonic Visualiser"));
|
Chris@66
|
625 connect(action, SIGNAL(triggered()), this, SLOT(close()));
|
Chris@162
|
626 m_keyReference->registerShortcut(action);
|
Chris@66
|
627 menu->addAction(action);
|
Chris@66
|
628 }
|
Chris@66
|
629
|
Chris@66
|
630 void
|
Chris@66
|
631 MainWindow::setupEditMenu()
|
Chris@66
|
632 {
|
Chris@66
|
633 if (m_mainMenusCreated) return;
|
Chris@66
|
634
|
Chris@66
|
635 QMenu *menu = menuBar()->addMenu(tr("&Edit"));
|
Chris@97
|
636 menu->setTearOffEnabled(true);
|
Chris@66
|
637 CommandHistory::getInstance()->registerMenu(menu);
|
Chris@66
|
638
|
Chris@162
|
639 m_keyReference->setCategory(tr("Editing"));
|
Chris@162
|
640
|
Chris@66
|
641 menu->addSeparator();
|
Chris@66
|
642
|
Chris@168
|
643 IconLoader il;
|
Chris@168
|
644
|
Chris@168
|
645 QAction *action = new QAction(il.load("editcut"),
|
Chris@66
|
646 tr("Cu&t"), this);
|
Chris@66
|
647 action->setShortcut(tr("Ctrl+X"));
|
Chris@90
|
648 action->setStatusTip(tr("Cut the selection from the current layer to the clipboard"));
|
Chris@66
|
649 connect(action, SIGNAL(triggered()), this, SLOT(cut()));
|
Chris@66
|
650 connect(this, SIGNAL(canEditSelection(bool)), action, SLOT(setEnabled(bool)));
|
Chris@162
|
651 m_keyReference->registerShortcut(action);
|
Chris@66
|
652 menu->addAction(action);
|
Chris@66
|
653 m_rightButtonMenu->addAction(action);
|
Chris@66
|
654
|
Chris@168
|
655 action = new QAction(il.load("editcopy"),
|
Chris@66
|
656 tr("&Copy"), this);
|
Chris@66
|
657 action->setShortcut(tr("Ctrl+C"));
|
Chris@90
|
658 action->setStatusTip(tr("Copy the selection from the current layer to the clipboard"));
|
Chris@66
|
659 connect(action, SIGNAL(triggered()), this, SLOT(copy()));
|
Chris@66
|
660 connect(this, SIGNAL(canEditSelection(bool)), action, SLOT(setEnabled(bool)));
|
Chris@162
|
661 m_keyReference->registerShortcut(action);
|
Chris@66
|
662 menu->addAction(action);
|
Chris@66
|
663 m_rightButtonMenu->addAction(action);
|
Chris@66
|
664
|
Chris@168
|
665 action = new QAction(il.load("editpaste"),
|
Chris@66
|
666 tr("&Paste"), this);
|
Chris@66
|
667 action->setShortcut(tr("Ctrl+V"));
|
Chris@90
|
668 action->setStatusTip(tr("Paste from the clipboard to the current layer"));
|
Chris@66
|
669 connect(action, SIGNAL(triggered()), this, SLOT(paste()));
|
Chris@66
|
670 connect(this, SIGNAL(canPaste(bool)), action, SLOT(setEnabled(bool)));
|
Chris@162
|
671 m_keyReference->registerShortcut(action);
|
Chris@66
|
672 menu->addAction(action);
|
Chris@66
|
673 m_rightButtonMenu->addAction(action);
|
Chris@66
|
674
|
Chris@164
|
675 m_deleteSelectedAction = new QAction(tr("&Delete Selected Items"), this);
|
Chris@164
|
676 m_deleteSelectedAction->setShortcut(tr("Del"));
|
Chris@164
|
677 m_deleteSelectedAction->setStatusTip(tr("Delete items in current selection from the current layer"));
|
Chris@164
|
678 connect(m_deleteSelectedAction, SIGNAL(triggered()), this, SLOT(deleteSelected()));
|
Chris@164
|
679 connect(this, SIGNAL(canDeleteSelection(bool)), m_deleteSelectedAction, SLOT(setEnabled(bool)));
|
Chris@164
|
680 m_keyReference->registerShortcut(m_deleteSelectedAction);
|
Chris@164
|
681 menu->addAction(m_deleteSelectedAction);
|
Chris@164
|
682 m_rightButtonMenu->addAction(m_deleteSelectedAction);
|
Chris@66
|
683
|
Chris@66
|
684 menu->addSeparator();
|
Chris@66
|
685 m_rightButtonMenu->addSeparator();
|
Chris@162
|
686
|
Chris@162
|
687 m_keyReference->setCategory(tr("Selection"));
|
Chris@162
|
688
|
Chris@66
|
689 action = new QAction(tr("Select &All"), this);
|
Chris@66
|
690 action->setShortcut(tr("Ctrl+A"));
|
Chris@90
|
691 action->setStatusTip(tr("Select the whole duration of the current session"));
|
Chris@66
|
692 connect(action, SIGNAL(triggered()), this, SLOT(selectAll()));
|
Chris@66
|
693 connect(this, SIGNAL(canSelect(bool)), action, SLOT(setEnabled(bool)));
|
Chris@162
|
694 m_keyReference->registerShortcut(action);
|
Chris@66
|
695 menu->addAction(action);
|
Chris@66
|
696 m_rightButtonMenu->addAction(action);
|
Chris@0
|
697
|
Chris@66
|
698 action = new QAction(tr("Select &Visible Range"), this);
|
Chris@66
|
699 action->setShortcut(tr("Ctrl+Shift+A"));
|
Chris@90
|
700 action->setStatusTip(tr("Select the time range corresponding to the current window width"));
|
Chris@66
|
701 connect(action, SIGNAL(triggered()), this, SLOT(selectVisible()));
|
Chris@66
|
702 connect(this, SIGNAL(canSelect(bool)), action, SLOT(setEnabled(bool)));
|
Chris@162
|
703 m_keyReference->registerShortcut(action);
|
Chris@66
|
704 menu->addAction(action);
|
Chris@0
|
705
|
Chris@66
|
706 action = new QAction(tr("Select to &Start"), this);
|
Chris@66
|
707 action->setShortcut(tr("Shift+Left"));
|
Chris@90
|
708 action->setStatusTip(tr("Select from the start of the session to the current playback position"));
|
Chris@66
|
709 connect(action, SIGNAL(triggered()), this, SLOT(selectToStart()));
|
Chris@66
|
710 connect(this, SIGNAL(canSelect(bool)), action, SLOT(setEnabled(bool)));
|
Chris@162
|
711 m_keyReference->registerShortcut(action);
|
Chris@66
|
712 menu->addAction(action);
|
Chris@0
|
713
|
Chris@66
|
714 action = new QAction(tr("Select to &End"), this);
|
Chris@66
|
715 action->setShortcut(tr("Shift+Right"));
|
Chris@90
|
716 action->setStatusTip(tr("Select from the current playback position to the end of the session"));
|
Chris@66
|
717 connect(action, SIGNAL(triggered()), this, SLOT(selectToEnd()));
|
Chris@66
|
718 connect(this, SIGNAL(canSelect(bool)), action, SLOT(setEnabled(bool)));
|
Chris@162
|
719 m_keyReference->registerShortcut(action);
|
Chris@66
|
720 menu->addAction(action);
|
Chris@66
|
721
|
Chris@66
|
722 action = new QAction(tr("C&lear Selection"), this);
|
Chris@66
|
723 action->setShortcut(tr("Esc"));
|
Chris@90
|
724 action->setStatusTip(tr("Clear the selection"));
|
Chris@66
|
725 connect(action, SIGNAL(triggered()), this, SLOT(clearSelection()));
|
Chris@66
|
726 connect(this, SIGNAL(canClearSelection(bool)), action, SLOT(setEnabled(bool)));
|
Chris@162
|
727 m_keyReference->registerShortcut(action);
|
Chris@66
|
728 menu->addAction(action);
|
Chris@66
|
729 m_rightButtonMenu->addAction(action);
|
Chris@66
|
730
|
Chris@66
|
731 menu->addSeparator();
|
Chris@66
|
732
|
Chris@162
|
733 m_keyReference->setCategory(tr("Tapping Time Instants"));
|
Chris@162
|
734
|
Chris@66
|
735 action = new QAction(tr("&Insert Instant at Playback Position"), this);
|
Chris@66
|
736 action->setShortcut(tr("Enter"));
|
Chris@90
|
737 action->setStatusTip(tr("Insert a new time instant at the current playback position, in a new layer if necessary"));
|
Chris@66
|
738 connect(action, SIGNAL(triggered()), this, SLOT(insertInstant()));
|
Chris@66
|
739 connect(this, SIGNAL(canInsertInstant(bool)), action, SLOT(setEnabled(bool)));
|
Chris@162
|
740 m_keyReference->registerShortcut(action);
|
Chris@66
|
741 menu->addAction(action);
|
Chris@66
|
742
|
Chris@162
|
743 // Laptop shortcut (no keypad Enter key)
|
Chris@162
|
744 QString shortcut(tr(";"));
|
Chris@162
|
745 connect(new QShortcut(shortcut, this), SIGNAL(activated()),
|
Chris@162
|
746 this, SLOT(insertInstant()));
|
Chris@162
|
747 m_keyReference->registerAlternativeShortcut(action, shortcut);
|
Chris@162
|
748
|
Chris@81
|
749 action = new QAction(tr("Insert Instants at Selection &Boundaries"), this);
|
Chris@81
|
750 action->setShortcut(tr("Shift+Enter"));
|
Chris@163
|
751 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
|
752 connect(action, SIGNAL(triggered()), this, SLOT(insertInstantsAtBoundaries()));
|
Chris@81
|
753 connect(this, SIGNAL(canInsertInstantsAtBoundaries(bool)), action, SLOT(setEnabled(bool)));
|
Chris@162
|
754 m_keyReference->registerShortcut(action);
|
Chris@81
|
755 menu->addAction(action);
|
Chris@189
|
756
|
Chris@190
|
757 QMenu *numberingMenu = menu->addMenu(tr("Number New Instants with"));
|
Chris@189
|
758 QActionGroup *numberingGroup = new QActionGroup(this);
|
Chris@189
|
759
|
Chris@189
|
760 Labeller::TypeNameMap types = m_labeller->getTypeNames();
|
Chris@189
|
761 for (Labeller::TypeNameMap::iterator i = types.begin(); i != types.end(); ++i) {
|
Chris@190
|
762
|
Chris@190
|
763 if (i->first == Labeller::ValueFromLabel ||
|
Chris@190
|
764 i->first == Labeller::ValueFromExistingNeighbour) continue;
|
Chris@190
|
765
|
Chris@189
|
766 action = new QAction(i->second, this);
|
Chris@189
|
767 connect(action, SIGNAL(triggered()), this, SLOT(setInstantsNumbering()));
|
Chris@189
|
768 action->setCheckable(true);
|
Chris@189
|
769 action->setChecked(m_labeller->getType() == i->first);
|
Chris@189
|
770 numberingGroup->addAction(action);
|
Chris@189
|
771 numberingMenu->addAction(action);
|
Chris@189
|
772 m_numberingActions[action] = (int)i->first;
|
Chris@190
|
773
|
Chris@190
|
774 if (i->first == Labeller::ValueFromTwoLevelCounter) {
|
Chris@192
|
775
|
Chris@190
|
776 QMenu *cycleMenu = numberingMenu->addMenu(tr("Cycle size"));
|
Chris@190
|
777 QActionGroup *cycleGroup = new QActionGroup(this);
|
Chris@190
|
778
|
Chris@190
|
779 int cycles[] = { 2, 3, 4, 5, 6, 7, 8, 10, 12, 16 };
|
Chris@190
|
780 for (int i = 0; i < sizeof(cycles)/sizeof(cycles[0]); ++i) {
|
Chris@190
|
781 action = new QAction(QString("%1").arg(cycles[i]), this);
|
Chris@190
|
782 connect(action, SIGNAL(triggered()), this, SLOT(setInstantsCounterCycle()));
|
Chris@190
|
783 action->setCheckable(true);
|
Chris@190
|
784 action->setChecked(cycles[i] == m_labeller->getCounterCycleSize());
|
Chris@190
|
785 cycleGroup->addAction(action);
|
Chris@190
|
786 cycleMenu->addAction(action);
|
Chris@190
|
787 }
|
Chris@192
|
788
|
Chris@192
|
789 action = new QAction(tr("Reset Counters..."), this);
|
Chris@192
|
790 connect(action, SIGNAL(triggered()), this, SLOT(resetInstantsCounters()));
|
Chris@192
|
791 numberingMenu->addAction(action);
|
Chris@190
|
792 }
|
Chris@190
|
793
|
Chris@190
|
794 if (i->first == Labeller::ValueNone ||
|
Chris@190
|
795 i->first == Labeller::ValueFromTwoLevelCounter ||
|
Chris@190
|
796 i->first == Labeller::ValueFromRealTime) {
|
Chris@190
|
797 numberingMenu->addSeparator();
|
Chris@190
|
798 }
|
Chris@189
|
799 }
|
Chris@189
|
800
|
Chris@189
|
801 action = new QAction(tr("Re-Number Selected Instants"), this);
|
Chris@189
|
802 action->setStatusTip(tr("Re-number the selected instants using the current labelling scheme"));
|
Chris@189
|
803 connect(action, SIGNAL(triggered()), this, SLOT(renumberInstants()));
|
Chris@189
|
804 connect(this, SIGNAL(canRenumberInstants(bool)), action, SLOT(setEnabled(bool)));
|
Chris@189
|
805 // m_keyReference->registerShortcut(action);
|
Chris@189
|
806 menu->addAction(action);
|
Chris@66
|
807 }
|
Chris@66
|
808
|
Chris@66
|
809 void
|
Chris@66
|
810 MainWindow::setupViewMenu()
|
Chris@66
|
811 {
|
Chris@66
|
812 if (m_mainMenusCreated) return;
|
Chris@66
|
813
|
Chris@168
|
814 IconLoader il;
|
Chris@168
|
815
|
Chris@90
|
816 QAction *action = 0;
|
Chris@90
|
817
|
Chris@162
|
818 m_keyReference->setCategory(tr("Panning and Navigation"));
|
Chris@162
|
819
|
Chris@66
|
820 QMenu *menu = menuBar()->addMenu(tr("&View"));
|
Chris@97
|
821 menu->setTearOffEnabled(true);
|
Chris@66
|
822 action = new QAction(tr("Scroll &Left"), this);
|
Chris@66
|
823 action->setShortcut(tr("Left"));
|
Chris@66
|
824 action->setStatusTip(tr("Scroll the current pane to the left"));
|
Chris@66
|
825 connect(action, SIGNAL(triggered()), this, SLOT(scrollLeft()));
|
Chris@66
|
826 connect(this, SIGNAL(canScroll(bool)), action, SLOT(setEnabled(bool)));
|
Chris@162
|
827 m_keyReference->registerShortcut(action);
|
Chris@66
|
828 menu->addAction(action);
|
Chris@0
|
829
|
Chris@66
|
830 action = new QAction(tr("Scroll &Right"), this);
|
Chris@66
|
831 action->setShortcut(tr("Right"));
|
Chris@66
|
832 action->setStatusTip(tr("Scroll the current pane to the right"));
|
Chris@66
|
833 connect(action, SIGNAL(triggered()), this, SLOT(scrollRight()));
|
Chris@66
|
834 connect(this, SIGNAL(canScroll(bool)), action, SLOT(setEnabled(bool)));
|
Chris@162
|
835 m_keyReference->registerShortcut(action);
|
Chris@66
|
836 menu->addAction(action);
|
Chris@0
|
837
|
Chris@90
|
838 action = new QAction(tr("&Jump Left"), this);
|
Chris@66
|
839 action->setShortcut(tr("Ctrl+Left"));
|
Chris@66
|
840 action->setStatusTip(tr("Scroll the current pane a big step to the left"));
|
Chris@66
|
841 connect(action, SIGNAL(triggered()), this, SLOT(jumpLeft()));
|
Chris@66
|
842 connect(this, SIGNAL(canScroll(bool)), action, SLOT(setEnabled(bool)));
|
Chris@162
|
843 m_keyReference->registerShortcut(action);
|
Chris@66
|
844 menu->addAction(action);
|
Chris@0
|
845
|
Chris@90
|
846 action = new QAction(tr("J&ump Right"), this);
|
Chris@66
|
847 action->setShortcut(tr("Ctrl+Right"));
|
Chris@66
|
848 action->setStatusTip(tr("Scroll the current pane a big step to the right"));
|
Chris@66
|
849 connect(action, SIGNAL(triggered()), this, SLOT(jumpRight()));
|
Chris@66
|
850 connect(this, SIGNAL(canScroll(bool)), action, SLOT(setEnabled(bool)));
|
Chris@162
|
851 m_keyReference->registerShortcut(action);
|
Chris@66
|
852 menu->addAction(action);
|
Chris@66
|
853
|
Chris@66
|
854 menu->addSeparator();
|
Chris@66
|
855
|
Chris@162
|
856 m_keyReference->setCategory(tr("Zoom"));
|
Chris@162
|
857
|
Chris@168
|
858 action = new QAction(il.load("zoom-in"),
|
Chris@66
|
859 tr("Zoom &In"), this);
|
Chris@66
|
860 action->setShortcut(tr("Up"));
|
Chris@66
|
861 action->setStatusTip(tr("Increase the zoom level"));
|
Chris@66
|
862 connect(action, SIGNAL(triggered()), this, SLOT(zoomIn()));
|
Chris@66
|
863 connect(this, SIGNAL(canZoom(bool)), action, SLOT(setEnabled(bool)));
|
Chris@162
|
864 m_keyReference->registerShortcut(action);
|
Chris@66
|
865 menu->addAction(action);
|
Chris@0
|
866
|
Chris@168
|
867 action = new QAction(il.load("zoom-out"),
|
Chris@66
|
868 tr("Zoom &Out"), this);
|
Chris@66
|
869 action->setShortcut(tr("Down"));
|
Chris@66
|
870 action->setStatusTip(tr("Decrease the zoom level"));
|
Chris@66
|
871 connect(action, SIGNAL(triggered()), this, SLOT(zoomOut()));
|
Chris@66
|
872 connect(this, SIGNAL(canZoom(bool)), action, SLOT(setEnabled(bool)));
|
Chris@162
|
873 m_keyReference->registerShortcut(action);
|
Chris@66
|
874 menu->addAction(action);
|
Chris@0
|
875
|
Chris@66
|
876 action = new QAction(tr("Restore &Default Zoom"), this);
|
Chris@90
|
877 action->setStatusTip(tr("Restore the zoom level to the default"));
|
Chris@66
|
878 connect(action, SIGNAL(triggered()), this, SLOT(zoomDefault()));
|
Chris@66
|
879 connect(this, SIGNAL(canZoom(bool)), action, SLOT(setEnabled(bool)));
|
Chris@66
|
880 menu->addAction(action);
|
Chris@66
|
881
|
Chris@168
|
882 action = new QAction(il.load("zoom-fit"),
|
Chris@138
|
883 tr("Zoom to &Fit"), this);
|
Chris@155
|
884 action->setShortcut(tr("F"));
|
Chris@66
|
885 action->setStatusTip(tr("Zoom to show the whole file"));
|
Chris@66
|
886 connect(action, SIGNAL(triggered()), this, SLOT(zoomToFit()));
|
Chris@66
|
887 connect(this, SIGNAL(canZoom(bool)), action, SLOT(setEnabled(bool)));
|
Chris@162
|
888 m_keyReference->registerShortcut(action);
|
Chris@66
|
889 menu->addAction(action);
|
Chris@90
|
890
|
Chris@90
|
891 menu->addSeparator();
|
Chris@90
|
892
|
Chris@162
|
893 m_keyReference->setCategory(tr("Display Features"));
|
Chris@162
|
894
|
Chris@90
|
895 QActionGroup *overlayGroup = new QActionGroup(this);
|
Chris@90
|
896
|
Chris@90
|
897 action = new QAction(tr("Show &No Overlays"), this);
|
Chris@90
|
898 action->setShortcut(tr("0"));
|
Chris@90
|
899 action->setStatusTip(tr("Hide centre indicator, frame times, layer names and scale"));
|
Chris@90
|
900 connect(action, SIGNAL(triggered()), this, SLOT(showNoOverlays()));
|
Chris@90
|
901 action->setCheckable(true);
|
Chris@90
|
902 action->setChecked(false);
|
Chris@90
|
903 overlayGroup->addAction(action);
|
Chris@162
|
904 m_keyReference->registerShortcut(action);
|
Chris@90
|
905 menu->addAction(action);
|
Chris@90
|
906
|
Chris@90
|
907 action = new QAction(tr("Show &Minimal Overlays"), this);
|
Chris@90
|
908 action->setShortcut(tr("9"));
|
Chris@90
|
909 action->setStatusTip(tr("Show centre indicator only"));
|
Chris@90
|
910 connect(action, SIGNAL(triggered()), this, SLOT(showMinimalOverlays()));
|
Chris@90
|
911 action->setCheckable(true);
|
Chris@90
|
912 action->setChecked(false);
|
Chris@90
|
913 overlayGroup->addAction(action);
|
Chris@162
|
914 m_keyReference->registerShortcut(action);
|
Chris@90
|
915 menu->addAction(action);
|
Chris@90
|
916
|
Chris@90
|
917 action = new QAction(tr("Show &Standard Overlays"), this);
|
Chris@90
|
918 action->setShortcut(tr("8"));
|
Chris@90
|
919 action->setStatusTip(tr("Show centre indicator, frame times and scale"));
|
Chris@90
|
920 connect(action, SIGNAL(triggered()), this, SLOT(showStandardOverlays()));
|
Chris@90
|
921 action->setCheckable(true);
|
Chris@90
|
922 action->setChecked(true);
|
Chris@90
|
923 overlayGroup->addAction(action);
|
Chris@162
|
924 m_keyReference->registerShortcut(action);
|
Chris@90
|
925 menu->addAction(action);
|
Chris@90
|
926
|
Chris@90
|
927 action = new QAction(tr("Show &All Overlays"), this);
|
Chris@90
|
928 action->setShortcut(tr("7"));
|
Chris@90
|
929 action->setStatusTip(tr("Show all texts and scale"));
|
Chris@90
|
930 connect(action, SIGNAL(triggered()), this, SLOT(showAllOverlays()));
|
Chris@90
|
931 action->setCheckable(true);
|
Chris@90
|
932 action->setChecked(false);
|
Chris@90
|
933 overlayGroup->addAction(action);
|
Chris@162
|
934 m_keyReference->registerShortcut(action);
|
Chris@90
|
935 menu->addAction(action);
|
Chris@7
|
936
|
Chris@72
|
937 menu->addSeparator();
|
Chris@72
|
938
|
Chris@66
|
939 action = new QAction(tr("Show &Zoom Wheels"), this);
|
Chris@66
|
940 action->setShortcut(tr("Z"));
|
Chris@66
|
941 action->setStatusTip(tr("Show thumbwheels for zooming horizontally and vertically"));
|
Chris@66
|
942 connect(action, SIGNAL(triggered()), this, SLOT(toggleZoomWheels()));
|
Chris@66
|
943 action->setCheckable(true);
|
Chris@66
|
944 action->setChecked(m_viewManager->getZoomWheelsEnabled());
|
Chris@162
|
945 m_keyReference->registerShortcut(action);
|
Chris@66
|
946 menu->addAction(action);
|
Chris@72
|
947
|
Chris@72
|
948 action = new QAction(tr("Show Property Bo&xes"), this);
|
Chris@72
|
949 action->setShortcut(tr("X"));
|
Chris@72
|
950 action->setStatusTip(tr("Show the layer property boxes at the side of the main window"));
|
Chris@72
|
951 connect(action, SIGNAL(triggered()), this, SLOT(togglePropertyBoxes()));
|
Chris@72
|
952 action->setCheckable(true);
|
Chris@72
|
953 action->setChecked(true);
|
Chris@162
|
954 m_keyReference->registerShortcut(action);
|
Chris@72
|
955 menu->addAction(action);
|
Chris@0
|
956
|
Chris@90
|
957 action = new QAction(tr("Show Status &Bar"), this);
|
Chris@90
|
958 action->setStatusTip(tr("Show context help information in the status bar at the bottom of the window"));
|
Chris@90
|
959 connect(action, SIGNAL(triggered()), this, SLOT(toggleStatusBar()));
|
Chris@90
|
960 action->setCheckable(true);
|
Chris@90
|
961 action->setChecked(true);
|
Chris@90
|
962 menu->addAction(action);
|
Chris@90
|
963
|
Chris@90
|
964 QSettings settings;
|
Chris@90
|
965 settings.beginGroup("MainWindow");
|
Chris@90
|
966 bool sb = settings.value("showstatusbar", true).toBool();
|
Chris@90
|
967 if (!sb) {
|
Chris@90
|
968 action->setChecked(false);
|
Chris@90
|
969 statusBar()->hide();
|
Chris@90
|
970 }
|
Chris@90
|
971 settings.endGroup();
|
Chris@90
|
972
|
Chris@66
|
973 menu->addSeparator();
|
Chris@66
|
974
|
Chris@90
|
975 action = new QAction(tr("Show La&yer Hierarchy"), this);
|
Chris@155
|
976 action->setShortcut(tr("H"));
|
Chris@90
|
977 action->setStatusTip(tr("Open a window displaying the hierarchy of panes and layers in this session"));
|
Chris@66
|
978 connect(action, SIGNAL(triggered()), this, SLOT(showLayerTree()));
|
Chris@162
|
979 m_keyReference->registerShortcut(action);
|
Chris@66
|
980 menu->addAction(action);
|
Chris@66
|
981 }
|
Chris@66
|
982
|
Chris@66
|
983 void
|
Chris@66
|
984 MainWindow::setupPaneAndLayerMenus()
|
Chris@66
|
985 {
|
Chris@0
|
986 if (m_paneMenu) {
|
Chris@0
|
987 m_paneActions.clear();
|
Chris@0
|
988 m_paneMenu->clear();
|
Chris@0
|
989 } else {
|
Chris@0
|
990 m_paneMenu = menuBar()->addMenu(tr("&Pane"));
|
Chris@97
|
991 m_paneMenu->setTearOffEnabled(true);
|
Chris@0
|
992 }
|
Chris@0
|
993
|
Chris@0
|
994 if (m_layerMenu) {
|
Chris@0
|
995 m_layerActions.clear();
|
Chris@0
|
996 m_layerMenu->clear();
|
Chris@0
|
997 } else {
|
Chris@0
|
998 m_layerMenu = menuBar()->addMenu(tr("&Layer"));
|
Chris@97
|
999 m_layerMenu->setTearOffEnabled(true);
|
Chris@0
|
1000 }
|
Chris@0
|
1001
|
Chris@66
|
1002 QMenu *menu = m_paneMenu;
|
Chris@66
|
1003
|
Chris@168
|
1004 IconLoader il;
|
Chris@168
|
1005
|
Chris@162
|
1006 m_keyReference->setCategory(tr("Managing Panes and Layers"));
|
Chris@162
|
1007
|
Chris@168
|
1008 QAction *action = new QAction(il.load("pane"), tr("Add &New Pane"), this);
|
Chris@155
|
1009 action->setShortcut(tr("N"));
|
Chris@66
|
1010 action->setStatusTip(tr("Add a new pane containing only a time ruler"));
|
Chris@66
|
1011 connect(action, SIGNAL(triggered()), this, SLOT(addPane()));
|
Chris@66
|
1012 connect(this, SIGNAL(canAddPane(bool)), action, SLOT(setEnabled(bool)));
|
Chris@66
|
1013 m_paneActions[action] = PaneConfiguration(LayerFactory::TimeRuler);
|
Chris@162
|
1014 m_keyReference->registerShortcut(action);
|
Chris@66
|
1015 menu->addAction(action);
|
Chris@66
|
1016
|
Chris@66
|
1017 menu->addSeparator();
|
Chris@66
|
1018
|
Chris@66
|
1019 menu = m_layerMenu;
|
Chris@66
|
1020
|
Chris@66
|
1021 // menu->addSeparator();
|
Chris@66
|
1022
|
Chris@66
|
1023 LayerFactory::LayerTypeSet emptyLayerTypes =
|
Chris@66
|
1024 LayerFactory::getInstance()->getValidEmptyLayerTypes();
|
Chris@66
|
1025
|
Chris@66
|
1026 for (LayerFactory::LayerTypeSet::iterator i = emptyLayerTypes.begin();
|
Chris@66
|
1027 i != emptyLayerTypes.end(); ++i) {
|
Chris@66
|
1028
|
Chris@66
|
1029 QIcon icon;
|
Chris@66
|
1030 QString mainText, tipText, channelText;
|
Chris@66
|
1031 LayerFactory::LayerType type = *i;
|
Chris@66
|
1032 QString name = LayerFactory::getInstance()->getLayerPresentationName(type);
|
Chris@66
|
1033
|
Chris@168
|
1034 icon = il.load(LayerFactory::getInstance()->getLayerIconName(type));
|
Chris@66
|
1035
|
Chris@66
|
1036 mainText = tr("Add New %1 Layer").arg(name);
|
Chris@66
|
1037 tipText = tr("Add a new empty layer of type %1").arg(name);
|
Chris@66
|
1038
|
Chris@66
|
1039 action = new QAction(icon, mainText, this);
|
Chris@66
|
1040 action->setStatusTip(tipText);
|
Chris@66
|
1041
|
Chris@66
|
1042 if (type == LayerFactory::Text) {
|
Chris@155
|
1043 action->setShortcut(tr("T"));
|
Chris@162
|
1044 m_keyReference->registerShortcut(action);
|
Chris@66
|
1045 }
|
Chris@66
|
1046
|
Chris@66
|
1047 connect(action, SIGNAL(triggered()), this, SLOT(addLayer()));
|
Chris@66
|
1048 connect(this, SIGNAL(canAddLayer(bool)), action, SLOT(setEnabled(bool)));
|
Chris@66
|
1049 m_layerActions[action] = type;
|
Chris@66
|
1050 menu->addAction(action);
|
Chris@66
|
1051 m_rightButtonLayerMenu->addAction(action);
|
Chris@66
|
1052 }
|
Chris@66
|
1053
|
Chris@66
|
1054 m_rightButtonLayerMenu->addSeparator();
|
Chris@66
|
1055 menu->addSeparator();
|
Chris@66
|
1056
|
Chris@66
|
1057 LayerFactory::LayerType backgroundTypes[] = {
|
Chris@66
|
1058 LayerFactory::Waveform,
|
Chris@66
|
1059 LayerFactory::Spectrogram,
|
Chris@66
|
1060 LayerFactory::MelodicRangeSpectrogram,
|
Chris@66
|
1061 LayerFactory::PeakFrequencySpectrogram,
|
Chris@66
|
1062 LayerFactory::Spectrum
|
Chris@66
|
1063 };
|
Chris@66
|
1064
|
Chris@66
|
1065 std::vector<Model *> models;
|
Chris@66
|
1066 if (m_document) models = m_document->getTransformInputModels(); //!!! not well named for this!
|
Chris@66
|
1067 bool plural = (models.size() > 1);
|
Chris@66
|
1068 if (models.empty()) {
|
Chris@67
|
1069 models.push_back(getMainModel()); // probably 0
|
Chris@66
|
1070 }
|
Chris@66
|
1071
|
Chris@66
|
1072 for (unsigned int i = 0;
|
Chris@66
|
1073 i < sizeof(backgroundTypes)/sizeof(backgroundTypes[0]); ++i) {
|
Chris@66
|
1074
|
Chris@66
|
1075 for (int menuType = 0; menuType <= 1; ++menuType) { // pane, layer
|
Chris@66
|
1076
|
Chris@66
|
1077 if (menuType == 0) menu = m_paneMenu;
|
Chris@66
|
1078 else menu = m_layerMenu;
|
Chris@66
|
1079
|
Chris@66
|
1080 QMenu *submenu = 0;
|
Chris@66
|
1081
|
Chris@66
|
1082 QIcon icon;
|
Chris@66
|
1083 QString mainText, shortcutText, tipText, channelText;
|
Chris@66
|
1084 LayerFactory::LayerType type = backgroundTypes[i];
|
Chris@66
|
1085 bool mono = true;
|
Chris@66
|
1086
|
Chris@66
|
1087 switch (type) {
|
Chris@66
|
1088
|
Chris@66
|
1089 case LayerFactory::Waveform:
|
Chris@168
|
1090 icon = il.load("waveform");
|
Chris@66
|
1091 mainText = tr("Add &Waveform");
|
Chris@66
|
1092 if (menuType == 0) {
|
Chris@155
|
1093 shortcutText = tr("W");
|
Chris@66
|
1094 tipText = tr("Add a new pane showing a waveform view");
|
Chris@66
|
1095 } else {
|
Chris@66
|
1096 tipText = tr("Add a new layer showing a waveform view");
|
Chris@66
|
1097 }
|
Chris@66
|
1098 mono = false;
|
Chris@66
|
1099 break;
|
Chris@66
|
1100
|
Chris@66
|
1101 case LayerFactory::Spectrogram:
|
Chris@168
|
1102 icon = il.load("spectrogram");
|
Chris@161
|
1103 mainText = tr("Add Spectro&gram");
|
Chris@66
|
1104 if (menuType == 0) {
|
Chris@155
|
1105 shortcutText = tr("G");
|
Chris@90
|
1106 tipText = tr("Add a new pane showing a spectrogram");
|
Chris@66
|
1107 } else {
|
Chris@90
|
1108 tipText = tr("Add a new layer showing a spectrogram");
|
Chris@66
|
1109 }
|
Chris@66
|
1110 break;
|
Chris@66
|
1111
|
Chris@66
|
1112 case LayerFactory::MelodicRangeSpectrogram:
|
Chris@168
|
1113 icon = il.load("spectrogram");
|
Chris@66
|
1114 mainText = tr("Add &Melodic Range Spectrogram");
|
Chris@66
|
1115 if (menuType == 0) {
|
Chris@155
|
1116 shortcutText = tr("M");
|
Chris@90
|
1117 tipText = tr("Add a new pane showing a spectrogram set up for an overview of note pitches");
|
Chris@66
|
1118 } else {
|
Chris@90
|
1119 tipText = tr("Add a new layer showing a spectrogram set up for an overview of note pitches");
|
Chris@66
|
1120 }
|
Chris@66
|
1121 break;
|
Chris@66
|
1122
|
Chris@66
|
1123 case LayerFactory::PeakFrequencySpectrogram:
|
Chris@168
|
1124 icon = il.load("spectrogram");
|
Chris@155
|
1125 mainText = tr("Add Pea&k Frequency Spectrogram");
|
Chris@66
|
1126 if (menuType == 0) {
|
Chris@155
|
1127 shortcutText = tr("K");
|
Chris@66
|
1128 tipText = tr("Add a new pane showing a spectrogram set up for tracking frequencies");
|
Chris@66
|
1129 } else {
|
Chris@66
|
1130 tipText = tr("Add a new layer showing a spectrogram set up for tracking frequencies");
|
Chris@66
|
1131 }
|
Chris@66
|
1132 break;
|
Chris@66
|
1133
|
Chris@66
|
1134 case LayerFactory::Spectrum:
|
Chris@168
|
1135 icon = il.load("spectrum");
|
Chris@66
|
1136 mainText = tr("Add Spectr&um");
|
Chris@66
|
1137 if (menuType == 0) {
|
Chris@155
|
1138 shortcutText = tr("U");
|
Chris@66
|
1139 tipText = tr("Add a new pane showing a frequency spectrum");
|
Chris@66
|
1140 } else {
|
Chris@66
|
1141 tipText = tr("Add a new layer showing a frequency spectrum");
|
Chris@66
|
1142 }
|
Chris@66
|
1143 break;
|
Chris@66
|
1144
|
Chris@66
|
1145 default: break;
|
Chris@66
|
1146 }
|
Chris@66
|
1147
|
Chris@66
|
1148 std::vector<Model *> candidateModels;
|
Chris@66
|
1149 if (menuType == 0) {
|
Chris@66
|
1150 candidateModels = models;
|
Chris@66
|
1151 } else {
|
Chris@66
|
1152 candidateModels.push_back(0);
|
Chris@66
|
1153 }
|
Chris@66
|
1154
|
Chris@66
|
1155 for (std::vector<Model *>::iterator mi =
|
Chris@66
|
1156 candidateModels.begin();
|
Chris@66
|
1157 mi != candidateModels.end(); ++mi) {
|
Chris@66
|
1158
|
Chris@66
|
1159 Model *model = *mi;
|
Chris@66
|
1160
|
Chris@66
|
1161 int channels = 0;
|
Chris@66
|
1162 if (model) {
|
Chris@66
|
1163 DenseTimeValueModel *dtvm =
|
Chris@66
|
1164 dynamic_cast<DenseTimeValueModel *>(model);
|
Chris@66
|
1165 if (dtvm) channels = dtvm->getChannelCount();
|
Chris@66
|
1166 }
|
Chris@66
|
1167 if (channels < 1 && getMainModel()) {
|
Chris@66
|
1168 channels = getMainModel()->getChannelCount();
|
Chris@66
|
1169 }
|
Chris@66
|
1170 if (channels < 1) channels = 1;
|
Chris@66
|
1171
|
Chris@66
|
1172 for (int c = 0; c <= channels; ++c) {
|
Chris@66
|
1173
|
Chris@66
|
1174 if (c == 1 && channels == 1) continue;
|
Chris@66
|
1175 bool isDefault = (c == 0);
|
Chris@66
|
1176 bool isOnly = (isDefault && (channels == 1));
|
Chris@66
|
1177
|
Chris@66
|
1178 if (menuType == 1) {
|
Chris@66
|
1179 if (isDefault) isOnly = true;
|
Chris@66
|
1180 else continue;
|
Chris@66
|
1181 }
|
Chris@66
|
1182
|
Chris@66
|
1183 if (isOnly && (!plural || menuType == 1)) {
|
Chris@66
|
1184
|
Chris@138
|
1185 if (menuType == 1 && type != LayerFactory::Waveform) {
|
Chris@67
|
1186 action = new QAction(mainText, this);
|
Chris@67
|
1187 } else {
|
Chris@67
|
1188 action = new QAction(icon, mainText, this);
|
Chris@67
|
1189 }
|
Chris@67
|
1190
|
Chris@66
|
1191 action->setShortcut(shortcutText);
|
Chris@66
|
1192 action->setStatusTip(tipText);
|
Chris@66
|
1193 if (menuType == 0) {
|
Chris@66
|
1194 connect(action, SIGNAL(triggered()),
|
Chris@66
|
1195 this, SLOT(addPane()));
|
Chris@66
|
1196 connect(this, SIGNAL(canAddPane(bool)),
|
Chris@66
|
1197 action, SLOT(setEnabled(bool)));
|
Chris@66
|
1198 m_paneActions[action] = PaneConfiguration(type);
|
Chris@66
|
1199 } else {
|
Chris@66
|
1200 connect(action, SIGNAL(triggered()),
|
Chris@66
|
1201 this, SLOT(addLayer()));
|
Chris@66
|
1202 connect(this, SIGNAL(canAddLayer(bool)),
|
Chris@66
|
1203 action, SLOT(setEnabled(bool)));
|
Chris@66
|
1204 m_layerActions[action] = type;
|
Chris@66
|
1205 }
|
Chris@162
|
1206 if (shortcutText != "") {
|
Chris@162
|
1207 m_keyReference->registerShortcut(action);
|
Chris@162
|
1208 }
|
Chris@66
|
1209 menu->addAction(action);
|
Chris@66
|
1210
|
Chris@66
|
1211 } else {
|
Chris@66
|
1212
|
Chris@66
|
1213 if (!submenu) {
|
Chris@66
|
1214 submenu = menu->addMenu(mainText);
|
Chris@97
|
1215 submenu->setTearOffEnabled(true);
|
Chris@67
|
1216 } else if (isDefault) {
|
Chris@67
|
1217 submenu->addSeparator();
|
Chris@66
|
1218 }
|
Chris@66
|
1219
|
Chris@66
|
1220 QString actionText;
|
Chris@66
|
1221 if (c == 0) {
|
Chris@66
|
1222 if (mono) {
|
Chris@66
|
1223 actionText = tr("&All Channels Mixed");
|
Chris@66
|
1224 } else {
|
Chris@66
|
1225 actionText = tr("&All Channels");
|
Chris@66
|
1226 }
|
Chris@66
|
1227 } else {
|
Chris@66
|
1228 actionText = tr("Channel &%1").arg(c);
|
Chris@66
|
1229 }
|
Chris@66
|
1230
|
Chris@66
|
1231 if (model) {
|
Chris@66
|
1232 actionText = tr("%1: %2")
|
Chris@66
|
1233 .arg(model->objectName())
|
Chris@66
|
1234 .arg(actionText);
|
Chris@66
|
1235 }
|
Chris@67
|
1236
|
Chris@67
|
1237 if (isDefault) {
|
Chris@67
|
1238 action = new QAction(icon, actionText, this);
|
Chris@67
|
1239 if (!model || model == getMainModel()) {
|
Chris@162
|
1240 action->setShortcut(shortcutText);
|
Chris@67
|
1241 }
|
Chris@67
|
1242 } else {
|
Chris@67
|
1243 action = new QAction(actionText, this);
|
Chris@67
|
1244 }
|
Chris@67
|
1245
|
Chris@66
|
1246 action->setStatusTip(tipText);
|
Chris@66
|
1247
|
Chris@66
|
1248 if (menuType == 0) {
|
Chris@66
|
1249 connect(action, SIGNAL(triggered()),
|
Chris@66
|
1250 this, SLOT(addPane()));
|
Chris@66
|
1251 connect(this, SIGNAL(canAddPane(bool)),
|
Chris@66
|
1252 action, SLOT(setEnabled(bool)));
|
Chris@66
|
1253 m_paneActions[action] =
|
Chris@66
|
1254 PaneConfiguration(type, model, c - 1);
|
Chris@66
|
1255 } else {
|
Chris@66
|
1256 connect(action, SIGNAL(triggered()),
|
Chris@66
|
1257 this, SLOT(addLayer()));
|
Chris@66
|
1258 connect(this, SIGNAL(canAddLayer(bool)),
|
Chris@66
|
1259 action, SLOT(setEnabled(bool)));
|
Chris@66
|
1260 m_layerActions[action] = type;
|
Chris@66
|
1261 }
|
Chris@66
|
1262
|
Chris@66
|
1263 submenu->addAction(action);
|
Chris@66
|
1264 }
|
Chris@66
|
1265 }
|
Chris@66
|
1266 }
|
Chris@66
|
1267 }
|
Chris@66
|
1268 }
|
Chris@66
|
1269
|
Chris@66
|
1270 menu = m_paneMenu;
|
Chris@66
|
1271
|
Chris@66
|
1272 menu->addSeparator();
|
Chris@66
|
1273
|
Chris@168
|
1274 action = new QAction(il.load("editdelete"), tr("&Delete Pane"), this);
|
Chris@155
|
1275 action->setShortcut(tr("Ctrl+Shift+D"));
|
Chris@90
|
1276 action->setStatusTip(tr("Delete the currently active pane"));
|
Chris@66
|
1277 connect(action, SIGNAL(triggered()), this, SLOT(deleteCurrentPane()));
|
Chris@66
|
1278 connect(this, SIGNAL(canDeleteCurrentPane(bool)), action, SLOT(setEnabled(bool)));
|
Chris@162
|
1279 m_keyReference->registerShortcut(action);
|
Chris@66
|
1280 menu->addAction(action);
|
Chris@66
|
1281
|
Chris@66
|
1282 menu = m_layerMenu;
|
Chris@66
|
1283
|
Chris@168
|
1284 action = new QAction(il.load("timeruler"), tr("Add &Time Ruler"), this);
|
Chris@66
|
1285 action->setStatusTip(tr("Add a new layer showing a time ruler"));
|
Chris@66
|
1286 connect(action, SIGNAL(triggered()), this, SLOT(addLayer()));
|
Chris@66
|
1287 connect(this, SIGNAL(canAddLayer(bool)), action, SLOT(setEnabled(bool)));
|
Chris@66
|
1288 m_layerActions[action] = LayerFactory::TimeRuler;
|
Chris@66
|
1289 menu->addAction(action);
|
Chris@66
|
1290
|
Chris@66
|
1291 menu->addSeparator();
|
Chris@66
|
1292
|
Chris@66
|
1293 m_existingLayersMenu = menu->addMenu(tr("Add &Existing Layer"));
|
Chris@97
|
1294 m_existingLayersMenu->setTearOffEnabled(true);
|
Chris@66
|
1295 m_rightButtonLayerMenu->addMenu(m_existingLayersMenu);
|
Chris@95
|
1296
|
Chris@95
|
1297 m_sliceMenu = menu->addMenu(tr("Add S&lice of Layer"));
|
Chris@97
|
1298 m_sliceMenu->setTearOffEnabled(true);
|
Chris@95
|
1299 m_rightButtonLayerMenu->addMenu(m_sliceMenu);
|
Chris@95
|
1300
|
Chris@95
|
1301 setupExistingLayersMenus();
|
Chris@66
|
1302
|
Chris@66
|
1303 m_rightButtonLayerMenu->addSeparator();
|
Chris@66
|
1304 menu->addSeparator();
|
Chris@66
|
1305
|
Chris@163
|
1306 QAction *raction = new QAction(tr("&Rename Layer..."), this);
|
Chris@163
|
1307 raction->setShortcut(tr("R"));
|
Chris@163
|
1308 raction->setStatusTip(tr("Rename the currently active layer"));
|
Chris@163
|
1309 connect(raction, SIGNAL(triggered()), this, SLOT(renameCurrentLayer()));
|
Chris@163
|
1310 connect(this, SIGNAL(canRenameLayer(bool)), raction, SLOT(setEnabled(bool)));
|
Chris@163
|
1311 menu->addAction(raction);
|
Chris@163
|
1312 m_rightButtonLayerMenu->addAction(raction);
|
Chris@66
|
1313
|
Chris@168
|
1314 action = new QAction(il.load("editdelete"), tr("&Delete Layer"), this);
|
Chris@155
|
1315 action->setShortcut(tr("Ctrl+D"));
|
Chris@66
|
1316 action->setStatusTip(tr("Delete the currently active layer"));
|
Chris@66
|
1317 connect(action, SIGNAL(triggered()), this, SLOT(deleteCurrentLayer()));
|
Chris@66
|
1318 connect(this, SIGNAL(canDeleteCurrentLayer(bool)), action, SLOT(setEnabled(bool)));
|
Chris@162
|
1319 m_keyReference->registerShortcut(action);
|
Chris@66
|
1320 menu->addAction(action);
|
Chris@66
|
1321 m_rightButtonLayerMenu->addAction(action);
|
Chris@163
|
1322
|
Chris@163
|
1323 m_keyReference->registerShortcut(raction); // rename after delete, so delete layer goes next to delete pane
|
Chris@66
|
1324 }
|
Chris@66
|
1325
|
Chris@66
|
1326 void
|
Chris@66
|
1327 MainWindow::setupTransformsMenu()
|
Chris@66
|
1328 {
|
Chris@34
|
1329 if (m_transformsMenu) {
|
Chris@34
|
1330 m_transformActions.clear();
|
Chris@34
|
1331 m_transformActionsReverse.clear();
|
Chris@34
|
1332 m_transformsMenu->clear();
|
Chris@34
|
1333 } else {
|
Chris@97
|
1334 m_transformsMenu = menuBar()->addMenu(tr("&Transform"));
|
Chris@97
|
1335 m_transformsMenu->setTearOffEnabled(true);
|
Chris@97
|
1336 }
|
Chris@34
|
1337
|
Chris@0
|
1338 TransformFactory::TransformList transforms =
|
Chris@0
|
1339 TransformFactory::getInstance()->getAllTransforms();
|
Chris@0
|
1340
|
Chris@33
|
1341 vector<QString> types =
|
Chris@0
|
1342 TransformFactory::getInstance()->getAllTransformTypes();
|
Chris@0
|
1343
|
Chris@37
|
1344 map<QString, map<QString, SubdividingMenu *> > categoryMenus;
|
Chris@37
|
1345 map<QString, map<QString, SubdividingMenu *> > makerMenus;
|
Chris@33
|
1346
|
Chris@36
|
1347 map<QString, SubdividingMenu *> byPluginNameMenus;
|
Chris@33
|
1348 map<QString, map<QString, QMenu *> > pluginNameMenus;
|
Chris@33
|
1349
|
Chris@37
|
1350 set<SubdividingMenu *> pendingMenus;
|
Chris@37
|
1351
|
Chris@34
|
1352 m_recentTransformsMenu = m_transformsMenu->addMenu(tr("&Recent Transforms"));
|
Chris@97
|
1353 m_recentTransformsMenu->setTearOffEnabled(true);
|
Chris@34
|
1354 m_rightButtonTransformsMenu->addMenu(m_recentTransformsMenu);
|
Chris@34
|
1355 connect(&m_recentTransforms, SIGNAL(recentChanged()),
|
Chris@34
|
1356 this, SLOT(setupRecentTransformsMenu()));
|
Chris@34
|
1357
|
Chris@34
|
1358 m_transformsMenu->addSeparator();
|
Chris@34
|
1359 m_rightButtonTransformsMenu->addSeparator();
|
Chris@34
|
1360
|
Chris@33
|
1361 for (vector<QString>::iterator i = types.begin(); i != types.end(); ++i) {
|
Chris@33
|
1362
|
Chris@33
|
1363 if (i != types.begin()) {
|
Chris@34
|
1364 m_transformsMenu->addSeparator();
|
Chris@34
|
1365 m_rightButtonTransformsMenu->addSeparator();
|
Chris@33
|
1366 }
|
Chris@33
|
1367
|
Chris@33
|
1368 QString byCategoryLabel = tr("%1 by Category").arg(*i);
|
Chris@37
|
1369 SubdividingMenu *byCategoryMenu = new SubdividingMenu(byCategoryLabel,
|
Chris@37
|
1370 20, 40);
|
Chris@97
|
1371 byCategoryMenu->setTearOffEnabled(true);
|
Chris@37
|
1372 m_transformsMenu->addMenu(byCategoryMenu);
|
Chris@34
|
1373 m_rightButtonTransformsMenu->addMenu(byCategoryMenu);
|
Chris@37
|
1374 pendingMenus.insert(byCategoryMenu);
|
Chris@33
|
1375
|
Chris@33
|
1376 vector<QString> categories =
|
Chris@33
|
1377 TransformFactory::getInstance()->getTransformCategories(*i);
|
Chris@33
|
1378
|
Chris@33
|
1379 for (vector<QString>::iterator j = categories.begin();
|
Chris@33
|
1380 j != categories.end(); ++j) {
|
Chris@33
|
1381
|
Chris@33
|
1382 QString category = *j;
|
Chris@33
|
1383 if (category == "") category = tr("Unclassified");
|
Chris@33
|
1384
|
Chris@33
|
1385 if (categories.size() < 2) {
|
Chris@33
|
1386 categoryMenus[*i][category] = byCategoryMenu;
|
Chris@33
|
1387 continue;
|
Chris@33
|
1388 }
|
Chris@33
|
1389
|
Chris@33
|
1390 QStringList components = category.split(" > ");
|
Chris@33
|
1391 QString key;
|
Chris@33
|
1392
|
Chris@33
|
1393 for (QStringList::iterator k = components.begin();
|
Chris@33
|
1394 k != components.end(); ++k) {
|
Chris@33
|
1395
|
Chris@33
|
1396 QString parentKey = key;
|
Chris@33
|
1397 if (key != "") key += " > ";
|
Chris@33
|
1398 key += *k;
|
Chris@33
|
1399
|
Chris@33
|
1400 if (categoryMenus[*i].find(key) == categoryMenus[*i].end()) {
|
Chris@37
|
1401 SubdividingMenu *m = new SubdividingMenu(*k, 20, 40);
|
Chris@97
|
1402 m->setTearOffEnabled(true);
|
Chris@37
|
1403 pendingMenus.insert(m);
|
Chris@37
|
1404 categoryMenus[*i][key] = m;
|
Chris@33
|
1405 if (parentKey == "") {
|
Chris@37
|
1406 byCategoryMenu->addMenu(m);
|
Chris@33
|
1407 } else {
|
Chris@37
|
1408 categoryMenus[*i][parentKey]->addMenu(m);
|
Chris@33
|
1409 }
|
Chris@33
|
1410 }
|
Chris@33
|
1411 }
|
Chris@33
|
1412 }
|
Chris@33
|
1413
|
Chris@34
|
1414 QString byPluginNameLabel = tr("%1 by Plugin Name").arg(*i);
|
Chris@36
|
1415 byPluginNameMenus[*i] = new SubdividingMenu(byPluginNameLabel);
|
Chris@97
|
1416 byPluginNameMenus[*i]->setTearOffEnabled(true);
|
Chris@36
|
1417 m_transformsMenu->addMenu(byPluginNameMenus[*i]);
|
Chris@34
|
1418 m_rightButtonTransformsMenu->addMenu(byPluginNameMenus[*i]);
|
Chris@37
|
1419 pendingMenus.insert(byPluginNameMenus[*i]);
|
Chris@34
|
1420
|
Chris@33
|
1421 QString byMakerLabel = tr("%1 by Maker").arg(*i);
|
Chris@37
|
1422 SubdividingMenu *byMakerMenu = new SubdividingMenu(byMakerLabel, 20, 40);
|
Chris@97
|
1423 byMakerMenu->setTearOffEnabled(true);
|
Chris@37
|
1424 m_transformsMenu->addMenu(byMakerMenu);
|
Chris@34
|
1425 m_rightButtonTransformsMenu->addMenu(byMakerMenu);
|
Chris@37
|
1426 pendingMenus.insert(byMakerMenu);
|
Chris@33
|
1427
|
Chris@33
|
1428 vector<QString> makers =
|
Chris@33
|
1429 TransformFactory::getInstance()->getTransformMakers(*i);
|
Chris@37
|
1430
|
Chris@33
|
1431 for (vector<QString>::iterator j = makers.begin();
|
Chris@33
|
1432 j != makers.end(); ++j) {
|
Chris@33
|
1433
|
Chris@33
|
1434 QString maker = *j;
|
Chris@33
|
1435 if (maker == "") maker = tr("Unknown");
|
Chris@55
|
1436 maker.replace(QRegExp(tr(" [\\(<].*$")), "");
|
Chris@55
|
1437
|
Chris@37
|
1438 makerMenus[*i][maker] = new SubdividingMenu(maker, 30, 40);
|
Chris@97
|
1439 makerMenus[*i][maker]->setTearOffEnabled(true);
|
Chris@37
|
1440 byMakerMenu->addMenu(makerMenus[*i][maker]);
|
Chris@37
|
1441 pendingMenus.insert(makerMenus[*i][maker]);
|
Chris@33
|
1442 }
|
Chris@0
|
1443 }
|
Chris@0
|
1444
|
Chris@0
|
1445 for (unsigned int i = 0; i < transforms.size(); ++i) {
|
Chris@0
|
1446
|
Chris@107
|
1447 QString name = transforms[i].name;
|
Chris@107
|
1448 if (name == "") name = transforms[i].identifier;
|
Chris@107
|
1449
|
Chris@107
|
1450 // std::cerr << "Plugin Name: " << name.toStdString() << std::endl;
|
Chris@80
|
1451
|
Chris@33
|
1452 QString type = transforms[i].type;
|
Chris@33
|
1453
|
Chris@33
|
1454 QString category = transforms[i].category;
|
Chris@33
|
1455 if (category == "") category = tr("Unclassified");
|
Chris@33
|
1456
|
Chris@33
|
1457 QString maker = transforms[i].maker;
|
Chris@33
|
1458 if (maker == "") maker = tr("Unknown");
|
Chris@55
|
1459 maker.replace(QRegExp(tr(" [\\(<].*$")), "");
|
Chris@33
|
1460
|
Chris@107
|
1461 QString pluginName = name.section(": ", 0, 0);
|
Chris@107
|
1462 QString output = name.section(": ", 1);
|
Chris@107
|
1463
|
Chris@107
|
1464 QAction *action = new QAction(tr("%1...").arg(name), this);
|
Chris@0
|
1465 connect(action, SIGNAL(triggered()), this, SLOT(addLayer()));
|
Chris@107
|
1466 m_transformActions[action] = transforms[i].identifier;
|
Chris@107
|
1467 m_transformActionsReverse[transforms[i].identifier] = action;
|
Chris@0
|
1468 connect(this, SIGNAL(canAddLayer(bool)), action, SLOT(setEnabled(bool)));
|
Chris@33
|
1469
|
Chris@108
|
1470 action->setStatusTip(transforms[i].description);
|
Chris@90
|
1471
|
Chris@33
|
1472 if (categoryMenus[type].find(category) == categoryMenus[type].end()) {
|
Chris@33
|
1473 std::cerr << "WARNING: MainWindow::setupMenus: Internal error: "
|
Chris@33
|
1474 << "No category menu for transform \""
|
Chris@107
|
1475 << name.toStdString() << "\" (category = \""
|
Chris@33
|
1476 << category.toStdString() << "\")" << std::endl;
|
Chris@33
|
1477 } else {
|
Chris@33
|
1478 categoryMenus[type][category]->addAction(action);
|
Chris@33
|
1479 }
|
Chris@33
|
1480
|
Chris@33
|
1481 if (makerMenus[type].find(maker) == makerMenus[type].end()) {
|
Chris@33
|
1482 std::cerr << "WARNING: MainWindow::setupMenus: Internal error: "
|
Chris@33
|
1483 << "No maker menu for transform \""
|
Chris@107
|
1484 << name.toStdString() << "\" (maker = \""
|
Chris@33
|
1485 << maker.toStdString() << "\")" << std::endl;
|
Chris@33
|
1486 } else {
|
Chris@80
|
1487 makerMenus[type][maker]->addAction(action);
|
Chris@33
|
1488 }
|
Chris@33
|
1489
|
Chris@33
|
1490 action = new QAction(tr("%1...").arg(output == "" ? pluginName : output), this);
|
Chris@33
|
1491 connect(action, SIGNAL(triggered()), this, SLOT(addLayer()));
|
Chris@107
|
1492 m_transformActions[action] = transforms[i].identifier;
|
Chris@33
|
1493 connect(this, SIGNAL(canAddLayer(bool)), action, SLOT(setEnabled(bool)));
|
Chris@108
|
1494 action->setStatusTip(transforms[i].description);
|
Chris@33
|
1495
|
Chris@34
|
1496 // cerr << "Transform: \"" << name.toStdString() << "\": plugin name \"" << pluginName.toStdString() << "\"" << endl;
|
Chris@34
|
1497
|
Chris@33
|
1498 if (pluginNameMenus[type].find(pluginName) ==
|
Chris@33
|
1499 pluginNameMenus[type].end()) {
|
Chris@33
|
1500
|
Chris@36
|
1501 SubdividingMenu *parentMenu = byPluginNameMenus[type];
|
Chris@97
|
1502 parentMenu->setTearOffEnabled(true);
|
Chris@34
|
1503
|
Chris@33
|
1504 if (output == "") {
|
Chris@36
|
1505 parentMenu->addAction(pluginName, action);
|
Chris@33
|
1506 } else {
|
Chris@34
|
1507 pluginNameMenus[type][pluginName] =
|
Chris@34
|
1508 parentMenu->addMenu(pluginName);
|
Chris@33
|
1509 connect(this, SIGNAL(canAddLayer(bool)),
|
Chris@33
|
1510 pluginNameMenus[type][pluginName],
|
Chris@33
|
1511 SLOT(setEnabled(bool)));
|
Chris@33
|
1512 }
|
Chris@33
|
1513 }
|
Chris@33
|
1514
|
Chris@33
|
1515 if (pluginNameMenus[type].find(pluginName) !=
|
Chris@33
|
1516 pluginNameMenus[type].end()) {
|
Chris@33
|
1517 pluginNameMenus[type][pluginName]->addAction(action);
|
Chris@33
|
1518 }
|
Chris@0
|
1519 }
|
Chris@0
|
1520
|
Chris@37
|
1521 for (set<SubdividingMenu *>::iterator i = pendingMenus.begin();
|
Chris@37
|
1522 i != pendingMenus.end(); ++i) {
|
Chris@37
|
1523 (*i)->entriesAdded();
|
Chris@37
|
1524 }
|
Chris@37
|
1525
|
Chris@34
|
1526 setupRecentTransformsMenu();
|
Chris@66
|
1527 }
|
Chris@66
|
1528
|
Chris@66
|
1529 void
|
Chris@66
|
1530 MainWindow::setupHelpMenu()
|
Chris@66
|
1531 {
|
Chris@66
|
1532 QMenu *menu = menuBar()->addMenu(tr("&Help"));
|
Chris@97
|
1533 menu->setTearOffEnabled(true);
|
Chris@66
|
1534
|
Chris@162
|
1535 m_keyReference->setCategory(tr("Help"));
|
Chris@162
|
1536
|
Chris@168
|
1537 IconLoader il;
|
Chris@168
|
1538
|
Chris@168
|
1539 QAction *action = new QAction(il.load("help"),
|
Chris@138
|
1540 tr("&Help Reference"), this);
|
Chris@162
|
1541 action->setShortcut(tr("F1"));
|
Chris@66
|
1542 action->setStatusTip(tr("Open the Sonic Visualiser reference manual"));
|
Chris@66
|
1543 connect(action, SIGNAL(triggered()), this, SLOT(help()));
|
Chris@162
|
1544 m_keyReference->registerShortcut(action);
|
Chris@0
|
1545 menu->addAction(action);
|
Chris@162
|
1546
|
Chris@163
|
1547 action = new QAction(tr("&Key and Mouse Reference"), this);
|
Chris@162
|
1548 action->setShortcut(tr("F2"));
|
Chris@162
|
1549 action->setStatusTip(tr("Open a window showing the keystrokes you can use in Sonic Visualiser"));
|
Chris@162
|
1550 connect(action, SIGNAL(triggered()), this, SLOT(keyReference()));
|
Chris@162
|
1551 m_keyReference->registerShortcut(action);
|
Chris@162
|
1552 menu->addAction(action);
|
Chris@66
|
1553
|
Chris@164
|
1554 action = new QAction(tr("Sonic Visualiser on the &Web"), this);
|
Chris@164
|
1555 action->setStatusTip(tr("Open the Sonic Visualiser website"));
|
Chris@164
|
1556 connect(action, SIGNAL(triggered()), this, SLOT(website()));
|
Chris@164
|
1557 menu->addAction(action);
|
Chris@164
|
1558
|
Chris@66
|
1559 action = new QAction(tr("&About Sonic Visualiser"), this);
|
Chris@66
|
1560 action->setStatusTip(tr("Show information about Sonic Visualiser"));
|
Chris@66
|
1561 connect(action, SIGNAL(triggered()), this, SLOT(about()));
|
Chris@0
|
1562 menu->addAction(action);
|
Chris@0
|
1563 }
|
Chris@0
|
1564
|
Chris@0
|
1565 void
|
Chris@0
|
1566 MainWindow::setupRecentFilesMenu()
|
Chris@0
|
1567 {
|
Chris@0
|
1568 m_recentFilesMenu->clear();
|
Chris@34
|
1569 vector<QString> files = m_recentFiles.getRecent();
|
Chris@0
|
1570 for (size_t i = 0; i < files.size(); ++i) {
|
Chris@0
|
1571 QAction *action = new QAction(files[i], this);
|
Chris@0
|
1572 connect(action, SIGNAL(triggered()), this, SLOT(openRecentFile()));
|
Chris@162
|
1573 if (i == 0) {
|
Chris@162
|
1574 action->setShortcut(tr("Ctrl+R"));
|
Chris@162
|
1575 m_keyReference->registerShortcut
|
Chris@163
|
1576 (tr("Re-open"),
|
Chris@163
|
1577 action->shortcut(),
|
Chris@163
|
1578 tr("Re-open the current or most recently opened file"));
|
Chris@162
|
1579 }
|
Chris@0
|
1580 m_recentFilesMenu->addAction(action);
|
Chris@0
|
1581 }
|
Chris@0
|
1582 }
|
Chris@0
|
1583
|
Chris@0
|
1584 void
|
Chris@34
|
1585 MainWindow::setupRecentTransformsMenu()
|
Chris@34
|
1586 {
|
Chris@34
|
1587 m_recentTransformsMenu->clear();
|
Chris@34
|
1588 vector<QString> transforms = m_recentTransforms.getRecent();
|
Chris@34
|
1589 for (size_t i = 0; i < transforms.size(); ++i) {
|
Chris@34
|
1590 TransformActionReverseMap::iterator ti =
|
Chris@34
|
1591 m_transformActionsReverse.find(transforms[i]);
|
Chris@34
|
1592 if (ti == m_transformActionsReverse.end()) {
|
Chris@34
|
1593 std::cerr << "WARNING: MainWindow::setupRecentTransformsMenu: "
|
Chris@34
|
1594 << "Unknown transform \"" << transforms[i].toStdString()
|
Chris@34
|
1595 << "\" in recent transforms list" << std::endl;
|
Chris@34
|
1596 continue;
|
Chris@34
|
1597 }
|
Chris@162
|
1598 if (i == 0) {
|
Chris@162
|
1599 ti->second->setShortcut(tr("Ctrl+T"));
|
Chris@162
|
1600 m_keyReference->registerShortcut
|
Chris@163
|
1601 (tr("Repeat Transform"),
|
Chris@162
|
1602 ti->second->shortcut(),
|
Chris@163
|
1603 tr("Re-select the most recently run transform"));
|
Chris@162
|
1604 }
|
Chris@34
|
1605 m_recentTransformsMenu->addAction(ti->second);
|
Chris@34
|
1606 }
|
Chris@34
|
1607 }
|
Chris@34
|
1608
|
Chris@34
|
1609 void
|
Chris@95
|
1610 MainWindow::setupExistingLayersMenus()
|
Chris@0
|
1611 {
|
Chris@0
|
1612 if (!m_existingLayersMenu) return; // should have been created by setupMenus
|
Chris@0
|
1613
|
Chris@0
|
1614 // std::cerr << "MainWindow::setupExistingLayersMenu" << std::endl;
|
Chris@0
|
1615
|
Chris@0
|
1616 m_existingLayersMenu->clear();
|
Chris@0
|
1617 m_existingLayerActions.clear();
|
Chris@0
|
1618
|
Chris@95
|
1619 m_sliceMenu->clear();
|
Chris@95
|
1620 m_sliceActions.clear();
|
Chris@95
|
1621
|
Chris@168
|
1622 IconLoader il;
|
Chris@168
|
1623
|
Chris@33
|
1624 vector<Layer *> orderedLayers;
|
Chris@33
|
1625 set<Layer *> observedLayers;
|
Chris@95
|
1626 set<Layer *> sliceableLayers;
|
Chris@95
|
1627
|
Chris@95
|
1628 LayerFactory *factory = LayerFactory::getInstance();
|
Chris@0
|
1629
|
Chris@0
|
1630 for (int i = 0; i < m_paneStack->getPaneCount(); ++i) {
|
Chris@0
|
1631
|
Chris@0
|
1632 Pane *pane = m_paneStack->getPane(i);
|
Chris@0
|
1633 if (!pane) continue;
|
Chris@0
|
1634
|
Chris@0
|
1635 for (int j = 0; j < pane->getLayerCount(); ++j) {
|
Chris@0
|
1636
|
Chris@0
|
1637 Layer *layer = pane->getLayer(j);
|
Chris@0
|
1638 if (!layer) continue;
|
Chris@0
|
1639 if (observedLayers.find(layer) != observedLayers.end()) {
|
Chris@137
|
1640 // std::cerr << "found duplicate layer " << layer << std::endl;
|
Chris@0
|
1641 continue;
|
Chris@0
|
1642 }
|
Chris@0
|
1643
|
Chris@0
|
1644 // std::cerr << "found new layer " << layer << " (name = "
|
Chris@0
|
1645 // << layer->getLayerPresentationName().toStdString() << ")" << std::endl;
|
Chris@0
|
1646
|
Chris@0
|
1647 orderedLayers.push_back(layer);
|
Chris@0
|
1648 observedLayers.insert(layer);
|
Chris@95
|
1649
|
Chris@95
|
1650 if (factory->isLayerSliceable(layer)) {
|
Chris@95
|
1651 sliceableLayers.insert(layer);
|
Chris@95
|
1652 }
|
Chris@0
|
1653 }
|
Chris@0
|
1654 }
|
Chris@0
|
1655
|
Chris@33
|
1656 map<QString, int> observedNames;
|
Chris@0
|
1657
|
Chris@137
|
1658 for (size_t i = 0; i < orderedLayers.size(); ++i) {
|
Chris@0
|
1659
|
Chris@95
|
1660 Layer *layer = orderedLayers[i];
|
Chris@95
|
1661
|
Chris@95
|
1662 QString name = layer->getLayerPresentationName();
|
Chris@0
|
1663 int n = ++observedNames[name];
|
Chris@0
|
1664 if (n > 1) name = QString("%1 <%2>").arg(name).arg(n);
|
Chris@0
|
1665
|
Chris@168
|
1666 QIcon icon = il.load(factory->getLayerIconName
|
Chris@168
|
1667 (factory->getLayerType(layer)));
|
Chris@95
|
1668
|
Chris@95
|
1669 QAction *action = new QAction(icon, name, this);
|
Chris@0
|
1670 connect(action, SIGNAL(triggered()), this, SLOT(addLayer()));
|
Chris@0
|
1671 connect(this, SIGNAL(canAddLayer(bool)), action, SLOT(setEnabled(bool)));
|
Chris@95
|
1672 m_existingLayerActions[action] = layer;
|
Chris@0
|
1673
|
Chris@0
|
1674 m_existingLayersMenu->addAction(action);
|
Chris@95
|
1675
|
Chris@95
|
1676 if (sliceableLayers.find(layer) != sliceableLayers.end()) {
|
Chris@95
|
1677 action = new QAction(icon, name, this);
|
Chris@95
|
1678 connect(action, SIGNAL(triggered()), this, SLOT(addLayer()));
|
Chris@95
|
1679 connect(this, SIGNAL(canAddLayer(bool)), action, SLOT(setEnabled(bool)));
|
Chris@95
|
1680 m_sliceActions[action] = layer;
|
Chris@95
|
1681 m_sliceMenu->addAction(action);
|
Chris@95
|
1682 }
|
Chris@0
|
1683 }
|
Chris@95
|
1684
|
Chris@95
|
1685 m_sliceMenu->setEnabled(!m_sliceActions.empty());
|
Chris@0
|
1686 }
|
Chris@0
|
1687
|
Chris@0
|
1688 void
|
Chris@0
|
1689 MainWindow::setupToolbars()
|
Chris@0
|
1690 {
|
Chris@162
|
1691 m_keyReference->setCategory(tr("Playback and Transport Controls"));
|
Chris@162
|
1692
|
Chris@168
|
1693 IconLoader il;
|
Chris@168
|
1694
|
Chris@155
|
1695 QMenu *menu = m_playbackMenu = menuBar()->addMenu(tr("Play&back"));
|
Chris@155
|
1696 menu->setTearOffEnabled(true);
|
Chris@155
|
1697 m_rightButtonMenu->addSeparator();
|
Chris@155
|
1698 m_rightButtonPlaybackMenu = m_rightButtonMenu->addMenu(tr("Playback"));
|
Chris@155
|
1699
|
Chris@155
|
1700 QToolBar *toolbar = addToolBar(tr("Playback Toolbar"));
|
Chris@155
|
1701
|
Chris@168
|
1702 QAction *rwdStartAction = toolbar->addAction(il.load("rewind-start"),
|
Chris@155
|
1703 tr("Rewind to Start"));
|
Chris@155
|
1704 rwdStartAction->setShortcut(tr("Home"));
|
Chris@155
|
1705 rwdStartAction->setStatusTip(tr("Rewind to the start"));
|
Chris@155
|
1706 connect(rwdStartAction, SIGNAL(triggered()), this, SLOT(rewindStart()));
|
Chris@155
|
1707 connect(this, SIGNAL(canPlay(bool)), rwdStartAction, SLOT(setEnabled(bool)));
|
Chris@155
|
1708
|
Chris@168
|
1709 QAction *m_rwdAction = toolbar->addAction(il.load("rewind"),
|
Chris@155
|
1710 tr("Rewind"));
|
Chris@155
|
1711 m_rwdAction->setShortcut(tr("PgUp"));
|
Chris@163
|
1712 m_rwdAction->setStatusTip(tr("Rewind to the previous time instant or time ruler notch"));
|
Chris@155
|
1713 connect(m_rwdAction, SIGNAL(triggered()), this, SLOT(rewind()));
|
Chris@155
|
1714 connect(this, SIGNAL(canRewind(bool)), m_rwdAction, SLOT(setEnabled(bool)));
|
Chris@155
|
1715
|
Chris@168
|
1716 QAction *playAction = toolbar->addAction(il.load("playpause"),
|
Chris@155
|
1717 tr("Play / Pause"));
|
Chris@155
|
1718 playAction->setCheckable(true);
|
Chris@155
|
1719 playAction->setShortcut(tr("Space"));
|
Chris@155
|
1720 playAction->setStatusTip(tr("Start or stop playback from the current position"));
|
Chris@155
|
1721 connect(playAction, SIGNAL(triggered()), this, SLOT(play()));
|
Chris@0
|
1722 connect(m_playSource, SIGNAL(playStatusChanged(bool)),
|
Chris@155
|
1723 playAction, SLOT(setChecked(bool)));
|
Chris@155
|
1724 connect(this, SIGNAL(canPlay(bool)), playAction, SLOT(setEnabled(bool)));
|
Chris@155
|
1725
|
Chris@168
|
1726 m_ffwdAction = toolbar->addAction(il.load("ffwd"),
|
Chris@155
|
1727 tr("Fast Forward"));
|
Chris@155
|
1728 m_ffwdAction->setShortcut(tr("PgDown"));
|
Chris@163
|
1729 m_ffwdAction->setStatusTip(tr("Fast-forward to the next time instant or time ruler notch"));
|
Chris@155
|
1730 connect(m_ffwdAction, SIGNAL(triggered()), this, SLOT(ffwd()));
|
Chris@155
|
1731 connect(this, SIGNAL(canFfwd(bool)), m_ffwdAction, SLOT(setEnabled(bool)));
|
Chris@155
|
1732
|
Chris@168
|
1733 QAction *ffwdEndAction = toolbar->addAction(il.load("ffwd-end"),
|
Chris@155
|
1734 tr("Fast Forward to End"));
|
Chris@155
|
1735 ffwdEndAction->setShortcut(tr("End"));
|
Chris@155
|
1736 ffwdEndAction->setStatusTip(tr("Fast-forward to the end"));
|
Chris@155
|
1737 connect(ffwdEndAction, SIGNAL(triggered()), this, SLOT(ffwdEnd()));
|
Chris@155
|
1738 connect(this, SIGNAL(canPlay(bool)), ffwdEndAction, SLOT(setEnabled(bool)));
|
Chris@0
|
1739
|
Chris@0
|
1740 toolbar = addToolBar(tr("Play Mode Toolbar"));
|
Chris@0
|
1741
|
Chris@168
|
1742 QAction *psAction = toolbar->addAction(il.load("playselection"),
|
Chris@155
|
1743 tr("Constrain Playback to Selection"));
|
Chris@155
|
1744 psAction->setCheckable(true);
|
Chris@155
|
1745 psAction->setChecked(m_viewManager->getPlaySelectionMode());
|
Chris@155
|
1746 psAction->setShortcut(tr("s"));
|
Chris@163
|
1747 psAction->setStatusTip(tr("Constrain playback to the selected regions"));
|
Chris@69
|
1748 connect(m_viewManager, SIGNAL(playSelectionModeChanged(bool)),
|
Chris@155
|
1749 psAction, SLOT(setChecked(bool)));
|
Chris@155
|
1750 connect(psAction, SIGNAL(triggered()), this, SLOT(playSelectionToggled()));
|
Chris@155
|
1751 connect(this, SIGNAL(canPlaySelection(bool)), psAction, SLOT(setEnabled(bool)));
|
Chris@155
|
1752
|
Chris@168
|
1753 QAction *plAction = toolbar->addAction(il.load("playloop"),
|
Chris@155
|
1754 tr("Loop Playback"));
|
Chris@155
|
1755 plAction->setCheckable(true);
|
Chris@155
|
1756 plAction->setChecked(m_viewManager->getPlayLoopMode());
|
Chris@155
|
1757 plAction->setShortcut(tr("l"));
|
Chris@155
|
1758 plAction->setStatusTip(tr("Loop playback"));
|
Chris@69
|
1759 connect(m_viewManager, SIGNAL(playLoopModeChanged(bool)),
|
Chris@155
|
1760 plAction, SLOT(setChecked(bool)));
|
Chris@155
|
1761 connect(plAction, SIGNAL(triggered()), this, SLOT(playLoopToggled()));
|
Chris@155
|
1762 connect(this, SIGNAL(canPlay(bool)), plAction, SLOT(setEnabled(bool)));
|
Chris@155
|
1763
|
Chris@180
|
1764 QAction *soAction = toolbar->addAction(il.load("solo"),
|
Chris@180
|
1765 tr("Solo Current Pane"));
|
Chris@180
|
1766 soAction->setCheckable(true);
|
Chris@180
|
1767 soAction->setChecked(m_viewManager->getPlaySoloMode());
|
Chris@180
|
1768 soAction->setShortcut(tr("o"));
|
Chris@180
|
1769 soAction->setStatusTip(tr("Solo the current pane during playback"));
|
Chris@180
|
1770 connect(m_viewManager, SIGNAL(playSoloModeChanged(bool)),
|
Chris@180
|
1771 soAction, SLOT(setChecked(bool)));
|
Chris@180
|
1772 connect(soAction, SIGNAL(triggered()), this, SLOT(playSoloToggled()));
|
Chris@180
|
1773 connect(this, SIGNAL(canPlay(bool)), soAction, SLOT(setEnabled(bool)));
|
Chris@180
|
1774
|
Chris@162
|
1775 m_keyReference->registerShortcut(playAction);
|
Chris@162
|
1776 m_keyReference->registerShortcut(psAction);
|
Chris@162
|
1777 m_keyReference->registerShortcut(plAction);
|
Chris@180
|
1778 m_keyReference->registerShortcut(soAction);
|
Chris@162
|
1779 m_keyReference->registerShortcut(m_rwdAction);
|
Chris@162
|
1780 m_keyReference->registerShortcut(m_ffwdAction);
|
Chris@162
|
1781 m_keyReference->registerShortcut(rwdStartAction);
|
Chris@162
|
1782 m_keyReference->registerShortcut(ffwdEndAction);
|
Chris@162
|
1783
|
Chris@155
|
1784 menu->addAction(playAction);
|
Chris@155
|
1785 menu->addAction(psAction);
|
Chris@155
|
1786 menu->addAction(plAction);
|
Chris@180
|
1787 menu->addAction(soAction);
|
Chris@155
|
1788 menu->addSeparator();
|
Chris@155
|
1789 menu->addAction(m_rwdAction);
|
Chris@155
|
1790 menu->addAction(m_ffwdAction);
|
Chris@155
|
1791 menu->addSeparator();
|
Chris@155
|
1792 menu->addAction(rwdStartAction);
|
Chris@155
|
1793 menu->addAction(ffwdEndAction);
|
Chris@155
|
1794 menu->addSeparator();
|
Chris@155
|
1795
|
Chris@155
|
1796 m_rightButtonPlaybackMenu->addAction(playAction);
|
Chris@155
|
1797 m_rightButtonPlaybackMenu->addAction(psAction);
|
Chris@155
|
1798 m_rightButtonPlaybackMenu->addAction(plAction);
|
Chris@180
|
1799 m_rightButtonPlaybackMenu->addAction(soAction);
|
Chris@155
|
1800 m_rightButtonPlaybackMenu->addSeparator();
|
Chris@155
|
1801 m_rightButtonPlaybackMenu->addAction(m_rwdAction);
|
Chris@155
|
1802 m_rightButtonPlaybackMenu->addAction(m_ffwdAction);
|
Chris@155
|
1803 m_rightButtonPlaybackMenu->addSeparator();
|
Chris@155
|
1804 m_rightButtonPlaybackMenu->addAction(rwdStartAction);
|
Chris@155
|
1805 m_rightButtonPlaybackMenu->addAction(ffwdEndAction);
|
Chris@155
|
1806 m_rightButtonPlaybackMenu->addSeparator();
|
Chris@155
|
1807
|
Chris@155
|
1808 QAction *fastAction = menu->addAction(tr("Speed Up"));
|
Chris@155
|
1809 fastAction->setShortcut(tr("Ctrl+PgUp"));
|
Chris@163
|
1810 fastAction->setStatusTip(tr("Time-stretch playback to speed it up without changing pitch"));
|
Chris@155
|
1811 connect(fastAction, SIGNAL(triggered()), this, SLOT(speedUpPlayback()));
|
Chris@155
|
1812 connect(this, SIGNAL(canSpeedUpPlayback(bool)), fastAction, SLOT(setEnabled(bool)));
|
Chris@155
|
1813
|
Chris@155
|
1814 QAction *slowAction = menu->addAction(tr("Slow Down"));
|
Chris@155
|
1815 slowAction->setShortcut(tr("Ctrl+PgDown"));
|
Chris@163
|
1816 slowAction->setStatusTip(tr("Time-stretch playback to slow it down without changing pitch"));
|
Chris@155
|
1817 connect(slowAction, SIGNAL(triggered()), this, SLOT(slowDownPlayback()));
|
Chris@155
|
1818 connect(this, SIGNAL(canSlowDownPlayback(bool)), slowAction, SLOT(setEnabled(bool)));
|
Chris@155
|
1819
|
Chris@155
|
1820 QAction *normalAction = menu->addAction(tr("Restore Normal Speed"));
|
Chris@155
|
1821 normalAction->setShortcut(tr("Ctrl+Home"));
|
Chris@163
|
1822 normalAction->setStatusTip(tr("Restore non-time-stretched playback"));
|
Chris@155
|
1823 connect(normalAction, SIGNAL(triggered()), this, SLOT(restoreNormalPlayback()));
|
Chris@155
|
1824 connect(this, SIGNAL(canChangePlaybackSpeed(bool)), normalAction, SLOT(setEnabled(bool)));
|
Chris@155
|
1825
|
Chris@162
|
1826 m_keyReference->registerShortcut(fastAction);
|
Chris@162
|
1827 m_keyReference->registerShortcut(slowAction);
|
Chris@162
|
1828 m_keyReference->registerShortcut(normalAction);
|
Chris@162
|
1829
|
Chris@155
|
1830 m_rightButtonPlaybackMenu->addAction(fastAction);
|
Chris@155
|
1831 m_rightButtonPlaybackMenu->addAction(slowAction);
|
Chris@155
|
1832 m_rightButtonPlaybackMenu->addAction(normalAction);
|
Chris@0
|
1833
|
Chris@0
|
1834 toolbar = addToolBar(tr("Edit Toolbar"));
|
Chris@0
|
1835 CommandHistory::getInstance()->registerToolbar(toolbar);
|
Chris@0
|
1836
|
Chris@162
|
1837 m_keyReference->setCategory(tr("Tool Selection"));
|
Chris@162
|
1838
|
Chris@0
|
1839 toolbar = addToolBar(tr("Tools Toolbar"));
|
Chris@0
|
1840 QActionGroup *group = new QActionGroup(this);
|
Chris@0
|
1841
|
Chris@168
|
1842 QAction *action = toolbar->addAction(il.load("navigate"),
|
Chris@155
|
1843 tr("Navigate"));
|
Chris@0
|
1844 action->setCheckable(true);
|
Chris@0
|
1845 action->setChecked(true);
|
Chris@0
|
1846 action->setShortcut(tr("1"));
|
Chris@90
|
1847 action->setStatusTip(tr("Navigate"));
|
Chris@0
|
1848 connect(action, SIGNAL(triggered()), this, SLOT(toolNavigateSelected()));
|
Chris@0
|
1849 group->addAction(action);
|
Chris@162
|
1850 m_keyReference->registerShortcut(action);
|
Chris@0
|
1851 m_toolActions[ViewManager::NavigateMode] = action;
|
Chris@0
|
1852
|
Chris@168
|
1853 action = toolbar->addAction(il.load("select"),
|
Chris@0
|
1854 tr("Select"));
|
Chris@0
|
1855 action->setCheckable(true);
|
Chris@0
|
1856 action->setShortcut(tr("2"));
|
Chris@90
|
1857 action->setStatusTip(tr("Select ranges"));
|
Chris@0
|
1858 connect(action, SIGNAL(triggered()), this, SLOT(toolSelectSelected()));
|
Chris@0
|
1859 group->addAction(action);
|
Chris@162
|
1860 m_keyReference->registerShortcut(action);
|
Chris@0
|
1861 m_toolActions[ViewManager::SelectMode] = action;
|
Chris@0
|
1862
|
Chris@168
|
1863 action = toolbar->addAction(il.load("move"),
|
Chris@0
|
1864 tr("Edit"));
|
Chris@0
|
1865 action->setCheckable(true);
|
Chris@0
|
1866 action->setShortcut(tr("3"));
|
Chris@90
|
1867 action->setStatusTip(tr("Edit items in layer"));
|
Chris@0
|
1868 connect(action, SIGNAL(triggered()), this, SLOT(toolEditSelected()));
|
Chris@0
|
1869 connect(this, SIGNAL(canEditLayer(bool)), action, SLOT(setEnabled(bool)));
|
Chris@0
|
1870 group->addAction(action);
|
Chris@162
|
1871 m_keyReference->registerShortcut(action);
|
Chris@0
|
1872 m_toolActions[ViewManager::EditMode] = action;
|
Chris@0
|
1873
|
Chris@168
|
1874 action = toolbar->addAction(il.load("draw"),
|
Chris@0
|
1875 tr("Draw"));
|
Chris@0
|
1876 action->setCheckable(true);
|
Chris@0
|
1877 action->setShortcut(tr("4"));
|
Chris@90
|
1878 action->setStatusTip(tr("Draw new items in layer"));
|
Chris@0
|
1879 connect(action, SIGNAL(triggered()), this, SLOT(toolDrawSelected()));
|
Chris@0
|
1880 connect(this, SIGNAL(canEditLayer(bool)), action, SLOT(setEnabled(bool)));
|
Chris@0
|
1881 group->addAction(action);
|
Chris@162
|
1882 m_keyReference->registerShortcut(action);
|
Chris@0
|
1883 m_toolActions[ViewManager::DrawMode] = action;
|
Chris@0
|
1884
|
Chris@168
|
1885 action = toolbar->addAction(il.load("measure"),
|
Chris@151
|
1886 tr("Measure"));
|
Chris@151
|
1887 action->setCheckable(true);
|
Chris@151
|
1888 action->setShortcut(tr("5"));
|
Chris@151
|
1889 action->setStatusTip(tr("Make measurements in layer"));
|
Chris@151
|
1890 connect(action, SIGNAL(triggered()), this, SLOT(toolMeasureSelected()));
|
Chris@169
|
1891 connect(this, SIGNAL(canMeasureLayer(bool)), action, SLOT(setEnabled(bool)));
|
Chris@151
|
1892 group->addAction(action);
|
Chris@162
|
1893 m_keyReference->registerShortcut(action);
|
Chris@151
|
1894 m_toolActions[ViewManager::MeasureMode] = action;
|
Chris@151
|
1895
|
Chris@168
|
1896 // action = toolbar->addAction(il.load("text"),
|
Chris@0
|
1897 // tr("Text"));
|
Chris@0
|
1898 // action->setCheckable(true);
|
Chris@0
|
1899 // action->setShortcut(tr("5"));
|
Chris@0
|
1900 // connect(action, SIGNAL(triggered()), this, SLOT(toolTextSelected()));
|
Chris@0
|
1901 // group->addAction(action);
|
Chris@0
|
1902 // m_toolActions[ViewManager::TextMode] = action;
|
Chris@0
|
1903
|
Chris@0
|
1904 toolNavigateSelected();
|
Chris@163
|
1905
|
Chris@163
|
1906 Pane::registerShortcuts(*m_keyReference);
|
Chris@0
|
1907 }
|
Chris@0
|
1908
|
Chris@0
|
1909 void
|
Chris@0
|
1910 MainWindow::updateMenuStates()
|
Chris@0
|
1911 {
|
Chris@117
|
1912 Pane *currentPane = 0;
|
Chris@117
|
1913 Layer *currentLayer = 0;
|
Chris@117
|
1914
|
Chris@117
|
1915 if (m_paneStack) currentPane = m_paneStack->getCurrentPane();
|
Chris@117
|
1916 if (currentPane) currentLayer = currentPane->getSelectedLayer();
|
Chris@117
|
1917
|
Chris@0
|
1918 bool haveCurrentPane =
|
Chris@117
|
1919 (currentPane != 0);
|
Chris@0
|
1920 bool haveCurrentLayer =
|
Chris@117
|
1921 (haveCurrentPane &&
|
Chris@117
|
1922 (currentLayer != 0));
|
Chris@0
|
1923 bool haveMainModel =
|
Chris@0
|
1924 (getMainModel() != 0);
|
Chris@0
|
1925 bool havePlayTarget =
|
Chris@0
|
1926 (m_playTarget != 0);
|
Chris@0
|
1927 bool haveSelection =
|
Chris@0
|
1928 (m_viewManager &&
|
Chris@0
|
1929 !m_viewManager->getSelections().empty());
|
Chris@0
|
1930 bool haveCurrentEditableLayer =
|
Chris@0
|
1931 (haveCurrentLayer &&
|
Chris@117
|
1932 currentLayer->isLayerEditable());
|
Chris@0
|
1933 bool haveCurrentTimeInstantsLayer =
|
Chris@0
|
1934 (haveCurrentLayer &&
|
Chris@117
|
1935 dynamic_cast<TimeInstantLayer *>(currentLayer));
|
Chris@0
|
1936 bool haveCurrentTimeValueLayer =
|
Chris@0
|
1937 (haveCurrentLayer &&
|
Chris@117
|
1938 dynamic_cast<TimeValueLayer *>(currentLayer));
|
Chris@0
|
1939 bool haveCurrentColour3DPlot =
|
Chris@0
|
1940 (haveCurrentLayer &&
|
Chris@117
|
1941 dynamic_cast<Colour3DPlotLayer *>(currentLayer));
|
Chris@0
|
1942 bool haveClipboardContents =
|
Chris@0
|
1943 (m_viewManager &&
|
Chris@0
|
1944 !m_viewManager->getClipboard().empty());
|
Chris@0
|
1945
|
Chris@0
|
1946 emit canAddPane(haveMainModel);
|
Chris@0
|
1947 emit canDeleteCurrentPane(haveCurrentPane);
|
Chris@0
|
1948 emit canZoom(haveMainModel && haveCurrentPane);
|
Chris@0
|
1949 emit canScroll(haveMainModel && haveCurrentPane);
|
Chris@0
|
1950 emit canAddLayer(haveMainModel && haveCurrentPane);
|
Chris@0
|
1951 emit canImportMoreAudio(haveMainModel);
|
Chris@0
|
1952 emit canImportLayer(haveMainModel && haveCurrentPane);
|
Chris@0
|
1953 emit canExportAudio(haveMainModel);
|
Chris@0
|
1954 emit canExportLayer(haveMainModel &&
|
Chris@0
|
1955 (haveCurrentEditableLayer || haveCurrentColour3DPlot));
|
Chris@121
|
1956 emit canExportImage(haveMainModel && haveCurrentPane);
|
Chris@0
|
1957 emit canDeleteCurrentLayer(haveCurrentLayer);
|
Chris@0
|
1958 emit canRenameLayer(haveCurrentLayer);
|
Chris@0
|
1959 emit canEditLayer(haveCurrentEditableLayer);
|
Chris@169
|
1960 emit canMeasureLayer(haveCurrentLayer);
|
Chris@0
|
1961 emit canSelect(haveMainModel && haveCurrentPane);
|
Chris@155
|
1962 emit canPlay(havePlayTarget);
|
Chris@155
|
1963 emit canFfwd(true);
|
Chris@155
|
1964 emit canRewind(true);
|
Chris@0
|
1965 emit canPaste(haveCurrentEditableLayer && haveClipboardContents);
|
Chris@0
|
1966 emit canInsertInstant(haveCurrentPane);
|
Chris@81
|
1967 emit canInsertInstantsAtBoundaries(haveCurrentPane && haveSelection);
|
Chris@189
|
1968 emit canRenumberInstants(haveCurrentTimeInstantsLayer && haveSelection);
|
Chris@0
|
1969 emit canPlaySelection(haveMainModel && havePlayTarget && haveSelection);
|
Chris@0
|
1970 emit canClearSelection(haveSelection);
|
Chris@0
|
1971 emit canEditSelection(haveSelection && haveCurrentEditableLayer);
|
Chris@0
|
1972 emit canSave(m_sessionFile != "" && m_documentModified);
|
Chris@155
|
1973
|
Chris@164
|
1974 if (m_viewManager &&
|
Chris@164
|
1975 (m_viewManager->getToolMode() == ViewManager::MeasureMode)) {
|
Chris@164
|
1976 emit canDeleteSelection(haveCurrentLayer);
|
Chris@164
|
1977 m_deleteSelectedAction->setText(tr("&Delete Current Measurement"));
|
Chris@164
|
1978 m_deleteSelectedAction->setStatusTip(tr("Delete the measurement currently under the mouse pointer"));
|
Chris@164
|
1979 } else {
|
Chris@164
|
1980 emit canDeleteSelection(haveSelection && haveCurrentEditableLayer);
|
Chris@164
|
1981 m_deleteSelectedAction->setText(tr("&Delete Selected Items"));
|
Chris@164
|
1982 m_deleteSelectedAction->setStatusTip(tr("Delete items in current selection from the current layer"));
|
Chris@164
|
1983 }
|
Chris@164
|
1984
|
Chris@155
|
1985 emit canChangePlaybackSpeed(true);
|
Chris@155
|
1986 int v = m_playSpeed->value();
|
Chris@155
|
1987 emit canSpeedUpPlayback(v < m_playSpeed->maximum());
|
Chris@155
|
1988 emit canSlowDownPlayback(v > m_playSpeed->minimum());
|
Chris@155
|
1989
|
Chris@155
|
1990 if (m_ffwdAction && m_rwdAction) {
|
Chris@155
|
1991 if (haveCurrentTimeInstantsLayer) {
|
Chris@155
|
1992 m_ffwdAction->setText(tr("Fast Forward to Next Instant"));
|
Chris@155
|
1993 m_ffwdAction->setStatusTip(tr("Fast forward to the next time instant in the current layer"));
|
Chris@155
|
1994 m_rwdAction->setText(tr("Rewind to Previous Instant"));
|
Chris@155
|
1995 m_rwdAction->setStatusTip(tr("Rewind to the previous time instant in the current layer"));
|
Chris@155
|
1996 } else if (haveCurrentTimeValueLayer) {
|
Chris@155
|
1997 m_ffwdAction->setText(tr("Fast Forward to Next Point"));
|
Chris@155
|
1998 m_ffwdAction->setStatusTip(tr("Fast forward to the next point in the current layer"));
|
Chris@155
|
1999 m_rwdAction->setText(tr("Rewind to Previous Point"));
|
Chris@155
|
2000 m_rwdAction->setStatusTip(tr("Rewind to the previous point in the current layer"));
|
Chris@155
|
2001 } else {
|
Chris@155
|
2002 m_ffwdAction->setText(tr("Fast Forward"));
|
Chris@155
|
2003 m_ffwdAction->setStatusTip(tr("Fast forward"));
|
Chris@155
|
2004 m_rwdAction->setText(tr("Rewind"));
|
Chris@155
|
2005 m_rwdAction->setStatusTip(tr("Rewind"));
|
Chris@155
|
2006 }
|
Chris@155
|
2007 }
|
Chris@0
|
2008 }
|
Chris@0
|
2009
|
Chris@0
|
2010 void
|
Chris@0
|
2011 MainWindow::updateDescriptionLabel()
|
Chris@0
|
2012 {
|
Chris@0
|
2013 if (!getMainModel()) {
|
Chris@0
|
2014 m_descriptionLabel->setText(tr("No audio file loaded."));
|
Chris@0
|
2015 return;
|
Chris@0
|
2016 }
|
Chris@0
|
2017
|
Chris@0
|
2018 QString description;
|
Chris@0
|
2019
|
Chris@0
|
2020 size_t ssr = getMainModel()->getSampleRate();
|
Chris@0
|
2021 size_t tsr = ssr;
|
Chris@0
|
2022 if (m_playSource) tsr = m_playSource->getTargetSampleRate();
|
Chris@0
|
2023
|
Chris@0
|
2024 if (ssr != tsr) {
|
Chris@0
|
2025 description = tr("%1Hz (resampling to %2Hz)").arg(ssr).arg(tsr);
|
Chris@0
|
2026 } else {
|
Chris@0
|
2027 description = QString("%1Hz").arg(ssr);
|
Chris@0
|
2028 }
|
Chris@0
|
2029
|
Chris@0
|
2030 description = QString("%1 - %2")
|
Chris@0
|
2031 .arg(RealTime::frame2RealTime(getMainModel()->getEndFrame(), ssr)
|
Chris@0
|
2032 .toText(false).c_str())
|
Chris@0
|
2033 .arg(description);
|
Chris@0
|
2034
|
Chris@0
|
2035 m_descriptionLabel->setText(description);
|
Chris@0
|
2036 }
|
Chris@0
|
2037
|
Chris@0
|
2038 void
|
Chris@0
|
2039 MainWindow::documentModified()
|
Chris@0
|
2040 {
|
Chris@0
|
2041 // std::cerr << "MainWindow::documentModified" << std::endl;
|
Chris@0
|
2042
|
Chris@0
|
2043 if (!m_documentModified) {
|
Chris@0
|
2044 setWindowTitle(tr("%1 (modified)").arg(windowTitle()));
|
Chris@0
|
2045 }
|
Chris@0
|
2046
|
Chris@0
|
2047 m_documentModified = true;
|
Chris@0
|
2048 updateMenuStates();
|
Chris@0
|
2049 }
|
Chris@0
|
2050
|
Chris@0
|
2051 void
|
Chris@0
|
2052 MainWindow::documentRestored()
|
Chris@0
|
2053 {
|
Chris@0
|
2054 // std::cerr << "MainWindow::documentRestored" << std::endl;
|
Chris@0
|
2055
|
Chris@0
|
2056 if (m_documentModified) {
|
Chris@0
|
2057 QString wt(windowTitle());
|
Chris@0
|
2058 wt.replace(tr(" (modified)"), "");
|
Chris@0
|
2059 setWindowTitle(wt);
|
Chris@0
|
2060 }
|
Chris@0
|
2061
|
Chris@0
|
2062 m_documentModified = false;
|
Chris@0
|
2063 updateMenuStates();
|
Chris@0
|
2064 }
|
Chris@0
|
2065
|
Chris@0
|
2066 void
|
Chris@0
|
2067 MainWindow::playLoopToggled()
|
Chris@0
|
2068 {
|
Chris@0
|
2069 QAction *action = dynamic_cast<QAction *>(sender());
|
Chris@0
|
2070
|
Chris@0
|
2071 if (action) {
|
Chris@0
|
2072 m_viewManager->setPlayLoopMode(action->isChecked());
|
Chris@0
|
2073 } else {
|
Chris@0
|
2074 m_viewManager->setPlayLoopMode(!m_viewManager->getPlayLoopMode());
|
Chris@0
|
2075 }
|
Chris@0
|
2076 }
|
Chris@0
|
2077
|
Chris@0
|
2078 void
|
Chris@0
|
2079 MainWindow::playSelectionToggled()
|
Chris@0
|
2080 {
|
Chris@0
|
2081 QAction *action = dynamic_cast<QAction *>(sender());
|
Chris@0
|
2082
|
Chris@0
|
2083 if (action) {
|
Chris@0
|
2084 m_viewManager->setPlaySelectionMode(action->isChecked());
|
Chris@0
|
2085 } else {
|
Chris@0
|
2086 m_viewManager->setPlaySelectionMode(!m_viewManager->getPlaySelectionMode());
|
Chris@0
|
2087 }
|
Chris@0
|
2088 }
|
Chris@0
|
2089
|
Chris@0
|
2090 void
|
Chris@180
|
2091 MainWindow::playSoloToggled()
|
Chris@180
|
2092 {
|
Chris@180
|
2093 QAction *action = dynamic_cast<QAction *>(sender());
|
Chris@180
|
2094
|
Chris@180
|
2095 if (action) {
|
Chris@180
|
2096 m_viewManager->setPlaySoloMode(action->isChecked());
|
Chris@180
|
2097 } else {
|
Chris@180
|
2098 m_viewManager->setPlaySoloMode(!m_viewManager->getPlaySoloMode());
|
Chris@180
|
2099 }
|
Chris@180
|
2100
|
Chris@184
|
2101 if (m_viewManager->getPlaySoloMode()) {
|
Chris@184
|
2102 currentPaneChanged(m_paneStack->getCurrentPane());
|
Chris@184
|
2103 } else {
|
Chris@180
|
2104 m_viewManager->setPlaybackModel(0);
|
Chris@180
|
2105 if (m_playSource) {
|
Chris@180
|
2106 m_playSource->clearSoloModelSet();
|
Chris@180
|
2107 }
|
Chris@180
|
2108 }
|
Chris@180
|
2109 }
|
Chris@180
|
2110
|
Chris@180
|
2111 void
|
Chris@116
|
2112 MainWindow::currentPaneChanged(Pane *p)
|
Chris@0
|
2113 {
|
Chris@0
|
2114 updateMenuStates();
|
Chris@116
|
2115 updateVisibleRangeDisplay(p);
|
Chris@180
|
2116
|
Chris@180
|
2117 if (!p) return;
|
Chris@180
|
2118
|
Chris@180
|
2119 if (!(m_viewManager &&
|
Chris@180
|
2120 m_playSource &&
|
Chris@180
|
2121 m_viewManager->getPlaySoloMode())) {
|
Chris@180
|
2122 if (m_viewManager) m_viewManager->setPlaybackModel(0);
|
Chris@180
|
2123 return;
|
Chris@180
|
2124 }
|
Chris@180
|
2125
|
Chris@180
|
2126 Model *prevPlaybackModel = m_viewManager->getPlaybackModel();
|
Chris@180
|
2127
|
Chris@194
|
2128 View::ModelSet soloModels = p->getModels();
|
Chris@194
|
2129
|
Chris@194
|
2130 for (View::ModelSet::iterator mi = soloModels.begin();
|
Chris@194
|
2131 mi != soloModels.end(); ++mi) {
|
Chris@194
|
2132 if (dynamic_cast<RangeSummarisableTimeValueModel *>(*mi)) {
|
Chris@194
|
2133 m_viewManager->setPlaybackModel(*mi);
|
Chris@180
|
2134 }
|
Chris@180
|
2135 }
|
Chris@180
|
2136
|
Chris@180
|
2137 RangeSummarisableTimeValueModel *a =
|
Chris@180
|
2138 dynamic_cast<RangeSummarisableTimeValueModel *>(prevPlaybackModel);
|
Chris@180
|
2139 RangeSummarisableTimeValueModel *b =
|
Chris@180
|
2140 dynamic_cast<RangeSummarisableTimeValueModel *>(m_viewManager->
|
Chris@180
|
2141 getPlaybackModel());
|
Chris@180
|
2142
|
Chris@180
|
2143 m_playSource->setSoloModelSet(soloModels);
|
Chris@180
|
2144
|
Chris@180
|
2145 if (a && b && (a != b)) {
|
Chris@180
|
2146 int frame = m_playSource->getCurrentPlayingFrame();
|
Chris@180
|
2147 //!!! I don't really believe that these functions are the right way around
|
Chris@180
|
2148 int rframe = a->alignFromReference(frame);
|
Chris@180
|
2149 int bframe = b->alignToReference(rframe);
|
Chris@180
|
2150 if (m_playSource->isPlaying()) m_playSource->play(bframe);
|
Chris@180
|
2151 }
|
Chris@0
|
2152 }
|
Chris@0
|
2153
|
Chris@0
|
2154 void
|
Chris@116
|
2155 MainWindow::currentLayerChanged(Pane *p, Layer *)
|
Chris@0
|
2156 {
|
Chris@0
|
2157 updateMenuStates();
|
Chris@116
|
2158 updateVisibleRangeDisplay(p);
|
Chris@0
|
2159 }
|
Chris@0
|
2160
|
Chris@0
|
2161 void
|
Chris@0
|
2162 MainWindow::toolNavigateSelected()
|
Chris@0
|
2163 {
|
Chris@0
|
2164 m_viewManager->setToolMode(ViewManager::NavigateMode);
|
Chris@0
|
2165 }
|
Chris@0
|
2166
|
Chris@0
|
2167 void
|
Chris@0
|
2168 MainWindow::toolSelectSelected()
|
Chris@0
|
2169 {
|
Chris@0
|
2170 m_viewManager->setToolMode(ViewManager::SelectMode);
|
Chris@0
|
2171 }
|
Chris@0
|
2172
|
Chris@0
|
2173 void
|
Chris@0
|
2174 MainWindow::toolEditSelected()
|
Chris@0
|
2175 {
|
Chris@0
|
2176 m_viewManager->setToolMode(ViewManager::EditMode);
|
Chris@0
|
2177 }
|
Chris@0
|
2178
|
Chris@0
|
2179 void
|
Chris@0
|
2180 MainWindow::toolDrawSelected()
|
Chris@0
|
2181 {
|
Chris@0
|
2182 m_viewManager->setToolMode(ViewManager::DrawMode);
|
Chris@0
|
2183 }
|
Chris@0
|
2184
|
Chris@151
|
2185 void
|
Chris@151
|
2186 MainWindow::toolMeasureSelected()
|
Chris@151
|
2187 {
|
Chris@151
|
2188 m_viewManager->setToolMode(ViewManager::MeasureMode);
|
Chris@151
|
2189 }
|
Chris@151
|
2190
|
Chris@0
|
2191 //void
|
Chris@0
|
2192 //MainWindow::toolTextSelected()
|
Chris@0
|
2193 //{
|
Chris@0
|
2194 // m_viewManager->setToolMode(ViewManager::TextMode);
|
Chris@0
|
2195 //}
|
Chris@0
|
2196
|
Chris@0
|
2197 void
|
Chris@0
|
2198 MainWindow::selectAll()
|
Chris@0
|
2199 {
|
Chris@0
|
2200 if (!getMainModel()) return;
|
Chris@0
|
2201 m_viewManager->setSelection(Selection(getMainModel()->getStartFrame(),
|
Chris@0
|
2202 getMainModel()->getEndFrame()));
|
Chris@0
|
2203 }
|
Chris@0
|
2204
|
Chris@0
|
2205 void
|
Chris@0
|
2206 MainWindow::selectToStart()
|
Chris@0
|
2207 {
|
Chris@0
|
2208 if (!getMainModel()) return;
|
Chris@0
|
2209 m_viewManager->setSelection(Selection(getMainModel()->getStartFrame(),
|
Chris@0
|
2210 m_viewManager->getGlobalCentreFrame()));
|
Chris@0
|
2211 }
|
Chris@0
|
2212
|
Chris@0
|
2213 void
|
Chris@0
|
2214 MainWindow::selectToEnd()
|
Chris@0
|
2215 {
|
Chris@0
|
2216 if (!getMainModel()) return;
|
Chris@0
|
2217 m_viewManager->setSelection(Selection(m_viewManager->getGlobalCentreFrame(),
|
Chris@0
|
2218 getMainModel()->getEndFrame()));
|
Chris@0
|
2219 }
|
Chris@0
|
2220
|
Chris@0
|
2221 void
|
Chris@0
|
2222 MainWindow::selectVisible()
|
Chris@0
|
2223 {
|
Chris@0
|
2224 Model *model = getMainModel();
|
Chris@0
|
2225 if (!model) return;
|
Chris@0
|
2226
|
Chris@0
|
2227 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@0
|
2228 if (!currentPane) return;
|
Chris@0
|
2229
|
Chris@0
|
2230 size_t startFrame, endFrame;
|
Chris@0
|
2231
|
Chris@0
|
2232 if (currentPane->getStartFrame() < 0) startFrame = 0;
|
Chris@0
|
2233 else startFrame = currentPane->getStartFrame();
|
Chris@0
|
2234
|
Chris@0
|
2235 if (currentPane->getEndFrame() > model->getEndFrame()) endFrame = model->getEndFrame();
|
Chris@0
|
2236 else endFrame = currentPane->getEndFrame();
|
Chris@0
|
2237
|
Chris@0
|
2238 m_viewManager->setSelection(Selection(startFrame, endFrame));
|
Chris@0
|
2239 }
|
Chris@0
|
2240
|
Chris@0
|
2241 void
|
Chris@0
|
2242 MainWindow::clearSelection()
|
Chris@0
|
2243 {
|
Chris@0
|
2244 m_viewManager->clearSelections();
|
Chris@0
|
2245 }
|
Chris@0
|
2246
|
Chris@0
|
2247 void
|
Chris@0
|
2248 MainWindow::cut()
|
Chris@0
|
2249 {
|
Chris@0
|
2250 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@0
|
2251 if (!currentPane) return;
|
Chris@0
|
2252
|
Chris@0
|
2253 Layer *layer = currentPane->getSelectedLayer();
|
Chris@0
|
2254 if (!layer) return;
|
Chris@0
|
2255
|
Chris@0
|
2256 Clipboard &clipboard = m_viewManager->getClipboard();
|
Chris@0
|
2257 clipboard.clear();
|
Chris@0
|
2258
|
Chris@0
|
2259 MultiSelection::SelectionList selections = m_viewManager->getSelections();
|
Chris@0
|
2260
|
Chris@0
|
2261 CommandHistory::getInstance()->startCompoundOperation(tr("Cut"), true);
|
Chris@0
|
2262
|
Chris@0
|
2263 for (MultiSelection::SelectionList::iterator i = selections.begin();
|
Chris@0
|
2264 i != selections.end(); ++i) {
|
Chris@0
|
2265 layer->copy(*i, clipboard);
|
Chris@0
|
2266 layer->deleteSelection(*i);
|
Chris@0
|
2267 }
|
Chris@0
|
2268
|
Chris@0
|
2269 CommandHistory::getInstance()->endCompoundOperation();
|
Chris@0
|
2270 }
|
Chris@0
|
2271
|
Chris@0
|
2272 void
|
Chris@0
|
2273 MainWindow::copy()
|
Chris@0
|
2274 {
|
Chris@0
|
2275 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@0
|
2276 if (!currentPane) return;
|
Chris@0
|
2277
|
Chris@0
|
2278 Layer *layer = currentPane->getSelectedLayer();
|
Chris@0
|
2279 if (!layer) return;
|
Chris@0
|
2280
|
Chris@0
|
2281 Clipboard &clipboard = m_viewManager->getClipboard();
|
Chris@0
|
2282 clipboard.clear();
|
Chris@0
|
2283
|
Chris@0
|
2284 MultiSelection::SelectionList selections = m_viewManager->getSelections();
|
Chris@0
|
2285
|
Chris@0
|
2286 for (MultiSelection::SelectionList::iterator i = selections.begin();
|
Chris@0
|
2287 i != selections.end(); ++i) {
|
Chris@0
|
2288 layer->copy(*i, clipboard);
|
Chris@0
|
2289 }
|
Chris@0
|
2290 }
|
Chris@0
|
2291
|
Chris@0
|
2292 void
|
Chris@0
|
2293 MainWindow::paste()
|
Chris@0
|
2294 {
|
Chris@0
|
2295 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@0
|
2296 if (!currentPane) return;
|
Chris@0
|
2297
|
Chris@0
|
2298 //!!! if we have no current layer, we should create one of the most
|
Chris@0
|
2299 // appropriate type
|
Chris@0
|
2300
|
Chris@0
|
2301 Layer *layer = currentPane->getSelectedLayer();
|
Chris@0
|
2302 if (!layer) return;
|
Chris@0
|
2303
|
Chris@0
|
2304 Clipboard &clipboard = m_viewManager->getClipboard();
|
Chris@0
|
2305 Clipboard::PointList contents = clipboard.getPoints();
|
Chris@0
|
2306 /*
|
Chris@0
|
2307 long minFrame = 0;
|
Chris@0
|
2308 bool have = false;
|
Chris@0
|
2309 for (int i = 0; i < contents.size(); ++i) {
|
Chris@0
|
2310 if (!contents[i].haveFrame()) continue;
|
Chris@0
|
2311 if (!have || contents[i].getFrame() < minFrame) {
|
Chris@0
|
2312 minFrame = contents[i].getFrame();
|
Chris@0
|
2313 have = true;
|
Chris@0
|
2314 }
|
Chris@0
|
2315 }
|
Chris@0
|
2316
|
Chris@0
|
2317 long frameOffset = long(m_viewManager->getGlobalCentreFrame()) - minFrame;
|
Chris@0
|
2318
|
Chris@0
|
2319 layer->paste(clipboard, frameOffset);
|
Chris@0
|
2320 */
|
Chris@0
|
2321 layer->paste(clipboard, 0, true);
|
Chris@0
|
2322 }
|
Chris@0
|
2323
|
Chris@0
|
2324 void
|
Chris@0
|
2325 MainWindow::deleteSelected()
|
Chris@0
|
2326 {
|
Chris@0
|
2327 if (m_paneStack->getCurrentPane() &&
|
Chris@0
|
2328 m_paneStack->getCurrentPane()->getSelectedLayer()) {
|
Chris@164
|
2329
|
Chris@164
|
2330 Layer *layer = m_paneStack->getCurrentPane()->getSelectedLayer();
|
Chris@164
|
2331
|
Chris@164
|
2332 if (m_viewManager &&
|
Chris@164
|
2333 (m_viewManager->getToolMode() == ViewManager::MeasureMode)) {
|
Chris@164
|
2334
|
Chris@164
|
2335 layer->deleteCurrentMeasureRect();
|
Chris@164
|
2336
|
Chris@164
|
2337 } else {
|
Chris@164
|
2338
|
Chris@164
|
2339 MultiSelection::SelectionList selections =
|
Chris@164
|
2340 m_viewManager->getSelections();
|
Chris@164
|
2341
|
Chris@164
|
2342 for (MultiSelection::SelectionList::iterator i = selections.begin();
|
Chris@164
|
2343 i != selections.end(); ++i) {
|
Chris@164
|
2344 layer->deleteSelection(*i);
|
Chris@164
|
2345 }
|
Chris@0
|
2346 }
|
Chris@0
|
2347 }
|
Chris@0
|
2348 }
|
Chris@0
|
2349
|
Chris@0
|
2350 void
|
Chris@0
|
2351 MainWindow::insertInstant()
|
Chris@0
|
2352 {
|
Chris@0
|
2353 int frame = m_viewManager->getPlaybackFrame();
|
Chris@81
|
2354 insertInstantAt(frame);
|
Chris@81
|
2355 }
|
Chris@81
|
2356
|
Chris@81
|
2357 void
|
Chris@81
|
2358 MainWindow::insertInstantsAtBoundaries()
|
Chris@81
|
2359 {
|
Chris@81
|
2360 MultiSelection::SelectionList selections = m_viewManager->getSelections();
|
Chris@81
|
2361 for (MultiSelection::SelectionList::iterator i = selections.begin();
|
Chris@81
|
2362 i != selections.end(); ++i) {
|
Chris@81
|
2363 size_t start = i->getStartFrame();
|
Chris@81
|
2364 size_t end = i->getEndFrame();
|
Chris@81
|
2365 if (start != end) {
|
Chris@81
|
2366 insertInstantAt(i->getStartFrame());
|
Chris@81
|
2367 insertInstantAt(i->getEndFrame());
|
Chris@81
|
2368 }
|
Chris@81
|
2369 }
|
Chris@81
|
2370 }
|
Chris@81
|
2371
|
Chris@81
|
2372 void
|
Chris@81
|
2373 MainWindow::insertInstantAt(size_t frame)
|
Chris@81
|
2374 {
|
Chris@0
|
2375 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@0
|
2376 if (!pane) {
|
Chris@0
|
2377 return;
|
Chris@0
|
2378 }
|
Chris@0
|
2379
|
Chris@0
|
2380 Layer *layer = dynamic_cast<TimeInstantLayer *>
|
Chris@0
|
2381 (pane->getSelectedLayer());
|
Chris@0
|
2382
|
Chris@0
|
2383 if (!layer) {
|
Chris@0
|
2384 for (int i = pane->getLayerCount(); i > 0; --i) {
|
Chris@0
|
2385 layer = dynamic_cast<TimeInstantLayer *>(pane->getLayer(i - 1));
|
Chris@0
|
2386 if (layer) break;
|
Chris@0
|
2387 }
|
Chris@0
|
2388
|
Chris@0
|
2389 if (!layer) {
|
Chris@0
|
2390 CommandHistory::getInstance()->startCompoundOperation
|
Chris@0
|
2391 (tr("Add Point"), true);
|
Chris@0
|
2392 layer = m_document->createEmptyLayer(LayerFactory::TimeInstants);
|
Chris@0
|
2393 if (layer) {
|
Chris@0
|
2394 m_document->addLayerToView(pane, layer);
|
Chris@0
|
2395 m_paneStack->setCurrentLayer(pane, layer);
|
Chris@0
|
2396 }
|
Chris@0
|
2397 CommandHistory::getInstance()->endCompoundOperation();
|
Chris@0
|
2398 }
|
Chris@0
|
2399 }
|
Chris@0
|
2400
|
Chris@0
|
2401 if (layer) {
|
Chris@0
|
2402
|
Chris@0
|
2403 Model *model = layer->getModel();
|
Chris@0
|
2404 SparseOneDimensionalModel *sodm = dynamic_cast<SparseOneDimensionalModel *>
|
Chris@0
|
2405 (model);
|
Chris@0
|
2406
|
Chris@0
|
2407 if (sodm) {
|
Chris@189
|
2408 SparseOneDimensionalModel::Point point(frame, "");
|
Chris@189
|
2409
|
Chris@189
|
2410 SparseOneDimensionalModel::Point prevPoint(0);
|
Chris@189
|
2411 bool havePrevPoint = false;
|
Chris@189
|
2412
|
Chris@189
|
2413 SparseOneDimensionalModel::EditCommand *command =
|
Chris@189
|
2414 new SparseOneDimensionalModel::EditCommand(sodm, tr("Add Point"));
|
Chris@189
|
2415
|
Chris@189
|
2416 if (m_labeller->actingOnPrevPoint()) {
|
Chris@189
|
2417
|
Chris@189
|
2418 SparseOneDimensionalModel::PointList prevPoints =
|
Chris@189
|
2419 sodm->getPreviousPoints(frame);
|
Chris@189
|
2420
|
Chris@189
|
2421 if (!prevPoints.empty()) {
|
Chris@189
|
2422 prevPoint = *prevPoints.begin();
|
Chris@189
|
2423 havePrevPoint = true;
|
Chris@189
|
2424 }
|
Chris@189
|
2425 }
|
Chris@189
|
2426
|
Chris@189
|
2427 if (m_labeller) {
|
Chris@189
|
2428
|
Chris@189
|
2429 m_labeller->setSampleRate(sodm->getSampleRate());
|
Chris@189
|
2430
|
Chris@189
|
2431 if (havePrevPoint) {
|
Chris@189
|
2432 command->deletePoint(prevPoint);
|
Chris@189
|
2433 }
|
Chris@189
|
2434
|
Chris@189
|
2435 m_labeller->label<SparseOneDimensionalModel::Point>
|
Chris@189
|
2436 (point, havePrevPoint ? &prevPoint : 0);
|
Chris@189
|
2437
|
Chris@189
|
2438 if (havePrevPoint) {
|
Chris@189
|
2439 command->addPoint(prevPoint);
|
Chris@189
|
2440 }
|
Chris@189
|
2441 }
|
Chris@189
|
2442
|
Chris@189
|
2443 command->addPoint(point);
|
Chris@189
|
2444
|
Chris@189
|
2445 command->setName(tr("Add Point at %1 s")
|
Chris@189
|
2446 .arg(RealTime::frame2RealTime
|
Chris@189
|
2447 (frame,
|
Chris@189
|
2448 sodm->getSampleRate())
|
Chris@189
|
2449 .toText(false).c_str()));
|
Chris@189
|
2450
|
Chris@189
|
2451 command->finish();
|
Chris@0
|
2452 }
|
Chris@0
|
2453 }
|
Chris@0
|
2454 }
|
Chris@0
|
2455
|
Chris@0
|
2456 void
|
Chris@189
|
2457 MainWindow::setInstantsNumbering()
|
Chris@189
|
2458 {
|
Chris@189
|
2459 QAction *a = dynamic_cast<QAction *>(sender());
|
Chris@189
|
2460 if (!a) return;
|
Chris@189
|
2461
|
Chris@189
|
2462 int type = m_numberingActions[a];
|
Chris@189
|
2463
|
Chris@189
|
2464 if (m_labeller) m_labeller->setType(Labeller::ValueType(type));
|
Chris@189
|
2465
|
Chris@189
|
2466 QSettings settings;
|
Chris@189
|
2467 settings.beginGroup("MainWindow");
|
Chris@189
|
2468 settings.setValue("labellertype", type);
|
Chris@189
|
2469 settings.endGroup();
|
Chris@189
|
2470 }
|
Chris@189
|
2471
|
Chris@189
|
2472 void
|
Chris@189
|
2473 MainWindow::setInstantsCounterCycle()
|
Chris@189
|
2474 {
|
Chris@189
|
2475 QAction *a = dynamic_cast<QAction *>(sender());
|
Chris@189
|
2476 if (!a) return;
|
Chris@189
|
2477
|
Chris@189
|
2478 int cycle = a->text().toInt();
|
Chris@189
|
2479 if (cycle == 0) return;
|
Chris@189
|
2480
|
Chris@189
|
2481 if (m_labeller) m_labeller->setCounterCycleSize(cycle);
|
Chris@189
|
2482
|
Chris@189
|
2483 QSettings settings;
|
Chris@189
|
2484 settings.beginGroup("MainWindow");
|
Chris@189
|
2485 settings.setValue("labellercycle", cycle);
|
Chris@189
|
2486 settings.endGroup();
|
Chris@189
|
2487 }
|
Chris@189
|
2488
|
Chris@189
|
2489 void
|
Chris@192
|
2490 MainWindow::resetInstantsCounters()
|
Chris@192
|
2491 {
|
Chris@192
|
2492 LabelCounterInputDialog dialog(m_labeller, this);
|
Chris@192
|
2493 dialog.exec();
|
Chris@192
|
2494 }
|
Chris@192
|
2495
|
Chris@192
|
2496 void
|
Chris@189
|
2497 MainWindow::renumberInstants()
|
Chris@189
|
2498 {
|
Chris@189
|
2499 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@189
|
2500 if (!pane) return;
|
Chris@189
|
2501
|
Chris@189
|
2502 Layer *layer = dynamic_cast<TimeInstantLayer *>(pane->getSelectedLayer());
|
Chris@189
|
2503 if (!layer) return;
|
Chris@189
|
2504
|
Chris@189
|
2505 MultiSelection ms(m_viewManager->getSelection());
|
Chris@189
|
2506
|
Chris@189
|
2507 Model *model = layer->getModel();
|
Chris@189
|
2508 SparseOneDimensionalModel *sodm = dynamic_cast<SparseOneDimensionalModel *>
|
Chris@189
|
2509 (model);
|
Chris@189
|
2510 if (!sodm) return;
|
Chris@189
|
2511
|
Chris@189
|
2512 if (!m_labeller) return;
|
Chris@189
|
2513
|
Chris@189
|
2514 Labeller labeller(*m_labeller);
|
Chris@189
|
2515 labeller.setSampleRate(sodm->getSampleRate());
|
Chris@189
|
2516
|
Chris@189
|
2517 // This uses a command
|
Chris@189
|
2518
|
Chris@189
|
2519 labeller.labelAll<SparseOneDimensionalModel::Point>(*sodm, &ms);
|
Chris@189
|
2520 }
|
Chris@189
|
2521
|
Chris@189
|
2522 void
|
Chris@0
|
2523 MainWindow::importAudio()
|
Chris@0
|
2524 {
|
Chris@88
|
2525 QString path = getOpenFileName(FileFinder::AudioFile);
|
Chris@0
|
2526
|
Chris@0
|
2527 if (path != "") {
|
Chris@82
|
2528 if (openAudioFile(path, ReplaceMainModel) == FileOpenFailed) {
|
Chris@0
|
2529 QMessageBox::critical(this, tr("Failed to open file"),
|
Chris@193
|
2530 tr("<b>File open failed</b><p>Audio file \"%1\" could not be opened").arg(path));
|
Chris@0
|
2531 }
|
Chris@0
|
2532 }
|
Chris@0
|
2533 }
|
Chris@0
|
2534
|
Chris@0
|
2535 void
|
Chris@0
|
2536 MainWindow::importMoreAudio()
|
Chris@0
|
2537 {
|
Chris@88
|
2538 QString path = getOpenFileName(FileFinder::AudioFile);
|
Chris@0
|
2539
|
Chris@0
|
2540 if (path != "") {
|
Chris@82
|
2541 if (openAudioFile(path, CreateAdditionalModel) == FileOpenFailed) {
|
Chris@0
|
2542 QMessageBox::critical(this, tr("Failed to open file"),
|
Chris@193
|
2543 tr("<b>File open failed</b><p>Audio file \"%1\" could not be opened").arg(path));
|
Chris@0
|
2544 }
|
Chris@0
|
2545 }
|
Chris@0
|
2546 }
|
Chris@0
|
2547
|
Chris@0
|
2548 void
|
Chris@0
|
2549 MainWindow::exportAudio()
|
Chris@0
|
2550 {
|
Chris@0
|
2551 if (!getMainModel()) return;
|
Chris@0
|
2552
|
Chris@88
|
2553 QString path = getSaveFileName(FileFinder::AudioFile);
|
Chris@0
|
2554
|
Chris@0
|
2555 if (path == "") return;
|
Chris@0
|
2556
|
Chris@0
|
2557 bool ok = false;
|
Chris@0
|
2558 QString error;
|
Chris@0
|
2559
|
Chris@0
|
2560 MultiSelection ms = m_viewManager->getSelection();
|
Chris@0
|
2561 MultiSelection::SelectionList selections = m_viewManager->getSelections();
|
Chris@0
|
2562
|
Chris@0
|
2563 bool multiple = false;
|
Chris@0
|
2564
|
Chris@38
|
2565 MultiSelection *selectionToWrite = 0;
|
Chris@38
|
2566
|
Chris@38
|
2567 if (selections.size() == 1) {
|
Chris@0
|
2568
|
Chris@0
|
2569 QStringList items;
|
Chris@0
|
2570 items << tr("Export the selected region only")
|
Chris@0
|
2571 << tr("Export the whole audio file");
|
Chris@0
|
2572
|
Chris@0
|
2573 bool ok = false;
|
Chris@0
|
2574 QString item = ListInputDialog::getItem
|
Chris@0
|
2575 (this, tr("Select region to export"),
|
Chris@0
|
2576 tr("Which region from the original audio file do you want to export?"),
|
Chris@0
|
2577 items, 0, &ok);
|
Chris@0
|
2578
|
Chris@0
|
2579 if (!ok || item.isEmpty()) return;
|
Chris@0
|
2580
|
Chris@38
|
2581 if (item == items[0]) selectionToWrite = &ms;
|
Chris@38
|
2582
|
Chris@38
|
2583 } else if (selections.size() > 1) {
|
Chris@0
|
2584
|
Chris@0
|
2585 QStringList items;
|
Chris@0
|
2586 items << tr("Export the selected regions into a single audio file")
|
Chris@0
|
2587 << tr("Export the selected regions into separate files")
|
Chris@0
|
2588 << tr("Export the whole audio file");
|
Chris@0
|
2589
|
Chris@0
|
2590 QString item = ListInputDialog::getItem
|
Chris@0
|
2591 (this, tr("Select region to export"),
|
Chris@0
|
2592 tr("Multiple regions of the original audio file are selected.\nWhat do you want to export?"),
|
Chris@0
|
2593 items, 0, &ok);
|
Chris@0
|
2594
|
Chris@0
|
2595 if (!ok || item.isEmpty()) return;
|
Chris@0
|
2596
|
Chris@0
|
2597 if (item == items[0]) {
|
Chris@0
|
2598
|
Chris@38
|
2599 selectionToWrite = &ms;
|
Chris@38
|
2600
|
Chris@38
|
2601 } else if (item == items[1]) {
|
Chris@0
|
2602
|
Chris@0
|
2603 multiple = true;
|
Chris@0
|
2604
|
Chris@0
|
2605 int n = 1;
|
Chris@0
|
2606 QString base = path;
|
Chris@0
|
2607 base.replace(".wav", "");
|
Chris@0
|
2608
|
Chris@0
|
2609 for (MultiSelection::SelectionList::iterator i = selections.begin();
|
Chris@0
|
2610 i != selections.end(); ++i) {
|
Chris@0
|
2611
|
Chris@0
|
2612 MultiSelection subms;
|
Chris@0
|
2613 subms.setSelection(*i);
|
Chris@0
|
2614
|
Chris@0
|
2615 QString subpath = QString("%1.%2.wav").arg(base).arg(n);
|
Chris@0
|
2616 ++n;
|
Chris@0
|
2617
|
Chris@0
|
2618 if (QFileInfo(subpath).exists()) {
|
Chris@0
|
2619 error = tr("Fragment file %1 already exists, aborting").arg(subpath);
|
Chris@0
|
2620 break;
|
Chris@0
|
2621 }
|
Chris@0
|
2622
|
Chris@38
|
2623 WavFileWriter subwriter(subpath,
|
Chris@38
|
2624 getMainModel()->getSampleRate(),
|
Chris@38
|
2625 getMainModel()->getChannelCount());
|
Chris@38
|
2626 subwriter.writeModel(getMainModel(), &subms);
|
Chris@0
|
2627 ok = subwriter.isOK();
|
Chris@0
|
2628
|
Chris@0
|
2629 if (!ok) {
|
Chris@0
|
2630 error = subwriter.getError();
|
Chris@0
|
2631 break;
|
Chris@0
|
2632 }
|
Chris@0
|
2633 }
|
Chris@0
|
2634 }
|
Chris@0
|
2635 }
|
Chris@0
|
2636
|
Chris@38
|
2637 if (!multiple) {
|
Chris@38
|
2638 WavFileWriter writer(path,
|
Chris@38
|
2639 getMainModel()->getSampleRate(),
|
Chris@38
|
2640 getMainModel()->getChannelCount());
|
Chris@38
|
2641 writer.writeModel(getMainModel(), selectionToWrite);
|
Chris@38
|
2642 ok = writer.isOK();
|
Chris@38
|
2643 error = writer.getError();
|
Chris@0
|
2644 }
|
Chris@0
|
2645
|
Chris@0
|
2646 if (ok) {
|
Chris@0
|
2647 if (!multiple) {
|
Chris@34
|
2648 m_recentFiles.addFile(path);
|
Chris@0
|
2649 }
|
Chris@0
|
2650 } else {
|
Chris@0
|
2651 QMessageBox::critical(this, tr("Failed to write file"), error);
|
Chris@0
|
2652 }
|
Chris@0
|
2653 }
|
Chris@0
|
2654
|
Chris@0
|
2655 void
|
Chris@0
|
2656 MainWindow::importLayer()
|
Chris@0
|
2657 {
|
Chris@0
|
2658 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@0
|
2659
|
Chris@0
|
2660 if (!pane) {
|
Chris@0
|
2661 // shouldn't happen, as the menu action should have been disabled
|
Chris@0
|
2662 std::cerr << "WARNING: MainWindow::importLayer: no current pane" << std::endl;
|
Chris@0
|
2663 return;
|
Chris@0
|
2664 }
|
Chris@0
|
2665
|
Chris@0
|
2666 if (!getMainModel()) {
|
Chris@0
|
2667 // shouldn't happen, as the menu action should have been disabled
|
Chris@0
|
2668 std::cerr << "WARNING: MainWindow::importLayer: No main model -- hence no default sample rate available" << std::endl;
|
Chris@0
|
2669 return;
|
Chris@0
|
2670 }
|
Chris@0
|
2671
|
Chris@88
|
2672 QString path = getOpenFileName(FileFinder::LayerFile);
|
Chris@0
|
2673
|
Chris@0
|
2674 if (path != "") {
|
Chris@0
|
2675
|
Chris@193
|
2676 FileOpenStatus status = openLayerFile(path);
|
Chris@193
|
2677
|
Chris@193
|
2678 if (status == FileOpenFailed) {
|
Chris@0
|
2679 QMessageBox::critical(this, tr("Failed to open file"),
|
Chris@193
|
2680 tr("<b>File open failed</b><p>Layer file %1 could not be opened.").arg(path));
|
Chris@0
|
2681 return;
|
Chris@193
|
2682 } else if (status == FileOpenWrongMode) {
|
Chris@193
|
2683 QMessageBox::critical(this, tr("Failed to open file"),
|
Chris@193
|
2684 tr("<b>Audio required</b><p>Please load at least one audio file before importing annotation data"));
|
Chris@0
|
2685 }
|
Chris@0
|
2686 }
|
Chris@0
|
2687 }
|
Chris@0
|
2688
|
Chris@82
|
2689 MainWindow::FileOpenStatus
|
Chris@0
|
2690 MainWindow::openLayerFile(QString path)
|
Chris@0
|
2691 {
|
Chris@86
|
2692 return openLayerFile(path, path);
|
Chris@86
|
2693 }
|
Chris@86
|
2694
|
Chris@86
|
2695 MainWindow::FileOpenStatus
|
Chris@86
|
2696 MainWindow::openLayerFile(QString path, QString location)
|
Chris@86
|
2697 {
|
Chris@0
|
2698 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@0
|
2699
|
Chris@0
|
2700 if (!pane) {
|
Chris@0
|
2701 // shouldn't happen, as the menu action should have been disabled
|
Chris@0
|
2702 std::cerr << "WARNING: MainWindow::openLayerFile: no current pane" << std::endl;
|
Chris@193
|
2703 return FileOpenWrongMode;
|
Chris@0
|
2704 }
|
Chris@0
|
2705
|
Chris@0
|
2706 if (!getMainModel()) {
|
Chris@0
|
2707 // shouldn't happen, as the menu action should have been disabled
|
Chris@0
|
2708 std::cerr << "WARNING: MainWindow::openLayerFile: No main model -- hence no default sample rate available" << std::endl;
|
Chris@193
|
2709 return FileOpenWrongMode;
|
Chris@0
|
2710 }
|
Chris@0
|
2711
|
Chris@86
|
2712 bool realFile = (location == path);
|
Chris@86
|
2713
|
Chris@0
|
2714 if (path.endsWith(".svl") || path.endsWith(".xml")) {
|
Chris@0
|
2715
|
Chris@0
|
2716 PaneCallback callback(this);
|
Chris@0
|
2717 QFile file(path);
|
Chris@0
|
2718
|
Chris@0
|
2719 if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
Chris@0
|
2720 std::cerr << "ERROR: MainWindow::openLayerFile("
|
Chris@86
|
2721 << location.toStdString()
|
Chris@0
|
2722 << "): Failed to open file for reading" << std::endl;
|
Chris@82
|
2723 return FileOpenFailed;
|
Chris@0
|
2724 }
|
Chris@0
|
2725
|
Chris@87
|
2726 SVFileReader reader(m_document, callback, location);
|
Chris@0
|
2727 reader.setCurrentPane(pane);
|
Chris@0
|
2728
|
Chris@0
|
2729 QXmlInputSource inputSource(&file);
|
Chris@0
|
2730 reader.parse(inputSource);
|
Chris@0
|
2731
|
Chris@0
|
2732 if (!reader.isOK()) {
|
Chris@0
|
2733 std::cerr << "ERROR: MainWindow::openLayerFile("
|
Chris@86
|
2734 << location.toStdString()
|
Chris@0
|
2735 << "): Failed to read XML file: "
|
Chris@0
|
2736 << reader.getErrorString().toStdString() << std::endl;
|
Chris@82
|
2737 return FileOpenFailed;
|
Chris@0
|
2738 }
|
Chris@0
|
2739
|
Chris@86
|
2740 m_recentFiles.addFile(location);
|
Chris@86
|
2741
|
Chris@86
|
2742 if (realFile) {
|
Chris@88
|
2743 registerLastOpenedFilePath(FileFinder::LayerFile, path); // for file dialog
|
Chris@86
|
2744 }
|
Chris@86
|
2745
|
Chris@82
|
2746 return FileOpenSucceeded;
|
Chris@0
|
2747
|
Chris@0
|
2748 } else {
|
Chris@0
|
2749
|
Chris@193
|
2750 try {
|
Chris@193
|
2751
|
Chris@193
|
2752 Model *model = DataFileReaderFactory::load
|
Chris@193
|
2753 (path, getMainModel()->getSampleRate());
|
Chris@0
|
2754
|
Chris@193
|
2755 if (model) {
|
Chris@193
|
2756
|
Chris@193
|
2757 Layer *newLayer = m_document->createImportedLayer(model);
|
Chris@193
|
2758
|
Chris@193
|
2759 if (newLayer) {
|
Chris@193
|
2760
|
Chris@193
|
2761 m_document->addLayerToView(pane, newLayer);
|
Chris@193
|
2762 m_recentFiles.addFile(location);
|
Chris@193
|
2763
|
Chris@193
|
2764 if (realFile) {
|
Chris@193
|
2765 registerLastOpenedFilePath(FileFinder::LayerFile, path); // for file dialog
|
Chris@193
|
2766 }
|
Chris@193
|
2767
|
Chris@193
|
2768 return FileOpenSucceeded;
|
Chris@86
|
2769 }
|
Chris@193
|
2770 }
|
Chris@193
|
2771 } catch (DataFileReaderFactory::Exception e) {
|
Chris@193
|
2772 if (e == DataFileReaderFactory::ImportCancelled) {
|
Chris@193
|
2773 return FileOpenCancelled;
|
Chris@0
|
2774 }
|
Chris@0
|
2775 }
|
Chris@0
|
2776 }
|
Chris@0
|
2777
|
Chris@82
|
2778 return FileOpenFailed;
|
Chris@0
|
2779 }
|
Chris@0
|
2780
|
Chris@193
|
2781 MainWindow::FileOpenStatus
|
Chris@193
|
2782 MainWindow::openImageFile(QString path)
|
Chris@193
|
2783 {
|
Chris@193
|
2784 return openImageFile(path, path);
|
Chris@193
|
2785 }
|
Chris@193
|
2786
|
Chris@193
|
2787 MainWindow::FileOpenStatus
|
Chris@193
|
2788 MainWindow::openImageFile(QString path, QString location)
|
Chris@193
|
2789 {
|
Chris@193
|
2790 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@193
|
2791
|
Chris@193
|
2792 if (!pane) {
|
Chris@193
|
2793 // shouldn't happen, as the menu action should have been disabled
|
Chris@193
|
2794 std::cerr << "WARNING: MainWindow::openImageFile: no current pane" << std::endl;
|
Chris@193
|
2795 return FileOpenWrongMode;
|
Chris@193
|
2796 }
|
Chris@193
|
2797
|
Chris@193
|
2798 if (!m_document->getMainModel()) {
|
Chris@193
|
2799 return FileOpenWrongMode;
|
Chris@193
|
2800 }
|
Chris@193
|
2801
|
Chris@193
|
2802 bool newLayer = false;
|
Chris@193
|
2803
|
Chris@193
|
2804 ImageLayer *il = dynamic_cast<ImageLayer *>(pane->getSelectedLayer());
|
Chris@193
|
2805 if (!il) {
|
Chris@193
|
2806 for (int i = pane->getLayerCount()-1; i >= 0; --i) {
|
Chris@193
|
2807 il = dynamic_cast<ImageLayer *>(pane->getLayer(i));
|
Chris@193
|
2808 if (il) break;
|
Chris@193
|
2809 }
|
Chris@193
|
2810 }
|
Chris@193
|
2811 if (!il) {
|
Chris@193
|
2812 il = dynamic_cast<ImageLayer *>
|
Chris@193
|
2813 (m_document->createEmptyLayer(LayerFactory::Image));
|
Chris@193
|
2814 if (!il) return FileOpenFailed;
|
Chris@193
|
2815 newLayer = true;
|
Chris@193
|
2816 }
|
Chris@193
|
2817
|
Chris@193
|
2818 // We don't put the image file in Recent Files
|
Chris@193
|
2819
|
Chris@193
|
2820 std::cerr << "openImageFile: trying location \"" << location.toStdString() << "\" in image layer" << std::endl;
|
Chris@193
|
2821
|
Chris@193
|
2822 if (!il->addImage(m_viewManager->getGlobalCentreFrame(), location)) {
|
Chris@193
|
2823 if (newLayer) {
|
Chris@193
|
2824 m_document->setModel(il, 0); // releasing its model
|
Chris@193
|
2825 delete il;
|
Chris@193
|
2826 }
|
Chris@193
|
2827 return FileOpenFailed;
|
Chris@193
|
2828 } else {
|
Chris@193
|
2829 if (newLayer) {
|
Chris@193
|
2830 m_document->addLayerToView(pane, il);
|
Chris@193
|
2831 }
|
Chris@193
|
2832 m_paneStack->setCurrentLayer(pane, il);
|
Chris@193
|
2833 return FileOpenSucceeded;
|
Chris@193
|
2834 }
|
Chris@193
|
2835 }
|
Chris@193
|
2836
|
Chris@0
|
2837 void
|
Chris@0
|
2838 MainWindow::exportLayer()
|
Chris@0
|
2839 {
|
Chris@0
|
2840 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@0
|
2841 if (!pane) return;
|
Chris@0
|
2842
|
Chris@0
|
2843 Layer *layer = pane->getSelectedLayer();
|
Chris@0
|
2844 if (!layer) return;
|
Chris@0
|
2845
|
Chris@0
|
2846 Model *model = layer->getModel();
|
Chris@0
|
2847 if (!model) return;
|
Chris@0
|
2848
|
Chris@185
|
2849 FileFinder::FileType type = FileFinder::LayerFileNoMidi;
|
Chris@185
|
2850
|
Chris@185
|
2851 if (dynamic_cast<NoteModel *>(model)) type = FileFinder::LayerFile;
|
Chris@185
|
2852
|
Chris@185
|
2853 QString path = getSaveFileName(type);
|
Chris@0
|
2854
|
Chris@0
|
2855 if (path == "") return;
|
Chris@0
|
2856
|
Chris@0
|
2857 if (QFileInfo(path).suffix() == "") path += ".svl";
|
Chris@0
|
2858
|
Chris@185
|
2859 QString suffix = QFileInfo(path).suffix().toLower();
|
Chris@185
|
2860
|
Chris@0
|
2861 QString error;
|
Chris@0
|
2862
|
Chris@185
|
2863 if (suffix == "xml" || suffix == "svl") {
|
Chris@0
|
2864
|
Chris@0
|
2865 QFile file(path);
|
Chris@0
|
2866 if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
Chris@0
|
2867 error = tr("Failed to open file %1 for writing").arg(path);
|
Chris@0
|
2868 } else {
|
Chris@0
|
2869 QTextStream out(&file);
|
Chris@0
|
2870 out << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
|
Chris@0
|
2871 << "<!DOCTYPE sonic-visualiser>\n"
|
Chris@0
|
2872 << "<sv>\n"
|
Chris@0
|
2873 << " <data>\n";
|
Chris@0
|
2874
|
Chris@0
|
2875 model->toXml(out, " ");
|
Chris@0
|
2876
|
Chris@0
|
2877 out << " </data>\n"
|
Chris@0
|
2878 << " <display>\n";
|
Chris@0
|
2879
|
Chris@0
|
2880 layer->toXml(out, " ");
|
Chris@0
|
2881
|
Chris@0
|
2882 out << " </display>\n"
|
Chris@0
|
2883 << "</sv>\n";
|
Chris@0
|
2884 }
|
Chris@0
|
2885
|
Chris@185
|
2886 } else if (suffix == "mid" || suffix == "midi") {
|
Chris@185
|
2887
|
Chris@185
|
2888 NoteModel *nm = dynamic_cast<NoteModel *>(model);
|
Chris@185
|
2889
|
Chris@185
|
2890 if (!nm) {
|
Chris@185
|
2891 error = tr("Can't export non-note layers to MIDI");
|
Chris@185
|
2892 } else {
|
Chris@185
|
2893 MIDIFileWriter writer(path, nm);
|
Chris@185
|
2894 writer.write();
|
Chris@185
|
2895 if (!writer.isOK()) {
|
Chris@185
|
2896 error = writer.getError();
|
Chris@185
|
2897 }
|
Chris@185
|
2898 }
|
Chris@185
|
2899
|
Chris@0
|
2900 } else {
|
Chris@0
|
2901
|
Chris@0
|
2902 CSVFileWriter writer(path, model,
|
Chris@185
|
2903 ((suffix == "csv") ? "," : "\t"));
|
Chris@0
|
2904 writer.write();
|
Chris@0
|
2905
|
Chris@0
|
2906 if (!writer.isOK()) {
|
Chris@0
|
2907 error = writer.getError();
|
Chris@0
|
2908 }
|
Chris@0
|
2909 }
|
Chris@0
|
2910
|
Chris@0
|
2911 if (error != "") {
|
Chris@0
|
2912 QMessageBox::critical(this, tr("Failed to write file"), error);
|
Chris@0
|
2913 } else {
|
Chris@34
|
2914 m_recentFiles.addFile(path);
|
Chris@0
|
2915 }
|
Chris@0
|
2916 }
|
Chris@0
|
2917
|
Chris@121
|
2918 void
|
Chris@121
|
2919 MainWindow::exportImage()
|
Chris@121
|
2920 {
|
Chris@121
|
2921 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@121
|
2922 if (!pane) return;
|
Chris@121
|
2923
|
Chris@121
|
2924 QString path = getSaveFileName(FileFinder::ImageFile);
|
Chris@121
|
2925
|
Chris@121
|
2926 if (path == "") return;
|
Chris@121
|
2927
|
Chris@121
|
2928 if (QFileInfo(path).suffix() == "") path += ".png";
|
Chris@121
|
2929
|
Chris@123
|
2930 bool haveSelection = m_viewManager && !m_viewManager->getSelections().empty();
|
Chris@123
|
2931
|
Chris@123
|
2932 QSize total, visible, selected;
|
Chris@123
|
2933 total = pane->getImageSize();
|
Chris@123
|
2934 visible = pane->getImageSize(pane->getFirstVisibleFrame(),
|
Chris@123
|
2935 pane->getLastVisibleFrame());
|
Chris@123
|
2936
|
Chris@123
|
2937 size_t sf0 = 0, sf1 = 0;
|
Chris@123
|
2938
|
Chris@123
|
2939 if (haveSelection) {
|
Chris@123
|
2940 MultiSelection::SelectionList selections = m_viewManager->getSelections();
|
Chris@123
|
2941 sf0 = selections.begin()->getStartFrame();
|
Chris@123
|
2942 MultiSelection::SelectionList::iterator e = selections.end();
|
Chris@123
|
2943 --e;
|
Chris@123
|
2944 sf1 = e->getEndFrame();
|
Chris@123
|
2945 selected = pane->getImageSize(sf0, sf1);
|
Chris@123
|
2946 }
|
Chris@123
|
2947
|
Chris@123
|
2948 QStringList items;
|
Chris@125
|
2949 items << tr("Export the whole pane (%1x%2 pixels)")
|
Chris@123
|
2950 .arg(total.width()).arg(total.height());
|
Chris@123
|
2951 items << tr("Export the visible area only (%1x%2 pixels)")
|
Chris@123
|
2952 .arg(visible.width()).arg(visible.height());
|
Chris@123
|
2953 if (haveSelection) {
|
Chris@123
|
2954 items << tr("Export the selection extent (%1x%2 pixels)")
|
Chris@123
|
2955 .arg(selected.width()).arg(selected.height());
|
Chris@124
|
2956 } else {
|
Chris@124
|
2957 items << tr("Export the selection extent");
|
Chris@123
|
2958 }
|
Chris@123
|
2959
|
Chris@123
|
2960 QSettings settings;
|
Chris@123
|
2961 settings.beginGroup("MainWindow");
|
Chris@123
|
2962 int deflt = settings.value("lastimageexportregion", 0).toInt();
|
Chris@123
|
2963 if (deflt == 2 && !haveSelection) deflt = 1;
|
Chris@124
|
2964 if (deflt == 0 && total.width() > 32767) deflt = 1;
|
Chris@124
|
2965
|
Chris@124
|
2966 ListInputDialog *lid = new ListInputDialog
|
Chris@123
|
2967 (this, tr("Select region to export"),
|
Chris@123
|
2968 tr("Which region of the current pane do you want to export as an image?"),
|
Chris@124
|
2969 items, deflt);
|
Chris@124
|
2970
|
Chris@124
|
2971 if (!haveSelection) {
|
Chris@124
|
2972 lid->setItemAvailability(2, false);
|
Chris@124
|
2973 }
|
Chris@124
|
2974 if (total.width() > 32767) { // appears to be the limit of a QImage
|
Chris@124
|
2975 lid->setItemAvailability(0, false);
|
Chris@124
|
2976 lid->setFootnote(tr("Note: the whole pane is too wide to be exported as a single image."));
|
Chris@124
|
2977 }
|
Chris@124
|
2978
|
Chris@124
|
2979 bool ok = lid->exec();
|
Chris@124
|
2980 QString item = lid->getCurrentString();
|
Chris@124
|
2981 delete lid;
|
Chris@123
|
2982
|
Chris@123
|
2983 if (!ok || item.isEmpty()) return;
|
Chris@123
|
2984
|
Chris@123
|
2985 settings.setValue("lastimageexportregion", deflt);
|
Chris@123
|
2986
|
Chris@123
|
2987 QImage *image = 0;
|
Chris@123
|
2988
|
Chris@123
|
2989 if (item == items[0]) {
|
Chris@123
|
2990 image = pane->toNewImage();
|
Chris@123
|
2991 } else if (item == items[1]) {
|
Chris@123
|
2992 image = pane->toNewImage(pane->getFirstVisibleFrame(),
|
Chris@123
|
2993 pane->getLastVisibleFrame());
|
Chris@123
|
2994 } else if (haveSelection) {
|
Chris@123
|
2995 image = pane->toNewImage(sf0, sf1);
|
Chris@123
|
2996 }
|
Chris@123
|
2997
|
Chris@121
|
2998 if (!image) return;
|
Chris@121
|
2999
|
Chris@121
|
3000 if (!image->save(path, "PNG")) {
|
Chris@121
|
3001 QMessageBox::critical(this, tr("Failed to save image file"),
|
Chris@121
|
3002 tr("Failed to save image file %1").arg(path));
|
Chris@121
|
3003 }
|
Chris@121
|
3004
|
Chris@121
|
3005 delete image;
|
Chris@121
|
3006 }
|
Chris@121
|
3007
|
Chris@82
|
3008 MainWindow::FileOpenStatus
|
Chris@0
|
3009 MainWindow::openAudioFile(QString path, AudioFileOpenMode mode)
|
Chris@0
|
3010 {
|
Chris@86
|
3011 return openAudioFile(path, path, mode);
|
Chris@86
|
3012 }
|
Chris@86
|
3013
|
Chris@86
|
3014 MainWindow::FileOpenStatus
|
Chris@86
|
3015 MainWindow::openAudioFile(QString path, QString location, AudioFileOpenMode mode)
|
Chris@86
|
3016 {
|
Chris@0
|
3017 if (!(QFileInfo(path).exists() &&
|
Chris@0
|
3018 QFileInfo(path).isFile() &&
|
Chris@0
|
3019 QFileInfo(path).isReadable())) {
|
Chris@82
|
3020 return FileOpenFailed;
|
Chris@0
|
3021 }
|
Chris@0
|
3022
|
Chris@70
|
3023 m_openingAudioFile = true;
|
Chris@70
|
3024
|
Chris@180
|
3025 size_t rate = 0;
|
Chris@180
|
3026
|
Chris@180
|
3027 if (Preferences::getInstance()->getResampleOnLoad()) {
|
Chris@180
|
3028 rate = m_playSource->getSourceSampleRate();
|
Chris@180
|
3029 }
|
Chris@180
|
3030
|
Chris@180
|
3031 WaveFileModel *newModel = new WaveFileModel(path, location, rate);
|
Chris@0
|
3032
|
Chris@0
|
3033 if (!newModel->isOK()) {
|
Chris@0
|
3034 delete newModel;
|
Chris@70
|
3035 m_openingAudioFile = false;
|
Chris@82
|
3036 return FileOpenFailed;
|
Chris@0
|
3037 }
|
Chris@0
|
3038
|
Chris@86
|
3039 bool realFile = (location == path);
|
Chris@86
|
3040
|
Chris@194
|
3041 std::cerr << "mode = " << mode << std::endl;
|
Chris@194
|
3042
|
Chris@194
|
3043 if (mode == AskUser) {
|
Chris@194
|
3044 if (getMainModel()) {
|
Chris@194
|
3045
|
Chris@194
|
3046 std::cerr << "ask user, have main model" << std::endl;
|
Chris@194
|
3047
|
Chris@194
|
3048 static bool prevSetAsMain = true;
|
Chris@194
|
3049 bool setAsMain = true;
|
Chris@194
|
3050
|
Chris@0
|
3051 QStringList items;
|
Chris@0
|
3052 items << tr("Replace the existing main waveform")
|
Chris@0
|
3053 << tr("Load this file into a new waveform pane");
|
Chris@0
|
3054
|
Chris@0
|
3055 bool ok = false;
|
Chris@0
|
3056 QString item = ListInputDialog::getItem
|
Chris@0
|
3057 (this, tr("Select target for import"),
|
Chris@0
|
3058 tr("You already have an audio waveform loaded.\nWhat would you like to do with the new audio file?"),
|
Chris@0
|
3059 items, prevSetAsMain ? 0 : 1, &ok);
|
Chris@0
|
3060
|
Chris@0
|
3061 if (!ok || item.isEmpty()) {
|
Chris@0
|
3062 delete newModel;
|
Chris@70
|
3063 m_openingAudioFile = false;
|
Chris@82
|
3064 return FileOpenCancelled;
|
Chris@0
|
3065 }
|
Chris@0
|
3066
|
Chris@0
|
3067 setAsMain = (item == items[0]);
|
Chris@0
|
3068 prevSetAsMain = setAsMain;
|
Chris@194
|
3069
|
Chris@194
|
3070 if (setAsMain) mode = ReplaceMainModel;
|
Chris@194
|
3071 else mode = CreateAdditionalModel;
|
Chris@194
|
3072
|
Chris@194
|
3073 } else {
|
Chris@194
|
3074 mode = ReplaceMainModel;
|
Chris@0
|
3075 }
|
Chris@0
|
3076 }
|
Chris@0
|
3077
|
Chris@194
|
3078 if (mode == ReplaceCurrentPane) {
|
Chris@194
|
3079
|
Chris@194
|
3080 std::cerr << "replace current pane" << std::endl;
|
Chris@194
|
3081
|
Chris@194
|
3082 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@194
|
3083 if (pane) {
|
Chris@194
|
3084 std::cerr << "have pane" << std::endl;
|
Chris@194
|
3085
|
Chris@194
|
3086 if (getMainModel()) {
|
Chris@194
|
3087 std::cerr << "have main model" << std::endl;
|
Chris@194
|
3088
|
Chris@194
|
3089 View::ModelSet models(pane->getModels());
|
Chris@194
|
3090 if (models.find(getMainModel()) != models.end()) {
|
Chris@194
|
3091 std::cerr << "main model is in pane, setting to ReplaceMainModel" << std::endl;
|
Chris@194
|
3092 mode = ReplaceMainModel;
|
Chris@194
|
3093 }
|
Chris@194
|
3094 } else {
|
Chris@194
|
3095 std::cerr << "no main model, setting to ReplaceMainModel" << std::endl;
|
Chris@194
|
3096 mode = ReplaceMainModel;
|
Chris@194
|
3097 }
|
Chris@194
|
3098 } else {
|
Chris@194
|
3099 std::cerr << "no pane, setting to CreateAdditionalModel" << std::endl;
|
Chris@194
|
3100 mode = CreateAdditionalModel;
|
Chris@194
|
3101 }
|
Chris@194
|
3102 }
|
Chris@194
|
3103
|
Chris@194
|
3104 if (mode == CreateAdditionalModel && !getMainModel()) {
|
Chris@194
|
3105 std::cerr << "mode is CreateAdditionalModel and no main model, setting to ReplaceMainModel" << std::endl;
|
Chris@194
|
3106 mode = ReplaceMainModel;
|
Chris@194
|
3107 }
|
Chris@194
|
3108
|
Chris@194
|
3109 std::cerr << "mode now " << mode << std::endl;
|
Chris@194
|
3110
|
Chris@194
|
3111 if (mode == ReplaceMainModel) {
|
Chris@0
|
3112
|
Chris@0
|
3113 Model *prevMain = getMainModel();
|
Chris@118
|
3114 if (prevMain) {
|
Chris@118
|
3115 m_playSource->removeModel(prevMain);
|
Chris@118
|
3116 PlayParameterRepository::getInstance()->removeModel(prevMain);
|
Chris@118
|
3117 }
|
Chris@118
|
3118 PlayParameterRepository::getInstance()->addModel(newModel);
|
Chris@0
|
3119
|
Chris@0
|
3120 m_document->setMainModel(newModel);
|
Chris@0
|
3121 setupMenus();
|
Chris@0
|
3122
|
Chris@0
|
3123 if (m_sessionFile == "") {
|
Chris@0
|
3124 setWindowTitle(tr("Sonic Visualiser: %1")
|
Chris@86
|
3125 .arg(QFileInfo(location).fileName()));
|
Chris@0
|
3126 CommandHistory::getInstance()->clear();
|
Chris@0
|
3127 CommandHistory::getInstance()->documentSaved();
|
Chris@0
|
3128 m_documentModified = false;
|
Chris@0
|
3129 } else {
|
Chris@0
|
3130 setWindowTitle(tr("Sonic Visualiser: %1 [%2]")
|
Chris@0
|
3131 .arg(QFileInfo(m_sessionFile).fileName())
|
Chris@86
|
3132 .arg(QFileInfo(location).fileName()));
|
Chris@0
|
3133 if (m_documentModified) {
|
Chris@0
|
3134 m_documentModified = false;
|
Chris@0
|
3135 documentModified(); // so as to restore "(modified)" window title
|
Chris@0
|
3136 }
|
Chris@0
|
3137 }
|
Chris@0
|
3138
|
Chris@86
|
3139 if (realFile) m_audioFile = path;
|
Chris@0
|
3140
|
Chris@194
|
3141 } else if (mode == CreateAdditionalModel) {
|
Chris@0
|
3142
|
Chris@0
|
3143 CommandHistory::getInstance()->startCompoundOperation
|
Chris@86
|
3144 (tr("Import \"%1\"").arg(QFileInfo(location).fileName()), true);
|
Chris@0
|
3145
|
Chris@0
|
3146 m_document->addImportedModel(newModel);
|
Chris@0
|
3147
|
Chris@0
|
3148 AddPaneCommand *command = new AddPaneCommand(this);
|
Chris@0
|
3149 CommandHistory::getInstance()->addCommand(command);
|
Chris@0
|
3150
|
Chris@0
|
3151 Pane *pane = command->getPane();
|
Chris@0
|
3152
|
Chris@0
|
3153 if (!m_timeRulerLayer) {
|
Chris@0
|
3154 m_timeRulerLayer = m_document->createMainModelLayer
|
Chris@0
|
3155 (LayerFactory::TimeRuler);
|
Chris@0
|
3156 }
|
Chris@0
|
3157
|
Chris@0
|
3158 m_document->addLayerToView(pane, m_timeRulerLayer);
|
Chris@0
|
3159
|
Chris@0
|
3160 Layer *newLayer = m_document->createImportedLayer(newModel);
|
Chris@0
|
3161
|
Chris@0
|
3162 if (newLayer) {
|
Chris@0
|
3163 m_document->addLayerToView(pane, newLayer);
|
Chris@0
|
3164 }
|
Chris@0
|
3165
|
Chris@0
|
3166 CommandHistory::getInstance()->endCompoundOperation();
|
Chris@194
|
3167
|
Chris@194
|
3168 } else if (mode == ReplaceCurrentPane) {
|
Chris@194
|
3169
|
Chris@194
|
3170 // We know there is a current pane, otherwise we would have
|
Chris@194
|
3171 // reset the mode to CreateAdditionalModel above; and we know
|
Chris@194
|
3172 // the current pane does not contain the main model, otherwise
|
Chris@194
|
3173 // we would have reset it to ReplaceMainModel. But we don't
|
Chris@194
|
3174 // know whether the pane contains a waveform model at all.
|
Chris@194
|
3175
|
Chris@194
|
3176 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@194
|
3177 Layer *replace = 0;
|
Chris@194
|
3178
|
Chris@194
|
3179 for (int i = 0; i < pane->getLayerCount(); ++i) {
|
Chris@194
|
3180 Layer *layer = pane->getLayer(i);
|
Chris@194
|
3181 if (dynamic_cast<WaveformLayer *>(layer)) {
|
Chris@194
|
3182 replace = layer;
|
Chris@194
|
3183 break;
|
Chris@194
|
3184 }
|
Chris@194
|
3185 }
|
Chris@194
|
3186
|
Chris@194
|
3187 CommandHistory::getInstance()->startCompoundOperation
|
Chris@194
|
3188 (tr("Import \"%1\"").arg(QFileInfo(location).fileName()), true);
|
Chris@194
|
3189
|
Chris@194
|
3190 m_document->addImportedModel(newModel);
|
Chris@194
|
3191
|
Chris@194
|
3192 if (replace) {
|
Chris@194
|
3193 m_document->removeLayerFromView(pane, replace);
|
Chris@194
|
3194 }
|
Chris@194
|
3195
|
Chris@194
|
3196 Layer *newLayer = m_document->createImportedLayer(newModel);
|
Chris@194
|
3197
|
Chris@194
|
3198 if (newLayer) {
|
Chris@194
|
3199 m_document->addLayerToView(pane, newLayer);
|
Chris@194
|
3200 }
|
Chris@194
|
3201
|
Chris@194
|
3202 CommandHistory::getInstance()->endCompoundOperation();
|
Chris@0
|
3203 }
|
Chris@0
|
3204
|
Chris@0
|
3205 updateMenuStates();
|
Chris@86
|
3206 m_recentFiles.addFile(location);
|
Chris@86
|
3207 if (realFile) {
|
Chris@88
|
3208 registerLastOpenedFilePath(FileFinder::AudioFile, path); // for file dialog
|
Chris@86
|
3209 }
|
Chris@70
|
3210 m_openingAudioFile = false;
|
Chris@0
|
3211
|
Chris@180
|
3212 currentPaneChanged(m_paneStack->getCurrentPane());
|
Chris@180
|
3213
|
Chris@82
|
3214 return FileOpenSucceeded;
|
Chris@0
|
3215 }
|
Chris@0
|
3216
|
Chris@180
|
3217 MainWindow::FileOpenStatus
|
Chris@180
|
3218 MainWindow::openPlaylistFile(QString path, AudioFileOpenMode mode)
|
Chris@180
|
3219 {
|
Chris@180
|
3220 return openPlaylistFile(path, path, mode);
|
Chris@180
|
3221 }
|
Chris@180
|
3222
|
Chris@180
|
3223 MainWindow::FileOpenStatus
|
Chris@180
|
3224 MainWindow::openPlaylistFile(QString path, QString location, AudioFileOpenMode mode)
|
Chris@180
|
3225 {
|
Chris@180
|
3226 if (!(QFileInfo(path).exists() &&
|
Chris@180
|
3227 QFileInfo(path).isFile() &&
|
Chris@180
|
3228 QFileInfo(path).isReadable())) {
|
Chris@180
|
3229 return FileOpenFailed;
|
Chris@180
|
3230 }
|
Chris@180
|
3231
|
Chris@180
|
3232 std::set<QString> extensions;
|
Chris@180
|
3233 PlaylistFileReader::getSupportedExtensions(extensions);
|
Chris@180
|
3234 QString extension = QFileInfo(path).suffix();
|
Chris@180
|
3235 if (extensions.find(extension) == extensions.end()) return FileOpenFailed;
|
Chris@180
|
3236
|
Chris@180
|
3237 PlaylistFileReader reader(path);
|
Chris@180
|
3238 if (!reader.isOK()) return FileOpenFailed;
|
Chris@180
|
3239
|
Chris@180
|
3240 PlaylistFileReader::Playlist playlist = reader.load();
|
Chris@180
|
3241
|
Chris@180
|
3242 bool someSuccess = false;
|
Chris@180
|
3243
|
Chris@180
|
3244 for (PlaylistFileReader::Playlist::const_iterator i = playlist.begin();
|
Chris@180
|
3245 i != playlist.end(); ++i) {
|
Chris@180
|
3246
|
Chris@180
|
3247 FileOpenStatus status = openURL(*i, mode);
|
Chris@180
|
3248
|
Chris@180
|
3249 if (status == FileOpenCancelled) {
|
Chris@180
|
3250 return FileOpenCancelled;
|
Chris@180
|
3251 }
|
Chris@180
|
3252
|
Chris@180
|
3253 if (status == FileOpenSucceeded) {
|
Chris@180
|
3254 someSuccess = true;
|
Chris@180
|
3255 mode = CreateAdditionalModel;
|
Chris@180
|
3256 }
|
Chris@180
|
3257 }
|
Chris@180
|
3258
|
Chris@180
|
3259 if (someSuccess) return FileOpenSucceeded;
|
Chris@180
|
3260 else return FileOpenFailed;
|
Chris@180
|
3261 }
|
Chris@180
|
3262
|
Chris@0
|
3263 void
|
Chris@0
|
3264 MainWindow::createPlayTarget()
|
Chris@0
|
3265 {
|
Chris@0
|
3266 if (m_playTarget) return;
|
Chris@0
|
3267
|
Chris@0
|
3268 m_playTarget = AudioTargetFactory::createCallbackTarget(m_playSource);
|
Chris@0
|
3269 if (!m_playTarget) {
|
Chris@0
|
3270 QMessageBox::warning
|
Chris@0
|
3271 (this, tr("Couldn't open audio device"),
|
Chris@193
|
3272 tr("<b>No audio available</b><p>Could not open an audio device for playback.<p>Audio playback will not be available during this session."),
|
Chris@165
|
3273 QMessageBox::Ok);
|
Chris@0
|
3274 }
|
Chris@0
|
3275 connect(m_fader, SIGNAL(valueChanged(float)),
|
Chris@0
|
3276 m_playTarget, SLOT(setOutputGain(float)));
|
Chris@0
|
3277 }
|
Chris@0
|
3278
|
Chris@0
|
3279 WaveFileModel *
|
Chris@0
|
3280 MainWindow::getMainModel()
|
Chris@0
|
3281 {
|
Chris@0
|
3282 if (!m_document) return 0;
|
Chris@0
|
3283 return m_document->getMainModel();
|
Chris@0
|
3284 }
|
Chris@0
|
3285
|
Chris@116
|
3286 const WaveFileModel *
|
Chris@116
|
3287 MainWindow::getMainModel() const
|
Chris@116
|
3288 {
|
Chris@116
|
3289 if (!m_document) return 0;
|
Chris@116
|
3290 return m_document->getMainModel();
|
Chris@116
|
3291 }
|
Chris@116
|
3292
|
Chris@0
|
3293 void
|
Chris@0
|
3294 MainWindow::newSession()
|
Chris@0
|
3295 {
|
Chris@0
|
3296 if (!checkSaveModified()) return;
|
Chris@0
|
3297
|
Chris@0
|
3298 closeSession();
|
Chris@0
|
3299 createDocument();
|
Chris@0
|
3300
|
Chris@0
|
3301 Pane *pane = m_paneStack->addPane();
|
Chris@0
|
3302
|
Chris@90
|
3303 connect(pane, SIGNAL(contextHelpChanged(const QString &)),
|
Chris@116
|
3304 this, SLOT(contextHelpChanged(const QString &)));
|
Chris@90
|
3305
|
Chris@0
|
3306 if (!m_timeRulerLayer) {
|
Chris@0
|
3307 m_timeRulerLayer = m_document->createMainModelLayer
|
Chris@0
|
3308 (LayerFactory::TimeRuler);
|
Chris@0
|
3309 }
|
Chris@0
|
3310
|
Chris@0
|
3311 m_document->addLayerToView(pane, m_timeRulerLayer);
|
Chris@0
|
3312
|
Chris@0
|
3313 Layer *waveform = m_document->createMainModelLayer(LayerFactory::Waveform);
|
Chris@0
|
3314 m_document->addLayerToView(pane, waveform);
|
Chris@0
|
3315
|
Chris@65
|
3316 m_overview->registerView(pane);
|
Chris@0
|
3317
|
Chris@0
|
3318 CommandHistory::getInstance()->clear();
|
Chris@0
|
3319 CommandHistory::getInstance()->documentSaved();
|
Chris@0
|
3320 documentRestored();
|
Chris@0
|
3321 updateMenuStates();
|
Chris@0
|
3322 }
|
Chris@0
|
3323
|
Chris@0
|
3324 void
|
Chris@0
|
3325 MainWindow::createDocument()
|
Chris@0
|
3326 {
|
Chris@0
|
3327 m_document = new Document;
|
Chris@0
|
3328
|
Chris@0
|
3329 connect(m_document, SIGNAL(layerAdded(Layer *)),
|
Chris@0
|
3330 this, SLOT(layerAdded(Layer *)));
|
Chris@0
|
3331 connect(m_document, SIGNAL(layerRemoved(Layer *)),
|
Chris@0
|
3332 this, SLOT(layerRemoved(Layer *)));
|
Chris@0
|
3333 connect(m_document, SIGNAL(layerAboutToBeDeleted(Layer *)),
|
Chris@0
|
3334 this, SLOT(layerAboutToBeDeleted(Layer *)));
|
Chris@0
|
3335 connect(m_document, SIGNAL(layerInAView(Layer *, bool)),
|
Chris@0
|
3336 this, SLOT(layerInAView(Layer *, bool)));
|
Chris@0
|
3337
|
Chris@0
|
3338 connect(m_document, SIGNAL(modelAdded(Model *)),
|
Chris@0
|
3339 this, SLOT(modelAdded(Model *)));
|
Chris@0
|
3340 connect(m_document, SIGNAL(mainModelChanged(WaveFileModel *)),
|
Chris@0
|
3341 this, SLOT(mainModelChanged(WaveFileModel *)));
|
Chris@0
|
3342 connect(m_document, SIGNAL(modelAboutToBeDeleted(Model *)),
|
Chris@0
|
3343 this, SLOT(modelAboutToBeDeleted(Model *)));
|
Chris@0
|
3344
|
Chris@0
|
3345 connect(m_document, SIGNAL(modelGenerationFailed(QString)),
|
Chris@0
|
3346 this, SLOT(modelGenerationFailed(QString)));
|
Chris@63
|
3347 connect(m_document, SIGNAL(modelRegenerationFailed(QString, QString)),
|
Chris@63
|
3348 this, SLOT(modelRegenerationFailed(QString, QString)));
|
Chris@0
|
3349 }
|
Chris@0
|
3350
|
Chris@0
|
3351 void
|
Chris@0
|
3352 MainWindow::closeSession()
|
Chris@0
|
3353 {
|
Chris@0
|
3354 if (!checkSaveModified()) return;
|
Chris@0
|
3355
|
Chris@0
|
3356 while (m_paneStack->getPaneCount() > 0) {
|
Chris@0
|
3357
|
Chris@0
|
3358 Pane *pane = m_paneStack->getPane(m_paneStack->getPaneCount() - 1);
|
Chris@0
|
3359
|
Chris@0
|
3360 while (pane->getLayerCount() > 0) {
|
Chris@0
|
3361 m_document->removeLayerFromView
|
Chris@0
|
3362 (pane, pane->getLayer(pane->getLayerCount() - 1));
|
Chris@0
|
3363 }
|
Chris@0
|
3364
|
Chris@65
|
3365 m_overview->unregisterView(pane);
|
Chris@0
|
3366 m_paneStack->deletePane(pane);
|
Chris@0
|
3367 }
|
Chris@0
|
3368
|
Chris@0
|
3369 while (m_paneStack->getHiddenPaneCount() > 0) {
|
Chris@0
|
3370
|
Chris@0
|
3371 Pane *pane = m_paneStack->getHiddenPane
|
Chris@0
|
3372 (m_paneStack->getHiddenPaneCount() - 1);
|
Chris@0
|
3373
|
Chris@0
|
3374 while (pane->getLayerCount() > 0) {
|
Chris@0
|
3375 m_document->removeLayerFromView
|
Chris@0
|
3376 (pane, pane->getLayer(pane->getLayerCount() - 1));
|
Chris@0
|
3377 }
|
Chris@0
|
3378
|
Chris@65
|
3379 m_overview->unregisterView(pane);
|
Chris@0
|
3380 m_paneStack->deletePane(pane);
|
Chris@0
|
3381 }
|
Chris@0
|
3382
|
Chris@0
|
3383 delete m_document;
|
Chris@0
|
3384 m_document = 0;
|
Chris@0
|
3385 m_viewManager->clearSelections();
|
Chris@0
|
3386 m_timeRulerLayer = 0; // document owned this
|
Chris@0
|
3387
|
Chris@0
|
3388 m_sessionFile = "";
|
Chris@0
|
3389 setWindowTitle(tr("Sonic Visualiser"));
|
Chris@0
|
3390
|
Chris@0
|
3391 CommandHistory::getInstance()->clear();
|
Chris@0
|
3392 CommandHistory::getInstance()->documentSaved();
|
Chris@0
|
3393 documentRestored();
|
Chris@0
|
3394 }
|
Chris@0
|
3395
|
Chris@0
|
3396 void
|
Chris@0
|
3397 MainWindow::openSession()
|
Chris@0
|
3398 {
|
Chris@0
|
3399 if (!checkSaveModified()) return;
|
Chris@0
|
3400
|
Chris@0
|
3401 QString orig = m_audioFile;
|
Chris@0
|
3402 if (orig == "") orig = ".";
|
Chris@0
|
3403 else orig = QFileInfo(orig).absoluteDir().canonicalPath();
|
Chris@0
|
3404
|
Chris@88
|
3405 QString path = getOpenFileName(FileFinder::SessionFile);
|
Chris@0
|
3406
|
Chris@0
|
3407 if (path.isEmpty()) return;
|
Chris@0
|
3408
|
Chris@82
|
3409 if (openSessionFile(path) == FileOpenFailed) {
|
Chris@0
|
3410 QMessageBox::critical(this, tr("Failed to open file"),
|
Chris@193
|
3411 tr("<b>File open failed</b><p>Session file \"%1\" could not be opened").arg(path));
|
Chris@0
|
3412 }
|
Chris@0
|
3413 }
|
Chris@0
|
3414
|
Chris@0
|
3415 void
|
Chris@0
|
3416 MainWindow::openSomething()
|
Chris@0
|
3417 {
|
Chris@0
|
3418 QString orig = m_audioFile;
|
Chris@0
|
3419 if (orig == "") orig = ".";
|
Chris@0
|
3420 else orig = QFileInfo(orig).absoluteDir().canonicalPath();
|
Chris@0
|
3421
|
Chris@88
|
3422 QString path = getOpenFileName(FileFinder::AnyFile);
|
Chris@0
|
3423
|
Chris@0
|
3424 if (path.isEmpty()) return;
|
Chris@0
|
3425
|
Chris@193
|
3426 FileOpenStatus status = openSomeFile(path, AskUser);
|
Chris@193
|
3427
|
Chris@193
|
3428 if (status == FileOpenFailed) {
|
Chris@193
|
3429 QMessageBox::critical(this, tr("Failed to open file"),
|
Chris@193
|
3430 tr("<b>File open failed</b><p>File \"%1\" could not be opened").arg(path));
|
Chris@193
|
3431 } else if (status == FileOpenWrongMode) {
|
Chris@193
|
3432 QMessageBox::critical(this, tr("Failed to open file"),
|
Chris@193
|
3433 tr("<b>Audio required</b><p>Please load at least one audio file before importing annotation data"));
|
Chris@0
|
3434 }
|
Chris@0
|
3435 }
|
Chris@0
|
3436
|
Chris@0
|
3437 void
|
Chris@86
|
3438 MainWindow::openLocation()
|
Chris@86
|
3439 {
|
Chris@103
|
3440 QSettings settings;
|
Chris@103
|
3441 settings.beginGroup("MainWindow");
|
Chris@103
|
3442 QString lastLocation = settings.value("lastremote", "").toString();
|
Chris@103
|
3443
|
Chris@86
|
3444 bool ok = false;
|
Chris@86
|
3445 QString text = QInputDialog::getText
|
Chris@86
|
3446 (this, tr("Open Location"),
|
Chris@86
|
3447 tr("Please enter the URL of the location to open:"),
|
Chris@103
|
3448 QLineEdit::Normal, lastLocation, &ok);
|
Chris@103
|
3449
|
Chris@103
|
3450 if (!ok) return;
|
Chris@103
|
3451
|
Chris@103
|
3452 settings.setValue("lastremote", text);
|
Chris@103
|
3453
|
Chris@103
|
3454 if (text.isEmpty()) return;
|
Chris@86
|
3455
|
Chris@193
|
3456 FileOpenStatus status = openURL(QUrl(text));
|
Chris@193
|
3457
|
Chris@193
|
3458 if (status == FileOpenFailed) {
|
Chris@86
|
3459 QMessageBox::critical(this, tr("Failed to open location"),
|
Chris@193
|
3460 tr("<b>Open failed</b><p>URL \"%1\" could not be opened").arg(text));
|
Chris@193
|
3461 } else if (status == FileOpenWrongMode) {
|
Chris@193
|
3462 QMessageBox::critical(this, tr("Failed to open location"),
|
Chris@193
|
3463 tr("<b>Audio required</b><p>Please load at least one audio file before importing annotation data"));
|
Chris@86
|
3464 }
|
Chris@86
|
3465 }
|
Chris@86
|
3466
|
Chris@86
|
3467 void
|
Chris@0
|
3468 MainWindow::openRecentFile()
|
Chris@0
|
3469 {
|
Chris@0
|
3470 QObject *obj = sender();
|
Chris@0
|
3471 QAction *action = dynamic_cast<QAction *>(obj);
|
Chris@0
|
3472
|
Chris@0
|
3473 if (!action) {
|
Chris@0
|
3474 std::cerr << "WARNING: MainWindow::openRecentFile: sender is not an action"
|
Chris@0
|
3475 << std::endl;
|
Chris@0
|
3476 return;
|
Chris@0
|
3477 }
|
Chris@0
|
3478
|
Chris@0
|
3479 QString path = action->text();
|
Chris@0
|
3480 if (path == "") return;
|
Chris@0
|
3481
|
Chris@193
|
3482 FileOpenStatus status = openURL(path);
|
Chris@193
|
3483
|
Chris@193
|
3484 if (status == FileOpenFailed) {
|
Chris@193
|
3485 QMessageBox::critical(this, tr("Failed to open location"),
|
Chris@193
|
3486 tr("<b>Open failed</b><p>File or URL \"%1\" could not be opened").arg(path));
|
Chris@193
|
3487 } else if (status == FileOpenWrongMode) {
|
Chris@193
|
3488 QMessageBox::critical(this, tr("Failed to open location"),
|
Chris@193
|
3489 tr("<b>Audio required</b><p>Please load at least one audio file before importing annotation data"));
|
Chris@0
|
3490 }
|
Chris@0
|
3491 }
|
Chris@0
|
3492
|
Chris@82
|
3493 MainWindow::FileOpenStatus
|
Chris@180
|
3494 MainWindow::openURL(QUrl url, AudioFileOpenMode mode)
|
Chris@85
|
3495 {
|
Chris@193
|
3496 if (url.scheme().toLower() == "file" || url.scheme() == "") {
|
Chris@180
|
3497
|
Chris@180
|
3498 return openSomeFile(url.toLocalFile(), mode);
|
Chris@180
|
3499
|
Chris@86
|
3500 } else if (!RemoteFile::canHandleScheme(url)) {
|
Chris@180
|
3501
|
Chris@85
|
3502 QMessageBox::critical(this, tr("Unsupported scheme in URL"),
|
Chris@193
|
3503 tr("<b>Download failed</b><p>The URL scheme \"%1\" is not supported")
|
Chris@85
|
3504 .arg(url.scheme()));
|
Chris@85
|
3505 return FileOpenFailed;
|
Chris@180
|
3506
|
Chris@85
|
3507 } else {
|
Chris@85
|
3508 RemoteFile rf(url);
|
Chris@85
|
3509 rf.wait();
|
Chris@85
|
3510 if (!rf.isOK()) {
|
Chris@85
|
3511 QMessageBox::critical(this, tr("File download failed"),
|
Chris@193
|
3512 tr("<b>Download failed</b><p>Failed to download URL \"%1\": %2")
|
Chris@85
|
3513 .arg(url.toString()).arg(rf.getErrorString()));
|
Chris@85
|
3514 return FileOpenFailed;
|
Chris@85
|
3515 }
|
Chris@88
|
3516 FileOpenStatus status;
|
Chris@180
|
3517 if ((status = openSomeFile(rf.getLocalFilename(), url.toString(),
|
Chris@180
|
3518 mode)) !=
|
Chris@88
|
3519 FileOpenSucceeded) {
|
Chris@88
|
3520 rf.deleteLocalFile();
|
Chris@88
|
3521 }
|
Chris@88
|
3522 return status;
|
Chris@85
|
3523 }
|
Chris@85
|
3524 }
|
Chris@85
|
3525
|
Chris@85
|
3526 MainWindow::FileOpenStatus
|
Chris@180
|
3527 MainWindow::openURL(QString ustr, AudioFileOpenMode mode)
|
Chris@180
|
3528 {
|
Chris@180
|
3529 // This function is used when we don't know whether the string is
|
Chris@180
|
3530 // an encoded or human-readable url
|
Chris@180
|
3531
|
Chris@180
|
3532 QUrl url(ustr);
|
Chris@180
|
3533
|
Chris@193
|
3534 if (url.scheme().toLower() == "file" || url.scheme() == "") {
|
Chris@193
|
3535
|
Chris@193
|
3536 FileOpenStatus status = openSomeFile(url.toLocalFile(), mode);
|
Chris@193
|
3537 if (status == FileOpenFailed) {
|
Chris@193
|
3538 url.setEncodedUrl(ustr.toAscii());
|
Chris@193
|
3539 status = openSomeFile(url.toLocalFile(), mode);
|
Chris@193
|
3540 }
|
Chris@193
|
3541 return status;
|
Chris@180
|
3542
|
Chris@180
|
3543 } else if (!RemoteFile::canHandleScheme(url)) {
|
Chris@180
|
3544
|
Chris@180
|
3545 QMessageBox::critical(this, tr("Unsupported scheme in URL"),
|
Chris@193
|
3546 tr("<b>Download failed</b><p>The URL scheme \"%1\" is not supported")
|
Chris@180
|
3547 .arg(url.scheme()));
|
Chris@180
|
3548 return FileOpenFailed;
|
Chris@180
|
3549
|
Chris@180
|
3550 } else {
|
Chris@180
|
3551 RemoteFile rf(url);
|
Chris@180
|
3552 rf.wait();
|
Chris@180
|
3553 if (!rf.isOK()) {
|
Chris@180
|
3554 // rf was created on the assumption that ustr was
|
Chris@180
|
3555 // human-readable. Let's try again, this time assuming it
|
Chris@180
|
3556 // was already encoded.
|
Chris@180
|
3557 std::cerr << "MainWindow::openURL: Failed to retrieve URL \""
|
Chris@180
|
3558 << ustr.toStdString() << "\" as human-readable URL; "
|
Chris@180
|
3559 << "trying again treating it as encoded URL"
|
Chris@180
|
3560 << std::endl;
|
Chris@180
|
3561 url.setEncodedUrl(ustr.toAscii());
|
Chris@180
|
3562 return openURL(url, mode);
|
Chris@180
|
3563 }
|
Chris@180
|
3564
|
Chris@180
|
3565 FileOpenStatus status;
|
Chris@180
|
3566 if ((status = openSomeFile(rf.getLocalFilename(), ustr, mode)) !=
|
Chris@180
|
3567 FileOpenSucceeded) {
|
Chris@180
|
3568 rf.deleteLocalFile();
|
Chris@180
|
3569 }
|
Chris@180
|
3570 return status;
|
Chris@180
|
3571 }
|
Chris@180
|
3572 }
|
Chris@180
|
3573
|
Chris@180
|
3574 MainWindow::FileOpenStatus
|
Chris@54
|
3575 MainWindow::openSomeFile(QString path, AudioFileOpenMode mode)
|
Chris@0
|
3576 {
|
Chris@86
|
3577 return openSomeFile(path, path, mode);
|
Chris@86
|
3578 }
|
Chris@86
|
3579
|
Chris@86
|
3580 MainWindow::FileOpenStatus
|
Chris@86
|
3581 MainWindow::openSomeFile(QString path, QString location,
|
Chris@86
|
3582 AudioFileOpenMode mode)
|
Chris@86
|
3583 {
|
Chris@82
|
3584 FileOpenStatus status;
|
Chris@82
|
3585
|
Chris@85
|
3586 bool canImportLayer = (getMainModel() != 0 &&
|
Chris@85
|
3587 m_paneStack != 0 &&
|
Chris@85
|
3588 m_paneStack->getCurrentPane() != 0);
|
Chris@85
|
3589
|
Chris@180
|
3590 if ((status = openPlaylistFile(path, location, mode)) != FileOpenFailed) {
|
Chris@180
|
3591 return status;
|
Chris@180
|
3592 } else if ((status = openAudioFile(path, location, mode)) != FileOpenFailed) {
|
Chris@82
|
3593 return status;
|
Chris@193
|
3594 } else if (QFileInfo(path).suffix().toLower() == "sv" &&
|
Chris@193
|
3595 (status = openSessionFile(path, location)) != FileOpenFailed) {
|
Chris@82
|
3596 return status;
|
Chris@85
|
3597 } else if (!canImportLayer) {
|
Chris@193
|
3598 return FileOpenWrongMode;
|
Chris@193
|
3599 } else if ((status = openImageFile(path, location)) != FileOpenFailed) {
|
Chris@193
|
3600 return status;
|
Chris@86
|
3601 } else if ((status = openLayerFile(path, location)) != FileOpenFailed) {
|
Chris@85
|
3602 return status;
|
Chris@0
|
3603 } else {
|
Chris@82
|
3604 return FileOpenFailed;
|
Chris@0
|
3605 }
|
Chris@0
|
3606 }
|
Chris@0
|
3607
|
Chris@82
|
3608 MainWindow::FileOpenStatus
|
Chris@0
|
3609 MainWindow::openSessionFile(QString path)
|
Chris@0
|
3610 {
|
Chris@86
|
3611 return openSessionFile(path, path);
|
Chris@86
|
3612 }
|
Chris@86
|
3613
|
Chris@86
|
3614 MainWindow::FileOpenStatus
|
Chris@86
|
3615 MainWindow::openSessionFile(QString path, QString location)
|
Chris@86
|
3616 {
|
Chris@0
|
3617 BZipFileDevice bzFile(path);
|
Chris@0
|
3618 if (!bzFile.open(QIODevice::ReadOnly)) {
|
Chris@86
|
3619 std::cerr << "Failed to open session file \"" << location.toStdString()
|
Chris@0
|
3620 << "\": " << bzFile.errorString().toStdString() << std::endl;
|
Chris@82
|
3621 return FileOpenFailed;
|
Chris@0
|
3622 }
|
Chris@0
|
3623
|
Chris@103
|
3624 if (!checkSaveModified()) return FileOpenCancelled;
|
Chris@103
|
3625
|
Chris@0
|
3626 QString error;
|
Chris@0
|
3627 closeSession();
|
Chris@0
|
3628 createDocument();
|
Chris@0
|
3629
|
Chris@0
|
3630 PaneCallback callback(this);
|
Chris@0
|
3631 m_viewManager->clearSelections();
|
Chris@0
|
3632
|
Chris@87
|
3633 SVFileReader reader(m_document, callback, location);
|
Chris@0
|
3634 QXmlInputSource inputSource(&bzFile);
|
Chris@0
|
3635 reader.parse(inputSource);
|
Chris@0
|
3636
|
Chris@0
|
3637 if (!reader.isOK()) {
|
Chris@0
|
3638 error = tr("SV XML file read error:\n%1").arg(reader.getErrorString());
|
Chris@0
|
3639 }
|
Chris@0
|
3640
|
Chris@0
|
3641 bzFile.close();
|
Chris@0
|
3642
|
Chris@0
|
3643 bool ok = (error == "");
|
Chris@86
|
3644
|
Chris@86
|
3645 bool realFile = (location == path);
|
Chris@0
|
3646
|
Chris@0
|
3647 if (ok) {
|
Chris@86
|
3648
|
Chris@0
|
3649 setWindowTitle(tr("Sonic Visualiser: %1")
|
Chris@86
|
3650 .arg(QFileInfo(location).fileName()));
|
Chris@86
|
3651
|
Chris@86
|
3652 if (realFile) m_sessionFile = path;
|
Chris@86
|
3653
|
Chris@0
|
3654 setupMenus();
|
Chris@0
|
3655 CommandHistory::getInstance()->clear();
|
Chris@0
|
3656 CommandHistory::getInstance()->documentSaved();
|
Chris@0
|
3657 m_documentModified = false;
|
Chris@0
|
3658 updateMenuStates();
|
Chris@86
|
3659
|
Chris@86
|
3660 m_recentFiles.addFile(location);
|
Chris@86
|
3661
|
Chris@86
|
3662 if (realFile) {
|
Chris@88
|
3663 registerLastOpenedFilePath(FileFinder::SessionFile, path); // for file dialog
|
Chris@86
|
3664 }
|
Chris@86
|
3665
|
Chris@0
|
3666 } else {
|
Chris@0
|
3667 setWindowTitle(tr("Sonic Visualiser"));
|
Chris@0
|
3668 }
|
Chris@0
|
3669
|
Chris@82
|
3670 return ok ? FileOpenSucceeded : FileOpenFailed;
|
Chris@0
|
3671 }
|
Chris@0
|
3672
|
Chris@0
|
3673 void
|
Chris@193
|
3674 MainWindow::paneDropAccepted(Pane *pane, QStringList uriList)
|
Chris@193
|
3675 {
|
Chris@193
|
3676 if (pane) m_paneStack->setCurrentPane(pane);
|
Chris@193
|
3677
|
Chris@193
|
3678 for (QStringList::iterator i = uriList.begin(); i != uriList.end(); ++i) {
|
Chris@193
|
3679
|
Chris@194
|
3680 FileOpenStatus status = openURL(*i, ReplaceCurrentPane);
|
Chris@193
|
3681
|
Chris@193
|
3682 if (status == FileOpenFailed) {
|
Chris@193
|
3683 QMessageBox::critical(this, tr("Failed to open dropped URL"),
|
Chris@193
|
3684 tr("<b>Open failed</b><p>Dropped URL \"%1\" could not be opened").arg(*i));
|
Chris@193
|
3685 } else if (status == FileOpenWrongMode) {
|
Chris@193
|
3686 QMessageBox::critical(this, tr("Failed to open dropped URL"),
|
Chris@193
|
3687 tr("<b>Audio required</b><p>Please load at least one audio file before importing annotation data"));
|
Chris@193
|
3688 }
|
Chris@193
|
3689 }
|
Chris@193
|
3690 }
|
Chris@193
|
3691
|
Chris@193
|
3692 void
|
Chris@193
|
3693 MainWindow::paneDropAccepted(Pane *pane, QString text)
|
Chris@193
|
3694 {
|
Chris@193
|
3695 if (pane) m_paneStack->setCurrentPane(pane);
|
Chris@193
|
3696
|
Chris@193
|
3697 QUrl testUrl(text);
|
Chris@193
|
3698 if (testUrl.scheme() == "file" ||
|
Chris@193
|
3699 testUrl.scheme() == "http" ||
|
Chris@193
|
3700 testUrl.scheme() == "ftp") {
|
Chris@193
|
3701 QStringList list;
|
Chris@193
|
3702 list.push_back(text);
|
Chris@193
|
3703 paneDropAccepted(pane, list);
|
Chris@193
|
3704 return;
|
Chris@193
|
3705 }
|
Chris@193
|
3706
|
Chris@193
|
3707 //!!! open as text -- but by importing as if a CSV, or just adding
|
Chris@193
|
3708 //to a text layer?
|
Chris@193
|
3709 }
|
Chris@193
|
3710
|
Chris@193
|
3711 void
|
Chris@0
|
3712 MainWindow::closeEvent(QCloseEvent *e)
|
Chris@0
|
3713 {
|
Chris@137
|
3714 // std::cerr << "MainWindow::closeEvent" << std::endl;
|
Chris@118
|
3715
|
Chris@136
|
3716 if (m_openingAudioFile) {
|
Chris@137
|
3717 // std::cerr << "Busy - ignoring close event" << std::endl;
|
Chris@136
|
3718 e->ignore();
|
Chris@136
|
3719 return;
|
Chris@136
|
3720 }
|
Chris@136
|
3721
|
Chris@70
|
3722 if (!m_abandoning && !checkSaveModified()) {
|
Chris@137
|
3723 // std::cerr << "Ignoring close event" << std::endl;
|
Chris@0
|
3724 e->ignore();
|
Chris@0
|
3725 return;
|
Chris@0
|
3726 }
|
Chris@0
|
3727
|
Chris@5
|
3728 QSettings settings;
|
Chris@5
|
3729 settings.beginGroup("MainWindow");
|
Chris@5
|
3730 settings.setValue("size", size());
|
Chris@5
|
3731 settings.setValue("position", pos());
|
Chris@5
|
3732 settings.endGroup();
|
Chris@5
|
3733
|
Chris@163
|
3734 delete m_keyReference;
|
Chris@163
|
3735 m_keyReference = 0;
|
Chris@163
|
3736
|
Chris@163
|
3737 if (m_preferencesDialog &&
|
Chris@163
|
3738 m_preferencesDialog->isVisible()) {
|
Chris@164
|
3739 closeSession(); // otherwise we'll have to wait for prefs changes
|
Chris@163
|
3740 m_preferencesDialog->applicationClosing(false);
|
Chris@163
|
3741 }
|
Chris@163
|
3742
|
Chris@177
|
3743 if (m_layerTreeView &&
|
Chris@177
|
3744 m_layerTreeView->isVisible()) {
|
Chris@177
|
3745 delete m_layerTreeView;
|
Chris@177
|
3746 }
|
Chris@177
|
3747
|
Chris@0
|
3748 e->accept();
|
Chris@0
|
3749 return;
|
Chris@0
|
3750 }
|
Chris@0
|
3751
|
Chris@0
|
3752 bool
|
Chris@11
|
3753 MainWindow::commitData(bool mayAskUser)
|
Chris@11
|
3754 {
|
Chris@11
|
3755 if (mayAskUser) {
|
Chris@163
|
3756 bool rv = checkSaveModified();
|
Chris@163
|
3757 if (rv) {
|
Chris@163
|
3758 if (m_preferencesDialog &&
|
Chris@163
|
3759 m_preferencesDialog->isVisible()) {
|
Chris@163
|
3760 m_preferencesDialog->applicationClosing(false);
|
Chris@163
|
3761 }
|
Chris@163
|
3762 }
|
Chris@163
|
3763 return rv;
|
Chris@11
|
3764 } else {
|
Chris@163
|
3765 if (m_preferencesDialog &&
|
Chris@163
|
3766 m_preferencesDialog->isVisible()) {
|
Chris@163
|
3767 m_preferencesDialog->applicationClosing(true);
|
Chris@163
|
3768 }
|
Chris@11
|
3769 if (!m_documentModified) return true;
|
Chris@11
|
3770
|
Chris@11
|
3771 // If we can't check with the user first, then we can't save
|
Chris@11
|
3772 // to the original session file (even if we have it) -- have
|
Chris@11
|
3773 // to use a temporary file
|
Chris@11
|
3774
|
Chris@11
|
3775 QString svDirBase = ".sv1";
|
Chris@11
|
3776 QString svDir = QDir::home().filePath(svDirBase);
|
Chris@11
|
3777
|
Chris@11
|
3778 if (!QFileInfo(svDir).exists()) {
|
Chris@11
|
3779 if (!QDir::home().mkdir(svDirBase)) return false;
|
Chris@11
|
3780 } else {
|
Chris@11
|
3781 if (!QFileInfo(svDir).isDir()) return false;
|
Chris@11
|
3782 }
|
Chris@11
|
3783
|
Chris@11
|
3784 // This name doesn't have to be unguessable
|
Chris@93
|
3785 #ifndef _WIN32
|
Chris@11
|
3786 QString fname = QString("tmp-%1-%2.sv")
|
Chris@11
|
3787 .arg(QDateTime::currentDateTime().toString("yyyyMMddhhmmsszzz"))
|
Chris@11
|
3788 .arg(QProcess().pid());
|
Chris@93
|
3789 #else
|
Chris@93
|
3790 QString fname = QString("tmp-%1.sv")
|
Chris@93
|
3791 .arg(QDateTime::currentDateTime().toString("yyyyMMddhhmmsszzz"));
|
Chris@93
|
3792 #endif
|
Chris@11
|
3793 QString fpath = QDir(svDir).filePath(fname);
|
Chris@11
|
3794 if (saveSessionFile(fpath)) {
|
Chris@34
|
3795 m_recentFiles.addFile(fpath);
|
Chris@11
|
3796 return true;
|
Chris@11
|
3797 } else {
|
Chris@11
|
3798 return false;
|
Chris@11
|
3799 }
|
Chris@11
|
3800 }
|
Chris@11
|
3801 }
|
Chris@11
|
3802
|
Chris@11
|
3803 bool
|
Chris@0
|
3804 MainWindow::checkSaveModified()
|
Chris@0
|
3805 {
|
Chris@0
|
3806 // Called before some destructive operation (e.g. new session,
|
Chris@0
|
3807 // exit program). Return true if we can safely proceed, false to
|
Chris@0
|
3808 // cancel.
|
Chris@0
|
3809
|
Chris@0
|
3810 if (!m_documentModified) return true;
|
Chris@0
|
3811
|
Chris@0
|
3812 int button =
|
Chris@0
|
3813 QMessageBox::warning(this,
|
Chris@0
|
3814 tr("Session modified"),
|
Chris@193
|
3815 tr("<b>Session modified</b><p>The current session has been modified.<br>Do you want to save it?<br>"),
|
Chris@165
|
3816 QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel,
|
Chris@165
|
3817 QMessageBox::Yes);
|
Chris@0
|
3818
|
Chris@0
|
3819 if (button == QMessageBox::Yes) {
|
Chris@0
|
3820 saveSession();
|
Chris@0
|
3821 if (m_documentModified) { // save failed -- don't proceed!
|
Chris@0
|
3822 return false;
|
Chris@0
|
3823 } else {
|
Chris@0
|
3824 return true; // saved, so it's safe to continue now
|
Chris@0
|
3825 }
|
Chris@0
|
3826 } else if (button == QMessageBox::No) {
|
Chris@0
|
3827 m_documentModified = false; // so we know to abandon it
|
Chris@0
|
3828 return true;
|
Chris@0
|
3829 }
|
Chris@0
|
3830
|
Chris@0
|
3831 // else cancel
|
Chris@0
|
3832 return false;
|
Chris@0
|
3833 }
|
Chris@0
|
3834
|
Chris@0
|
3835 void
|
Chris@0
|
3836 MainWindow::saveSession()
|
Chris@0
|
3837 {
|
Chris@0
|
3838 if (m_sessionFile != "") {
|
Chris@0
|
3839 if (!saveSessionFile(m_sessionFile)) {
|
Chris@0
|
3840 QMessageBox::critical(this, tr("Failed to save file"),
|
Chris@193
|
3841 tr("<b>Save failed</b><p>Session file \"%1\" could not be saved.").arg(m_sessionFile));
|
Chris@0
|
3842 } else {
|
Chris@0
|
3843 CommandHistory::getInstance()->documentSaved();
|
Chris@0
|
3844 documentRestored();
|
Chris@0
|
3845 }
|
Chris@0
|
3846 } else {
|
Chris@0
|
3847 saveSessionAs();
|
Chris@0
|
3848 }
|
Chris@0
|
3849 }
|
Chris@0
|
3850
|
Chris@0
|
3851 void
|
Chris@0
|
3852 MainWindow::saveSessionAs()
|
Chris@0
|
3853 {
|
Chris@0
|
3854 QString orig = m_audioFile;
|
Chris@0
|
3855 if (orig == "") orig = ".";
|
Chris@0
|
3856 else orig = QFileInfo(orig).absoluteDir().canonicalPath();
|
Chris@0
|
3857
|
Chris@88
|
3858 QString path = getSaveFileName(FileFinder::SessionFile);
|
Chris@81
|
3859
|
Chris@81
|
3860 if (path == "") return;
|
Chris@0
|
3861
|
Chris@0
|
3862 if (!saveSessionFile(path)) {
|
Chris@0
|
3863 QMessageBox::critical(this, tr("Failed to save file"),
|
Chris@193
|
3864 tr("<b>Save failed</b><p>Session file \"%1\" could not be saved.").arg(path));
|
Chris@0
|
3865 } else {
|
Chris@0
|
3866 setWindowTitle(tr("Sonic Visualiser: %1")
|
Chris@0
|
3867 .arg(QFileInfo(path).fileName()));
|
Chris@0
|
3868 m_sessionFile = path;
|
Chris@0
|
3869 CommandHistory::getInstance()->documentSaved();
|
Chris@0
|
3870 documentRestored();
|
Chris@34
|
3871 m_recentFiles.addFile(path);
|
Chris@0
|
3872 }
|
Chris@0
|
3873 }
|
Chris@0
|
3874
|
Chris@0
|
3875 bool
|
Chris@0
|
3876 MainWindow::saveSessionFile(QString path)
|
Chris@0
|
3877 {
|
Chris@0
|
3878 BZipFileDevice bzFile(path);
|
Chris@0
|
3879 if (!bzFile.open(QIODevice::WriteOnly)) {
|
Chris@0
|
3880 std::cerr << "Failed to open session file \"" << path.toStdString()
|
Chris@0
|
3881 << "\" for writing: "
|
Chris@0
|
3882 << bzFile.errorString().toStdString() << std::endl;
|
Chris@0
|
3883 return false;
|
Chris@0
|
3884 }
|
Chris@0
|
3885
|
Chris@0
|
3886 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
|
Chris@0
|
3887
|
Chris@0
|
3888 QTextStream out(&bzFile);
|
Chris@0
|
3889 toXml(out);
|
Chris@0
|
3890 out.flush();
|
Chris@0
|
3891
|
Chris@0
|
3892 QApplication::restoreOverrideCursor();
|
Chris@0
|
3893
|
Chris@84
|
3894 if (!bzFile.isOK()) {
|
Chris@0
|
3895 QMessageBox::critical(this, tr("Failed to write file"),
|
Chris@193
|
3896 tr("<b>Save failed</b><p>Failed to write to file \"%1\": %2")
|
Chris@0
|
3897 .arg(path).arg(bzFile.errorString()));
|
Chris@0
|
3898 bzFile.close();
|
Chris@0
|
3899 return false;
|
Chris@0
|
3900 }
|
Chris@0
|
3901
|
Chris@0
|
3902 bzFile.close();
|
Chris@0
|
3903 return true;
|
Chris@0
|
3904 }
|
Chris@0
|
3905
|
Chris@0
|
3906 void
|
Chris@0
|
3907 MainWindow::toXml(QTextStream &out)
|
Chris@0
|
3908 {
|
Chris@0
|
3909 QString indent(" ");
|
Chris@0
|
3910
|
Chris@0
|
3911 out << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
|
Chris@0
|
3912 out << "<!DOCTYPE sonic-visualiser>\n";
|
Chris@0
|
3913 out << "<sv>\n";
|
Chris@0
|
3914
|
Chris@0
|
3915 m_document->toXml(out, "", "");
|
Chris@0
|
3916
|
Chris@0
|
3917 out << "<display>\n";
|
Chris@0
|
3918
|
Chris@0
|
3919 out << QString(" <window width=\"%1\" height=\"%2\"/>\n")
|
Chris@0
|
3920 .arg(width()).arg(height());
|
Chris@0
|
3921
|
Chris@0
|
3922 for (int i = 0; i < m_paneStack->getPaneCount(); ++i) {
|
Chris@0
|
3923
|
Chris@0
|
3924 Pane *pane = m_paneStack->getPane(i);
|
Chris@0
|
3925
|
Chris@0
|
3926 if (pane) {
|
Chris@0
|
3927 pane->toXml(out, indent);
|
Chris@0
|
3928 }
|
Chris@0
|
3929 }
|
Chris@0
|
3930
|
Chris@0
|
3931 out << "</display>\n";
|
Chris@0
|
3932
|
Chris@0
|
3933 m_viewManager->getSelection().toXml(out);
|
Chris@0
|
3934
|
Chris@0
|
3935 out << "</sv>\n";
|
Chris@0
|
3936 }
|
Chris@0
|
3937
|
Chris@0
|
3938 Pane *
|
Chris@0
|
3939 MainWindow::addPaneToStack()
|
Chris@0
|
3940 {
|
Chris@0
|
3941 AddPaneCommand *command = new AddPaneCommand(this);
|
Chris@0
|
3942 CommandHistory::getInstance()->addCommand(command);
|
Chris@0
|
3943 return command->getPane();
|
Chris@0
|
3944 }
|
Chris@0
|
3945
|
Chris@0
|
3946 void
|
Chris@0
|
3947 MainWindow::zoomIn()
|
Chris@0
|
3948 {
|
Chris@0
|
3949 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@0
|
3950 if (currentPane) currentPane->zoom(true);
|
Chris@0
|
3951 }
|
Chris@0
|
3952
|
Chris@0
|
3953 void
|
Chris@0
|
3954 MainWindow::zoomOut()
|
Chris@0
|
3955 {
|
Chris@0
|
3956 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@0
|
3957 if (currentPane) currentPane->zoom(false);
|
Chris@0
|
3958 }
|
Chris@0
|
3959
|
Chris@0
|
3960 void
|
Chris@0
|
3961 MainWindow::zoomToFit()
|
Chris@0
|
3962 {
|
Chris@0
|
3963 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@0
|
3964 if (!currentPane) return;
|
Chris@0
|
3965
|
Chris@0
|
3966 Model *model = getMainModel();
|
Chris@0
|
3967 if (!model) return;
|
Chris@0
|
3968
|
Chris@0
|
3969 size_t start = model->getStartFrame();
|
Chris@0
|
3970 size_t end = model->getEndFrame();
|
Chris@0
|
3971 size_t pixels = currentPane->width();
|
Chris@159
|
3972
|
Chris@158
|
3973 size_t sw = currentPane->getVerticalScaleWidth();
|
Chris@158
|
3974 if (pixels > sw * 2) pixels -= sw * 2;
|
Chris@158
|
3975 else pixels = 1;
|
Chris@159
|
3976 if (pixels > 4) pixels -= 4;
|
Chris@159
|
3977
|
Chris@0
|
3978 size_t zoomLevel = (end - start) / pixels;
|
Chris@0
|
3979
|
Chris@0
|
3980 currentPane->setZoomLevel(zoomLevel);
|
Chris@159
|
3981 currentPane->setCentreFrame((start + end) / 2);
|
Chris@0
|
3982 }
|
Chris@0
|
3983
|
Chris@0
|
3984 void
|
Chris@0
|
3985 MainWindow::zoomDefault()
|
Chris@0
|
3986 {
|
Chris@0
|
3987 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@0
|
3988 if (currentPane) currentPane->setZoomLevel(1024);
|
Chris@0
|
3989 }
|
Chris@0
|
3990
|
Chris@0
|
3991 void
|
Chris@0
|
3992 MainWindow::scrollLeft()
|
Chris@0
|
3993 {
|
Chris@0
|
3994 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@0
|
3995 if (currentPane) currentPane->scroll(false, false);
|
Chris@0
|
3996 }
|
Chris@0
|
3997
|
Chris@0
|
3998 void
|
Chris@0
|
3999 MainWindow::jumpLeft()
|
Chris@0
|
4000 {
|
Chris@0
|
4001 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@0
|
4002 if (currentPane) currentPane->scroll(false, true);
|
Chris@0
|
4003 }
|
Chris@0
|
4004
|
Chris@0
|
4005 void
|
Chris@0
|
4006 MainWindow::scrollRight()
|
Chris@0
|
4007 {
|
Chris@0
|
4008 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@0
|
4009 if (currentPane) currentPane->scroll(true, false);
|
Chris@0
|
4010 }
|
Chris@0
|
4011
|
Chris@0
|
4012 void
|
Chris@0
|
4013 MainWindow::jumpRight()
|
Chris@0
|
4014 {
|
Chris@0
|
4015 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@0
|
4016 if (currentPane) currentPane->scroll(true, true);
|
Chris@0
|
4017 }
|
Chris@0
|
4018
|
Chris@0
|
4019 void
|
Chris@0
|
4020 MainWindow::showNoOverlays()
|
Chris@0
|
4021 {
|
Chris@0
|
4022 m_viewManager->setOverlayMode(ViewManager::NoOverlays);
|
Chris@0
|
4023 }
|
Chris@0
|
4024
|
Chris@0
|
4025 void
|
Chris@90
|
4026 MainWindow::showMinimalOverlays()
|
Chris@0
|
4027 {
|
Chris@90
|
4028 m_viewManager->setOverlayMode(ViewManager::MinimalOverlays);
|
Chris@0
|
4029 }
|
Chris@0
|
4030
|
Chris@0
|
4031 void
|
Chris@90
|
4032 MainWindow::showStandardOverlays()
|
Chris@90
|
4033 {
|
Chris@90
|
4034 m_viewManager->setOverlayMode(ViewManager::StandardOverlays);
|
Chris@90
|
4035 }
|
Chris@90
|
4036
|
Chris@90
|
4037 void
|
Chris@90
|
4038 MainWindow::showAllOverlays()
|
Chris@0
|
4039 {
|
Chris@0
|
4040 m_viewManager->setOverlayMode(ViewManager::AllOverlays);
|
Chris@0
|
4041 }
|
Chris@0
|
4042
|
Chris@0
|
4043 void
|
Chris@7
|
4044 MainWindow::toggleZoomWheels()
|
Chris@7
|
4045 {
|
Chris@7
|
4046 if (m_viewManager->getZoomWheelsEnabled()) {
|
Chris@7
|
4047 m_viewManager->setZoomWheelsEnabled(false);
|
Chris@7
|
4048 } else {
|
Chris@7
|
4049 m_viewManager->setZoomWheelsEnabled(true);
|
Chris@7
|
4050 }
|
Chris@7
|
4051 }
|
Chris@7
|
4052
|
Chris@7
|
4053 void
|
Chris@72
|
4054 MainWindow::togglePropertyBoxes()
|
Chris@72
|
4055 {
|
Chris@72
|
4056 if (m_paneStack->getLayoutStyle() == PaneStack::NoPropertyStacks) {
|
Chris@72
|
4057 if (Preferences::getInstance()->getPropertyBoxLayout() ==
|
Chris@72
|
4058 Preferences::VerticallyStacked) {
|
Chris@72
|
4059 m_paneStack->setLayoutStyle(PaneStack::PropertyStackPerPaneLayout);
|
Chris@72
|
4060 } else {
|
Chris@72
|
4061 m_paneStack->setLayoutStyle(PaneStack::SinglePropertyStackLayout);
|
Chris@72
|
4062 }
|
Chris@72
|
4063 } else {
|
Chris@72
|
4064 m_paneStack->setLayoutStyle(PaneStack::NoPropertyStacks);
|
Chris@72
|
4065 }
|
Chris@72
|
4066 }
|
Chris@72
|
4067
|
Chris@72
|
4068 void
|
Chris@90
|
4069 MainWindow::toggleStatusBar()
|
Chris@90
|
4070 {
|
Chris@90
|
4071 QSettings settings;
|
Chris@90
|
4072 settings.beginGroup("MainWindow");
|
Chris@90
|
4073 bool sb = settings.value("showstatusbar", true).toBool();
|
Chris@90
|
4074
|
Chris@90
|
4075 if (sb) {
|
Chris@90
|
4076 statusBar()->hide();
|
Chris@90
|
4077 } else {
|
Chris@90
|
4078 statusBar()->show();
|
Chris@90
|
4079 }
|
Chris@90
|
4080
|
Chris@90
|
4081 settings.setValue("showstatusbar", !sb);
|
Chris@90
|
4082
|
Chris@90
|
4083 settings.endGroup();
|
Chris@90
|
4084 }
|
Chris@90
|
4085
|
Chris@90
|
4086 void
|
Chris@72
|
4087 MainWindow::preferenceChanged(PropertyContainer::PropertyName name)
|
Chris@72
|
4088 {
|
Chris@72
|
4089 if (name == "Property Box Layout") {
|
Chris@72
|
4090 if (m_paneStack->getLayoutStyle() != PaneStack::NoPropertyStacks) {
|
Chris@72
|
4091 if (Preferences::getInstance()->getPropertyBoxLayout() ==
|
Chris@72
|
4092 Preferences::VerticallyStacked) {
|
Chris@72
|
4093 m_paneStack->setLayoutStyle(PaneStack::PropertyStackPerPaneLayout);
|
Chris@72
|
4094 } else {
|
Chris@72
|
4095 m_paneStack->setLayoutStyle(PaneStack::SinglePropertyStackLayout);
|
Chris@72
|
4096 }
|
Chris@72
|
4097 }
|
Chris@180
|
4098 } else if (name == "Background Mode" && m_viewManager) {
|
Chris@180
|
4099 Preferences::BackgroundMode mode =
|
Chris@180
|
4100 Preferences::getInstance()->getBackgroundMode();
|
Chris@180
|
4101 if (mode == Preferences::BackgroundFromTheme) {
|
Chris@180
|
4102 m_viewManager->setGlobalDarkBackground(m_initialDarkBackground);
|
Chris@180
|
4103 } else if (mode == Preferences::DarkBackground) {
|
Chris@180
|
4104 m_viewManager->setGlobalDarkBackground(true);
|
Chris@180
|
4105 } else {
|
Chris@180
|
4106 m_viewManager->setGlobalDarkBackground(false);
|
Chris@180
|
4107 }
|
Chris@180
|
4108 if (m_viewManager->getGlobalDarkBackground()) {
|
Chris@180
|
4109 m_panLayer->setBaseColour
|
Chris@180
|
4110 (ColourDatabase::getInstance()->getColourIndex(tr("Bright Green")));
|
Chris@180
|
4111 } else {
|
Chris@180
|
4112 m_panLayer->setBaseColour
|
Chris@180
|
4113 (ColourDatabase::getInstance()->getColourIndex(tr("Green")));
|
Chris@180
|
4114 }
|
Chris@180
|
4115 }
|
Chris@72
|
4116 }
|
Chris@72
|
4117
|
Chris@72
|
4118 void
|
Chris@0
|
4119 MainWindow::play()
|
Chris@0
|
4120 {
|
Chris@0
|
4121 if (m_playSource->isPlaying()) {
|
Chris@116
|
4122 stop();
|
Chris@0
|
4123 } else {
|
Chris@116
|
4124 playbackFrameChanged(m_viewManager->getPlaybackFrame());
|
Chris@0
|
4125 m_playSource->play(m_viewManager->getPlaybackFrame());
|
Chris@0
|
4126 }
|
Chris@0
|
4127 }
|
Chris@0
|
4128
|
Chris@0
|
4129 void
|
Chris@0
|
4130 MainWindow::ffwd()
|
Chris@0
|
4131 {
|
Chris@0
|
4132 if (!getMainModel()) return;
|
Chris@0
|
4133
|
Chris@0
|
4134 int frame = m_viewManager->getPlaybackFrame();
|
Chris@0
|
4135 ++frame;
|
Chris@0
|
4136
|
Chris@155
|
4137 Layer *layer = getSnapLayer();
|
Chris@155
|
4138 size_t sr = getMainModel()->getSampleRate();
|
Chris@155
|
4139
|
Chris@155
|
4140 if (!layer) {
|
Chris@155
|
4141
|
Chris@155
|
4142 frame = RealTime::realTime2Frame
|
Chris@155
|
4143 (RealTime::frame2RealTime(frame, sr) + RealTime(2, 0), sr);
|
Chris@155
|
4144 if (frame > int(getMainModel()->getEndFrame())) {
|
Chris@155
|
4145 frame = getMainModel()->getEndFrame();
|
Chris@155
|
4146 }
|
Chris@155
|
4147
|
Chris@155
|
4148 } else {
|
Chris@155
|
4149
|
Chris@155
|
4150 size_t resolution = 0;
|
Chris@155
|
4151 if (!layer->snapToFeatureFrame(m_paneStack->getCurrentPane(),
|
Chris@155
|
4152 frame, resolution, Layer::SnapRight)) {
|
Chris@155
|
4153 frame = getMainModel()->getEndFrame();
|
Chris@155
|
4154 }
|
Chris@0
|
4155 }
|
Chris@155
|
4156
|
Chris@155
|
4157 if (frame < 0) frame = 0;
|
Chris@147
|
4158
|
Chris@147
|
4159 if (m_viewManager->getPlaySelectionMode()) {
|
Chris@155
|
4160 frame = m_viewManager->constrainFrameToSelection(size_t(frame));
|
Chris@147
|
4161 }
|
Chris@0
|
4162
|
Chris@0
|
4163 m_viewManager->setPlaybackFrame(frame);
|
Chris@0
|
4164 }
|
Chris@0
|
4165
|
Chris@0
|
4166 void
|
Chris@0
|
4167 MainWindow::ffwdEnd()
|
Chris@0
|
4168 {
|
Chris@0
|
4169 if (!getMainModel()) return;
|
Chris@147
|
4170
|
Chris@147
|
4171 size_t frame = getMainModel()->getEndFrame();
|
Chris@147
|
4172
|
Chris@147
|
4173 if (m_viewManager->getPlaySelectionMode()) {
|
Chris@155
|
4174 frame = m_viewManager->constrainFrameToSelection(frame);
|
Chris@147
|
4175 }
|
Chris@147
|
4176
|
Chris@147
|
4177 m_viewManager->setPlaybackFrame(frame);
|
Chris@0
|
4178 }
|
Chris@0
|
4179
|
Chris@0
|
4180 void
|
Chris@0
|
4181 MainWindow::rewind()
|
Chris@0
|
4182 {
|
Chris@0
|
4183 if (!getMainModel()) return;
|
Chris@0
|
4184
|
Chris@0
|
4185 int frame = m_viewManager->getPlaybackFrame();
|
Chris@0
|
4186 if (frame > 0) --frame;
|
Chris@0
|
4187
|
Chris@155
|
4188 Layer *layer = getSnapLayer();
|
Chris@155
|
4189 size_t sr = getMainModel()->getSampleRate();
|
Chris@156
|
4190
|
Chris@156
|
4191 // when rewinding during playback, we want to allow a period
|
Chris@156
|
4192 // following a rewind target point at which the rewind will go to
|
Chris@156
|
4193 // the prior point instead of the immediately neighbouring one
|
Chris@156
|
4194 if (m_playSource && m_playSource->isPlaying()) {
|
Chris@156
|
4195 RealTime ct = RealTime::frame2RealTime(frame, sr);
|
Chris@156
|
4196 ct = ct - RealTime::fromSeconds(0.25);
|
Chris@156
|
4197 if (ct < RealTime::zeroTime) ct = RealTime::zeroTime;
|
Chris@156
|
4198 // std::cerr << "rewind: frame " << frame << " -> ";
|
Chris@156
|
4199 frame = RealTime::realTime2Frame(ct, sr);
|
Chris@156
|
4200 // std::cerr << frame << std::endl;
|
Chris@156
|
4201 }
|
Chris@155
|
4202
|
Chris@155
|
4203 if (!layer) {
|
Chris@155
|
4204
|
Chris@155
|
4205 frame = RealTime::realTime2Frame
|
Chris@155
|
4206 (RealTime::frame2RealTime(frame, sr) - RealTime(2, 0), sr);
|
Chris@155
|
4207 if (frame < int(getMainModel()->getStartFrame())) {
|
Chris@155
|
4208 frame = getMainModel()->getStartFrame();
|
Chris@155
|
4209 }
|
Chris@155
|
4210
|
Chris@155
|
4211 } else {
|
Chris@155
|
4212
|
Chris@155
|
4213 size_t resolution = 0;
|
Chris@155
|
4214 if (!layer->snapToFeatureFrame(m_paneStack->getCurrentPane(),
|
Chris@155
|
4215 frame, resolution, Layer::SnapLeft)) {
|
Chris@155
|
4216 frame = getMainModel()->getStartFrame();
|
Chris@155
|
4217 }
|
Chris@0
|
4218 }
|
Chris@147
|
4219
|
Chris@155
|
4220 if (frame < 0) frame = 0;
|
Chris@155
|
4221
|
Chris@147
|
4222 if (m_viewManager->getPlaySelectionMode()) {
|
Chris@155
|
4223 frame = m_viewManager->constrainFrameToSelection(size_t(frame));
|
Chris@147
|
4224 }
|
Chris@147
|
4225
|
Chris@0
|
4226 m_viewManager->setPlaybackFrame(frame);
|
Chris@0
|
4227 }
|
Chris@0
|
4228
|
Chris@0
|
4229 void
|
Chris@0
|
4230 MainWindow::rewindStart()
|
Chris@0
|
4231 {
|
Chris@0
|
4232 if (!getMainModel()) return;
|
Chris@147
|
4233
|
Chris@147
|
4234 size_t frame = getMainModel()->getStartFrame();
|
Chris@147
|
4235
|
Chris@147
|
4236 if (m_viewManager->getPlaySelectionMode()) {
|
Chris@155
|
4237 frame = m_viewManager->constrainFrameToSelection(frame);
|
Chris@155
|
4238 }
|
Chris@155
|
4239
|
Chris@155
|
4240 m_viewManager->setPlaybackFrame(frame);
|
Chris@155
|
4241 }
|
Chris@155
|
4242
|
Chris@155
|
4243 Layer *
|
Chris@155
|
4244 MainWindow::getSnapLayer() const
|
Chris@155
|
4245 {
|
Chris@155
|
4246 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@155
|
4247 if (!pane) return 0;
|
Chris@155
|
4248
|
Chris@155
|
4249 Layer *layer = pane->getSelectedLayer();
|
Chris@155
|
4250
|
Chris@155
|
4251 if (!dynamic_cast<TimeInstantLayer *>(layer) &&
|
Chris@155
|
4252 !dynamic_cast<TimeValueLayer *>(layer) &&
|
Chris@155
|
4253 !dynamic_cast<TimeRulerLayer *>(layer)) {
|
Chris@155
|
4254
|
Chris@155
|
4255 layer = 0;
|
Chris@155
|
4256
|
Chris@155
|
4257 for (int i = pane->getLayerCount(); i > 0; --i) {
|
Chris@155
|
4258 Layer *l = pane->getLayer(i-1);
|
Chris@155
|
4259 if (dynamic_cast<TimeRulerLayer *>(l)) {
|
Chris@155
|
4260 layer = l;
|
Chris@155
|
4261 break;
|
Chris@155
|
4262 }
|
Chris@147
|
4263 }
|
Chris@147
|
4264 }
|
Chris@147
|
4265
|
Chris@155
|
4266 return layer;
|
Chris@0
|
4267 }
|
Chris@0
|
4268
|
Chris@0
|
4269 void
|
Chris@0
|
4270 MainWindow::stop()
|
Chris@0
|
4271 {
|
Chris@0
|
4272 m_playSource->stop();
|
Chris@116
|
4273
|
Chris@116
|
4274 if (m_paneStack && m_paneStack->getCurrentPane()) {
|
Chris@116
|
4275 updateVisibleRangeDisplay(m_paneStack->getCurrentPane());
|
Chris@116
|
4276 } else {
|
Chris@116
|
4277 m_myStatusMessage = "";
|
Chris@116
|
4278 statusBar()->showMessage("");
|
Chris@116
|
4279 }
|
Chris@0
|
4280 }
|
Chris@0
|
4281
|
Chris@0
|
4282 void
|
Chris@0
|
4283 MainWindow::addPane()
|
Chris@0
|
4284 {
|
Chris@0
|
4285 QObject *s = sender();
|
Chris@0
|
4286 QAction *action = dynamic_cast<QAction *>(s);
|
Chris@0
|
4287
|
Chris@0
|
4288 if (!action) {
|
Chris@0
|
4289 std::cerr << "WARNING: MainWindow::addPane: sender is not an action"
|
Chris@0
|
4290 << std::endl;
|
Chris@0
|
4291 return;
|
Chris@0
|
4292 }
|
Chris@0
|
4293
|
Chris@0
|
4294 PaneActionMap::iterator i = m_paneActions.find(action);
|
Chris@0
|
4295
|
Chris@0
|
4296 if (i == m_paneActions.end()) {
|
Chris@0
|
4297 std::cerr << "WARNING: MainWindow::addPane: unknown action "
|
Chris@0
|
4298 << action->objectName().toStdString() << std::endl;
|
Chris@0
|
4299 return;
|
Chris@0
|
4300 }
|
Chris@0
|
4301
|
Chris@69
|
4302 addPane(i->second, action->text());
|
Chris@69
|
4303 }
|
Chris@69
|
4304
|
Chris@69
|
4305 void
|
Chris@69
|
4306 MainWindow::addPane(const PaneConfiguration &configuration, QString text)
|
Chris@69
|
4307 {
|
Chris@69
|
4308 CommandHistory::getInstance()->startCompoundOperation(text, true);
|
Chris@0
|
4309
|
Chris@0
|
4310 AddPaneCommand *command = new AddPaneCommand(this);
|
Chris@0
|
4311 CommandHistory::getInstance()->addCommand(command);
|
Chris@0
|
4312
|
Chris@0
|
4313 Pane *pane = command->getPane();
|
Chris@0
|
4314
|
Chris@69
|
4315 if (configuration.layer == LayerFactory::Spectrum) {
|
Chris@109
|
4316 pane->setPlaybackFollow(PlaybackScrollContinuous);
|
Chris@110
|
4317 pane->setFollowGlobalZoom(false);
|
Chris@112
|
4318 pane->setZoomLevel(512);
|
Chris@7
|
4319 }
|
Chris@7
|
4320
|
Chris@69
|
4321 if (configuration.layer != LayerFactory::TimeRuler &&
|
Chris@69
|
4322 configuration.layer != LayerFactory::Spectrum) {
|
Chris@8
|
4323
|
Chris@0
|
4324 if (!m_timeRulerLayer) {
|
Chris@0
|
4325 // std::cerr << "no time ruler layer, creating one" << std::endl;
|
Chris@0
|
4326 m_timeRulerLayer = m_document->createMainModelLayer
|
Chris@0
|
4327 (LayerFactory::TimeRuler);
|
Chris@0
|
4328 }
|
Chris@0
|
4329
|
Chris@0
|
4330 // std::cerr << "adding time ruler layer " << m_timeRulerLayer << std::endl;
|
Chris@0
|
4331
|
Chris@0
|
4332 m_document->addLayerToView(pane, m_timeRulerLayer);
|
Chris@0
|
4333 }
|
Chris@0
|
4334
|
Chris@69
|
4335 Layer *newLayer = m_document->createLayer(configuration.layer);
|
Chris@69
|
4336
|
Chris@69
|
4337 Model *suggestedModel = configuration.sourceModel;
|
Chris@66
|
4338 Model *model = 0;
|
Chris@66
|
4339
|
Chris@66
|
4340 if (suggestedModel) {
|
Chris@66
|
4341
|
Chris@66
|
4342 // check its validity
|
Chris@66
|
4343 std::vector<Model *> inputModels = m_document->getTransformInputModels();
|
Chris@66
|
4344 for (size_t j = 0; j < inputModels.size(); ++j) {
|
Chris@66
|
4345 if (inputModels[j] == suggestedModel) {
|
Chris@66
|
4346 model = suggestedModel;
|
Chris@66
|
4347 break;
|
Chris@66
|
4348 }
|
Chris@66
|
4349 }
|
Chris@66
|
4350
|
Chris@66
|
4351 if (!model) {
|
Chris@66
|
4352 std::cerr << "WARNING: Model " << (void *)suggestedModel
|
Chris@66
|
4353 << " appears in pane action map, but is not reported "
|
Chris@66
|
4354 << "by document as a valid transform source" << std::endl;
|
Chris@66
|
4355 }
|
Chris@66
|
4356 }
|
Chris@66
|
4357
|
Chris@66
|
4358 if (!model) model = m_document->getMainModel();
|
Chris@66
|
4359
|
Chris@66
|
4360 m_document->setModel(newLayer, model);
|
Chris@66
|
4361
|
Chris@69
|
4362 m_document->setChannel(newLayer, configuration.channel);
|
Chris@0
|
4363 m_document->addLayerToView(pane, newLayer);
|
Chris@0
|
4364
|
Chris@0
|
4365 m_paneStack->setCurrentPane(pane);
|
Chris@70
|
4366 m_paneStack->setCurrentLayer(pane, newLayer);
|
Chris@0
|
4367
|
Chris@130
|
4368 // std::cerr << "MainWindow::addPane: global centre frame is "
|
Chris@130
|
4369 // << m_viewManager->getGlobalCentreFrame() << std::endl;
|
Chris@130
|
4370 // pane->setCentreFrame(m_viewManager->getGlobalCentreFrame());
|
Chris@73
|
4371
|
Chris@0
|
4372 CommandHistory::getInstance()->endCompoundOperation();
|
Chris@0
|
4373
|
Chris@0
|
4374 updateMenuStates();
|
Chris@0
|
4375 }
|
Chris@0
|
4376
|
Chris@0
|
4377 MainWindow::AddPaneCommand::AddPaneCommand(MainWindow *mw) :
|
Chris@0
|
4378 m_mw(mw),
|
Chris@0
|
4379 m_pane(0),
|
Chris@0
|
4380 m_prevCurrentPane(0),
|
Chris@0
|
4381 m_added(false)
|
Chris@0
|
4382 {
|
Chris@0
|
4383 }
|
Chris@0
|
4384
|
Chris@0
|
4385 MainWindow::AddPaneCommand::~AddPaneCommand()
|
Chris@0
|
4386 {
|
Chris@0
|
4387 if (m_pane && !m_added) {
|
Chris@0
|
4388 m_mw->m_paneStack->deletePane(m_pane);
|
Chris@0
|
4389 }
|
Chris@0
|
4390 }
|
Chris@0
|
4391
|
Chris@0
|
4392 QString
|
Chris@0
|
4393 MainWindow::AddPaneCommand::getName() const
|
Chris@0
|
4394 {
|
Chris@0
|
4395 return tr("Add Pane");
|
Chris@0
|
4396 }
|
Chris@0
|
4397
|
Chris@0
|
4398 void
|
Chris@0
|
4399 MainWindow::AddPaneCommand::execute()
|
Chris@0
|
4400 {
|
Chris@0
|
4401 if (!m_pane) {
|
Chris@0
|
4402 m_prevCurrentPane = m_mw->m_paneStack->getCurrentPane();
|
Chris@0
|
4403 m_pane = m_mw->m_paneStack->addPane();
|
Chris@90
|
4404
|
Chris@90
|
4405 connect(m_pane, SIGNAL(contextHelpChanged(const QString &)),
|
Chris@116
|
4406 m_mw, SLOT(contextHelpChanged(const QString &)));
|
Chris@0
|
4407 } else {
|
Chris@0
|
4408 m_mw->m_paneStack->showPane(m_pane);
|
Chris@0
|
4409 }
|
Chris@0
|
4410
|
Chris@0
|
4411 m_mw->m_paneStack->setCurrentPane(m_pane);
|
Chris@65
|
4412 m_mw->m_overview->registerView(m_pane);
|
Chris@0
|
4413 m_added = true;
|
Chris@0
|
4414 }
|
Chris@0
|
4415
|
Chris@0
|
4416 void
|
Chris@0
|
4417 MainWindow::AddPaneCommand::unexecute()
|
Chris@0
|
4418 {
|
Chris@0
|
4419 m_mw->m_paneStack->hidePane(m_pane);
|
Chris@0
|
4420 m_mw->m_paneStack->setCurrentPane(m_prevCurrentPane);
|
Chris@65
|
4421 m_mw->m_overview->unregisterView(m_pane);
|
Chris@0
|
4422 m_added = false;
|
Chris@0
|
4423 }
|
Chris@0
|
4424
|
Chris@0
|
4425 MainWindow::RemovePaneCommand::RemovePaneCommand(MainWindow *mw, Pane *pane) :
|
Chris@0
|
4426 m_mw(mw),
|
Chris@0
|
4427 m_pane(pane),
|
Chris@0
|
4428 m_added(true)
|
Chris@0
|
4429 {
|
Chris@0
|
4430 }
|
Chris@0
|
4431
|
Chris@0
|
4432 MainWindow::RemovePaneCommand::~RemovePaneCommand()
|
Chris@0
|
4433 {
|
Chris@0
|
4434 if (m_pane && !m_added) {
|
Chris@0
|
4435 m_mw->m_paneStack->deletePane(m_pane);
|
Chris@0
|
4436 }
|
Chris@0
|
4437 }
|
Chris@0
|
4438
|
Chris@0
|
4439 QString
|
Chris@0
|
4440 MainWindow::RemovePaneCommand::getName() const
|
Chris@0
|
4441 {
|
Chris@0
|
4442 return tr("Remove Pane");
|
Chris@0
|
4443 }
|
Chris@0
|
4444
|
Chris@0
|
4445 void
|
Chris@0
|
4446 MainWindow::RemovePaneCommand::execute()
|
Chris@0
|
4447 {
|
Chris@0
|
4448 m_prevCurrentPane = m_mw->m_paneStack->getCurrentPane();
|
Chris@0
|
4449 m_mw->m_paneStack->hidePane(m_pane);
|
Chris@65
|
4450 m_mw->m_overview->unregisterView(m_pane);
|
Chris@0
|
4451 m_added = false;
|
Chris@0
|
4452 }
|
Chris@0
|
4453
|
Chris@0
|
4454 void
|
Chris@0
|
4455 MainWindow::RemovePaneCommand::unexecute()
|
Chris@0
|
4456 {
|
Chris@0
|
4457 m_mw->m_paneStack->showPane(m_pane);
|
Chris@0
|
4458 m_mw->m_paneStack->setCurrentPane(m_prevCurrentPane);
|
Chris@65
|
4459 m_mw->m_overview->registerView(m_pane);
|
Chris@0
|
4460 m_added = true;
|
Chris@0
|
4461 }
|
Chris@0
|
4462
|
Chris@0
|
4463 void
|
Chris@0
|
4464 MainWindow::addLayer()
|
Chris@0
|
4465 {
|
Chris@0
|
4466 QObject *s = sender();
|
Chris@0
|
4467 QAction *action = dynamic_cast<QAction *>(s);
|
Chris@0
|
4468
|
Chris@0
|
4469 if (!action) {
|
Chris@0
|
4470 std::cerr << "WARNING: MainWindow::addLayer: sender is not an action"
|
Chris@0
|
4471 << std::endl;
|
Chris@0
|
4472 return;
|
Chris@0
|
4473 }
|
Chris@0
|
4474
|
Chris@0
|
4475 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@0
|
4476
|
Chris@0
|
4477 if (!pane) {
|
Chris@0
|
4478 std::cerr << "WARNING: MainWindow::addLayer: no current pane" << std::endl;
|
Chris@0
|
4479 return;
|
Chris@0
|
4480 }
|
Chris@0
|
4481
|
Chris@0
|
4482 ExistingLayerActionMap::iterator ei = m_existingLayerActions.find(action);
|
Chris@0
|
4483
|
Chris@0
|
4484 if (ei != m_existingLayerActions.end()) {
|
Chris@0
|
4485 Layer *newLayer = ei->second;
|
Chris@0
|
4486 m_document->addLayerToView(pane, newLayer);
|
Chris@0
|
4487 m_paneStack->setCurrentLayer(pane, newLayer);
|
Chris@0
|
4488 return;
|
Chris@0
|
4489 }
|
Chris@0
|
4490
|
Chris@95
|
4491 ei = m_sliceActions.find(action);
|
Chris@95
|
4492
|
Chris@95
|
4493 if (ei != m_sliceActions.end()) {
|
Chris@95
|
4494 Layer *newLayer = m_document->createLayer(LayerFactory::Slice);
|
Chris@95
|
4495 // document->setModel(newLayer, ei->second->getModel());
|
Chris@95
|
4496 SliceableLayer *source = dynamic_cast<SliceableLayer *>(ei->second);
|
Chris@95
|
4497 SliceLayer *dest = dynamic_cast<SliceLayer *>(newLayer);
|
Chris@95
|
4498 if (source && dest) {
|
Chris@95
|
4499 dest->setSliceableModel(source->getSliceableModel());
|
Chris@95
|
4500 connect(source, SIGNAL(sliceableModelReplaced(const Model *, const Model *)),
|
Chris@95
|
4501 dest, SLOT(sliceableModelReplaced(const Model *, const Model *)));
|
Chris@95
|
4502 connect(m_document, SIGNAL(modelAboutToBeDeleted(Model *)),
|
Chris@95
|
4503 dest, SLOT(modelAboutToBeDeleted(Model *)));
|
Chris@95
|
4504 }
|
Chris@95
|
4505 m_document->addLayerToView(pane, newLayer);
|
Chris@95
|
4506 m_paneStack->setCurrentLayer(pane, newLayer);
|
Chris@95
|
4507 return;
|
Chris@95
|
4508 }
|
Chris@95
|
4509
|
Chris@34
|
4510 TransformActionMap::iterator i = m_transformActions.find(action);
|
Chris@34
|
4511
|
Chris@34
|
4512 if (i == m_transformActions.end()) {
|
Chris@0
|
4513
|
Chris@0
|
4514 LayerActionMap::iterator i = m_layerActions.find(action);
|
Chris@0
|
4515
|
Chris@0
|
4516 if (i == m_layerActions.end()) {
|
Chris@0
|
4517 std::cerr << "WARNING: MainWindow::addLayer: unknown action "
|
Chris@0
|
4518 << action->objectName().toStdString() << std::endl;
|
Chris@0
|
4519 return;
|
Chris@0
|
4520 }
|
Chris@0
|
4521
|
Chris@0
|
4522 LayerFactory::LayerType type = i->second;
|
Chris@0
|
4523
|
Chris@0
|
4524 LayerFactory::LayerTypeSet emptyTypes =
|
Chris@0
|
4525 LayerFactory::getInstance()->getValidEmptyLayerTypes();
|
Chris@0
|
4526
|
Chris@0
|
4527 Layer *newLayer;
|
Chris@0
|
4528
|
Chris@0
|
4529 if (emptyTypes.find(type) != emptyTypes.end()) {
|
Chris@0
|
4530
|
Chris@0
|
4531 newLayer = m_document->createEmptyLayer(type);
|
Chris@0
|
4532 m_toolActions[ViewManager::DrawMode]->trigger();
|
Chris@0
|
4533
|
Chris@0
|
4534 } else {
|
Chris@0
|
4535
|
Chris@0
|
4536 newLayer = m_document->createMainModelLayer(type);
|
Chris@0
|
4537 }
|
Chris@0
|
4538
|
Chris@0
|
4539 m_document->addLayerToView(pane, newLayer);
|
Chris@0
|
4540 m_paneStack->setCurrentLayer(pane, newLayer);
|
Chris@0
|
4541
|
Chris@0
|
4542 return;
|
Chris@0
|
4543 }
|
Chris@0
|
4544
|
Chris@107
|
4545 TransformId transform = i->second;
|
Chris@0
|
4546 TransformFactory *factory = TransformFactory::getInstance();
|
Chris@0
|
4547
|
Chris@0
|
4548 QString configurationXml;
|
Chris@0
|
4549
|
Chris@0
|
4550 int channel = -1;
|
Chris@0
|
4551 // pick up the default channel from any existing layers on the same pane
|
Chris@0
|
4552 for (int j = 0; j < pane->getLayerCount(); ++j) {
|
Chris@0
|
4553 int c = LayerFactory::getInstance()->getChannel(pane->getLayer(j));
|
Chris@0
|
4554 if (c != -1) {
|
Chris@0
|
4555 channel = c;
|
Chris@0
|
4556 break;
|
Chris@0
|
4557 }
|
Chris@0
|
4558 }
|
Chris@0
|
4559
|
Chris@33
|
4560 // We always ask for configuration, even if the plugin isn't
|
Chris@33
|
4561 // supposed to be configurable, because we need to let the user
|
Chris@33
|
4562 // change the execution context (block size etc).
|
Chris@0
|
4563
|
Chris@27
|
4564 PluginTransform::ExecutionContext context(channel);
|
Chris@27
|
4565
|
Chris@66
|
4566 std::vector<Model *> candidateInputModels =
|
Chris@66
|
4567 m_document->getTransformInputModels();
|
Chris@53
|
4568
|
Chris@184
|
4569 size_t startFrame = 0, duration = 0;
|
Chris@184
|
4570 size_t endFrame = 0;
|
Chris@184
|
4571 m_viewManager->getSelection().getExtents(startFrame, endFrame);
|
Chris@184
|
4572 if (endFrame > startFrame) duration = endFrame - startFrame;
|
Chris@184
|
4573 else startFrame = 0;
|
Chris@184
|
4574
|
Chris@54
|
4575 Model *inputModel = factory->getConfigurationForTransform(transform,
|
Chris@54
|
4576 candidateInputModels,
|
Chris@54
|
4577 context,
|
Chris@54
|
4578 configurationXml,
|
Chris@184
|
4579 m_playSource,
|
Chris@184
|
4580 startFrame,
|
Chris@184
|
4581 duration);
|
Chris@54
|
4582 if (!inputModel) return;
|
Chris@54
|
4583
|
Chris@135
|
4584 // std::cerr << "MainWindow::addLayer: Input model is " << inputModel << " \"" << inputModel->objectName().toStdString() << "\"" << std::endl;
|
Chris@0
|
4585
|
Chris@0
|
4586 Layer *newLayer = m_document->createDerivedLayer(transform,
|
Chris@54
|
4587 inputModel,
|
Chris@27
|
4588 context,
|
Chris@0
|
4589 configurationXml);
|
Chris@0
|
4590
|
Chris@0
|
4591 if (newLayer) {
|
Chris@0
|
4592 m_document->addLayerToView(pane, newLayer);
|
Chris@27
|
4593 m_document->setChannel(newLayer, context.channel);
|
Chris@34
|
4594 m_recentTransforms.add(transform);
|
Chris@70
|
4595 m_paneStack->setCurrentLayer(pane, newLayer);
|
Chris@0
|
4596 }
|
Chris@0
|
4597
|
Chris@0
|
4598 updateMenuStates();
|
Chris@0
|
4599 }
|
Chris@0
|
4600
|
Chris@0
|
4601 void
|
Chris@0
|
4602 MainWindow::deleteCurrentPane()
|
Chris@0
|
4603 {
|
Chris@0
|
4604 CommandHistory::getInstance()->startCompoundOperation
|
Chris@0
|
4605 (tr("Delete Pane"), true);
|
Chris@0
|
4606
|
Chris@0
|
4607 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@0
|
4608 if (pane) {
|
Chris@0
|
4609 while (pane->getLayerCount() > 0) {
|
Chris@0
|
4610 Layer *layer = pane->getLayer(0);
|
Chris@0
|
4611 if (layer) {
|
Chris@0
|
4612 m_document->removeLayerFromView(pane, layer);
|
Chris@0
|
4613 } else {
|
Chris@0
|
4614 break;
|
Chris@0
|
4615 }
|
Chris@0
|
4616 }
|
Chris@0
|
4617
|
Chris@0
|
4618 RemovePaneCommand *command = new RemovePaneCommand(this, pane);
|
Chris@0
|
4619 CommandHistory::getInstance()->addCommand(command);
|
Chris@0
|
4620 }
|
Chris@0
|
4621
|
Chris@0
|
4622 CommandHistory::getInstance()->endCompoundOperation();
|
Chris@0
|
4623
|
Chris@0
|
4624 updateMenuStates();
|
Chris@0
|
4625 }
|
Chris@0
|
4626
|
Chris@0
|
4627 void
|
Chris@0
|
4628 MainWindow::deleteCurrentLayer()
|
Chris@0
|
4629 {
|
Chris@0
|
4630 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@0
|
4631 if (pane) {
|
Chris@0
|
4632 Layer *layer = pane->getSelectedLayer();
|
Chris@0
|
4633 if (layer) {
|
Chris@0
|
4634 m_document->removeLayerFromView(pane, layer);
|
Chris@0
|
4635 }
|
Chris@0
|
4636 }
|
Chris@0
|
4637 updateMenuStates();
|
Chris@0
|
4638 }
|
Chris@0
|
4639
|
Chris@0
|
4640 void
|
Chris@0
|
4641 MainWindow::renameCurrentLayer()
|
Chris@0
|
4642 {
|
Chris@0
|
4643 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@0
|
4644 if (pane) {
|
Chris@0
|
4645 Layer *layer = pane->getSelectedLayer();
|
Chris@0
|
4646 if (layer) {
|
Chris@0
|
4647 bool ok = false;
|
Chris@0
|
4648 QString newName = QInputDialog::getText
|
Chris@0
|
4649 (this, tr("Rename Layer"),
|
Chris@0
|
4650 tr("New name for this layer:"),
|
Chris@0
|
4651 QLineEdit::Normal, layer->objectName(), &ok);
|
Chris@0
|
4652 if (ok) {
|
Chris@0
|
4653 layer->setObjectName(newName);
|
Chris@95
|
4654 setupExistingLayersMenus();
|
Chris@0
|
4655 }
|
Chris@0
|
4656 }
|
Chris@0
|
4657 }
|
Chris@0
|
4658 }
|
Chris@0
|
4659
|
Chris@0
|
4660 void
|
Chris@59
|
4661 MainWindow::playSpeedChanged(int position)
|
Chris@0
|
4662 {
|
Chris@59
|
4663 PlaySpeedRangeMapper mapper(0, 200);
|
Chris@60
|
4664
|
Chris@60
|
4665 float percent = m_playSpeed->mappedValue();
|
Chris@60
|
4666 float factor = mapper.getFactorForValue(percent);
|
Chris@60
|
4667
|
Chris@60
|
4668 std::cerr << "speed = " << position << " percent = " << percent << " factor = " << factor << std::endl;
|
Chris@60
|
4669
|
Chris@59
|
4670 bool something = (position != 100);
|
Chris@155
|
4671
|
Chris@59
|
4672 int pc = lrintf(percent);
|
Chris@21
|
4673
|
Chris@155
|
4674 if (!something) {
|
Chris@155
|
4675 contextHelpChanged(tr("Playback speed: Normal"));
|
Chris@155
|
4676 } else {
|
Chris@155
|
4677 contextHelpChanged(tr("Playback speed: %1%2%")
|
Chris@155
|
4678 .arg(position > 100 ? "+" : "")
|
Chris@155
|
4679 .arg(pc));
|
Chris@155
|
4680 }
|
Chris@155
|
4681
|
Chris@25
|
4682 m_playSharpen->setEnabled(something);
|
Chris@26
|
4683 m_playMono->setEnabled(something);
|
Chris@25
|
4684 bool sharpen = (something && m_playSharpen->isChecked());
|
Chris@26
|
4685 bool mono = (something && m_playMono->isChecked());
|
Chris@26
|
4686 m_playSource->setTimeStretch(factor, sharpen, mono);
|
Chris@155
|
4687
|
Chris@155
|
4688 updateMenuStates();
|
Chris@16
|
4689 }
|
Chris@16
|
4690
|
Chris@16
|
4691 void
|
Chris@16
|
4692 MainWindow::playSharpenToggled()
|
Chris@16
|
4693 {
|
Chris@21
|
4694 QSettings settings;
|
Chris@21
|
4695 settings.beginGroup("MainWindow");
|
Chris@21
|
4696 settings.setValue("playsharpen", m_playSharpen->isChecked());
|
Chris@21
|
4697 settings.endGroup();
|
Chris@21
|
4698
|
Chris@16
|
4699 playSpeedChanged(m_playSpeed->value());
|
Chris@0
|
4700 }
|
Chris@0
|
4701
|
Chris@0
|
4702 void
|
Chris@26
|
4703 MainWindow::playMonoToggled()
|
Chris@26
|
4704 {
|
Chris@26
|
4705 QSettings settings;
|
Chris@26
|
4706 settings.beginGroup("MainWindow");
|
Chris@26
|
4707 settings.setValue("playmono", m_playMono->isChecked());
|
Chris@26
|
4708 settings.endGroup();
|
Chris@26
|
4709
|
Chris@26
|
4710 playSpeedChanged(m_playSpeed->value());
|
Chris@26
|
4711 }
|
Chris@26
|
4712
|
Chris@26
|
4713 void
|
Chris@155
|
4714 MainWindow::speedUpPlayback()
|
Chris@155
|
4715 {
|
Chris@155
|
4716 int value = m_playSpeed->value();
|
Chris@155
|
4717 value = value + m_playSpeed->pageStep();
|
Chris@155
|
4718 if (value > m_playSpeed->maximum()) value = m_playSpeed->maximum();
|
Chris@155
|
4719 m_playSpeed->setValue(value);
|
Chris@155
|
4720 }
|
Chris@155
|
4721
|
Chris@155
|
4722 void
|
Chris@155
|
4723 MainWindow::slowDownPlayback()
|
Chris@155
|
4724 {
|
Chris@155
|
4725 int value = m_playSpeed->value();
|
Chris@155
|
4726 value = value - m_playSpeed->pageStep();
|
Chris@155
|
4727 if (value < m_playSpeed->minimum()) value = m_playSpeed->minimum();
|
Chris@155
|
4728 m_playSpeed->setValue(value);
|
Chris@155
|
4729 }
|
Chris@155
|
4730
|
Chris@155
|
4731 void
|
Chris@155
|
4732 MainWindow::restoreNormalPlayback()
|
Chris@155
|
4733 {
|
Chris@155
|
4734 m_playSpeed->setValue(m_playSpeed->defaultValue());
|
Chris@155
|
4735 }
|
Chris@155
|
4736
|
Chris@155
|
4737 void
|
Chris@116
|
4738 MainWindow::playbackFrameChanged(unsigned long frame)
|
Chris@116
|
4739 {
|
Chris@116
|
4740 if (!(m_playSource && m_playSource->isPlaying()) || !getMainModel()) return;
|
Chris@116
|
4741
|
Chris@116
|
4742 RealTime now = RealTime::frame2RealTime
|
Chris@116
|
4743 (frame, getMainModel()->getSampleRate());
|
Chris@116
|
4744
|
Chris@116
|
4745 if (now.sec == m_lastPlayStatusSec) return;
|
Chris@116
|
4746
|
Chris@116
|
4747 RealTime then = RealTime::frame2RealTime
|
Chris@116
|
4748 (m_playSource->getPlayEndFrame(), getMainModel()->getSampleRate());
|
Chris@116
|
4749
|
Chris@116
|
4750 QString nowStr;
|
Chris@116
|
4751 QString thenStr;
|
Chris@116
|
4752 QString remainingStr;
|
Chris@116
|
4753
|
Chris@116
|
4754 if (then.sec > 10) {
|
Chris@116
|
4755 nowStr = now.toSecText().c_str();
|
Chris@116
|
4756 thenStr = then.toSecText().c_str();
|
Chris@116
|
4757 remainingStr = (then - now).toSecText().c_str();
|
Chris@116
|
4758 m_lastPlayStatusSec = now.sec;
|
Chris@116
|
4759 } else {
|
Chris@116
|
4760 nowStr = now.toText(true).c_str();
|
Chris@116
|
4761 thenStr = then.toText(true).c_str();
|
Chris@116
|
4762 remainingStr = (then - now).toText(true).c_str();
|
Chris@116
|
4763 }
|
Chris@116
|
4764
|
Chris@116
|
4765 m_myStatusMessage = tr("Playing: %1 of %2 (%3 remaining)")
|
Chris@116
|
4766 .arg(nowStr).arg(thenStr).arg(remainingStr);
|
Chris@116
|
4767
|
Chris@116
|
4768 statusBar()->showMessage(m_myStatusMessage);
|
Chris@116
|
4769 }
|
Chris@116
|
4770
|
Chris@116
|
4771 void
|
Chris@137
|
4772 MainWindow::globalCentreFrameChanged(unsigned long )
|
Chris@116
|
4773 {
|
Chris@116
|
4774 if ((m_playSource && m_playSource->isPlaying()) || !getMainModel()) return;
|
Chris@116
|
4775 Pane *p = 0;
|
Chris@116
|
4776 if (!m_paneStack || !(p = m_paneStack->getCurrentPane())) return;
|
Chris@116
|
4777 if (!p->getFollowGlobalPan()) return;
|
Chris@116
|
4778 updateVisibleRangeDisplay(p);
|
Chris@116
|
4779 }
|
Chris@116
|
4780
|
Chris@116
|
4781 void
|
Chris@137
|
4782 MainWindow::viewCentreFrameChanged(View *v, unsigned long )
|
Chris@116
|
4783 {
|
Chris@116
|
4784 if ((m_playSource && m_playSource->isPlaying()) || !getMainModel()) return;
|
Chris@116
|
4785 Pane *p = 0;
|
Chris@116
|
4786 if (!m_paneStack || !(p = m_paneStack->getCurrentPane())) return;
|
Chris@116
|
4787 if (v == p) updateVisibleRangeDisplay(p);
|
Chris@116
|
4788 }
|
Chris@116
|
4789
|
Chris@116
|
4790 void
|
Chris@137
|
4791 MainWindow::viewZoomLevelChanged(View *v, unsigned long , bool )
|
Chris@116
|
4792 {
|
Chris@116
|
4793 if ((m_playSource && m_playSource->isPlaying()) || !getMainModel()) return;
|
Chris@116
|
4794 Pane *p = 0;
|
Chris@116
|
4795 if (!m_paneStack || !(p = m_paneStack->getCurrentPane())) return;
|
Chris@116
|
4796 if (v == p) updateVisibleRangeDisplay(p);
|
Chris@116
|
4797 }
|
Chris@116
|
4798
|
Chris@116
|
4799 void
|
Chris@116
|
4800 MainWindow::updateVisibleRangeDisplay(Pane *p) const
|
Chris@116
|
4801 {
|
Chris@116
|
4802 if (!getMainModel() || !p) {
|
Chris@116
|
4803 return;
|
Chris@116
|
4804 }
|
Chris@116
|
4805
|
Chris@117
|
4806 bool haveSelection = false;
|
Chris@117
|
4807 size_t startFrame = 0, endFrame = 0;
|
Chris@117
|
4808
|
Chris@117
|
4809 if (m_viewManager && m_viewManager->haveInProgressSelection()) {
|
Chris@117
|
4810
|
Chris@117
|
4811 bool exclusive = false;
|
Chris@117
|
4812 Selection s = m_viewManager->getInProgressSelection(exclusive);
|
Chris@117
|
4813
|
Chris@117
|
4814 if (!s.isEmpty()) {
|
Chris@117
|
4815 haveSelection = true;
|
Chris@117
|
4816 startFrame = s.getStartFrame();
|
Chris@117
|
4817 endFrame = s.getEndFrame();
|
Chris@117
|
4818 }
|
Chris@117
|
4819 }
|
Chris@117
|
4820
|
Chris@117
|
4821 if (!haveSelection) {
|
Chris@117
|
4822 startFrame = p->getFirstVisibleFrame();
|
Chris@117
|
4823 endFrame = p->getLastVisibleFrame();
|
Chris@117
|
4824 }
|
Chris@117
|
4825
|
Chris@116
|
4826 RealTime start = RealTime::frame2RealTime
|
Chris@117
|
4827 (startFrame, getMainModel()->getSampleRate());
|
Chris@116
|
4828
|
Chris@116
|
4829 RealTime end = RealTime::frame2RealTime
|
Chris@117
|
4830 (endFrame, getMainModel()->getSampleRate());
|
Chris@116
|
4831
|
Chris@116
|
4832 RealTime duration = end - start;
|
Chris@116
|
4833
|
Chris@116
|
4834 QString startStr, endStr, durationStr;
|
Chris@116
|
4835 startStr = start.toText(true).c_str();
|
Chris@116
|
4836 endStr = end.toText(true).c_str();
|
Chris@116
|
4837 durationStr = duration.toText(true).c_str();
|
Chris@116
|
4838
|
Chris@117
|
4839 if (haveSelection) {
|
Chris@117
|
4840 m_myStatusMessage = tr("Selection: %1 to %2 (duration %3)")
|
Chris@117
|
4841 .arg(startStr).arg(endStr).arg(durationStr);
|
Chris@117
|
4842 } else {
|
Chris@117
|
4843 m_myStatusMessage = tr("Visible: %1 to %2 (duration %3)")
|
Chris@117
|
4844 .arg(startStr).arg(endStr).arg(durationStr);
|
Chris@117
|
4845 }
|
Chris@116
|
4846
|
Chris@116
|
4847 statusBar()->showMessage(m_myStatusMessage);
|
Chris@116
|
4848 }
|
Chris@116
|
4849
|
Chris@116
|
4850 void
|
Chris@0
|
4851 MainWindow::outputLevelsChanged(float left, float right)
|
Chris@0
|
4852 {
|
Chris@0
|
4853 m_fader->setPeakLeft(left);
|
Chris@0
|
4854 m_fader->setPeakRight(right);
|
Chris@0
|
4855 }
|
Chris@0
|
4856
|
Chris@0
|
4857 void
|
Chris@0
|
4858 MainWindow::sampleRateMismatch(size_t requested, size_t actual,
|
Chris@0
|
4859 bool willResample)
|
Chris@0
|
4860 {
|
Chris@0
|
4861 if (!willResample) {
|
Chris@0
|
4862 QMessageBox::information
|
Chris@0
|
4863 (this, tr("Sample rate mismatch"),
|
Chris@193
|
4864 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
|
4865 .arg(requested).arg(actual));
|
Chris@0
|
4866 }
|
Chris@0
|
4867
|
Chris@0
|
4868 updateDescriptionLabel();
|
Chris@0
|
4869 }
|
Chris@0
|
4870
|
Chris@0
|
4871 void
|
Chris@42
|
4872 MainWindow::audioOverloadPluginDisabled()
|
Chris@42
|
4873 {
|
Chris@42
|
4874 QMessageBox::information
|
Chris@42
|
4875 (this, tr("Audio processing overload"),
|
Chris@193
|
4876 tr("<b>Overloaded</b><p>Audio effects plugin auditioning has been disabled due to a processing overload."));
|
Chris@42
|
4877 }
|
Chris@42
|
4878
|
Chris@42
|
4879 void
|
Chris@137
|
4880 MainWindow::layerAdded(Layer *)
|
Chris@0
|
4881 {
|
Chris@0
|
4882 // std::cerr << "MainWindow::layerAdded(" << layer << ")" << std::endl;
|
Chris@0
|
4883 // setupExistingLayersMenu();
|
Chris@0
|
4884 updateMenuStates();
|
Chris@0
|
4885 }
|
Chris@0
|
4886
|
Chris@0
|
4887 void
|
Chris@137
|
4888 MainWindow::layerRemoved(Layer *)
|
Chris@0
|
4889 {
|
Chris@0
|
4890 // std::cerr << "MainWindow::layerRemoved(" << layer << ")" << std::endl;
|
Chris@95
|
4891 setupExistingLayersMenus();
|
Chris@0
|
4892 updateMenuStates();
|
Chris@0
|
4893 }
|
Chris@0
|
4894
|
Chris@0
|
4895 void
|
Chris@0
|
4896 MainWindow::layerAboutToBeDeleted(Layer *layer)
|
Chris@0
|
4897 {
|
Chris@0
|
4898 // std::cerr << "MainWindow::layerAboutToBeDeleted(" << layer << ")" << std::endl;
|
Chris@0
|
4899 if (layer == m_timeRulerLayer) {
|
Chris@0
|
4900 // std::cerr << "(this is the time ruler layer)" << std::endl;
|
Chris@0
|
4901 m_timeRulerLayer = 0;
|
Chris@0
|
4902 }
|
Chris@0
|
4903 }
|
Chris@0
|
4904
|
Chris@0
|
4905 void
|
Chris@0
|
4906 MainWindow::layerInAView(Layer *layer, bool inAView)
|
Chris@0
|
4907 {
|
Chris@0
|
4908 // std::cerr << "MainWindow::layerInAView(" << layer << "," << inAView << ")" << std::endl;
|
Chris@0
|
4909
|
Chris@0
|
4910 // Check whether we need to add or remove model from play source
|
Chris@0
|
4911 Model *model = layer->getModel();
|
Chris@0
|
4912 if (model) {
|
Chris@0
|
4913 if (inAView) {
|
Chris@0
|
4914 m_playSource->addModel(model);
|
Chris@0
|
4915 } else {
|
Chris@0
|
4916 bool found = false;
|
Chris@0
|
4917 for (int i = 0; i < m_paneStack->getPaneCount(); ++i) {
|
Chris@0
|
4918 Pane *pane = m_paneStack->getPane(i);
|
Chris@0
|
4919 if (!pane) continue;
|
Chris@0
|
4920 for (int j = 0; j < pane->getLayerCount(); ++j) {
|
Chris@0
|
4921 Layer *pl = pane->getLayer(j);
|
Chris@0
|
4922 if (pl && pl->getModel() == model) {
|
Chris@0
|
4923 found = true;
|
Chris@0
|
4924 break;
|
Chris@0
|
4925 }
|
Chris@0
|
4926 }
|
Chris@0
|
4927 if (found) break;
|
Chris@0
|
4928 }
|
Chris@0
|
4929 if (!found) m_playSource->removeModel(model);
|
Chris@0
|
4930 }
|
Chris@0
|
4931 }
|
Chris@0
|
4932
|
Chris@95
|
4933 setupExistingLayersMenus();
|
Chris@0
|
4934 updateMenuStates();
|
Chris@0
|
4935 }
|
Chris@0
|
4936
|
Chris@0
|
4937 void
|
Chris@0
|
4938 MainWindow::modelAdded(Model *model)
|
Chris@0
|
4939 {
|
Chris@0
|
4940 // std::cerr << "MainWindow::modelAdded(" << model << ")" << std::endl;
|
Chris@0
|
4941 m_playSource->addModel(model);
|
Chris@66
|
4942 if (dynamic_cast<DenseTimeValueModel *>(model)) {
|
Chris@66
|
4943 setupPaneAndLayerMenus();
|
Chris@66
|
4944 }
|
Chris@0
|
4945 }
|
Chris@0
|
4946
|
Chris@0
|
4947 void
|
Chris@0
|
4948 MainWindow::mainModelChanged(WaveFileModel *model)
|
Chris@0
|
4949 {
|
Chris@0
|
4950 // std::cerr << "MainWindow::mainModelChanged(" << model << ")" << std::endl;
|
Chris@0
|
4951 updateDescriptionLabel();
|
Chris@0
|
4952 m_panLayer->setModel(model);
|
Chris@0
|
4953 if (model) m_viewManager->setMainModelSampleRate(model->getSampleRate());
|
Chris@46
|
4954 if (model && !m_playTarget && m_audioOutput) createPlayTarget();
|
Chris@0
|
4955 }
|
Chris@0
|
4956
|
Chris@0
|
4957 void
|
Chris@0
|
4958 MainWindow::modelAboutToBeDeleted(Model *model)
|
Chris@0
|
4959 {
|
Chris@0
|
4960 // std::cerr << "MainWindow::modelAboutToBeDeleted(" << model << ")" << std::endl;
|
Chris@180
|
4961 if (model == m_viewManager->getPlaybackModel()) {
|
Chris@180
|
4962 m_viewManager->setPlaybackModel(0);
|
Chris@180
|
4963 }
|
Chris@0
|
4964 m_playSource->removeModel(model);
|
Chris@91
|
4965 FFTDataServer::modelAboutToBeDeleted(model);
|
Chris@0
|
4966 }
|
Chris@0
|
4967
|
Chris@0
|
4968 void
|
Chris@0
|
4969 MainWindow::modelGenerationFailed(QString transformName)
|
Chris@0
|
4970 {
|
Chris@0
|
4971 QMessageBox::warning
|
Chris@0
|
4972 (this,
|
Chris@0
|
4973 tr("Failed to generate layer"),
|
Chris@193
|
4974 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
|
4975 .arg(transformName),
|
Chris@165
|
4976 QMessageBox::Ok);
|
Chris@0
|
4977 }
|
Chris@0
|
4978
|
Chris@0
|
4979 void
|
Chris@0
|
4980 MainWindow::modelRegenerationFailed(QString layerName, QString transformName)
|
Chris@0
|
4981 {
|
Chris@0
|
4982 QMessageBox::warning
|
Chris@0
|
4983 (this,
|
Chris@0
|
4984 tr("Failed to regenerate layer"),
|
Chris@193
|
4985 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
|
4986 .arg(layerName).arg(transformName),
|
Chris@165
|
4987 QMessageBox::Ok);
|
Chris@0
|
4988 }
|
Chris@0
|
4989
|
Chris@0
|
4990 void
|
Chris@0
|
4991 MainWindow::rightButtonMenuRequested(Pane *pane, QPoint position)
|
Chris@0
|
4992 {
|
Chris@0
|
4993 // std::cerr << "MainWindow::rightButtonMenuRequested(" << pane << ", " << position.x() << ", " << position.y() << ")" << std::endl;
|
Chris@0
|
4994 m_paneStack->setCurrentPane(pane);
|
Chris@0
|
4995 m_rightButtonMenu->popup(position);
|
Chris@0
|
4996 }
|
Chris@0
|
4997
|
Chris@0
|
4998 void
|
Chris@73
|
4999 MainWindow::propertyStacksResized()
|
Chris@73
|
5000 {
|
Chris@73
|
5001 /*
|
Chris@73
|
5002 std::cerr << "MainWindow::propertyStacksResized" << std::endl;
|
Chris@73
|
5003 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@73
|
5004 if (pane && m_overview) {
|
Chris@73
|
5005 std::cerr << "Fixed width: " << pane->width() << std::endl;
|
Chris@73
|
5006 m_overview->setFixedWidth(pane->width());
|
Chris@73
|
5007 }
|
Chris@73
|
5008 */
|
Chris@73
|
5009 }
|
Chris@73
|
5010
|
Chris@73
|
5011 void
|
Chris@0
|
5012 MainWindow::showLayerTree()
|
Chris@0
|
5013 {
|
Chris@177
|
5014 if (!m_layerTreeView.isNull()) {
|
Chris@177
|
5015 m_layerTreeView->show();
|
Chris@177
|
5016 m_layerTreeView->raise();
|
Chris@177
|
5017 return;
|
Chris@177
|
5018 }
|
Chris@177
|
5019
|
Chris@177
|
5020 //!!! should use an actual dialog class
|
Chris@177
|
5021
|
Chris@177
|
5022 m_layerTreeView = new QTreeView();
|
Chris@0
|
5023 LayerTreeModel *tree = new LayerTreeModel(m_paneStack);
|
Chris@177
|
5024 m_layerTreeView->resize(500, 300); //!!!
|
Chris@177
|
5025 m_layerTreeView->setModel(tree);
|
Chris@177
|
5026 m_layerTreeView->expandAll();
|
Chris@177
|
5027 m_layerTreeView->show();
|
Chris@0
|
5028 }
|
Chris@0
|
5029
|
Chris@0
|
5030 void
|
Chris@69
|
5031 MainWindow::pollOSC()
|
Chris@69
|
5032 {
|
Chris@70
|
5033 if (!m_oscQueue || m_oscQueue->isEmpty()) return;
|
Chris@69
|
5034 std::cerr << "MainWindow::pollOSC: have " << m_oscQueue->getMessagesAvailable() << " messages" << std::endl;
|
Chris@69
|
5035
|
Chris@70
|
5036 if (m_openingAudioFile) return;
|
Chris@70
|
5037
|
Chris@69
|
5038 OSCMessage message = m_oscQueue->readMessage();
|
Chris@69
|
5039
|
Chris@69
|
5040 if (message.getTarget() != 0) {
|
Chris@69
|
5041 return; //!!! for now -- this class is target 0, others not handled yet
|
Chris@69
|
5042 }
|
Chris@69
|
5043
|
Chris@69
|
5044 handleOSCMessage(message);
|
Chris@69
|
5045 }
|
Chris@69
|
5046
|
Chris@69
|
5047 void
|
Chris@69
|
5048 MainWindow::handleOSCMessage(const OSCMessage &message)
|
Chris@69
|
5049 {
|
Chris@70
|
5050 std::cerr << "MainWindow::handleOSCMessage: thread id = "
|
Chris@70
|
5051 << QThread::currentThreadId() << std::endl;
|
Chris@70
|
5052
|
Chris@69
|
5053 // This large function should really be abstracted out.
|
Chris@69
|
5054
|
Chris@69
|
5055 if (message.getMethod() == "open") {
|
Chris@69
|
5056
|
Chris@69
|
5057 if (message.getArgCount() == 1 &&
|
Chris@69
|
5058 message.getArg(0).canConvert(QVariant::String)) {
|
Chris@69
|
5059 QString path = message.getArg(0).toString();
|
Chris@82
|
5060 if (openSomeFile(path, ReplaceMainModel) != FileOpenSucceeded) {
|
Chris@69
|
5061 std::cerr << "MainWindow::handleOSCMessage: File open failed for path \""
|
Chris@69
|
5062 << path.toStdString() << "\"" << std::endl;
|
Chris@69
|
5063 }
|
Chris@69
|
5064 //!!! we really need to spin here and not return until the
|
Chris@69
|
5065 // file has been completely decoded...
|
Chris@69
|
5066 }
|
Chris@69
|
5067
|
Chris@69
|
5068 } else if (message.getMethod() == "openadditional") {
|
Chris@69
|
5069
|
Chris@69
|
5070 if (message.getArgCount() == 1 &&
|
Chris@69
|
5071 message.getArg(0).canConvert(QVariant::String)) {
|
Chris@69
|
5072 QString path = message.getArg(0).toString();
|
Chris@82
|
5073 if (openSomeFile(path, CreateAdditionalModel) != FileOpenSucceeded) {
|
Chris@69
|
5074 std::cerr << "MainWindow::handleOSCMessage: File open failed for path \""
|
Chris@69
|
5075 << path.toStdString() << "\"" << std::endl;
|
Chris@69
|
5076 }
|
Chris@69
|
5077 }
|
Chris@69
|
5078
|
Chris@69
|
5079 } else if (message.getMethod() == "recent" ||
|
Chris@69
|
5080 message.getMethod() == "last") {
|
Chris@69
|
5081
|
Chris@69
|
5082 int n = 0;
|
Chris@69
|
5083 if (message.getMethod() == "recent" &&
|
Chris@69
|
5084 message.getArgCount() == 1 &&
|
Chris@69
|
5085 message.getArg(0).canConvert(QVariant::Int)) {
|
Chris@69
|
5086 n = message.getArg(0).toInt() - 1;
|
Chris@69
|
5087 }
|
Chris@69
|
5088 std::vector<QString> recent = m_recentFiles.getRecent();
|
Chris@137
|
5089 if (n >= 0 && n < int(recent.size())) {
|
Chris@82
|
5090 if (openSomeFile(recent[n], ReplaceMainModel) != FileOpenSucceeded) {
|
Chris@69
|
5091 std::cerr << "MainWindow::handleOSCMessage: File open failed for path \""
|
Chris@69
|
5092 << recent[n].toStdString() << "\"" << std::endl;
|
Chris@69
|
5093 }
|
Chris@69
|
5094 }
|
Chris@69
|
5095
|
Chris@69
|
5096 } else if (message.getMethod() == "save") {
|
Chris@69
|
5097
|
Chris@69
|
5098 QString path;
|
Chris@69
|
5099 if (message.getArgCount() == 1 &&
|
Chris@69
|
5100 message.getArg(0).canConvert(QVariant::String)) {
|
Chris@69
|
5101 path = message.getArg(0).toString();
|
Chris@69
|
5102 if (QFileInfo(path).exists()) {
|
Chris@69
|
5103 std::cerr << "MainWindow::handleOSCMessage: Refusing to overwrite existing file in save" << std::endl;
|
Chris@69
|
5104 } else {
|
Chris@69
|
5105 saveSessionFile(path);
|
Chris@69
|
5106 }
|
Chris@69
|
5107 }
|
Chris@69
|
5108
|
Chris@69
|
5109 } else if (message.getMethod() == "export") {
|
Chris@69
|
5110
|
Chris@69
|
5111 QString path;
|
Chris@69
|
5112 if (getMainModel()) {
|
Chris@69
|
5113 if (message.getArgCount() == 1 &&
|
Chris@69
|
5114 message.getArg(0).canConvert(QVariant::String)) {
|
Chris@69
|
5115 path = message.getArg(0).toString();
|
Chris@69
|
5116 if (QFileInfo(path).exists()) {
|
Chris@69
|
5117 std::cerr << "MainWindow::handleOSCMessage: Refusing to overwrite existing file in export" << std::endl;
|
Chris@69
|
5118 } else {
|
Chris@69
|
5119 WavFileWriter writer(path,
|
Chris@69
|
5120 getMainModel()->getSampleRate(),
|
Chris@69
|
5121 getMainModel()->getChannelCount());
|
Chris@69
|
5122 MultiSelection ms = m_viewManager->getSelection();
|
Chris@69
|
5123 if (!ms.getSelections().empty()) {
|
Chris@69
|
5124 writer.writeModel(getMainModel(), &ms);
|
Chris@69
|
5125 } else {
|
Chris@69
|
5126 writer.writeModel(getMainModel());
|
Chris@69
|
5127 }
|
Chris@69
|
5128 }
|
Chris@69
|
5129 }
|
Chris@69
|
5130 }
|
Chris@69
|
5131
|
Chris@69
|
5132 } else if (message.getMethod() == "jump" ||
|
Chris@69
|
5133 message.getMethod() == "play") {
|
Chris@69
|
5134
|
Chris@69
|
5135 if (getMainModel()) {
|
Chris@69
|
5136
|
Chris@69
|
5137 unsigned long frame = m_viewManager->getPlaybackFrame();
|
Chris@69
|
5138 bool selection = false;
|
Chris@69
|
5139 bool play = (message.getMethod() == "play");
|
Chris@69
|
5140
|
Chris@69
|
5141 if (message.getArgCount() == 1) {
|
Chris@69
|
5142
|
Chris@69
|
5143 if (message.getArg(0).canConvert(QVariant::String) &&
|
Chris@69
|
5144 message.getArg(0).toString() == "selection") {
|
Chris@69
|
5145
|
Chris@69
|
5146 selection = true;
|
Chris@69
|
5147
|
Chris@69
|
5148 } else if (message.getArg(0).canConvert(QVariant::String) &&
|
Chris@69
|
5149 message.getArg(0).toString() == "end") {
|
Chris@69
|
5150
|
Chris@69
|
5151 frame = getMainModel()->getEndFrame();
|
Chris@69
|
5152
|
Chris@69
|
5153 } else if (message.getArg(0).canConvert(QVariant::Double)) {
|
Chris@69
|
5154
|
Chris@69
|
5155 double time = message.getArg(0).toDouble();
|
Chris@69
|
5156 if (time < 0.0) time = 0.0;
|
Chris@69
|
5157
|
Chris@69
|
5158 frame = lrint(time * getMainModel()->getSampleRate());
|
Chris@69
|
5159 }
|
Chris@69
|
5160 }
|
Chris@69
|
5161
|
Chris@69
|
5162 if (frame > getMainModel()->getEndFrame()) {
|
Chris@69
|
5163 frame = getMainModel()->getEndFrame();
|
Chris@69
|
5164 }
|
Chris@69
|
5165
|
Chris@69
|
5166 if (play) {
|
Chris@69
|
5167 m_viewManager->setPlaySelectionMode(selection);
|
Chris@69
|
5168 }
|
Chris@69
|
5169
|
Chris@69
|
5170 if (selection) {
|
Chris@69
|
5171 MultiSelection::SelectionList sl = m_viewManager->getSelections();
|
Chris@69
|
5172 if (!sl.empty()) {
|
Chris@69
|
5173 frame = sl.begin()->getStartFrame();
|
Chris@69
|
5174 }
|
Chris@69
|
5175 }
|
Chris@69
|
5176
|
Chris@69
|
5177 m_viewManager->setPlaybackFrame(frame);
|
Chris@69
|
5178
|
Chris@69
|
5179 if (play && !m_playSource->isPlaying()) {
|
Chris@69
|
5180 m_playSource->play(frame);
|
Chris@69
|
5181 }
|
Chris@69
|
5182 }
|
Chris@69
|
5183
|
Chris@69
|
5184 } else if (message.getMethod() == "stop") {
|
Chris@69
|
5185
|
Chris@69
|
5186 if (m_playSource->isPlaying()) m_playSource->stop();
|
Chris@69
|
5187
|
Chris@69
|
5188 } else if (message.getMethod() == "loop") {
|
Chris@69
|
5189
|
Chris@69
|
5190 if (message.getArgCount() == 1 &&
|
Chris@69
|
5191 message.getArg(0).canConvert(QVariant::String)) {
|
Chris@69
|
5192
|
Chris@69
|
5193 QString str = message.getArg(0).toString();
|
Chris@69
|
5194 if (str == "on") {
|
Chris@69
|
5195 m_viewManager->setPlayLoopMode(true);
|
Chris@69
|
5196 } else if (str == "off") {
|
Chris@69
|
5197 m_viewManager->setPlayLoopMode(false);
|
Chris@69
|
5198 }
|
Chris@69
|
5199 }
|
Chris@69
|
5200
|
Chris@180
|
5201 } else if (message.getMethod() == "solo") {
|
Chris@180
|
5202
|
Chris@180
|
5203 if (message.getArgCount() == 1 &&
|
Chris@180
|
5204 message.getArg(0).canConvert(QVariant::String)) {
|
Chris@180
|
5205
|
Chris@180
|
5206 QString str = message.getArg(0).toString();
|
Chris@180
|
5207 if (str == "on") {
|
Chris@180
|
5208 m_viewManager->setPlaySoloMode(true);
|
Chris@180
|
5209 } else if (str == "off") {
|
Chris@180
|
5210 m_viewManager->setPlaySoloMode(false);
|
Chris@180
|
5211 }
|
Chris@180
|
5212 }
|
Chris@180
|
5213
|
Chris@69
|
5214 } else if (message.getMethod() == "select" ||
|
Chris@69
|
5215 message.getMethod() == "addselect") {
|
Chris@69
|
5216
|
Chris@69
|
5217 if (getMainModel()) {
|
Chris@69
|
5218
|
Chris@73
|
5219 int f0 = getMainModel()->getStartFrame();
|
Chris@73
|
5220 int f1 = getMainModel()->getEndFrame();
|
Chris@69
|
5221
|
Chris@69
|
5222 bool done = false;
|
Chris@69
|
5223
|
Chris@69
|
5224 if (message.getArgCount() == 2 &&
|
Chris@69
|
5225 message.getArg(0).canConvert(QVariant::Double) &&
|
Chris@69
|
5226 message.getArg(1).canConvert(QVariant::Double)) {
|
Chris@69
|
5227
|
Chris@69
|
5228 double t0 = message.getArg(0).toDouble();
|
Chris@69
|
5229 double t1 = message.getArg(1).toDouble();
|
Chris@69
|
5230 if (t1 < t0) { double temp = t0; t0 = t1; t1 = temp; }
|
Chris@69
|
5231 if (t0 < 0.0) t0 = 0.0;
|
Chris@69
|
5232 if (t1 < 0.0) t1 = 0.0;
|
Chris@69
|
5233
|
Chris@69
|
5234 f0 = lrint(t0 * getMainModel()->getSampleRate());
|
Chris@69
|
5235 f1 = lrint(t1 * getMainModel()->getSampleRate());
|
Chris@73
|
5236
|
Chris@73
|
5237 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@73
|
5238 Layer *layer = 0;
|
Chris@73
|
5239 if (pane) layer = pane->getSelectedLayer();
|
Chris@73
|
5240 if (layer) {
|
Chris@73
|
5241 size_t resolution;
|
Chris@73
|
5242 layer->snapToFeatureFrame(pane, f0, resolution,
|
Chris@73
|
5243 Layer::SnapLeft);
|
Chris@73
|
5244 layer->snapToFeatureFrame(pane, f1, resolution,
|
Chris@73
|
5245 Layer::SnapRight);
|
Chris@73
|
5246 }
|
Chris@69
|
5247
|
Chris@69
|
5248 } else if (message.getArgCount() == 1 &&
|
Chris@69
|
5249 message.getArg(0).canConvert(QVariant::String)) {
|
Chris@69
|
5250
|
Chris@69
|
5251 QString str = message.getArg(0).toString();
|
Chris@69
|
5252 if (str == "none") {
|
Chris@69
|
5253 m_viewManager->clearSelections();
|
Chris@69
|
5254 done = true;
|
Chris@69
|
5255 }
|
Chris@69
|
5256 }
|
Chris@69
|
5257
|
Chris@69
|
5258 if (!done) {
|
Chris@69
|
5259 if (message.getMethod() == "select") {
|
Chris@69
|
5260 m_viewManager->setSelection(Selection(f0, f1));
|
Chris@69
|
5261 } else {
|
Chris@69
|
5262 m_viewManager->addSelection(Selection(f0, f1));
|
Chris@69
|
5263 }
|
Chris@69
|
5264 }
|
Chris@69
|
5265 }
|
Chris@69
|
5266
|
Chris@69
|
5267 } else if (message.getMethod() == "add") {
|
Chris@69
|
5268
|
Chris@69
|
5269 if (getMainModel()) {
|
Chris@69
|
5270
|
Chris@69
|
5271 if (message.getArgCount() >= 1 &&
|
Chris@69
|
5272 message.getArg(0).canConvert(QVariant::String)) {
|
Chris@69
|
5273
|
Chris@69
|
5274 int channel = -1;
|
Chris@69
|
5275 if (message.getArgCount() == 2 &&
|
Chris@69
|
5276 message.getArg(0).canConvert(QVariant::Int)) {
|
Chris@69
|
5277 channel = message.getArg(0).toInt();
|
Chris@69
|
5278 if (channel < -1 ||
|
Chris@137
|
5279 channel > int(getMainModel()->getChannelCount())) {
|
Chris@69
|
5280 std::cerr << "WARNING: MainWindow::handleOSCMessage: channel "
|
Chris@69
|
5281 << channel << " out of range" << std::endl;
|
Chris@69
|
5282 channel = -1;
|
Chris@69
|
5283 }
|
Chris@69
|
5284 }
|
Chris@69
|
5285
|
Chris@69
|
5286 QString str = message.getArg(0).toString();
|
Chris@69
|
5287
|
Chris@69
|
5288 LayerFactory::LayerType type =
|
Chris@69
|
5289 LayerFactory::getInstance()->getLayerTypeForName(str);
|
Chris@69
|
5290
|
Chris@69
|
5291 if (type == LayerFactory::UnknownLayer) {
|
Chris@69
|
5292 std::cerr << "WARNING: MainWindow::handleOSCMessage: unknown layer "
|
Chris@69
|
5293 << "type " << str.toStdString() << std::endl;
|
Chris@69
|
5294 } else {
|
Chris@69
|
5295
|
Chris@69
|
5296 PaneConfiguration configuration(type,
|
Chris@69
|
5297 getMainModel(),
|
Chris@69
|
5298 channel);
|
Chris@69
|
5299
|
Chris@69
|
5300 addPane(configuration,
|
Chris@69
|
5301 tr("Add %1 Pane")
|
Chris@69
|
5302 .arg(LayerFactory::getInstance()->
|
Chris@69
|
5303 getLayerPresentationName(type)));
|
Chris@69
|
5304 }
|
Chris@69
|
5305 }
|
Chris@69
|
5306 }
|
Chris@69
|
5307
|
Chris@69
|
5308 } else if (message.getMethod() == "undo") {
|
Chris@69
|
5309
|
Chris@69
|
5310 CommandHistory::getInstance()->undo();
|
Chris@69
|
5311
|
Chris@69
|
5312 } else if (message.getMethod() == "redo") {
|
Chris@69
|
5313
|
Chris@69
|
5314 CommandHistory::getInstance()->redo();
|
Chris@69
|
5315
|
Chris@69
|
5316 } else if (message.getMethod() == "set") {
|
Chris@69
|
5317
|
Chris@70
|
5318 if (message.getArgCount() == 2 &&
|
Chris@69
|
5319 message.getArg(0).canConvert(QVariant::String) &&
|
Chris@69
|
5320 message.getArg(1).canConvert(QVariant::Double)) {
|
Chris@69
|
5321
|
Chris@69
|
5322 QString property = message.getArg(0).toString();
|
Chris@69
|
5323 float value = (float)message.getArg(1).toDouble();
|
Chris@69
|
5324
|
Chris@69
|
5325 if (property == "gain") {
|
Chris@69
|
5326 if (value < 0.0) value = 0.0;
|
Chris@69
|
5327 m_fader->setValue(value);
|
Chris@69
|
5328 if (m_playTarget) m_playTarget->setOutputGain(value);
|
Chris@69
|
5329 } else if (property == "speedup") {
|
Chris@69
|
5330 m_playSpeed->setMappedValue(value);
|
Chris@69
|
5331 } else if (property == "overlays") {
|
Chris@69
|
5332 if (value < 0.5) {
|
Chris@69
|
5333 m_viewManager->setOverlayMode(ViewManager::NoOverlays);
|
Chris@69
|
5334 } else if (value < 1.5) {
|
Chris@90
|
5335 m_viewManager->setOverlayMode(ViewManager::MinimalOverlays);
|
Chris@90
|
5336 } else if (value < 2.5) {
|
Chris@90
|
5337 m_viewManager->setOverlayMode(ViewManager::StandardOverlays);
|
Chris@69
|
5338 } else {
|
Chris@69
|
5339 m_viewManager->setOverlayMode(ViewManager::AllOverlays);
|
Chris@69
|
5340 }
|
Chris@70
|
5341 } else if (property == "zoomwheels") {
|
Chris@70
|
5342 m_viewManager->setZoomWheelsEnabled(value > 0.5);
|
Chris@72
|
5343 } else if (property == "propertyboxes") {
|
Chris@72
|
5344 bool toggle = ((value < 0.5) !=
|
Chris@72
|
5345 (m_paneStack->getLayoutStyle() == PaneStack::NoPropertyStacks));
|
Chris@72
|
5346 if (toggle) togglePropertyBoxes();
|
Chris@70
|
5347 }
|
Chris@70
|
5348
|
Chris@70
|
5349 } else {
|
Chris@70
|
5350 PropertyContainer *container = 0;
|
Chris@70
|
5351 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@70
|
5352 if (pane &&
|
Chris@70
|
5353 message.getArgCount() == 3 &&
|
Chris@70
|
5354 message.getArg(0).canConvert(QVariant::String) &&
|
Chris@70
|
5355 message.getArg(1).canConvert(QVariant::String) &&
|
Chris@70
|
5356 message.getArg(2).canConvert(QVariant::String)) {
|
Chris@70
|
5357 if (message.getArg(0).toString() == "pane") {
|
Chris@70
|
5358 container = pane->getPropertyContainer(0);
|
Chris@70
|
5359 } else if (message.getArg(0).toString() == "layer") {
|
Chris@70
|
5360 container = pane->getSelectedLayer();
|
Chris@70
|
5361 }
|
Chris@70
|
5362 }
|
Chris@70
|
5363 if (container) {
|
Chris@70
|
5364 QString nameString = message.getArg(1).toString();
|
Chris@70
|
5365 QString valueString = message.getArg(2).toString();
|
Chris@70
|
5366 container->setPropertyWithCommand(nameString, valueString);
|
Chris@69
|
5367 }
|
Chris@69
|
5368 }
|
Chris@69
|
5369
|
Chris@69
|
5370 } else if (message.getMethod() == "setcurrent") {
|
Chris@69
|
5371
|
Chris@69
|
5372 int paneIndex = -1, layerIndex = -1;
|
Chris@69
|
5373 bool wantLayer = false;
|
Chris@69
|
5374
|
Chris@69
|
5375 if (message.getArgCount() >= 1 &&
|
Chris@69
|
5376 message.getArg(0).canConvert(QVariant::Int)) {
|
Chris@69
|
5377
|
Chris@69
|
5378 paneIndex = message.getArg(0).toInt() - 1;
|
Chris@69
|
5379
|
Chris@69
|
5380 if (message.getArgCount() >= 2 &&
|
Chris@69
|
5381 message.getArg(1).canConvert(QVariant::Int)) {
|
Chris@69
|
5382 wantLayer = true;
|
Chris@69
|
5383 layerIndex = message.getArg(1).toInt() - 1;
|
Chris@69
|
5384 }
|
Chris@69
|
5385 }
|
Chris@69
|
5386
|
Chris@69
|
5387 if (paneIndex >= 0 && paneIndex < m_paneStack->getPaneCount()) {
|
Chris@69
|
5388 Pane *pane = m_paneStack->getPane(paneIndex);
|
Chris@70
|
5389 m_paneStack->setCurrentPane(pane);
|
Chris@69
|
5390 if (layerIndex >= 0 && layerIndex < pane->getLayerCount()) {
|
Chris@69
|
5391 Layer *layer = pane->getLayer(layerIndex);
|
Chris@69
|
5392 m_paneStack->setCurrentLayer(pane, layer);
|
Chris@69
|
5393 } else if (wantLayer && layerIndex == -1) {
|
Chris@69
|
5394 m_paneStack->setCurrentLayer(pane, 0);
|
Chris@69
|
5395 }
|
Chris@69
|
5396 }
|
Chris@69
|
5397
|
Chris@69
|
5398 } else if (message.getMethod() == "delete") {
|
Chris@69
|
5399
|
Chris@69
|
5400 if (message.getArgCount() == 1 &&
|
Chris@69
|
5401 message.getArg(0).canConvert(QVariant::String)) {
|
Chris@69
|
5402
|
Chris@69
|
5403 QString target = message.getArg(0).toString();
|
Chris@69
|
5404
|
Chris@69
|
5405 if (target == "pane") {
|
Chris@69
|
5406
|
Chris@69
|
5407 deleteCurrentPane();
|
Chris@69
|
5408
|
Chris@69
|
5409 } else if (target == "layer") {
|
Chris@69
|
5410
|
Chris@69
|
5411 deleteCurrentLayer();
|
Chris@69
|
5412
|
Chris@69
|
5413 } else {
|
Chris@69
|
5414
|
Chris@69
|
5415 std::cerr << "WARNING: MainWindow::handleOSCMessage: Unknown delete target " << target.toStdString() << std::endl;
|
Chris@69
|
5416 }
|
Chris@69
|
5417 }
|
Chris@69
|
5418
|
Chris@69
|
5419 } else if (message.getMethod() == "zoom") {
|
Chris@69
|
5420
|
Chris@69
|
5421 if (message.getArgCount() == 1) {
|
Chris@69
|
5422 if (message.getArg(0).canConvert(QVariant::String) &&
|
Chris@69
|
5423 message.getArg(0).toString() == "in") {
|
Chris@69
|
5424 zoomIn();
|
Chris@69
|
5425 } else if (message.getArg(0).canConvert(QVariant::String) &&
|
Chris@69
|
5426 message.getArg(0).toString() == "out") {
|
Chris@69
|
5427 zoomOut();
|
Chris@69
|
5428 } else if (message.getArg(0).canConvert(QVariant::String) &&
|
Chris@69
|
5429 message.getArg(0).toString() == "default") {
|
Chris@69
|
5430 zoomDefault();
|
Chris@69
|
5431 } else if (message.getArg(0).canConvert(QVariant::Double)) {
|
Chris@69
|
5432 double level = message.getArg(0).toDouble();
|
Chris@69
|
5433 Pane *currentPane = m_paneStack->getCurrentPane();
|
Chris@69
|
5434 if (level < 1.0) level = 1.0;
|
Chris@69
|
5435 if (currentPane) currentPane->setZoomLevel(lrint(level));
|
Chris@69
|
5436 }
|
Chris@69
|
5437 }
|
Chris@69
|
5438
|
Chris@73
|
5439 } else if (message.getMethod() == "zoomvertical") {
|
Chris@73
|
5440
|
Chris@73
|
5441 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@73
|
5442 Layer *layer = 0;
|
Chris@73
|
5443 if (pane && pane->getLayerCount() > 0) {
|
Chris@73
|
5444 layer = pane->getLayer(pane->getLayerCount() - 1);
|
Chris@73
|
5445 }
|
Chris@73
|
5446 int defaultStep = 0;
|
Chris@73
|
5447 int steps = 0;
|
Chris@73
|
5448 if (layer) {
|
Chris@73
|
5449 steps = layer->getVerticalZoomSteps(defaultStep);
|
Chris@73
|
5450 if (message.getArgCount() == 1 && steps > 0) {
|
Chris@73
|
5451 if (message.getArg(0).canConvert(QVariant::String) &&
|
Chris@73
|
5452 message.getArg(0).toString() == "in") {
|
Chris@73
|
5453 int step = layer->getCurrentVerticalZoomStep() + 1;
|
Chris@73
|
5454 if (step < steps) layer->setVerticalZoomStep(step);
|
Chris@73
|
5455 } else if (message.getArg(0).canConvert(QVariant::String) &&
|
Chris@73
|
5456 message.getArg(0).toString() == "out") {
|
Chris@73
|
5457 int step = layer->getCurrentVerticalZoomStep() - 1;
|
Chris@73
|
5458 if (step >= 0) layer->setVerticalZoomStep(step);
|
Chris@73
|
5459 } else if (message.getArg(0).canConvert(QVariant::String) &&
|
Chris@73
|
5460 message.getArg(0).toString() == "default") {
|
Chris@73
|
5461 layer->setVerticalZoomStep(defaultStep);
|
Chris@73
|
5462 }
|
Chris@73
|
5463 } else if (message.getArgCount() == 2) {
|
Chris@73
|
5464 if (message.getArg(0).canConvert(QVariant::Double) &&
|
Chris@73
|
5465 message.getArg(1).canConvert(QVariant::Double)) {
|
Chris@73
|
5466 double min = message.getArg(0).toDouble();
|
Chris@73
|
5467 double max = message.getArg(1).toDouble();
|
Chris@73
|
5468 layer->setDisplayExtents(min, max);
|
Chris@73
|
5469 }
|
Chris@73
|
5470 }
|
Chris@73
|
5471 }
|
Chris@73
|
5472
|
Chris@70
|
5473 } else if (message.getMethod() == "quit") {
|
Chris@70
|
5474
|
Chris@70
|
5475 m_abandoning = true;
|
Chris@70
|
5476 close();
|
Chris@70
|
5477
|
Chris@70
|
5478 } else if (message.getMethod() == "resize") {
|
Chris@70
|
5479
|
Chris@70
|
5480 if (message.getArgCount() == 2) {
|
Chris@70
|
5481
|
Chris@70
|
5482 int width = 0, height = 0;
|
Chris@70
|
5483
|
Chris@70
|
5484 if (message.getArg(1).canConvert(QVariant::Int)) {
|
Chris@70
|
5485
|
Chris@70
|
5486 height = message.getArg(1).toInt();
|
Chris@70
|
5487
|
Chris@70
|
5488 if (message.getArg(0).canConvert(QVariant::String) &&
|
Chris@70
|
5489 message.getArg(0).toString() == "pane") {
|
Chris@70
|
5490
|
Chris@70
|
5491 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@70
|
5492 if (pane) pane->resize(pane->width(), height);
|
Chris@70
|
5493
|
Chris@70
|
5494 } else if (message.getArg(0).canConvert(QVariant::Int)) {
|
Chris@70
|
5495
|
Chris@70
|
5496 width = message.getArg(0).toInt();
|
Chris@70
|
5497 resize(width, height);
|
Chris@70
|
5498 }
|
Chris@70
|
5499 }
|
Chris@70
|
5500 }
|
Chris@70
|
5501
|
Chris@70
|
5502 } else if (message.getMethod() == "transform") {
|
Chris@70
|
5503
|
Chris@70
|
5504 Pane *pane = m_paneStack->getCurrentPane();
|
Chris@70
|
5505
|
Chris@70
|
5506 if (getMainModel() &&
|
Chris@70
|
5507 pane &&
|
Chris@70
|
5508 message.getArgCount() == 1 &&
|
Chris@70
|
5509 message.getArg(0).canConvert(QVariant::String)) {
|
Chris@70
|
5510
|
Chris@107
|
5511 TransformId transform = message.getArg(0).toString();
|
Chris@70
|
5512
|
Chris@70
|
5513 Layer *newLayer = m_document->createDerivedLayer
|
Chris@70
|
5514 (transform,
|
Chris@70
|
5515 getMainModel(),
|
Chris@73
|
5516 TransformFactory::getInstance()->getDefaultContextForTransform
|
Chris@73
|
5517 (transform, getMainModel()),
|
Chris@70
|
5518 "");
|
Chris@70
|
5519
|
Chris@70
|
5520 if (newLayer) {
|
Chris@70
|
5521 m_document->addLayerToView(pane, newLayer);
|
Chris@70
|
5522 m_recentTransforms.add(transform);
|
Chris@70
|
5523 m_paneStack->setCurrentLayer(pane, newLayer);
|
Chris@70
|
5524 }
|
Chris@70
|
5525 }
|
Chris@70
|
5526
|
Chris@69
|
5527 } else {
|
Chris@69
|
5528 std::cerr << "WARNING: MainWindow::handleOSCMessage: Unknown or unsupported "
|
Chris@69
|
5529 << "method \"" << message.getMethod().toStdString()
|
Chris@69
|
5530 << "\"" << std::endl;
|
Chris@69
|
5531 }
|
Chris@69
|
5532
|
Chris@69
|
5533 }
|
Chris@69
|
5534
|
Chris@69
|
5535 void
|
Chris@0
|
5536 MainWindow::preferences()
|
Chris@0
|
5537 {
|
Chris@0
|
5538 if (!m_preferencesDialog.isNull()) {
|
Chris@0
|
5539 m_preferencesDialog->show();
|
Chris@0
|
5540 m_preferencesDialog->raise();
|
Chris@0
|
5541 return;
|
Chris@0
|
5542 }
|
Chris@0
|
5543
|
Chris@0
|
5544 m_preferencesDialog = new PreferencesDialog(this);
|
Chris@0
|
5545
|
Chris@0
|
5546 // DeleteOnClose is safe here, because m_preferencesDialog is a
|
Chris@0
|
5547 // QPointer that will be zeroed when the dialog is deleted. We
|
Chris@0
|
5548 // use it in preference to leaving the dialog lying around because
|
Chris@0
|
5549 // if you Cancel the dialog, it resets the preferences state
|
Chris@0
|
5550 // without resetting its own widgets, so its state will be
|
Chris@0
|
5551 // incorrect when next shown unless we construct it afresh
|
Chris@0
|
5552 m_preferencesDialog->setAttribute(Qt::WA_DeleteOnClose);
|
Chris@0
|
5553
|
Chris@0
|
5554 m_preferencesDialog->show();
|
Chris@0
|
5555 }
|
Chris@0
|
5556
|
Chris@0
|
5557 void
|
Chris@90
|
5558 MainWindow::mouseEnteredWidget()
|
Chris@90
|
5559 {
|
Chris@90
|
5560 QWidget *w = dynamic_cast<QWidget *>(sender());
|
Chris@90
|
5561 if (!w) return;
|
Chris@90
|
5562
|
Chris@90
|
5563 if (w == m_fader) {
|
Chris@116
|
5564 contextHelpChanged(tr("Adjust the master playback level"));
|
Chris@90
|
5565 } else if (w == m_playSpeed) {
|
Chris@116
|
5566 contextHelpChanged(tr("Adjust the master playback speed"));
|
Chris@90
|
5567 } else if (w == m_playSharpen && w->isEnabled()) {
|
Chris@116
|
5568 contextHelpChanged(tr("Toggle transient sharpening for playback time scaling"));
|
Chris@90
|
5569 } else if (w == m_playMono && w->isEnabled()) {
|
Chris@116
|
5570 contextHelpChanged(tr("Toggle mono mode for playback time scaling"));
|
Chris@90
|
5571 }
|
Chris@90
|
5572 }
|
Chris@90
|
5573
|
Chris@90
|
5574 void
|
Chris@90
|
5575 MainWindow::mouseLeftWidget()
|
Chris@90
|
5576 {
|
Chris@116
|
5577 contextHelpChanged("");
|
Chris@116
|
5578 }
|
Chris@116
|
5579
|
Chris@116
|
5580 void
|
Chris@117
|
5581 MainWindow::inProgressSelectionChanged()
|
Chris@117
|
5582 {
|
Chris@117
|
5583 Pane *currentPane = 0;
|
Chris@117
|
5584 if (m_paneStack) currentPane = m_paneStack->getCurrentPane();
|
Chris@117
|
5585 if (currentPane) updateVisibleRangeDisplay(currentPane);
|
Chris@117
|
5586 }
|
Chris@117
|
5587
|
Chris@117
|
5588 void
|
Chris@116
|
5589 MainWindow::contextHelpChanged(const QString &s)
|
Chris@116
|
5590 {
|
Chris@116
|
5591 if (s == "" && m_myStatusMessage != "") {
|
Chris@116
|
5592 statusBar()->showMessage(m_myStatusMessage);
|
Chris@116
|
5593 return;
|
Chris@116
|
5594 }
|
Chris@116
|
5595 statusBar()->showMessage(s);
|
Chris@90
|
5596 }
|
Chris@90
|
5597
|
Chris@90
|
5598 void
|
Chris@0
|
5599 MainWindow::website()
|
Chris@0
|
5600 {
|
Chris@0
|
5601 openHelpUrl(tr("http://www.sonicvisualiser.org/"));
|
Chris@0
|
5602 }
|
Chris@0
|
5603
|
Chris@0
|
5604 void
|
Chris@0
|
5605 MainWindow::help()
|
Chris@0
|
5606 {
|
Chris@126
|
5607 openHelpUrl(tr("http://www.sonicvisualiser.org/doc/reference/1.0/en/"));
|
Chris@0
|
5608 }
|
Chris@0
|
5609
|
Chris@0
|
5610 void
|
Chris@0
|
5611 MainWindow::openHelpUrl(QString url)
|
Chris@0
|
5612 {
|
Chris@0
|
5613 // This method mostly lifted from Qt Assistant source code
|
Chris@0
|
5614
|
Chris@0
|
5615 QProcess *process = new QProcess(this);
|
Chris@0
|
5616 connect(process, SIGNAL(finished(int)), process, SLOT(deleteLater()));
|
Chris@0
|
5617
|
Chris@0
|
5618 QStringList args;
|
Chris@0
|
5619
|
Chris@0
|
5620 #ifdef Q_OS_MAC
|
Chris@0
|
5621 args.append(url);
|
Chris@0
|
5622 process->start("open", args);
|
Chris@0
|
5623 #else
|
Chris@0
|
5624 #ifdef Q_OS_WIN32
|
Chris@0
|
5625
|
Chris@0
|
5626 QString pf(getenv("ProgramFiles"));
|
Chris@0
|
5627 QString command = pf + QString("\\Internet Explorer\\IEXPLORE.EXE");
|
Chris@0
|
5628
|
Chris@0
|
5629 args.append(url);
|
Chris@0
|
5630 process->start(command, args);
|
Chris@0
|
5631
|
Chris@0
|
5632 #else
|
Chris@0
|
5633 #ifdef Q_WS_X11
|
Chris@0
|
5634 if (!qgetenv("KDE_FULL_SESSION").isEmpty()) {
|
Chris@0
|
5635 args.append("exec");
|
Chris@0
|
5636 args.append(url);
|
Chris@0
|
5637 process->start("kfmclient", args);
|
Chris@0
|
5638 } else if (!qgetenv("BROWSER").isEmpty()) {
|
Chris@0
|
5639 args.append(url);
|
Chris@0
|
5640 process->start(qgetenv("BROWSER"), args);
|
Chris@0
|
5641 } else {
|
Chris@0
|
5642 args.append(url);
|
Chris@0
|
5643 process->start("firefox", args);
|
Chris@0
|
5644 }
|
Chris@0
|
5645 #endif
|
Chris@0
|
5646 #endif
|
Chris@0
|
5647 #endif
|
Chris@0
|
5648 }
|
Chris@0
|
5649
|
Chris@0
|
5650 void
|
Chris@0
|
5651 MainWindow::about()
|
Chris@0
|
5652 {
|
Chris@0
|
5653 bool debug = false;
|
Chris@0
|
5654 QString version = "(unknown version)";
|
Chris@0
|
5655
|
Chris@0
|
5656 #ifdef BUILD_DEBUG
|
Chris@0
|
5657 debug = true;
|
Chris@0
|
5658 #endif
|
Chris@0
|
5659 #ifdef SV_VERSION
|
Chris@0
|
5660 #ifdef SVNREV
|
Chris@0
|
5661 version = tr("Release %1 : Revision %2").arg(SV_VERSION).arg(SVNREV);
|
Chris@0
|
5662 #else
|
Chris@0
|
5663 version = tr("Release %1").arg(SV_VERSION);
|
Chris@0
|
5664 #endif
|
Chris@0
|
5665 #else
|
Chris@0
|
5666 #ifdef SVNREV
|
Chris@0
|
5667 version = tr("Unreleased : Revision %1").arg(SVNREV);
|
Chris@0
|
5668 #endif
|
Chris@0
|
5669 #endif
|
Chris@0
|
5670
|
Chris@0
|
5671 QString aboutText;
|
Chris@0
|
5672
|
Chris@0
|
5673 aboutText += tr("<h3>About Sonic Visualiser</h3>");
|
Chris@90
|
5674 aboutText += tr("<p>Sonic Visualiser is a program for viewing and exploring audio data for<br>semantic music analysis and annotation.</p>");
|
Chris@111
|
5675 aboutText += tr("<p>%1 : %2 configuration</p>")
|
Chris@0
|
5676 .arg(version)
|
Chris@0
|
5677 .arg(debug ? tr("Debug") : tr("Release"));
|
Chris@0
|
5678
|
Chris@132
|
5679 #ifndef BUILD_STATIC
|
Chris@132
|
5680 aboutText += tr("<br>Using Qt v%1 © Trolltech AS").arg(QT_VERSION_STR);
|
Chris@132
|
5681 #else
|
Chris@132
|
5682 #ifdef QT_SHARED
|
Chris@132
|
5683 aboutText += tr("<br>Using Qt v%1 © Trolltech AS").arg(QT_VERSION_STR);
|
Chris@132
|
5684 #endif
|
Chris@132
|
5685 #endif
|
Chris@132
|
5686
|
Chris@0
|
5687 #ifdef BUILD_STATIC
|
Chris@0
|
5688 aboutText += tr("<p>Statically linked");
|
Chris@0
|
5689 #ifndef QT_SHARED
|
Chris@0
|
5690 aboutText += tr("<br>With Qt (v%1) © Trolltech AS").arg(QT_VERSION_STR);
|
Chris@0
|
5691 #endif
|
Chris@0
|
5692 #ifdef HAVE_JACK
|
Chris@93
|
5693 #ifdef JACK_VERSION
|
Chris@0
|
5694 aboutText += tr("<br>With JACK audio output (v%1) © Paul Davis and Jack O'Quin").arg(JACK_VERSION);
|
Chris@93
|
5695 #else
|
Chris@93
|
5696 aboutText += tr("<br>With JACK audio output © Paul Davis and Jack O'Quin");
|
Chris@93
|
5697 #endif
|
Chris@0
|
5698 #endif
|
Chris@0
|
5699 #ifdef HAVE_PORTAUDIO
|
Chris@0
|
5700 aboutText += tr("<br>With PortAudio audio output © Ross Bencina and Phil Burk");
|
Chris@0
|
5701 #endif
|
Chris@0
|
5702 #ifdef HAVE_OGGZ
|
Chris@93
|
5703 #ifdef OGGZ_VERSION
|
Chris@0
|
5704 aboutText += tr("<br>With Ogg file decoder (oggz v%1, fishsound v%2) © CSIRO Australia").arg(OGGZ_VERSION).arg(FISHSOUND_VERSION);
|
Chris@93
|
5705 #else
|
Chris@93
|
5706 aboutText += tr("<br>With Ogg file decoder © CSIRO Australia");
|
Chris@93
|
5707 #endif
|
Chris@0
|
5708 #endif
|
Chris@0
|
5709 #ifdef HAVE_MAD
|
Chris@93
|
5710 #ifdef MAD_VERSION
|
Chris@0
|
5711 aboutText += tr("<br>With MAD mp3 decoder (v%1) © Underbit Technologies Inc").arg(MAD_VERSION);
|
Chris@93
|
5712 #else
|
Chris@93
|
5713 aboutText += tr("<br>With MAD mp3 decoder © Underbit Technologies Inc");
|
Chris@93
|
5714 #endif
|
Chris@0
|
5715 #endif
|
Chris@0
|
5716 #ifdef HAVE_SAMPLERATE
|
Chris@93
|
5717 #ifdef SAMPLERATE_VERSION
|
Chris@0
|
5718 aboutText += tr("<br>With libsamplerate (v%1) © Erik de Castro Lopo").arg(SAMPLERATE_VERSION);
|
Chris@93
|
5719 #else
|
Chris@93
|
5720 aboutText += tr("<br>With libsamplerate © Erik de Castro Lopo");
|
Chris@93
|
5721 #endif
|
Chris@0
|
5722 #endif
|
Chris@0
|
5723 #ifdef HAVE_SNDFILE
|
Chris@93
|
5724 #ifdef SNDFILE_VERSION
|
Chris@0
|
5725 aboutText += tr("<br>With libsndfile (v%1) © Erik de Castro Lopo").arg(SNDFILE_VERSION);
|
Chris@93
|
5726 #else
|
Chris@93
|
5727 aboutText += tr("<br>With libsndfile © Erik de Castro Lopo");
|
Chris@93
|
5728 #endif
|
Chris@0
|
5729 #endif
|
Chris@127
|
5730 #ifdef HAVE_FFTW3F
|
Chris@93
|
5731 #ifdef FFTW3_VERSION
|
Chris@0
|
5732 aboutText += tr("<br>With FFTW3 (v%1) © Matteo Frigo and MIT").arg(FFTW3_VERSION);
|
Chris@93
|
5733 #else
|
Chris@93
|
5734 aboutText += tr("<br>With FFTW3 © Matteo Frigo and MIT");
|
Chris@93
|
5735 #endif
|
Chris@0
|
5736 #endif
|
Chris@0
|
5737 #ifdef HAVE_VAMP
|
Chris@114
|
5738 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
|
5739 #endif
|
Chris@0
|
5740 aboutText += tr("<br>With LADSPA plugin support (API v%1) © Richard Furse, Paul Davis, Stefan Westerfeld").arg(LADSPA_VERSION);
|
Chris@0
|
5741 aboutText += tr("<br>With DSSI plugin support (API v%1) © Chris Cannam, Steve Harris, Sean Bolton").arg(DSSI_VERSION);
|
Chris@69
|
5742 #ifdef HAVE_LIBLO
|
Chris@93
|
5743 #ifdef LIBLO_VERSION
|
Chris@69
|
5744 aboutText += tr("<br>With liblo Lite OSC library (v%1) © Steve Harris").arg(LIBLO_VERSION);
|
Chris@93
|
5745 #else
|
Chris@93
|
5746 aboutText += tr("<br>With liblo Lite OSC library © Steve Harris").arg(LIBLO_VERSION);
|
Chris@93
|
5747 #endif
|
Chris@70
|
5748 if (m_oscQueue && m_oscQueue->isOK()) {
|
Chris@69
|
5749 aboutText += tr("<p>The OSC URL for this instance is: \"%1\"").arg(m_oscQueue->getOSCURL());
|
Chris@69
|
5750 }
|
Chris@69
|
5751 #endif
|
Chris@0
|
5752 aboutText += "</p>";
|
Chris@0
|
5753 #endif
|
Chris@0
|
5754
|
Chris@0
|
5755 aboutText +=
|
Chris@90
|
5756 "<p>Sonic Visualiser Copyright © 2005 - 2007 Chris Cannam and<br>"
|
Chris@90
|
5757 "Queen Mary, University of London.</p>"
|
Chris@0
|
5758 "<p>This program is free software; you can redistribute it and/or<br>"
|
Chris@0
|
5759 "modify it under the terms of the GNU General Public License as<br>"
|
Chris@0
|
5760 "published by the Free Software Foundation; either version 2 of the<br>"
|
Chris@0
|
5761 "License, or (at your option) any later version.<br>See the file "
|
Chris@0
|
5762 "COPYING included with this distribution for more information.</p>";
|
Chris@0
|
5763
|
Chris@0
|
5764 QMessageBox::about(this, tr("About Sonic Visualiser"), aboutText);
|
Chris@0
|
5765 }
|
Chris@0
|
5766
|
Chris@162
|
5767 void
|
Chris@162
|
5768 MainWindow::keyReference()
|
Chris@162
|
5769 {
|
Chris@162
|
5770 m_keyReference->show();
|
Chris@162
|
5771 }
|
Chris@162
|
5772
|