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