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