comparison framework/MainWindowBase.h @ 45:9ea770d93fae

* document -> framework (will not compile, path fixes not in yet)
author Chris Cannam
date Wed, 24 Oct 2007 16:37:58 +0000
parents
children 7fbe1c99d5d8
comparison
equal deleted inserted replaced
44:9ebe12983f3e 45:9ea770d93fae
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-2007 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_BASE_H_
17 #define _MAIN_WINDOW_BASE_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 "plugin/transform/Transform.h"
31 #include "document/SVFileReader.h"
32 #include "data/fileio/FileFinder.h"
33 #include "data/fileio/FileSource.h"
34 #include <map>
35
36 class Document;
37 class PaneStack;
38 class Pane;
39 class View;
40 class Fader;
41 class Overview;
42 class Layer;
43 class WaveformLayer;
44 class WaveFileModel;
45 class AudioCallbackPlaySource;
46 class AudioCallbackPlayTarget;
47 class CommandHistory;
48 class QMenu;
49 class AudioDial;
50 class QLabel;
51 class QCheckBox;
52 class PreferencesDialog;
53 class QTreeView;
54 class QPushButton;
55 class OSCQueue;
56 class OSCMessage;
57 class KeyReference;
58 class Labeller;
59
60 /**
61 * The base class for the SV main window. This includes everything to
62 * do with general document and pane stack management, but nothing
63 * that involves user interaction -- this doesn't create the widget or
64 * menu structures or editing tools, and if a function needs to open a
65 * dialog, it shouldn't be in here. This permits "variations on SV"
66 * to use different subclasses retaining the same general structure.
67 */
68
69 class MainWindowBase : public QMainWindow
70 {
71 Q_OBJECT
72
73 public:
74 MainWindowBase(bool withAudioOutput, bool withOSCSupport);
75 virtual ~MainWindowBase();
76
77 enum AudioFileOpenMode {
78 ReplaceMainModel,
79 CreateAdditionalModel,
80 ReplaceCurrentPane,
81 AskUser
82 };
83
84 enum FileOpenStatus {
85 FileOpenSucceeded,
86 FileOpenFailed,
87 FileOpenCancelled,
88 FileOpenWrongMode // attempted to open layer when no main model present
89 };
90
91 virtual FileOpenStatus open(QString fileOrUrl, AudioFileOpenMode = AskUser);
92 virtual FileOpenStatus open(FileSource source, AudioFileOpenMode = AskUser);
93
94 virtual FileOpenStatus openAudio(FileSource source, AudioFileOpenMode = AskUser);
95 virtual FileOpenStatus openPlaylist(FileSource source, AudioFileOpenMode = AskUser);
96 virtual FileOpenStatus openLayer(FileSource source);
97 virtual FileOpenStatus openImage(FileSource source);
98
99 virtual FileOpenStatus openSessionFile(QString fileOrUrl);
100 virtual FileOpenStatus openSession(FileSource source);
101
102 virtual bool saveSessionFile(QString path);
103
104 signals:
105 // Used to toggle the availability of menu actions
106 void canAddPane(bool);
107 void canDeleteCurrentPane(bool);
108 void canAddLayer(bool);
109 void canImportMoreAudio(bool);
110 void canImportLayer(bool);
111 void canExportAudio(bool);
112 void canExportLayer(bool);
113 void canExportImage(bool);
114 void canRenameLayer(bool);
115 void canEditLayer(bool);
116 void canMeasureLayer(bool);
117 void canSelect(bool);
118 void canClearSelection(bool);
119 void canEditSelection(bool);
120 void canDeleteSelection(bool);
121 void canPaste(bool);
122 void canInsertInstant(bool);
123 void canInsertInstantsAtBoundaries(bool);
124 void canRenumberInstants(bool);
125 void canDeleteCurrentLayer(bool);
126 void canZoom(bool);
127 void canScroll(bool);
128 void canPlay(bool);
129 void canFfwd(bool);
130 void canRewind(bool);
131 void canPlaySelection(bool);
132 void canSpeedUpPlayback(bool);
133 void canSlowDownPlayback(bool);
134 void canChangePlaybackSpeed(bool);
135 void canSave(bool);
136
137 public slots:
138 virtual void preferenceChanged(PropertyContainer::PropertyName);
139
140 protected slots:
141 virtual void zoomIn();
142 virtual void zoomOut();
143 virtual void zoomToFit();
144 virtual void zoomDefault();
145 virtual void scrollLeft();
146 virtual void scrollRight();
147 virtual void jumpLeft();
148 virtual void jumpRight();
149
150 virtual void showNoOverlays();
151 virtual void showMinimalOverlays();
152 virtual void showStandardOverlays();
153 virtual void showAllOverlays();
154
155 virtual void toggleZoomWheels();
156 virtual void togglePropertyBoxes();
157 virtual void toggleStatusBar();
158
159 virtual void play();
160 virtual void ffwd();
161 virtual void ffwdEnd();
162 virtual void rewind();
163 virtual void rewindStart();
164 virtual void stop();
165
166 virtual void deleteCurrentPane();
167 virtual void deleteCurrentLayer();
168
169 virtual void playLoopToggled();
170 virtual void playSelectionToggled();
171 virtual void playSoloToggled();
172
173 virtual void sampleRateMismatch(size_t, size_t, bool) = 0;
174 virtual void audioOverloadPluginDisabled() = 0;
175
176 virtual void playbackFrameChanged(unsigned long);
177 virtual void globalCentreFrameChanged(unsigned long);
178 virtual void viewCentreFrameChanged(View *, unsigned long);
179 virtual void viewZoomLevelChanged(View *, unsigned long, bool);
180 virtual void outputLevelsChanged(float, float) = 0;
181
182 virtual void currentPaneChanged(Pane *);
183 virtual void currentLayerChanged(Pane *, Layer *);
184
185 virtual void selectAll();
186 virtual void selectToStart();
187 virtual void selectToEnd();
188 virtual void selectVisible();
189 virtual void clearSelection();
190
191 virtual void cut();
192 virtual void copy();
193 virtual void paste();
194 virtual void deleteSelected();
195
196 virtual void insertInstant();
197 virtual void insertInstantAt(size_t);
198 virtual void insertInstantsAtBoundaries();
199 virtual void renumberInstants();
200
201 virtual void documentModified();
202 virtual void documentRestored();
203
204 virtual void layerAdded(Layer *);
205 virtual void layerRemoved(Layer *);
206 virtual void layerAboutToBeDeleted(Layer *);
207 virtual void layerInAView(Layer *, bool);
208
209 virtual void mainModelChanged(WaveFileModel *);
210 virtual void modelAdded(Model *);
211 virtual void modelAboutToBeDeleted(Model *);
212
213 virtual void updateMenuStates();
214 virtual void updateDescriptionLabel() = 0;
215
216 virtual void modelGenerationFailed(QString) = 0;
217 virtual void modelRegenerationFailed(QString, QString) = 0;
218
219 virtual void rightButtonMenuRequested(Pane *, QPoint point) = 0;
220
221 virtual void paneAdded(Pane *) = 0;
222 virtual void paneHidden(Pane *) = 0;
223 virtual void paneAboutToBeDeleted(Pane *) = 0;
224 virtual void paneDropAccepted(Pane *, QStringList) = 0;
225 virtual void paneDropAccepted(Pane *, QString) = 0;
226
227 virtual void pollOSC();
228 virtual void handleOSCMessage(const OSCMessage &) = 0;
229
230 virtual void contextHelpChanged(const QString &);
231 virtual void inProgressSelectionChanged();
232
233 virtual void closeSession() = 0;
234
235 protected:
236 QString m_sessionFile;
237 QString m_audioFile;
238 Document *m_document;
239
240 QLabel *m_descriptionLabel;
241 PaneStack *m_paneStack;
242 ViewManager *m_viewManager;
243 Layer *m_timeRulerLayer;
244
245 bool m_audioOutput;
246 AudioCallbackPlaySource *m_playSource;
247 AudioCallbackPlayTarget *m_playTarget;
248
249 OSCQueue *m_oscQueue;
250
251 RecentFiles m_recentFiles;
252 RecentFiles m_recentTransforms;
253
254 bool m_documentModified;
255 bool m_openingAudioFile;
256 bool m_abandoning;
257
258 Labeller *m_labeller;
259
260 int m_lastPlayStatusSec;
261 mutable QString m_myStatusMessage;
262
263 bool m_initialDarkBackground;
264
265 WaveFileModel *getMainModel();
266 const WaveFileModel *getMainModel() const;
267 void createDocument();
268
269 Pane *addPaneToStack();
270 Layer *getSnapLayer() const;
271
272 class PaneCallback : public SVFileReaderPaneCallback
273 {
274 public:
275 PaneCallback(MainWindowBase *mw) : m_mw(mw) { }
276 virtual Pane *addPane() { return m_mw->addPaneToStack(); }
277 virtual void setWindowSize(int width, int height) {
278 m_mw->resize(width, height);
279 }
280 virtual void addSelection(int start, int end) {
281 m_mw->m_viewManager->addSelection(Selection(start, end));
282 }
283 protected:
284 MainWindowBase *m_mw;
285 };
286
287 class AddPaneCommand : public Command
288 {
289 public:
290 AddPaneCommand(MainWindowBase *mw);
291 virtual ~AddPaneCommand();
292
293 virtual void execute();
294 virtual void unexecute();
295 virtual QString getName() const;
296
297 Pane *getPane() { return m_pane; }
298
299 protected:
300 MainWindowBase *m_mw;
301 Pane *m_pane; // Main window owns this, but I determine its lifespan
302 Pane *m_prevCurrentPane; // I don't own this
303 bool m_added;
304 };
305
306 class RemovePaneCommand : public Command
307 {
308 public:
309 RemovePaneCommand(MainWindowBase *mw, Pane *pane);
310 virtual ~RemovePaneCommand();
311
312 virtual void execute();
313 virtual void unexecute();
314 virtual QString getName() const;
315
316 protected:
317 MainWindowBase *m_mw;
318 Pane *m_pane; // Main window owns this, but I determine its lifespan
319 Pane *m_prevCurrentPane; // I don't own this
320 bool m_added;
321 };
322
323 virtual bool checkSaveModified() = 0;
324
325 virtual QString getOpenFileName(FileFinder::FileType type);
326 virtual QString getSaveFileName(FileFinder::FileType type);
327 virtual void registerLastOpenedFilePath(FileFinder::FileType type, QString path);
328
329 virtual void createPlayTarget();
330 virtual void openHelpUrl(QString url);
331
332 virtual void setupMenus() = 0;
333 virtual void updateVisibleRangeDisplay(Pane *p) const = 0;
334
335 virtual void toXml(QTextStream &stream);
336 };
337
338
339 #endif