Chris@0: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@0: Chris@0: /* Chris@0: Sonic Visualiser Chris@0: An audio file viewer and annotation editor. Chris@0: Centre for Digital Music, Queen Mary, University of London. Chris@77: This file copyright 2006 Chris Cannam and QMUL. Chris@0: Chris@0: This program is free software; you can redistribute it and/or Chris@0: modify it under the terms of the GNU General Public License as Chris@0: published by the Free Software Foundation; either version 2 of the Chris@0: License, or (at your option) any later version. See the file Chris@0: COPYING included with this distribution for more information. Chris@0: */ Chris@0: Chris@0: #ifndef _MAIN_WINDOW_H_ Chris@0: #define _MAIN_WINDOW_H_ Chris@0: Chris@0: #include Chris@0: #include Chris@85: #include Chris@0: #include Chris@0: #include Chris@0: Chris@0: #include "base/Command.h" Chris@1: #include "view/ViewManager.h" Chris@0: #include "base/PropertyContainer.h" Chris@34: #include "base/RecentFiles.h" Chris@0: #include "layer/LayerFactory.h" Chris@0: #include "transform/Transform.h" Chris@1: #include "document/SVFileReader.h" Chris@88: #include "data/fileio/FileFinder.h" Chris@0: #include Chris@0: Chris@0: class Document; Chris@0: class PaneStack; Chris@0: class Pane; Chris@0: class View; Chris@0: class Fader; Chris@65: class Overview; Chris@0: class Layer; Chris@0: class WaveformLayer; Chris@0: class WaveFileModel; Chris@0: class AudioCallbackPlaySource; Chris@0: class AudioCallbackPlayTarget; Chris@0: class CommandHistory; Chris@0: class QMenu; Chris@0: class AudioDial; Chris@0: class QLabel; Chris@16: class QCheckBox; Chris@0: class PreferencesDialog; Chris@26: class QPushButton; Chris@69: class OSCQueue; Chris@69: class OSCMessage; Chris@0: Chris@0: Chris@0: class MainWindow : public QMainWindow Chris@0: { Chris@0: Q_OBJECT Chris@0: Chris@0: public: Chris@70: MainWindow(bool withAudioOutput = true, Chris@70: bool withOSCSupport = true); Chris@0: virtual ~MainWindow(); Chris@0: Chris@0: enum AudioFileOpenMode { Chris@0: ReplaceMainModel, Chris@0: CreateAdditionalModel, Chris@0: AskUser Chris@0: }; Chris@0: Chris@82: enum FileOpenStatus { Chris@82: FileOpenSucceeded, Chris@82: FileOpenFailed, Chris@82: FileOpenCancelled Chris@82: }; Chris@82: Chris@82: FileOpenStatus openSomeFile(QString path, AudioFileOpenMode = AskUser); Chris@82: FileOpenStatus openAudioFile(QString path, AudioFileOpenMode = AskUser); Chris@82: FileOpenStatus openLayerFile(QString path); Chris@82: FileOpenStatus openSessionFile(QString path); Chris@85: FileOpenStatus openURL(QUrl url); Chris@82: Chris@0: bool saveSessionFile(QString path); Chris@11: bool commitData(bool mayAskUser); // on session shutdown Chris@0: Chris@0: signals: Chris@0: // Used to toggle the availability of menu actions Chris@0: void canAddPane(bool); Chris@0: void canDeleteCurrentPane(bool); Chris@0: void canAddLayer(bool); Chris@0: void canImportMoreAudio(bool); Chris@0: void canImportLayer(bool); Chris@0: void canExportAudio(bool); Chris@0: void canExportLayer(bool); Chris@121: void canExportImage(bool); Chris@0: void canRenameLayer(bool); Chris@0: void canEditLayer(bool); Chris@0: void canSelect(bool); Chris@0: void canClearSelection(bool); Chris@0: void canEditSelection(bool); Chris@0: void canPaste(bool); Chris@0: void canInsertInstant(bool); Chris@81: void canInsertInstantsAtBoundaries(bool); Chris@0: void canDeleteCurrentLayer(bool); Chris@0: void canZoom(bool); Chris@0: void canScroll(bool); Chris@0: void canPlay(bool); Chris@0: void canFfwd(bool); Chris@0: void canRewind(bool); Chris@0: void canPlaySelection(bool); Chris@0: void canSave(bool); Chris@0: Chris@118: public slots: Chris@118: void preferenceChanged(PropertyContainer::PropertyName); Chris@118: Chris@0: protected slots: Chris@0: void openSession(); Chris@0: void importAudio(); Chris@0: void importMoreAudio(); Chris@0: void openSomething(); Chris@86: void openLocation(); Chris@0: void openRecentFile(); Chris@0: void exportAudio(); Chris@0: void importLayer(); Chris@0: void exportLayer(); Chris@121: void exportImage(); Chris@0: void saveSession(); Chris@0: void saveSessionAs(); Chris@0: void newSession(); Chris@0: void closeSession(); Chris@0: void preferences(); Chris@0: Chris@0: void zoomIn(); Chris@0: void zoomOut(); Chris@0: void zoomToFit(); Chris@0: void zoomDefault(); Chris@0: void scrollLeft(); Chris@0: void scrollRight(); Chris@0: void jumpLeft(); Chris@0: void jumpRight(); Chris@0: Chris@0: void showNoOverlays(); Chris@90: void showMinimalOverlays(); Chris@90: void showStandardOverlays(); Chris@90: void showAllOverlays(); Chris@7: Chris@7: void toggleZoomWheels(); Chris@72: void togglePropertyBoxes(); Chris@90: void toggleStatusBar(); Chris@0: Chris@0: void play(); Chris@0: void ffwd(); Chris@0: void ffwdEnd(); Chris@0: void rewind(); Chris@0: void rewindStart(); Chris@0: void stop(); Chris@0: Chris@0: void addPane(); Chris@0: void addLayer(); Chris@0: void deleteCurrentPane(); Chris@0: void renameCurrentLayer(); Chris@0: void deleteCurrentLayer(); Chris@0: Chris@0: void playLoopToggled(); Chris@0: void playSelectionToggled(); Chris@0: void playSpeedChanged(int); Chris@16: void playSharpenToggled(); Chris@26: void playMonoToggled(); Chris@0: void sampleRateMismatch(size_t, size_t, bool); Chris@42: void audioOverloadPluginDisabled(); Chris@0: Chris@116: void playbackFrameChanged(unsigned long); Chris@116: void globalCentreFrameChanged(unsigned long); Chris@116: void viewCentreFrameChanged(View *, unsigned long); Chris@116: void viewZoomLevelChanged(View *, unsigned long, bool); Chris@0: void outputLevelsChanged(float, float); Chris@0: Chris@0: void currentPaneChanged(Pane *); Chris@0: void currentLayerChanged(Pane *, Layer *); Chris@0: Chris@0: void toolNavigateSelected(); Chris@0: void toolSelectSelected(); Chris@0: void toolEditSelected(); Chris@0: void toolDrawSelected(); Chris@151: void toolMeasureSelected(); Chris@0: Chris@0: void selectAll(); Chris@0: void selectToStart(); Chris@0: void selectToEnd(); Chris@0: void selectVisible(); Chris@0: void clearSelection(); Chris@0: void cut(); Chris@0: void copy(); Chris@0: void paste(); Chris@0: void deleteSelected(); Chris@0: void insertInstant(); Chris@81: void insertInstantAt(size_t); Chris@81: void insertInstantsAtBoundaries(); Chris@0: Chris@0: void documentModified(); Chris@0: void documentRestored(); Chris@0: Chris@0: void updateMenuStates(); Chris@0: void updateDescriptionLabel(); Chris@0: Chris@0: void layerAdded(Layer *); Chris@0: void layerRemoved(Layer *); Chris@0: void layerAboutToBeDeleted(Layer *); Chris@0: void layerInAView(Layer *, bool); Chris@0: Chris@0: void mainModelChanged(WaveFileModel *); Chris@0: void modelAdded(Model *); Chris@0: void modelAboutToBeDeleted(Model *); Chris@0: Chris@0: void modelGenerationFailed(QString); Chris@0: void modelRegenerationFailed(QString, QString); Chris@0: Chris@0: void rightButtonMenuRequested(Pane *, QPoint point); Chris@0: Chris@73: void propertyStacksResized(); Chris@73: Chris@0: void setupRecentFilesMenu(); Chris@34: void setupRecentTransformsMenu(); Chris@0: Chris@0: void showLayerTree(); Chris@0: Chris@69: void pollOSC(); Chris@69: void handleOSCMessage(const OSCMessage &); Chris@69: Chris@90: void mouseEnteredWidget(); Chris@90: void mouseLeftWidget(); Chris@116: void contextHelpChanged(const QString &); Chris@117: void inProgressSelectionChanged(); Chris@90: Chris@0: void website(); Chris@0: void help(); Chris@0: void about(); Chris@0: Chris@0: protected: Chris@0: QString m_sessionFile; Chris@0: QString m_audioFile; Chris@0: Document *m_document; Chris@0: Chris@0: QLabel *m_descriptionLabel; Chris@0: PaneStack *m_paneStack; Chris@0: ViewManager *m_viewManager; Chris@65: Overview *m_overview; Chris@0: Fader *m_fader; Chris@0: AudioDial *m_playSpeed; Chris@26: QPushButton *m_playSharpen; Chris@26: QPushButton *m_playMono; Chris@0: WaveformLayer *m_panLayer; Chris@0: Layer *m_timeRulerLayer; Chris@0: Chris@46: bool m_audioOutput; Chris@0: AudioCallbackPlaySource *m_playSource; Chris@0: AudioCallbackPlayTarget *m_playTarget; Chris@0: Chris@69: OSCQueue *m_oscQueue; Chris@69: Chris@34: RecentFiles m_recentFiles; Chris@34: RecentFiles m_recentTransforms; Chris@34: Chris@0: bool m_mainMenusCreated; Chris@0: QMenu *m_paneMenu; Chris@0: QMenu *m_layerMenu; Chris@34: QMenu *m_transformsMenu; Chris@0: QMenu *m_existingLayersMenu; Chris@95: QMenu *m_sliceMenu; Chris@0: QMenu *m_recentFilesMenu; Chris@34: QMenu *m_recentTransformsMenu; Chris@0: QMenu *m_rightButtonMenu; Chris@0: QMenu *m_rightButtonLayerMenu; Chris@34: QMenu *m_rightButtonTransformsMenu; Chris@0: Chris@0: bool m_documentModified; Chris@70: bool m_openingAudioFile; Chris@70: bool m_abandoning; Chris@0: Chris@116: int m_lastPlayStatusSec; Chris@116: mutable QString m_myStatusMessage; Chris@116: Chris@0: QPointer m_preferencesDialog; Chris@0: Chris@0: WaveFileModel *getMainModel(); Chris@116: const WaveFileModel *getMainModel() const; Chris@0: void createDocument(); Chris@0: Chris@0: struct PaneConfiguration { Chris@0: PaneConfiguration(LayerFactory::LayerType _layer Chris@0: = LayerFactory::TimeRuler, Chris@66: Model *_source = 0, Chris@0: int _channel = -1) : Chris@66: layer(_layer), sourceModel(_source), channel(_channel) { } Chris@0: LayerFactory::LayerType layer; Chris@66: Model *sourceModel; Chris@0: int channel; Chris@0: }; Chris@0: Chris@0: typedef std::map PaneActionMap; Chris@0: PaneActionMap m_paneActions; Chris@0: Chris@107: typedef std::map TransformActionMap; Chris@34: TransformActionMap m_transformActions; Chris@34: Chris@107: typedef std::map TransformActionReverseMap; Chris@34: TransformActionReverseMap m_transformActionsReverse; Chris@0: Chris@0: typedef std::map LayerActionMap; Chris@0: LayerActionMap m_layerActions; Chris@0: Chris@0: typedef std::map ExistingLayerActionMap; Chris@0: ExistingLayerActionMap m_existingLayerActions; Chris@95: ExistingLayerActionMap m_sliceActions; Chris@0: Chris@0: typedef std::map ToolActionMap; Chris@0: ToolActionMap m_toolActions; Chris@0: Chris@0: void setupMenus(); Chris@66: void setupFileMenu(); Chris@66: void setupEditMenu(); Chris@66: void setupViewMenu(); Chris@66: void setupPaneAndLayerMenus(); Chris@66: void setupTransformsMenu(); Chris@66: void setupHelpMenu(); Chris@95: void setupExistingLayersMenus(); Chris@0: void setupToolbars(); Chris@66: Chris@0: Pane *addPaneToStack(); Chris@0: Chris@69: void addPane(const PaneConfiguration &configuration, QString text); Chris@69: Chris@0: class PaneCallback : public SVFileReaderPaneCallback Chris@0: { Chris@0: public: Chris@0: PaneCallback(MainWindow *mw) : m_mw(mw) { } Chris@0: virtual Pane *addPane() { return m_mw->addPaneToStack(); } Chris@0: virtual void setWindowSize(int width, int height) { Chris@0: m_mw->resize(width, height); Chris@0: } Chris@0: virtual void addSelection(int start, int end) { Chris@0: m_mw->m_viewManager->addSelection(Selection(start, end)); Chris@0: } Chris@0: protected: Chris@0: MainWindow *m_mw; Chris@0: }; Chris@0: Chris@0: class AddPaneCommand : public Command Chris@0: { Chris@0: public: Chris@0: AddPaneCommand(MainWindow *mw); Chris@0: virtual ~AddPaneCommand(); Chris@0: Chris@0: virtual void execute(); Chris@0: virtual void unexecute(); Chris@0: virtual QString getName() const; Chris@0: Chris@0: Pane *getPane() { return m_pane; } Chris@0: Chris@0: protected: Chris@0: MainWindow *m_mw; Chris@0: Pane *m_pane; // Main window owns this, but I determine its lifespan Chris@0: Pane *m_prevCurrentPane; // I don't own this Chris@0: bool m_added; Chris@0: }; Chris@0: Chris@0: class RemovePaneCommand : public Command Chris@0: { Chris@0: public: Chris@0: RemovePaneCommand(MainWindow *mw, Pane *pane); Chris@0: virtual ~RemovePaneCommand(); Chris@0: Chris@0: virtual void execute(); Chris@0: virtual void unexecute(); Chris@0: virtual QString getName() const; Chris@0: Chris@0: protected: Chris@0: MainWindow *m_mw; Chris@0: Pane *m_pane; // Main window owns this, but I determine its lifespan Chris@0: Pane *m_prevCurrentPane; // I don't own this Chris@0: bool m_added; Chris@0: }; Chris@0: Chris@0: virtual void closeEvent(QCloseEvent *e); Chris@0: bool checkSaveModified(); Chris@0: Chris@86: FileOpenStatus openSomeFile(QString path, QString location, Chris@86: AudioFileOpenMode = AskUser); Chris@86: FileOpenStatus openAudioFile(QString path, QString location, Chris@86: AudioFileOpenMode = AskUser); Chris@86: FileOpenStatus openLayerFile(QString path, QString location); Chris@86: FileOpenStatus openSessionFile(QString path, QString location); Chris@86: Chris@88: QString getOpenFileName(FileFinder::FileType type); Chris@88: QString getSaveFileName(FileFinder::FileType type); Chris@88: void registerLastOpenedFilePath(FileFinder::FileType type, QString path); Chris@81: Chris@0: void createPlayTarget(); Chris@0: Chris@0: void openHelpUrl(QString url); Chris@0: Chris@116: void updateVisibleRangeDisplay(Pane *p) const; Chris@116: Chris@0: void toXml(QTextStream &stream); Chris@0: }; Chris@0: Chris@0: Chris@0: #endif