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@0
|
16 #ifndef _MAIN_WINDOW_H_
|
Chris@0
|
17 #define _MAIN_WINDOW_H_
|
Chris@0
|
18
|
Chris@0
|
19 #include <QFrame>
|
Chris@0
|
20 #include <QString>
|
Chris@85
|
21 #include <QUrl>
|
Chris@0
|
22 #include <QMainWindow>
|
Chris@0
|
23 #include <QPointer>
|
Chris@0
|
24
|
Chris@0
|
25 #include "base/Command.h"
|
Chris@1
|
26 #include "view/ViewManager.h"
|
Chris@0
|
27 #include "base/PropertyContainer.h"
|
Chris@34
|
28 #include "base/RecentFiles.h"
|
Chris@0
|
29 #include "layer/LayerFactory.h"
|
Chris@0
|
30 #include "transform/Transform.h"
|
Chris@1
|
31 #include "document/SVFileReader.h"
|
Chris@88
|
32 #include "data/fileio/FileFinder.h"
|
Chris@198
|
33 #include "data/fileio/FileSource.h"
|
Chris@0
|
34 #include <map>
|
Chris@0
|
35
|
Chris@0
|
36 class Document;
|
Chris@0
|
37 class PaneStack;
|
Chris@0
|
38 class Pane;
|
Chris@0
|
39 class View;
|
Chris@0
|
40 class Fader;
|
Chris@65
|
41 class Overview;
|
Chris@0
|
42 class Layer;
|
Chris@0
|
43 class WaveformLayer;
|
Chris@0
|
44 class WaveFileModel;
|
Chris@0
|
45 class AudioCallbackPlaySource;
|
Chris@0
|
46 class AudioCallbackPlayTarget;
|
Chris@0
|
47 class CommandHistory;
|
Chris@0
|
48 class QMenu;
|
Chris@0
|
49 class AudioDial;
|
Chris@0
|
50 class QLabel;
|
Chris@16
|
51 class QCheckBox;
|
Chris@0
|
52 class PreferencesDialog;
|
Chris@177
|
53 class QTreeView;
|
Chris@26
|
54 class QPushButton;
|
Chris@69
|
55 class OSCQueue;
|
Chris@69
|
56 class OSCMessage;
|
Chris@162
|
57 class KeyReference;
|
Chris@189
|
58 class Labeller;
|
Chris@0
|
59
|
Chris@0
|
60
|
Chris@0
|
61 class MainWindow : public QMainWindow
|
Chris@0
|
62 {
|
Chris@0
|
63 Q_OBJECT
|
Chris@0
|
64
|
Chris@0
|
65 public:
|
Chris@70
|
66 MainWindow(bool withAudioOutput = true,
|
Chris@70
|
67 bool withOSCSupport = true);
|
Chris@0
|
68 virtual ~MainWindow();
|
Chris@0
|
69
|
Chris@0
|
70 enum AudioFileOpenMode {
|
Chris@0
|
71 ReplaceMainModel,
|
Chris@0
|
72 CreateAdditionalModel,
|
Chris@194
|
73 ReplaceCurrentPane,
|
Chris@0
|
74 AskUser
|
Chris@0
|
75 };
|
Chris@0
|
76
|
Chris@82
|
77 enum FileOpenStatus {
|
Chris@82
|
78 FileOpenSucceeded,
|
Chris@82
|
79 FileOpenFailed,
|
Chris@193
|
80 FileOpenCancelled,
|
Chris@193
|
81 FileOpenWrongMode // attempted to open layer when no main model present
|
Chris@82
|
82 };
|
Chris@82
|
83
|
Chris@197
|
84 FileOpenStatus open(QString fileOrUrl, AudioFileOpenMode = AskUser);
|
Chris@198
|
85 FileOpenStatus open(FileSource source, AudioFileOpenMode = AskUser);
|
Chris@197
|
86
|
Chris@198
|
87 FileOpenStatus openAudio(FileSource source, AudioFileOpenMode = AskUser);
|
Chris@198
|
88 FileOpenStatus openPlaylist(FileSource source, AudioFileOpenMode = AskUser);
|
Chris@198
|
89 FileOpenStatus openLayer(FileSource source);
|
Chris@198
|
90 FileOpenStatus openImage(FileSource source);
|
Chris@198
|
91 FileOpenStatus openSession(FileSource source);
|
Chris@82
|
92
|
Chris@0
|
93 bool saveSessionFile(QString path);
|
Chris@11
|
94 bool commitData(bool mayAskUser); // on session shutdown
|
Chris@0
|
95
|
Chris@0
|
96 signals:
|
Chris@0
|
97 // Used to toggle the availability of menu actions
|
Chris@0
|
98 void canAddPane(bool);
|
Chris@0
|
99 void canDeleteCurrentPane(bool);
|
Chris@0
|
100 void canAddLayer(bool);
|
Chris@0
|
101 void canImportMoreAudio(bool);
|
Chris@0
|
102 void canImportLayer(bool);
|
Chris@0
|
103 void canExportAudio(bool);
|
Chris@0
|
104 void canExportLayer(bool);
|
Chris@121
|
105 void canExportImage(bool);
|
Chris@0
|
106 void canRenameLayer(bool);
|
Chris@0
|
107 void canEditLayer(bool);
|
Chris@169
|
108 void canMeasureLayer(bool);
|
Chris@0
|
109 void canSelect(bool);
|
Chris@0
|
110 void canClearSelection(bool);
|
Chris@0
|
111 void canEditSelection(bool);
|
Chris@164
|
112 void canDeleteSelection(bool);
|
Chris@0
|
113 void canPaste(bool);
|
Chris@0
|
114 void canInsertInstant(bool);
|
Chris@81
|
115 void canInsertInstantsAtBoundaries(bool);
|
Chris@189
|
116 void canRenumberInstants(bool);
|
Chris@0
|
117 void canDeleteCurrentLayer(bool);
|
Chris@0
|
118 void canZoom(bool);
|
Chris@0
|
119 void canScroll(bool);
|
Chris@0
|
120 void canPlay(bool);
|
Chris@0
|
121 void canFfwd(bool);
|
Chris@0
|
122 void canRewind(bool);
|
Chris@0
|
123 void canPlaySelection(bool);
|
Chris@155
|
124 void canSpeedUpPlayback(bool);
|
Chris@155
|
125 void canSlowDownPlayback(bool);
|
Chris@155
|
126 void canChangePlaybackSpeed(bool);
|
Chris@0
|
127 void canSave(bool);
|
Chris@0
|
128
|
Chris@118
|
129 public slots:
|
Chris@118
|
130 void preferenceChanged(PropertyContainer::PropertyName);
|
Chris@118
|
131
|
Chris@0
|
132 protected slots:
|
Chris@0
|
133 void openSession();
|
Chris@0
|
134 void importAudio();
|
Chris@0
|
135 void importMoreAudio();
|
Chris@0
|
136 void openSomething();
|
Chris@86
|
137 void openLocation();
|
Chris@0
|
138 void openRecentFile();
|
Chris@0
|
139 void exportAudio();
|
Chris@0
|
140 void importLayer();
|
Chris@0
|
141 void exportLayer();
|
Chris@121
|
142 void exportImage();
|
Chris@0
|
143 void saveSession();
|
Chris@0
|
144 void saveSessionAs();
|
Chris@0
|
145 void newSession();
|
Chris@0
|
146 void closeSession();
|
Chris@0
|
147 void preferences();
|
Chris@0
|
148
|
Chris@0
|
149 void zoomIn();
|
Chris@0
|
150 void zoomOut();
|
Chris@0
|
151 void zoomToFit();
|
Chris@0
|
152 void zoomDefault();
|
Chris@0
|
153 void scrollLeft();
|
Chris@0
|
154 void scrollRight();
|
Chris@0
|
155 void jumpLeft();
|
Chris@0
|
156 void jumpRight();
|
Chris@0
|
157
|
Chris@0
|
158 void showNoOverlays();
|
Chris@90
|
159 void showMinimalOverlays();
|
Chris@90
|
160 void showStandardOverlays();
|
Chris@90
|
161 void showAllOverlays();
|
Chris@7
|
162
|
Chris@7
|
163 void toggleZoomWheels();
|
Chris@72
|
164 void togglePropertyBoxes();
|
Chris@90
|
165 void toggleStatusBar();
|
Chris@0
|
166
|
Chris@0
|
167 void play();
|
Chris@0
|
168 void ffwd();
|
Chris@0
|
169 void ffwdEnd();
|
Chris@0
|
170 void rewind();
|
Chris@0
|
171 void rewindStart();
|
Chris@0
|
172 void stop();
|
Chris@0
|
173
|
Chris@0
|
174 void addPane();
|
Chris@0
|
175 void addLayer();
|
Chris@0
|
176 void deleteCurrentPane();
|
Chris@0
|
177 void renameCurrentLayer();
|
Chris@0
|
178 void deleteCurrentLayer();
|
Chris@0
|
179
|
Chris@0
|
180 void playLoopToggled();
|
Chris@0
|
181 void playSelectionToggled();
|
Chris@180
|
182 void playSoloToggled();
|
Chris@0
|
183 void playSpeedChanged(int);
|
Chris@16
|
184 void playSharpenToggled();
|
Chris@26
|
185 void playMonoToggled();
|
Chris@155
|
186 void speedUpPlayback();
|
Chris@155
|
187 void slowDownPlayback();
|
Chris@155
|
188 void restoreNormalPlayback();
|
Chris@0
|
189 void sampleRateMismatch(size_t, size_t, bool);
|
Chris@42
|
190 void audioOverloadPluginDisabled();
|
Chris@0
|
191
|
Chris@116
|
192 void playbackFrameChanged(unsigned long);
|
Chris@116
|
193 void globalCentreFrameChanged(unsigned long);
|
Chris@116
|
194 void viewCentreFrameChanged(View *, unsigned long);
|
Chris@116
|
195 void viewZoomLevelChanged(View *, unsigned long, bool);
|
Chris@0
|
196 void outputLevelsChanged(float, float);
|
Chris@0
|
197
|
Chris@0
|
198 void currentPaneChanged(Pane *);
|
Chris@0
|
199 void currentLayerChanged(Pane *, Layer *);
|
Chris@0
|
200
|
Chris@0
|
201 void toolNavigateSelected();
|
Chris@0
|
202 void toolSelectSelected();
|
Chris@0
|
203 void toolEditSelected();
|
Chris@0
|
204 void toolDrawSelected();
|
Chris@151
|
205 void toolMeasureSelected();
|
Chris@0
|
206
|
Chris@0
|
207 void selectAll();
|
Chris@0
|
208 void selectToStart();
|
Chris@0
|
209 void selectToEnd();
|
Chris@0
|
210 void selectVisible();
|
Chris@0
|
211 void clearSelection();
|
Chris@0
|
212 void cut();
|
Chris@0
|
213 void copy();
|
Chris@0
|
214 void paste();
|
Chris@0
|
215 void deleteSelected();
|
Chris@0
|
216 void insertInstant();
|
Chris@81
|
217 void insertInstantAt(size_t);
|
Chris@81
|
218 void insertInstantsAtBoundaries();
|
Chris@189
|
219 void setInstantsNumbering();
|
Chris@189
|
220 void setInstantsCounterCycle();
|
Chris@192
|
221 void resetInstantsCounters();
|
Chris@189
|
222 void renumberInstants();
|
Chris@0
|
223
|
Chris@0
|
224 void documentModified();
|
Chris@0
|
225 void documentRestored();
|
Chris@0
|
226
|
Chris@0
|
227 void updateMenuStates();
|
Chris@0
|
228 void updateDescriptionLabel();
|
Chris@0
|
229
|
Chris@0
|
230 void layerAdded(Layer *);
|
Chris@0
|
231 void layerRemoved(Layer *);
|
Chris@0
|
232 void layerAboutToBeDeleted(Layer *);
|
Chris@0
|
233 void layerInAView(Layer *, bool);
|
Chris@0
|
234
|
Chris@0
|
235 void mainModelChanged(WaveFileModel *);
|
Chris@0
|
236 void modelAdded(Model *);
|
Chris@0
|
237 void modelAboutToBeDeleted(Model *);
|
Chris@0
|
238
|
Chris@0
|
239 void modelGenerationFailed(QString);
|
Chris@0
|
240 void modelRegenerationFailed(QString, QString);
|
Chris@0
|
241
|
Chris@0
|
242 void rightButtonMenuRequested(Pane *, QPoint point);
|
Chris@0
|
243
|
Chris@73
|
244 void propertyStacksResized();
|
Chris@73
|
245
|
Chris@193
|
246 void paneDropAccepted(Pane *, QStringList);
|
Chris@193
|
247 void paneDropAccepted(Pane *, QString);
|
Chris@193
|
248
|
Chris@0
|
249 void setupRecentFilesMenu();
|
Chris@34
|
250 void setupRecentTransformsMenu();
|
Chris@0
|
251
|
Chris@0
|
252 void showLayerTree();
|
Chris@0
|
253
|
Chris@69
|
254 void pollOSC();
|
Chris@69
|
255 void handleOSCMessage(const OSCMessage &);
|
Chris@69
|
256
|
Chris@90
|
257 void mouseEnteredWidget();
|
Chris@90
|
258 void mouseLeftWidget();
|
Chris@116
|
259 void contextHelpChanged(const QString &);
|
Chris@117
|
260 void inProgressSelectionChanged();
|
Chris@90
|
261
|
Chris@0
|
262 void website();
|
Chris@0
|
263 void help();
|
Chris@0
|
264 void about();
|
Chris@162
|
265 void keyReference();
|
Chris@0
|
266
|
Chris@0
|
267 protected:
|
Chris@0
|
268 QString m_sessionFile;
|
Chris@0
|
269 QString m_audioFile;
|
Chris@0
|
270 Document *m_document;
|
Chris@0
|
271
|
Chris@0
|
272 QLabel *m_descriptionLabel;
|
Chris@0
|
273 PaneStack *m_paneStack;
|
Chris@0
|
274 ViewManager *m_viewManager;
|
Chris@65
|
275 Overview *m_overview;
|
Chris@0
|
276 Fader *m_fader;
|
Chris@0
|
277 AudioDial *m_playSpeed;
|
Chris@26
|
278 QPushButton *m_playSharpen;
|
Chris@26
|
279 QPushButton *m_playMono;
|
Chris@0
|
280 WaveformLayer *m_panLayer;
|
Chris@0
|
281 Layer *m_timeRulerLayer;
|
Chris@0
|
282
|
Chris@46
|
283 bool m_audioOutput;
|
Chris@0
|
284 AudioCallbackPlaySource *m_playSource;
|
Chris@0
|
285 AudioCallbackPlayTarget *m_playTarget;
|
Chris@0
|
286
|
Chris@69
|
287 OSCQueue *m_oscQueue;
|
Chris@69
|
288
|
Chris@34
|
289 RecentFiles m_recentFiles;
|
Chris@34
|
290 RecentFiles m_recentTransforms;
|
Chris@34
|
291
|
Chris@0
|
292 bool m_mainMenusCreated;
|
Chris@0
|
293 QMenu *m_paneMenu;
|
Chris@0
|
294 QMenu *m_layerMenu;
|
Chris@34
|
295 QMenu *m_transformsMenu;
|
Chris@155
|
296 QMenu *m_playbackMenu;
|
Chris@0
|
297 QMenu *m_existingLayersMenu;
|
Chris@95
|
298 QMenu *m_sliceMenu;
|
Chris@0
|
299 QMenu *m_recentFilesMenu;
|
Chris@34
|
300 QMenu *m_recentTransformsMenu;
|
Chris@0
|
301 QMenu *m_rightButtonMenu;
|
Chris@0
|
302 QMenu *m_rightButtonLayerMenu;
|
Chris@34
|
303 QMenu *m_rightButtonTransformsMenu;
|
Chris@155
|
304 QMenu *m_rightButtonPlaybackMenu;
|
Chris@155
|
305
|
Chris@164
|
306 QAction *m_deleteSelectedAction;
|
Chris@155
|
307 QAction *m_ffwdAction;
|
Chris@155
|
308 QAction *m_rwdAction;
|
Chris@0
|
309
|
Chris@0
|
310 bool m_documentModified;
|
Chris@70
|
311 bool m_openingAudioFile;
|
Chris@70
|
312 bool m_abandoning;
|
Chris@0
|
313
|
Chris@189
|
314 Labeller *m_labeller;
|
Chris@189
|
315
|
Chris@116
|
316 int m_lastPlayStatusSec;
|
Chris@116
|
317 mutable QString m_myStatusMessage;
|
Chris@116
|
318
|
Chris@0
|
319 QPointer<PreferencesDialog> m_preferencesDialog;
|
Chris@177
|
320 QPointer<QTreeView> m_layerTreeView;
|
Chris@0
|
321
|
Chris@180
|
322 bool m_initialDarkBackground;
|
Chris@180
|
323
|
Chris@162
|
324 KeyReference *m_keyReference;
|
Chris@162
|
325
|
Chris@0
|
326 WaveFileModel *getMainModel();
|
Chris@116
|
327 const WaveFileModel *getMainModel() const;
|
Chris@0
|
328 void createDocument();
|
Chris@0
|
329
|
Chris@0
|
330 struct PaneConfiguration {
|
Chris@0
|
331 PaneConfiguration(LayerFactory::LayerType _layer
|
Chris@0
|
332 = LayerFactory::TimeRuler,
|
Chris@66
|
333 Model *_source = 0,
|
Chris@0
|
334 int _channel = -1) :
|
Chris@66
|
335 layer(_layer), sourceModel(_source), channel(_channel) { }
|
Chris@0
|
336 LayerFactory::LayerType layer;
|
Chris@66
|
337 Model *sourceModel;
|
Chris@0
|
338 int channel;
|
Chris@0
|
339 };
|
Chris@0
|
340
|
Chris@0
|
341 typedef std::map<QAction *, PaneConfiguration> PaneActionMap;
|
Chris@0
|
342 PaneActionMap m_paneActions;
|
Chris@0
|
343
|
Chris@107
|
344 typedef std::map<QAction *, TransformId> TransformActionMap;
|
Chris@34
|
345 TransformActionMap m_transformActions;
|
Chris@34
|
346
|
Chris@107
|
347 typedef std::map<TransformId, QAction *> TransformActionReverseMap;
|
Chris@34
|
348 TransformActionReverseMap m_transformActionsReverse;
|
Chris@0
|
349
|
Chris@0
|
350 typedef std::map<QAction *, LayerFactory::LayerType> LayerActionMap;
|
Chris@0
|
351 LayerActionMap m_layerActions;
|
Chris@0
|
352
|
Chris@0
|
353 typedef std::map<QAction *, Layer *> ExistingLayerActionMap;
|
Chris@0
|
354 ExistingLayerActionMap m_existingLayerActions;
|
Chris@95
|
355 ExistingLayerActionMap m_sliceActions;
|
Chris@0
|
356
|
Chris@0
|
357 typedef std::map<ViewManager::ToolMode, QAction *> ToolActionMap;
|
Chris@0
|
358 ToolActionMap m_toolActions;
|
Chris@0
|
359
|
Chris@189
|
360 typedef std::map<QAction *, int> NumberingActionMap;
|
Chris@189
|
361 NumberingActionMap m_numberingActions;
|
Chris@189
|
362
|
Chris@0
|
363 void setupMenus();
|
Chris@66
|
364 void setupFileMenu();
|
Chris@66
|
365 void setupEditMenu();
|
Chris@66
|
366 void setupViewMenu();
|
Chris@66
|
367 void setupPaneAndLayerMenus();
|
Chris@66
|
368 void setupTransformsMenu();
|
Chris@66
|
369 void setupHelpMenu();
|
Chris@95
|
370 void setupExistingLayersMenus();
|
Chris@0
|
371 void setupToolbars();
|
Chris@66
|
372
|
Chris@0
|
373 Pane *addPaneToStack();
|
Chris@0
|
374
|
Chris@69
|
375 void addPane(const PaneConfiguration &configuration, QString text);
|
Chris@69
|
376
|
Chris@155
|
377 Layer *getSnapLayer() const;
|
Chris@155
|
378
|
Chris@0
|
379 class PaneCallback : public SVFileReaderPaneCallback
|
Chris@0
|
380 {
|
Chris@0
|
381 public:
|
Chris@0
|
382 PaneCallback(MainWindow *mw) : m_mw(mw) { }
|
Chris@0
|
383 virtual Pane *addPane() { return m_mw->addPaneToStack(); }
|
Chris@0
|
384 virtual void setWindowSize(int width, int height) {
|
Chris@0
|
385 m_mw->resize(width, height);
|
Chris@0
|
386 }
|
Chris@0
|
387 virtual void addSelection(int start, int end) {
|
Chris@0
|
388 m_mw->m_viewManager->addSelection(Selection(start, end));
|
Chris@0
|
389 }
|
Chris@0
|
390 protected:
|
Chris@0
|
391 MainWindow *m_mw;
|
Chris@0
|
392 };
|
Chris@0
|
393
|
Chris@0
|
394 class AddPaneCommand : public Command
|
Chris@0
|
395 {
|
Chris@0
|
396 public:
|
Chris@0
|
397 AddPaneCommand(MainWindow *mw);
|
Chris@0
|
398 virtual ~AddPaneCommand();
|
Chris@0
|
399
|
Chris@0
|
400 virtual void execute();
|
Chris@0
|
401 virtual void unexecute();
|
Chris@0
|
402 virtual QString getName() const;
|
Chris@0
|
403
|
Chris@0
|
404 Pane *getPane() { return m_pane; }
|
Chris@0
|
405
|
Chris@0
|
406 protected:
|
Chris@0
|
407 MainWindow *m_mw;
|
Chris@0
|
408 Pane *m_pane; // Main window owns this, but I determine its lifespan
|
Chris@0
|
409 Pane *m_prevCurrentPane; // I don't own this
|
Chris@0
|
410 bool m_added;
|
Chris@0
|
411 };
|
Chris@0
|
412
|
Chris@0
|
413 class RemovePaneCommand : public Command
|
Chris@0
|
414 {
|
Chris@0
|
415 public:
|
Chris@0
|
416 RemovePaneCommand(MainWindow *mw, Pane *pane);
|
Chris@0
|
417 virtual ~RemovePaneCommand();
|
Chris@0
|
418
|
Chris@0
|
419 virtual void execute();
|
Chris@0
|
420 virtual void unexecute();
|
Chris@0
|
421 virtual QString getName() const;
|
Chris@0
|
422
|
Chris@0
|
423 protected:
|
Chris@0
|
424 MainWindow *m_mw;
|
Chris@0
|
425 Pane *m_pane; // Main window owns this, but I determine its lifespan
|
Chris@0
|
426 Pane *m_prevCurrentPane; // I don't own this
|
Chris@0
|
427 bool m_added;
|
Chris@0
|
428 };
|
Chris@0
|
429
|
Chris@0
|
430 virtual void closeEvent(QCloseEvent *e);
|
Chris@0
|
431 bool checkSaveModified();
|
Chris@0
|
432
|
Chris@88
|
433 QString getOpenFileName(FileFinder::FileType type);
|
Chris@88
|
434 QString getSaveFileName(FileFinder::FileType type);
|
Chris@88
|
435 void registerLastOpenedFilePath(FileFinder::FileType type, QString path);
|
Chris@81
|
436
|
Chris@0
|
437 void createPlayTarget();
|
Chris@0
|
438
|
Chris@0
|
439 void openHelpUrl(QString url);
|
Chris@0
|
440
|
Chris@116
|
441 void updateVisibleRangeDisplay(Pane *p) const;
|
Chris@116
|
442
|
Chris@0
|
443 void toXml(QTextStream &stream);
|
Chris@0
|
444 };
|
Chris@0
|
445
|
Chris@0
|
446
|
Chris@0
|
447 #endif
|