Mercurial > hg > sonic-visualiser
comparison main/MainWindow.h @ 200:1871581e4da9
* Split MainWindow out into MainWindowBase (pane stack management, basic file
I/O etc) and MainWindow (widget structure, menus and actions etc)
author | Chris Cannam |
---|---|
date | Mon, 22 Oct 2007 14:24:31 +0000 |
parents | 24ac2e4010c5 |
children | 0de89bce24e4 |
comparison
equal
deleted
inserted
replaced
199:6e1d4d500092 | 200:1871581e4da9 |
---|---|
2 | 2 |
3 /* | 3 /* |
4 Sonic Visualiser | 4 Sonic Visualiser |
5 An audio file viewer and annotation editor. | 5 An audio file viewer and annotation editor. |
6 Centre for Digital Music, Queen Mary, University of London. | 6 Centre for Digital Music, Queen Mary, University of London. |
7 This file copyright 2006 Chris Cannam and QMUL. | 7 This file copyright 2006-2007 Chris Cannam and QMUL. |
8 | 8 |
9 This program is free software; you can redistribute it and/or | 9 This program is free software; you can redistribute it and/or |
10 modify it under the terms of the GNU General Public License as | 10 modify it under the terms of the GNU General Public License as |
11 published by the Free Software Foundation; either version 2 of the | 11 published by the Free Software Foundation; either version 2 of the |
12 License, or (at your option) any later version. See the file | 12 License, or (at your option) any later version. See the file |
17 #define _MAIN_WINDOW_H_ | 17 #define _MAIN_WINDOW_H_ |
18 | 18 |
19 #include <QFrame> | 19 #include <QFrame> |
20 #include <QString> | 20 #include <QString> |
21 #include <QUrl> | 21 #include <QUrl> |
22 #include <QMainWindow> | |
23 #include <QPointer> | 22 #include <QPointer> |
23 | |
24 #include "MainWindowBase.h" | |
24 | 25 |
25 #include "base/Command.h" | 26 #include "base/Command.h" |
26 #include "view/ViewManager.h" | 27 #include "view/ViewManager.h" |
27 #include "base/PropertyContainer.h" | 28 #include "base/PropertyContainer.h" |
28 #include "base/RecentFiles.h" | 29 #include "base/RecentFiles.h" |
56 class OSCMessage; | 57 class OSCMessage; |
57 class KeyReference; | 58 class KeyReference; |
58 class Labeller; | 59 class Labeller; |
59 | 60 |
60 | 61 |
61 class MainWindow : public QMainWindow | 62 class MainWindow : public MainWindowBase |
62 { | 63 { |
63 Q_OBJECT | 64 Q_OBJECT |
64 | 65 |
65 public: | 66 public: |
66 MainWindow(bool withAudioOutput = true, | 67 MainWindow(bool withAudioOutput = true, |
67 bool withOSCSupport = true); | 68 bool withOSCSupport = true); |
68 virtual ~MainWindow(); | 69 virtual ~MainWindow(); |
69 | |
70 enum AudioFileOpenMode { | |
71 ReplaceMainModel, | |
72 CreateAdditionalModel, | |
73 ReplaceCurrentPane, | |
74 AskUser | |
75 }; | |
76 | |
77 enum FileOpenStatus { | |
78 FileOpenSucceeded, | |
79 FileOpenFailed, | |
80 FileOpenCancelled, | |
81 FileOpenWrongMode // attempted to open layer when no main model present | |
82 }; | |
83 | |
84 FileOpenStatus open(QString fileOrUrl, AudioFileOpenMode = AskUser); | |
85 FileOpenStatus open(FileSource source, AudioFileOpenMode = AskUser); | |
86 | |
87 FileOpenStatus openAudio(FileSource source, AudioFileOpenMode = AskUser); | |
88 FileOpenStatus openPlaylist(FileSource source, AudioFileOpenMode = AskUser); | |
89 FileOpenStatus openLayer(FileSource source); | |
90 FileOpenStatus openImage(FileSource source); | |
91 FileOpenStatus openSession(FileSource source); | |
92 | |
93 bool saveSessionFile(QString path); | |
94 bool commitData(bool mayAskUser); // on session shutdown | |
95 | 70 |
96 signals: | 71 signals: |
97 // Used to toggle the availability of menu actions | |
98 void canAddPane(bool); | |
99 void canDeleteCurrentPane(bool); | |
100 void canAddLayer(bool); | |
101 void canImportMoreAudio(bool); | |
102 void canImportLayer(bool); | |
103 void canExportAudio(bool); | |
104 void canExportLayer(bool); | |
105 void canExportImage(bool); | |
106 void canRenameLayer(bool); | |
107 void canEditLayer(bool); | |
108 void canMeasureLayer(bool); | |
109 void canSelect(bool); | |
110 void canClearSelection(bool); | |
111 void canEditSelection(bool); | |
112 void canDeleteSelection(bool); | |
113 void canPaste(bool); | |
114 void canInsertInstant(bool); | |
115 void canInsertInstantsAtBoundaries(bool); | |
116 void canRenumberInstants(bool); | |
117 void canDeleteCurrentLayer(bool); | |
118 void canZoom(bool); | |
119 void canScroll(bool); | |
120 void canPlay(bool); | |
121 void canFfwd(bool); | |
122 void canRewind(bool); | |
123 void canPlaySelection(bool); | |
124 void canSpeedUpPlayback(bool); | |
125 void canSlowDownPlayback(bool); | |
126 void canChangePlaybackSpeed(bool); | |
127 void canSave(bool); | |
128 | 72 |
129 public slots: | 73 public slots: |
130 void preferenceChanged(PropertyContainer::PropertyName); | 74 virtual void preferenceChanged(PropertyContainer::PropertyName); |
75 virtual bool commitData(bool mayAskUser); | |
131 | 76 |
132 protected slots: | 77 protected slots: |
133 void openSession(); | 78 virtual void openSession(); |
134 void importAudio(); | 79 virtual void importAudio(); |
135 void importMoreAudio(); | 80 virtual void importMoreAudio(); |
136 void openSomething(); | 81 virtual void openSomething(); |
137 void openLocation(); | 82 virtual void openLocation(); |
138 void openRecentFile(); | 83 virtual void openRecentFile(); |
139 void exportAudio(); | 84 virtual void exportAudio(); |
140 void importLayer(); | 85 virtual void importLayer(); |
141 void exportLayer(); | 86 virtual void exportLayer(); |
142 void exportImage(); | 87 virtual void exportImage(); |
143 void saveSession(); | 88 virtual void saveSession(); |
144 void saveSessionAs(); | 89 virtual void saveSessionAs(); |
145 void newSession(); | 90 virtual void newSession(); |
146 void closeSession(); | 91 virtual void closeSession(); |
147 void preferences(); | 92 virtual void preferences(); |
148 | 93 |
149 void zoomIn(); | 94 virtual void sampleRateMismatch(size_t, size_t, bool); |
150 void zoomOut(); | 95 virtual void audioOverloadPluginDisabled(); |
151 void zoomToFit(); | 96 |
152 void zoomDefault(); | 97 virtual void toolNavigateSelected(); |
153 void scrollLeft(); | 98 virtual void toolSelectSelected(); |
154 void scrollRight(); | 99 virtual void toolEditSelected(); |
155 void jumpLeft(); | 100 virtual void toolDrawSelected(); |
156 void jumpRight(); | 101 virtual void toolMeasureSelected(); |
157 | 102 |
158 void showNoOverlays(); | 103 virtual void documentModified(); |
159 void showMinimalOverlays(); | 104 virtual void documentRestored(); |
160 void showStandardOverlays(); | 105 |
161 void showAllOverlays(); | 106 virtual void updateMenuStates(); |
162 | 107 virtual void updateDescriptionLabel(); |
163 void toggleZoomWheels(); | 108 |
164 void togglePropertyBoxes(); | 109 virtual void setInstantsNumbering(); |
165 void toggleStatusBar(); | 110 virtual void setInstantsCounterCycle(); |
166 | 111 virtual void resetInstantsCounters(); |
167 void play(); | 112 |
168 void ffwd(); | 113 virtual void modelGenerationFailed(QString); |
169 void ffwdEnd(); | 114 virtual void modelRegenerationFailed(QString, QString); |
170 void rewind(); | 115 |
171 void rewindStart(); | 116 virtual void rightButtonMenuRequested(Pane *, QPoint point); |
172 void stop(); | 117 |
173 | 118 virtual void addPane(); |
174 void addPane(); | 119 virtual void addLayer(); |
175 void addLayer(); | 120 virtual void renameCurrentLayer(); |
176 void deleteCurrentPane(); | 121 |
177 void renameCurrentLayer(); | 122 virtual void paneAdded(Pane *); |
178 void deleteCurrentLayer(); | 123 virtual void paneHidden(Pane *); |
179 | 124 virtual void paneAboutToBeDeleted(Pane *); |
180 void playLoopToggled(); | 125 virtual void paneDropAccepted(Pane *, QStringList); |
181 void playSelectionToggled(); | 126 virtual void paneDropAccepted(Pane *, QString); |
182 void playSoloToggled(); | 127 |
183 void playSpeedChanged(int); | 128 virtual void setupRecentFilesMenu(); |
184 void playSharpenToggled(); | 129 virtual void setupRecentTransformsMenu(); |
185 void playMonoToggled(); | 130 |
186 void speedUpPlayback(); | 131 virtual void playSpeedChanged(int); |
187 void slowDownPlayback(); | 132 virtual void playSharpenToggled(); |
188 void restoreNormalPlayback(); | 133 virtual void playMonoToggled(); |
189 void sampleRateMismatch(size_t, size_t, bool); | 134 |
190 void audioOverloadPluginDisabled(); | 135 virtual void speedUpPlayback(); |
191 | 136 virtual void slowDownPlayback(); |
192 void playbackFrameChanged(unsigned long); | 137 virtual void restoreNormalPlayback(); |
193 void globalCentreFrameChanged(unsigned long); | 138 |
194 void viewCentreFrameChanged(View *, unsigned long); | 139 virtual void outputLevelsChanged(float, float); |
195 void viewZoomLevelChanged(View *, unsigned long, bool); | 140 |
196 void outputLevelsChanged(float, float); | 141 virtual void layerRemoved(Layer *); |
197 | 142 virtual void layerInAView(Layer *, bool); |
198 void currentPaneChanged(Pane *); | 143 |
199 void currentLayerChanged(Pane *, Layer *); | 144 virtual void mainModelChanged(WaveFileModel *); |
200 | 145 virtual void modelAdded(Model *); |
201 void toolNavigateSelected(); | 146 |
202 void toolSelectSelected(); | 147 virtual void showLayerTree(); |
203 void toolEditSelected(); | 148 |
204 void toolDrawSelected(); | 149 virtual void mouseEnteredWidget(); |
205 void toolMeasureSelected(); | 150 virtual void mouseLeftWidget(); |
206 | 151 |
207 void selectAll(); | 152 virtual void handleOSCMessage(const OSCMessage &); |
208 void selectToStart(); | 153 |
209 void selectToEnd(); | 154 virtual void website(); |
210 void selectVisible(); | 155 virtual void help(); |
211 void clearSelection(); | 156 virtual void about(); |
212 void cut(); | 157 virtual void keyReference(); |
213 void copy(); | |
214 void paste(); | |
215 void deleteSelected(); | |
216 void insertInstant(); | |
217 void insertInstantAt(size_t); | |
218 void insertInstantsAtBoundaries(); | |
219 void setInstantsNumbering(); | |
220 void setInstantsCounterCycle(); | |
221 void resetInstantsCounters(); | |
222 void renumberInstants(); | |
223 | |
224 void documentModified(); | |
225 void documentRestored(); | |
226 | |
227 void updateMenuStates(); | |
228 void updateDescriptionLabel(); | |
229 | |
230 void layerAdded(Layer *); | |
231 void layerRemoved(Layer *); | |
232 void layerAboutToBeDeleted(Layer *); | |
233 void layerInAView(Layer *, bool); | |
234 | |
235 void mainModelChanged(WaveFileModel *); | |
236 void modelAdded(Model *); | |
237 void modelAboutToBeDeleted(Model *); | |
238 | |
239 void modelGenerationFailed(QString); | |
240 void modelRegenerationFailed(QString, QString); | |
241 | |
242 void rightButtonMenuRequested(Pane *, QPoint point); | |
243 | |
244 void propertyStacksResized(); | |
245 | |
246 void paneDropAccepted(Pane *, QStringList); | |
247 void paneDropAccepted(Pane *, QString); | |
248 | |
249 void setupRecentFilesMenu(); | |
250 void setupRecentTransformsMenu(); | |
251 | |
252 void showLayerTree(); | |
253 | |
254 void pollOSC(); | |
255 void handleOSCMessage(const OSCMessage &); | |
256 | |
257 void mouseEnteredWidget(); | |
258 void mouseLeftWidget(); | |
259 void contextHelpChanged(const QString &); | |
260 void inProgressSelectionChanged(); | |
261 | |
262 void website(); | |
263 void help(); | |
264 void about(); | |
265 void keyReference(); | |
266 | 158 |
267 protected: | 159 protected: |
268 QString m_sessionFile; | |
269 QString m_audioFile; | |
270 Document *m_document; | |
271 | |
272 QLabel *m_descriptionLabel; | |
273 PaneStack *m_paneStack; | |
274 ViewManager *m_viewManager; | |
275 Overview *m_overview; | 160 Overview *m_overview; |
276 Fader *m_fader; | 161 Fader *m_fader; |
277 AudioDial *m_playSpeed; | 162 AudioDial *m_playSpeed; |
278 QPushButton *m_playSharpen; | 163 QPushButton *m_playSharpen; |
279 QPushButton *m_playMono; | 164 QPushButton *m_playMono; |
280 WaveformLayer *m_panLayer; | 165 WaveformLayer *m_panLayer; |
281 Layer *m_timeRulerLayer; | |
282 | |
283 bool m_audioOutput; | |
284 AudioCallbackPlaySource *m_playSource; | |
285 AudioCallbackPlayTarget *m_playTarget; | |
286 | |
287 OSCQueue *m_oscQueue; | |
288 | |
289 RecentFiles m_recentFiles; | |
290 RecentFiles m_recentTransforms; | |
291 | 166 |
292 bool m_mainMenusCreated; | 167 bool m_mainMenusCreated; |
293 QMenu *m_paneMenu; | 168 QMenu *m_paneMenu; |
294 QMenu *m_layerMenu; | 169 QMenu *m_layerMenu; |
295 QMenu *m_transformsMenu; | 170 QMenu *m_transformsMenu; |
305 | 180 |
306 QAction *m_deleteSelectedAction; | 181 QAction *m_deleteSelectedAction; |
307 QAction *m_ffwdAction; | 182 QAction *m_ffwdAction; |
308 QAction *m_rwdAction; | 183 QAction *m_rwdAction; |
309 | 184 |
310 bool m_documentModified; | |
311 bool m_openingAudioFile; | |
312 bool m_abandoning; | |
313 | |
314 Labeller *m_labeller; | |
315 | |
316 int m_lastPlayStatusSec; | |
317 mutable QString m_myStatusMessage; | |
318 | |
319 QPointer<PreferencesDialog> m_preferencesDialog; | 185 QPointer<PreferencesDialog> m_preferencesDialog; |
320 QPointer<QTreeView> m_layerTreeView; | 186 QPointer<QTreeView> m_layerTreeView; |
321 | 187 |
322 bool m_initialDarkBackground; | |
323 | |
324 KeyReference *m_keyReference; | 188 KeyReference *m_keyReference; |
325 | |
326 WaveFileModel *getMainModel(); | |
327 const WaveFileModel *getMainModel() const; | |
328 void createDocument(); | |
329 | 189 |
330 struct PaneConfiguration { | 190 struct PaneConfiguration { |
331 PaneConfiguration(LayerFactory::LayerType _layer | 191 PaneConfiguration(LayerFactory::LayerType _layer |
332 = LayerFactory::TimeRuler, | 192 = LayerFactory::TimeRuler, |
333 Model *_source = 0, | 193 Model *_source = 0, |
358 ToolActionMap m_toolActions; | 218 ToolActionMap m_toolActions; |
359 | 219 |
360 typedef std::map<QAction *, int> NumberingActionMap; | 220 typedef std::map<QAction *, int> NumberingActionMap; |
361 NumberingActionMap m_numberingActions; | 221 NumberingActionMap m_numberingActions; |
362 | 222 |
363 void setupMenus(); | 223 virtual void setupMenus(); |
364 void setupFileMenu(); | 224 virtual void setupFileMenu(); |
365 void setupEditMenu(); | 225 virtual void setupEditMenu(); |
366 void setupViewMenu(); | 226 virtual void setupViewMenu(); |
367 void setupPaneAndLayerMenus(); | 227 virtual void setupPaneAndLayerMenus(); |
368 void setupTransformsMenu(); | 228 virtual void setupTransformsMenu(); |
369 void setupHelpMenu(); | 229 virtual void setupHelpMenu(); |
370 void setupExistingLayersMenus(); | 230 virtual void setupExistingLayersMenus(); |
371 void setupToolbars(); | 231 virtual void setupToolbars(); |
372 | 232 |
373 Pane *addPaneToStack(); | 233 virtual void addPane(const PaneConfiguration &configuration, QString text); |
374 | |
375 void addPane(const PaneConfiguration &configuration, QString text); | |
376 | |
377 Layer *getSnapLayer() const; | |
378 | |
379 class PaneCallback : public SVFileReaderPaneCallback | |
380 { | |
381 public: | |
382 PaneCallback(MainWindow *mw) : m_mw(mw) { } | |
383 virtual Pane *addPane() { return m_mw->addPaneToStack(); } | |
384 virtual void setWindowSize(int width, int height) { | |
385 m_mw->resize(width, height); | |
386 } | |
387 virtual void addSelection(int start, int end) { | |
388 m_mw->m_viewManager->addSelection(Selection(start, end)); | |
389 } | |
390 protected: | |
391 MainWindow *m_mw; | |
392 }; | |
393 | |
394 class AddPaneCommand : public Command | |
395 { | |
396 public: | |
397 AddPaneCommand(MainWindow *mw); | |
398 virtual ~AddPaneCommand(); | |
399 | |
400 virtual void execute(); | |
401 virtual void unexecute(); | |
402 virtual QString getName() const; | |
403 | |
404 Pane *getPane() { return m_pane; } | |
405 | |
406 protected: | |
407 MainWindow *m_mw; | |
408 Pane *m_pane; // Main window owns this, but I determine its lifespan | |
409 Pane *m_prevCurrentPane; // I don't own this | |
410 bool m_added; | |
411 }; | |
412 | |
413 class RemovePaneCommand : public Command | |
414 { | |
415 public: | |
416 RemovePaneCommand(MainWindow *mw, Pane *pane); | |
417 virtual ~RemovePaneCommand(); | |
418 | |
419 virtual void execute(); | |
420 virtual void unexecute(); | |
421 virtual QString getName() const; | |
422 | |
423 protected: | |
424 MainWindow *m_mw; | |
425 Pane *m_pane; // Main window owns this, but I determine its lifespan | |
426 Pane *m_prevCurrentPane; // I don't own this | |
427 bool m_added; | |
428 }; | |
429 | 234 |
430 virtual void closeEvent(QCloseEvent *e); | 235 virtual void closeEvent(QCloseEvent *e); |
431 bool checkSaveModified(); | 236 virtual bool checkSaveModified(); |
432 | 237 |
433 QString getOpenFileName(FileFinder::FileType type); | 238 virtual void updateVisibleRangeDisplay(Pane *p) const; |
434 QString getSaveFileName(FileFinder::FileType type); | |
435 void registerLastOpenedFilePath(FileFinder::FileType type, QString path); | |
436 | |
437 void createPlayTarget(); | |
438 | |
439 void openHelpUrl(QString url); | |
440 | |
441 void updateVisibleRangeDisplay(Pane *p) const; | |
442 | |
443 void toXml(QTextStream &stream); | |
444 }; | 239 }; |
445 | 240 |
446 | 241 |
447 #endif | 242 #endif |