comparison sv/main/MainWindow.h @ 0:fc9323a41f5a

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