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