annotate framework/MainWindowBase.h @ 344:63dec7dc11cc tonioni

Fix potential for crash on reloading session file - loading selections should not emit signal as if user had just made them manually
author Chris Cannam
date Thu, 03 Apr 2014 08:51:30 +0100
parents 4eccff14b4d8
children b3609adae921
rev   line source
Chris@45 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@45 2
Chris@45 3 /*
Chris@45 4 Sonic Visualiser
Chris@45 5 An audio file viewer and annotation editor.
Chris@45 6 Centre for Digital Music, Queen Mary, University of London.
Chris@45 7 This file copyright 2006-2007 Chris Cannam and QMUL.
Chris@45 8
Chris@45 9 This program is free software; you can redistribute it and/or
Chris@45 10 modify it under the terms of the GNU General Public License as
Chris@45 11 published by the Free Software Foundation; either version 2 of the
Chris@45 12 License, or (at your option) any later version. See the file
Chris@45 13 COPYING included with this distribution for more information.
Chris@45 14 */
Chris@45 15
Chris@45 16 #ifndef _MAIN_WINDOW_BASE_H_
Chris@45 17 #define _MAIN_WINDOW_BASE_H_
Chris@45 18
Chris@45 19 #include <QFrame>
Chris@45 20 #include <QString>
Chris@45 21 #include <QUrl>
Chris@45 22 #include <QMainWindow>
Chris@45 23 #include <QPointer>
Chris@113 24 #include <QThread>
Chris@45 25
Chris@45 26 #include "base/Command.h"
Chris@45 27 #include "view/ViewManager.h"
Chris@45 28 #include "base/PropertyContainer.h"
Chris@45 29 #include "base/RecentFiles.h"
Chris@161 30 #include "base/FrameTimer.h"
Chris@45 31 #include "layer/LayerFactory.h"
Chris@106 32 #include "transform/Transform.h"
Chris@46 33 #include "SVFileReader.h"
Chris@170 34 #include "data/fileio/FileFinder.h"
Chris@45 35 #include "data/fileio/FileSource.h"
Chris@113 36 #include "data/osc/OSCQueue.h"
Chris@45 37 #include <map>
Chris@45 38
Chris@45 39 class Document;
Chris@45 40 class PaneStack;
Chris@45 41 class Pane;
Chris@45 42 class View;
Chris@45 43 class Fader;
Chris@45 44 class Overview;
Chris@45 45 class Layer;
Chris@45 46 class WaveformLayer;
Chris@45 47 class WaveFileModel;
Chris@45 48 class AudioCallbackPlaySource;
Chris@45 49 class AudioCallbackPlayTarget;
Chris@45 50 class CommandHistory;
Chris@45 51 class QMenu;
Chris@45 52 class AudioDial;
Chris@45 53 class QLabel;
Chris@45 54 class QCheckBox;
Chris@45 55 class PreferencesDialog;
Chris@45 56 class QTreeView;
Chris@45 57 class QPushButton;
Chris@45 58 class OSCMessage;
Chris@157 59 class MIDIInput;
Chris@45 60 class KeyReference;
Chris@45 61 class Labeller;
Chris@123 62 class ModelDataTableDialog;
Chris@45 63
Chris@45 64 /**
Chris@45 65 * The base class for the SV main window. This includes everything to
Chris@45 66 * do with general document and pane stack management, but nothing
Chris@45 67 * that involves user interaction -- this doesn't create the widget or
Chris@45 68 * menu structures or editing tools, and if a function needs to open a
Chris@45 69 * dialog, it shouldn't be in here. This permits "variations on SV"
Chris@45 70 * to use different subclasses retaining the same general structure.
Chris@45 71 */
Chris@45 72
Chris@161 73 class MainWindowBase : public QMainWindow, public FrameTimer
Chris@45 74 {
Chris@45 75 Q_OBJECT
Chris@45 76
Chris@45 77 public:
Chris@161 78 MainWindowBase(bool withAudioOutput, bool withOSCSupport, bool withMIDIInput);
Chris@45 79 virtual ~MainWindowBase();
Chris@45 80
Chris@45 81 enum AudioFileOpenMode {
Chris@221 82 ReplaceSession,
Chris@45 83 ReplaceMainModel,
Chris@45 84 CreateAdditionalModel,
Chris@45 85 ReplaceCurrentPane,
Chris@45 86 AskUser
Chris@45 87 };
Chris@45 88
Chris@45 89 enum FileOpenStatus {
Chris@45 90 FileOpenSucceeded,
Chris@45 91 FileOpenFailed,
Chris@45 92 FileOpenCancelled,
Chris@45 93 FileOpenWrongMode // attempted to open layer when no main model present
Chris@45 94 };
Chris@45 95
Chris@45 96 virtual FileOpenStatus open(QString fileOrUrl, AudioFileOpenMode = AskUser);
Chris@45 97 virtual FileOpenStatus open(FileSource source, AudioFileOpenMode = AskUser);
Chris@45 98
dan@210 99 virtual FileOpenStatus openAudio(FileSource source, AudioFileOpenMode = AskUser, QString templateName = "");
Chris@45 100 virtual FileOpenStatus openPlaylist(FileSource source, AudioFileOpenMode = AskUser);
Chris@45 101 virtual FileOpenStatus openLayer(FileSource source);
Chris@45 102 virtual FileOpenStatus openImage(FileSource source);
Chris@45 103
Chris@45 104 virtual FileOpenStatus openSessionFile(QString fileOrUrl);
Chris@45 105 virtual FileOpenStatus openSession(FileSource source);
Chris@230 106 virtual FileOpenStatus openSessionTemplate(QString templateName);
Chris@227 107 virtual FileOpenStatus openSessionTemplate(FileSource source);
Chris@45 108
Chris@45 109 virtual bool saveSessionFile(QString path);
Chris@224 110 virtual bool saveSessionTemplate(QString path);
Chris@45 111
Chris@161 112 /// Implementation of FrameTimer interface method
Chris@161 113 virtual unsigned long getFrame() const;
Chris@161 114
Chris@45 115 signals:
Chris@45 116 // Used to toggle the availability of menu actions
Chris@45 117 void canAddPane(bool);
Chris@45 118 void canDeleteCurrentPane(bool);
Chris@45 119 void canAddLayer(bool);
Chris@45 120 void canImportMoreAudio(bool);
Chris@259 121 void canReplaceMainAudio(bool);
Chris@45 122 void canImportLayer(bool);
Chris@289 123 void canChangeSessionTemplate(bool);
Chris@45 124 void canExportAudio(bool);
Chris@45 125 void canExportLayer(bool);
Chris@45 126 void canExportImage(bool);
Chris@45 127 void canRenameLayer(bool);
Chris@45 128 void canEditLayer(bool);
Chris@146 129 void canEditLayerTabular(bool);
Chris@45 130 void canMeasureLayer(bool);
Chris@45 131 void canSelect(bool);
Chris@45 132 void canClearSelection(bool);
Chris@45 133 void canEditSelection(bool);
Chris@45 134 void canDeleteSelection(bool);
Chris@45 135 void canPaste(bool);
Chris@45 136 void canInsertInstant(bool);
Chris@45 137 void canInsertInstantsAtBoundaries(bool);
Chris@184 138 void canInsertItemAtSelection(bool);
Chris@45 139 void canRenumberInstants(bool);
Chris@45 140 void canDeleteCurrentLayer(bool);
Chris@45 141 void canZoom(bool);
Chris@45 142 void canScroll(bool);
Chris@45 143 void canPlay(bool);
Chris@45 144 void canFfwd(bool);
Chris@45 145 void canRewind(bool);
Chris@45 146 void canPlaySelection(bool);
Chris@45 147 void canSpeedUpPlayback(bool);
Chris@45 148 void canSlowDownPlayback(bool);
Chris@45 149 void canChangePlaybackSpeed(bool);
Chris@73 150 void canSelectPreviousPane(bool);
Chris@73 151 void canSelectNextPane(bool);
Chris@73 152 void canSelectPreviousLayer(bool);
Chris@73 153 void canSelectNextLayer(bool);
Chris@45 154 void canSave(bool);
Chris@104 155 void hideSplash();
Chris@342 156 void sessionLoaded();
Chris@342 157 void audioFileLoaded();
Chris@160 158 void replacedDocument();
Chris@164 159 void activity(QString);
Chris@45 160
Chris@45 161 public slots:
Chris@45 162 virtual void preferenceChanged(PropertyContainer::PropertyName);
Chris@168 163 virtual void resizeConstrained(QSize);
Chris@45 164
Chris@45 165 protected slots:
Chris@45 166 virtual void zoomIn();
Chris@45 167 virtual void zoomOut();
Chris@45 168 virtual void zoomToFit();
Chris@45 169 virtual void zoomDefault();
Chris@45 170 virtual void scrollLeft();
Chris@45 171 virtual void scrollRight();
Chris@45 172 virtual void jumpLeft();
Chris@45 173 virtual void jumpRight();
Chris@162 174 virtual void peekLeft();
Chris@162 175 virtual void peekRight();
Chris@45 176
Chris@45 177 virtual void showNoOverlays();
Chris@45 178 virtual void showMinimalOverlays();
Chris@45 179 virtual void showAllOverlays();
Chris@45 180
Chris@211 181 virtual void toggleTimeRulers();
Chris@45 182 virtual void toggleZoomWheels();
Chris@45 183 virtual void togglePropertyBoxes();
Chris@45 184 virtual void toggleStatusBar();
Chris@256 185 virtual void toggleCentreLine();
Chris@45 186
Chris@45 187 virtual void play();
Chris@45 188 virtual void ffwd();
Chris@45 189 virtual void ffwdEnd();
Chris@45 190 virtual void rewind();
Chris@45 191 virtual void rewindStart();
Chris@45 192 virtual void stop();
Chris@45 193
Chris@166 194 virtual void ffwdSimilar();
Chris@166 195 virtual void rewindSimilar();
Chris@166 196
Chris@45 197 virtual void deleteCurrentPane();
Chris@45 198 virtual void deleteCurrentLayer();
Chris@123 199 virtual void editCurrentLayer();
Chris@45 200
Chris@73 201 virtual void previousPane();
Chris@73 202 virtual void nextPane();
Chris@73 203 virtual void previousLayer();
Chris@73 204 virtual void nextLayer();
Chris@73 205
Chris@45 206 virtual void playLoopToggled();
Chris@45 207 virtual void playSelectionToggled();
Chris@45 208 virtual void playSoloToggled();
Chris@45 209
Chris@45 210 virtual void sampleRateMismatch(size_t, size_t, bool) = 0;
Chris@45 211 virtual void audioOverloadPluginDisabled() = 0;
Chris@130 212 virtual void audioTimeStretchMultiChannelDisabled() = 0;
Chris@45 213
Chris@45 214 virtual void playbackFrameChanged(unsigned long);
Chris@45 215 virtual void globalCentreFrameChanged(unsigned long);
Chris@45 216 virtual void viewCentreFrameChanged(View *, unsigned long);
Chris@45 217 virtual void viewZoomLevelChanged(View *, unsigned long, bool);
Chris@45 218 virtual void outputLevelsChanged(float, float) = 0;
Chris@45 219
Chris@45 220 virtual void currentPaneChanged(Pane *);
Chris@45 221 virtual void currentLayerChanged(Pane *, Layer *);
Chris@45 222
Chris@45 223 virtual void selectAll();
Chris@45 224 virtual void selectToStart();
Chris@45 225 virtual void selectToEnd();
Chris@45 226 virtual void selectVisible();
Chris@45 227 virtual void clearSelection();
Chris@45 228
Chris@45 229 virtual void cut();
Chris@45 230 virtual void copy();
Chris@45 231 virtual void paste();
Chris@215 232 virtual void pasteAtPlaybackPosition();
Chris@215 233 virtual void pasteRelative(int offset);
Chris@45 234 virtual void deleteSelected();
Chris@45 235
Chris@45 236 virtual void insertInstant();
Chris@45 237 virtual void insertInstantAt(size_t);
Chris@45 238 virtual void insertInstantsAtBoundaries();
Chris@184 239 virtual void insertItemAtSelection();
Chris@184 240 virtual void insertItemAt(size_t, size_t);
Chris@45 241 virtual void renumberInstants();
Chris@45 242
Chris@45 243 virtual void documentModified();
Chris@45 244 virtual void documentRestored();
Chris@45 245
Chris@45 246 virtual void layerAdded(Layer *);
Chris@45 247 virtual void layerRemoved(Layer *);
Chris@45 248 virtual void layerAboutToBeDeleted(Layer *);
Chris@45 249 virtual void layerInAView(Layer *, bool);
Chris@45 250
Chris@45 251 virtual void mainModelChanged(WaveFileModel *);
Chris@45 252 virtual void modelAdded(Model *);
Chris@45 253 virtual void modelAboutToBeDeleted(Model *);
Chris@45 254
Chris@45 255 virtual void updateMenuStates();
Chris@45 256 virtual void updateDescriptionLabel() = 0;
Chris@45 257
Chris@78 258 virtual void modelGenerationFailed(QString, QString) = 0;
Chris@78 259 virtual void modelGenerationWarning(QString, QString) = 0;
Chris@78 260 virtual void modelRegenerationFailed(QString, QString, QString) = 0;
Chris@78 261 virtual void modelRegenerationWarning(QString, QString, QString) = 0;
Chris@78 262 virtual void alignmentFailed(QString, QString) = 0;
Chris@45 263
Chris@45 264 virtual void rightButtonMenuRequested(Pane *, QPoint point) = 0;
Chris@45 265
Chris@45 266 virtual void paneAdded(Pane *) = 0;
Chris@45 267 virtual void paneHidden(Pane *) = 0;
Chris@45 268 virtual void paneAboutToBeDeleted(Pane *) = 0;
Chris@45 269 virtual void paneDropAccepted(Pane *, QStringList) = 0;
Chris@45 270 virtual void paneDropAccepted(Pane *, QString) = 0;
Chris@55 271 virtual void paneDeleteButtonClicked(Pane *);
Chris@45 272
Chris@113 273 virtual void oscReady();
Chris@45 274 virtual void pollOSC();
Chris@45 275 virtual void handleOSCMessage(const OSCMessage &) = 0;
Chris@45 276
Chris@45 277 virtual void contextHelpChanged(const QString &);
Chris@45 278 virtual void inProgressSelectionChanged();
Chris@45 279
Chris@141 280 virtual FileOpenStatus openSessionFromRDF(FileSource source);
Chris@145 281 virtual FileOpenStatus openLayersFromRDF(FileSource source);
Chris@141 282
Chris@45 283 virtual void closeSession() = 0;
Chris@45 284
Chris@180 285 virtual void newerVersionAvailable(QString) { }
Chris@180 286
Chris@45 287 protected:
Chris@45 288 QString m_sessionFile;
Chris@45 289 QString m_audioFile;
Chris@45 290 Document *m_document;
Chris@45 291
Chris@45 292 PaneStack *m_paneStack;
Chris@45 293 ViewManager *m_viewManager;
Chris@45 294 Layer *m_timeRulerLayer;
Chris@45 295
Chris@45 296 bool m_audioOutput;
Chris@45 297 AudioCallbackPlaySource *m_playSource;
Chris@45 298 AudioCallbackPlayTarget *m_playTarget;
Chris@45 299
Chris@113 300 class OSCQueueStarter : public QThread
Chris@113 301 {
Chris@113 302 public:
Chris@113 303 OSCQueueStarter(MainWindowBase *mwb) : QThread(mwb), m_mwb(mwb) { }
Chris@113 304 virtual void run() {
Chris@113 305 OSCQueue *queue = new OSCQueue(); // can take a long time
Chris@113 306 m_mwb->m_oscQueue = queue;
Chris@113 307 }
Chris@113 308 private:
Chris@113 309 MainWindowBase *m_mwb;
Chris@113 310 };
Chris@113 311
Chris@45 312 OSCQueue *m_oscQueue;
Chris@113 313 OSCQueueStarter *m_oscQueueStarter;
Chris@45 314
Chris@157 315 MIDIInput *m_midiInput;
Chris@157 316
Chris@45 317 RecentFiles m_recentFiles;
Chris@54 318 RecentFiles m_recentTransforms;
Chris@45 319
Chris@45 320 bool m_documentModified;
Chris@45 321 bool m_openingAudioFile;
Chris@45 322 bool m_abandoning;
Chris@45 323
Chris@45 324 Labeller *m_labeller;
Chris@45 325
Chris@45 326 int m_lastPlayStatusSec;
Chris@45 327 mutable QString m_myStatusMessage;
Chris@45 328
Chris@45 329 bool m_initialDarkBackground;
Chris@45 330
Chris@45 331 WaveFileModel *getMainModel();
Chris@45 332 const WaveFileModel *getMainModel() const;
Chris@45 333 void createDocument();
Chris@45 334
Chris@45 335 Pane *addPaneToStack();
Chris@45 336 Layer *getSnapLayer() const;
Chris@45 337
Chris@126 338 typedef std::map<Layer *, QPointer<ModelDataTableDialog> > LayerDataDialogMap;
Chris@126 339 typedef std::set<QPointer<ModelDataTableDialog> > DataDialogSet;
Chris@123 340 typedef std::map<View *, DataDialogSet> ViewDataDialogMap;
Chris@123 341
Chris@123 342 LayerDataDialogMap m_layerDataDialogMap;
Chris@123 343 ViewDataDialogMap m_viewDataDialogMap;
Chris@123 344
Chris@128 345 void removeLayerEditDialog(Layer *);
Chris@128 346
Chris@45 347 class PaneCallback : public SVFileReaderPaneCallback
Chris@45 348 {
Chris@45 349 public:
Chris@45 350 PaneCallback(MainWindowBase *mw) : m_mw(mw) { }
Chris@45 351 virtual Pane *addPane() { return m_mw->addPaneToStack(); }
Chris@45 352 virtual void setWindowSize(int width, int height) {
Chris@168 353 m_mw->resizeConstrained(QSize(width, height));
Chris@45 354 }
Chris@45 355 virtual void addSelection(int start, int end) {
Chris@344 356 m_mw->m_viewManager->addSelectionQuietly(Selection(start, end));
Chris@45 357 }
Chris@45 358 protected:
Chris@45 359 MainWindowBase *m_mw;
Chris@45 360 };
Chris@45 361
Chris@45 362 class AddPaneCommand : public Command
Chris@45 363 {
Chris@45 364 public:
Chris@45 365 AddPaneCommand(MainWindowBase *mw);
Chris@45 366 virtual ~AddPaneCommand();
Chris@45 367
Chris@45 368 virtual void execute();
Chris@45 369 virtual void unexecute();
Chris@45 370 virtual QString getName() const;
Chris@45 371
Chris@45 372 Pane *getPane() { return m_pane; }
Chris@45 373
Chris@45 374 protected:
Chris@45 375 MainWindowBase *m_mw;
Chris@45 376 Pane *m_pane; // Main window owns this, but I determine its lifespan
Chris@45 377 Pane *m_prevCurrentPane; // I don't own this
Chris@45 378 bool m_added;
Chris@45 379 };
Chris@45 380
Chris@45 381 class RemovePaneCommand : public Command
Chris@45 382 {
Chris@45 383 public:
Chris@45 384 RemovePaneCommand(MainWindowBase *mw, Pane *pane);
Chris@45 385 virtual ~RemovePaneCommand();
Chris@45 386
Chris@45 387 virtual void execute();
Chris@45 388 virtual void unexecute();
Chris@45 389 virtual QString getName() const;
Chris@45 390
Chris@45 391 protected:
Chris@45 392 MainWindowBase *m_mw;
Chris@45 393 Pane *m_pane; // Main window owns this, but I determine its lifespan
Chris@45 394 Pane *m_prevCurrentPane; // I don't own this
Chris@45 395 bool m_added;
Chris@45 396 };
Chris@45 397
Chris@45 398 virtual bool checkSaveModified() = 0;
Chris@45 399
Chris@45 400 virtual QString getOpenFileName(FileFinder::FileType type);
Chris@45 401 virtual QString getSaveFileName(FileFinder::FileType type);
Chris@45 402 virtual void registerLastOpenedFilePath(FileFinder::FileType type, QString path);
Chris@45 403
Chris@222 404 virtual QString getDefaultSessionTemplate() const;
Chris@251 405 virtual void setDefaultSessionTemplate(QString);
Chris@222 406
Chris@45 407 virtual void createPlayTarget();
Chris@45 408 virtual void openHelpUrl(QString url);
Chris@45 409
Chris@45 410 virtual void setupMenus() = 0;
Chris@45 411 virtual void updateVisibleRangeDisplay(Pane *p) const = 0;
Chris@187 412 virtual void updatePositionStatusDisplays() const = 0;
Chris@45 413
Chris@147 414 virtual bool shouldCreateNewSessionForRDFAudio(bool *) { return true; }
Chris@145 415
Chris@128 416 virtual void connectLayerEditDialog(ModelDataTableDialog *dialog);
Chris@128 417
Chris@226 418 virtual void toXml(QTextStream &stream, bool asTemplate);
Chris@45 419 };
Chris@45 420
Chris@45 421
Chris@45 422 #endif