view sv/main/MainWindow.h @ 129:587ad94d6ac2

(none)
author ivand_qmul
date Thu, 08 Nov 2007 13:29:48 +0000
parents 541b3e357979
children b3df8b8185db
line wrap: on
line source
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */

/*
    Sonic Visualiser
    An audio file viewer and annotation editor.
    Centre for Digital Music, Queen Mary, University of London.
    This file copyright 2006 Chris Cannam and QMUL.
    
    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License as
    published by the Free Software Foundation; either version 2 of the
    License, or (at your option) any later version.  See the file
    COPYING included with this distribution for more information.
*/

#ifndef _MAIN_WINDOW_H_
#define _MAIN_WINDOW_H_

#include <QFrame>
#include <QString>
#include <QUrl>
#include <QMainWindow>
#include <QPointer>
#include <QTabWidget>
#include <QStatusBar>
#include <time.h>
#include "base/Command.h"
#include "view/ViewManager.h"
#include "base/PropertyContainer.h"
#include "base/RecentFiles.h"
#include "layer/LayerFactory.h"
#include "transform/Transform.h"
#include "document/SVFileReader.h"
#include "data/fileio/FileFinder.h"
#include "data/fileio/HttpClient.h"
#include "widgets/WidgetGallery.h"
#include "document/ESFileReader.h"
#include "widgets/MultiPaneLayerContainer.h"

//Ivan Damnjanovic 12/07/2007
#include "data/fileio/VideoFileReader.h"

#include <map>

class Document;
class PaneStack;
class Pane;
class View;
class Fader;
class Overview;
class Layer;
class WaveformLayer;
class WaveFileModel;
class AudioCallbackPlaySource;
class AudioCallbackPlayTarget;
class CommandHistory;
class QMenu;
class AudioDial;
class QLabel;
class QCheckBox;
class PreferencesDialog;
class QPushButton;
class OSCQueue;
class OSCMessage;
class InfoWidget;
class SearchWidget;
class QueryResultsWidget;
class AdvancedToolBox;
class EasaierSessionManager;
class QueryModel;
class RealTimeFilterPropertyStack;
class ExpandWidget;

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(bool withAudioOutput = true,
               bool withOSCSupport = true);
    virtual ~MainWindow();
    
    enum AudioFileOpenMode {
        ReplaceMainModel,
        CreateAdditionalModel,
        AskUser
    };

    enum FileOpenStatus {
        FileOpenSucceeded,
        FileOpenFailed,
        FileOpenCancelled
    };

	enum TabName {
		Search, 
		Result, 
		Info, 
		RelatedMedia, 
    };

    FileOpenStatus openSomeFile(QString path, AudioFileOpenMode = AskUser);
    FileOpenStatus openAudioFile(QString path, AudioFileOpenMode = AskUser);
// Ivan Damnjanovic 09-10/2007 added video file import
	FileOpenStatus openVideoFile(QString path, AudioFileOpenMode = AskUser);
	unsigned long Get_CurAudioTime();
	unsigned long long Get_HardwareBufferTime();
	bool isAudioPlaying();
//
    FileOpenStatus openLayerFile(QString path);
    FileOpenStatus openSessionFile(QString path);
    FileOpenStatus openURL(QUrl url);

    bool saveSessionFile(QString path);
    bool commitData(bool mayAskUser); // on session shutdown

	static MainWindow *instance();

	QueryResultsWidget *getQueryResultsWidget();

	bool openEasaierSessionFile(QString path);
	bool saveEasaierSessionFile(QString path);

signals:
    // Used to toggle the availability of menu actions
    void canAddPane(bool);
    void canDeleteCurrentPane(bool);
    void canAddLayer(bool);
    void canImportMoreAudio(bool);
    void canImportLayer(bool);
    void canExportAudio(bool);
    void canExportLayer(bool);
    void canExportImage(bool);
    void canRenameLayer(bool);
    void canEditLayer(bool);
    void canSelect(bool);
    void canClearSelection(bool);
    void canEditSelection(bool);
    void canPaste(bool);
    void canInsertInstant(bool);
    void canInsertInstantsAtBoundaries(bool);
    void canDeleteCurrentLayer(bool);
    void canZoom(bool);
    void canScroll(bool);
    void canPlay(bool);
    void canFfwd(bool);
    void canRewind(bool);
    void canPlaySelection(bool);
    void canSave(bool);
	void newCurrentPane(Pane *pane);

	void canAddFilter(bool);

public slots:
    void preferenceChanged(PropertyContainer::PropertyName);

protected slots:
    void openSession();
    void importAudio();
    void importMoreAudio();
// Ivan Damnjanovic 09-10/2007 added video file import
	void importVideo();
// Ivan Damnjanovic 09-10/2007 added video file import
    void openSomething();
    void openLocation();
    void openRecentFile();
    void exportAudio();
    void importLayer();
    void exportLayer();
    void exportImage();
    void saveSession();
    void saveSessionAs();
    void newSession();
    void closeSession();
    void preferences();

    void zoomIn();
    void zoomOut();
    void zoomToFit();
    void zoomDefault();
    void scrollLeft();
    void scrollRight();
    void jumpLeft();
    void jumpRight();

    void showNoOverlays();
    void showMinimalOverlays();
    void showStandardOverlays();
    void showAllOverlays();

    void toggleZoomWheels();
    void togglePropertyBoxes();
    void toggleStatusBar();

    void play();
    void ffwd();
    void ffwdEnd();
    void rewind();
    void rewindStart();
    void stop();

    void addPane();
    void addLayer();
    void deleteCurrentPane();
    void renameCurrentLayer();
    void deleteCurrentLayer();

	void addFilter();
	void removeFilter(QString);

    void playLoopToggled();
    void playSelectionToggled();
    void playSpeedChanged(float);
    //void playSharpenToggled();
    //void playMonoToggled();
    void sampleRateMismatch(size_t, size_t, bool);
    void audioOverloadPluginDisabled();

    void playbackFrameChanged(unsigned long);
    void globalCentreFrameChanged(unsigned long);
    void viewCentreFrameChanged(View *, unsigned long);
    void viewZoomLevelChanged(View *, unsigned long, bool);
    void outputLevelsChanged(float, float);

    void currentPaneChanged(Pane *);
    void currentLayerChanged(Pane *, Layer *);

    void toolNavigateSelected();
    void toolSelectSelected();
    void toolEditSelected();
    void toolDrawSelected();

    void selectAll();
    void selectToStart();
    void selectToEnd();
    void selectVisible();
    void clearSelection();
    void cut();
    void copy();
    void paste();
    void deleteSelected();
    void insertInstant();
    void insertInstantAt(size_t);
    void insertInstantsAtBoundaries();

    void documentModified();
    void documentRestored();

    void updateMenuStates();
    void updateDescriptionLabel();

    void layerAdded(Layer *);
    void layerRemoved(Layer *);
    void layerAboutToBeDeleted(Layer *);
    void layerInAView(Layer *, bool);

    void mainModelChanged(WaveFileModel *);
    void modelAdded(Model *);
    void modelAboutToBeDeleted(Model *);

    void modelGenerationFailed(QString);
    void modelRegenerationFailed(QString, QString);

    void rightButtonMenuRequested(Pane *, QPoint point);

    void propertyStacksResized();

    void setupRecentFilesMenu();
    void setupRecentTransformsMenu();

    void showLayerTree();

    void pollOSC();
    void handleOSCMessage(const OSCMessage &);

    void mouseEnteredWidget();
    void mouseLeftWidget();
    void contextHelpChanged(const QString &);
    void inProgressSelectionChanged();

    void website();
    void help();
    void about();

	void newEasaierSession();
	void openEasaierSession();
	void saveEasaierSession();
    void saveEasaierSessionAs();
	void importEasaierLayer(const QString& filename);
	void importEasaierFile(const QString& filename);

	void connectionSettings();
	void styleSetting();

	void queryModelLoaded(QueryModel* queryModel);

	void audioSourceInfoAdded(AudioSourceInfoModel *);

	void queryDatabase();

	void exit();

protected:
    QString                  m_sessionFile;
    QString                  m_audioFile;
// Ivan Damnjanovic 09-10/2007 added video file import	
	QString					 m_videoFile;  
//
	Document                *m_document;

    QLabel                  *m_descriptionLabel;
    PaneStack               *m_paneStack;
    ViewManager             *m_viewManager;
    Overview                *m_overview;
    Fader                   *m_fader;
    //AudioDial               *m_playSpeed;
    //QPushButton             *m_playSharpen;
    //QPushButton             *m_playMono;
    WaveformLayer           *m_panLayer;
    Layer                   *m_timeRulerLayer;

    bool                     m_audioOutput;
    AudioCallbackPlaySource *m_playSource;
    AudioCallbackPlayTarget *m_playTarget;

    OSCQueue                *m_oscQueue;

    RecentFiles              m_recentFiles;
    RecentFiles              m_recentTransforms;

    bool                     m_mainMenusCreated;
    QMenu                   *m_paneMenu;
    QMenu                   *m_layerMenu;
    QMenu                   *m_transformsMenu;
    QMenu                   *m_existingLayersMenu;
    QMenu                   *m_sliceMenu;
    QMenu                   *m_recentFilesMenu;
    QMenu                   *m_recentTransformsMenu;
    QMenu                   *m_rightButtonMenu;
    QMenu                   *m_rightButtonLayerMenu;
    QMenu                   *m_rightButtonTransformsMenu;

    bool                     m_documentModified;
    bool                     m_openingAudioFile;
    bool                     m_abandoning;

    int                      m_lastPlayStatusSec;
    mutable QString          m_myStatusMessage;

    QPointer<PreferencesDialog> m_preferencesDialog;

    WaveFileModel *getMainModel();
    const WaveFileModel *getMainModel() const;
    void createDocument();

    struct PaneConfiguration {
	PaneConfiguration(LayerFactory::LayerType _layer
			                       = LayerFactory::TimeRuler,
                          Model *_source = 0,
			  int _channel = -1) :
	    layer(_layer), sourceModel(_source), channel(_channel) { }
	LayerFactory::LayerType layer;
        Model *sourceModel;
	int channel;
    };

    typedef std::map<QAction *, PaneConfiguration> PaneActionMap;
    PaneActionMap m_paneActions;

    typedef std::map<QAction *, TransformId> TransformActionMap;
    TransformActionMap m_transformActions;

    typedef std::map<TransformId, QAction *> TransformActionReverseMap;
    TransformActionReverseMap m_transformActionsReverse;

    typedef std::map<QAction *, LayerFactory::LayerType> LayerActionMap;
    LayerActionMap m_layerActions;

    typedef std::map<QAction *, Layer *> ExistingLayerActionMap;
    ExistingLayerActionMap m_existingLayerActions;
    ExistingLayerActionMap m_sliceActions;

    typedef std::map<ViewManager::ToolMode, QAction *> ToolActionMap;
    ToolActionMap m_toolActions;

    void setupMenus();
    void setupFileMenu();
	void setupEasaierMenu();
    void setupEditMenu();
	void setupSettingMenu();
    void setupViewMenu();
    void setupPaneAndLayerMenus();
    void setupTransformsMenu();
	void setupFiltersMenu();
	void setupHelpMenu();
    void setupExistingLayersMenus();
    void setupToolbars();

    Pane *addPaneToStack();

    void addPane(const PaneConfiguration &configuration, QString text);

    class PaneCallback : public SVFileReaderPaneCallback , public ESFileReaderPaneCallback
    {
    public:
	PaneCallback(MainWindow *mw) : m_mw(mw) { }
	virtual Pane *addPane() { return m_mw->addPaneToStack(); }
	virtual void setWindowSize(int width, int height) {
	    m_mw->resize(width, height);
	}
	virtual void addSelection(int start, int end) {
	    m_mw->m_viewManager->addSelection(Selection(start, end));
	}
    protected:
	MainWindow *m_mw;
    };

    class AddPaneCommand : public Command
    {
    public:
	AddPaneCommand(MainWindow *mw);
	virtual ~AddPaneCommand();
	
	virtual void execute();
	virtual void unexecute();
	virtual QString getName() const;

	Pane *getPane() { return m_pane; }

    protected:
	MainWindow *m_mw;
	Pane *m_pane; // Main window owns this, but I determine its lifespan
	Pane *m_prevCurrentPane; // I don't own this
	bool m_added;
    };

    class RemovePaneCommand : public Command
    {
    public:
	RemovePaneCommand(MainWindow *mw, Pane *pane);
	virtual ~RemovePaneCommand();
	
	virtual void execute();
	virtual void unexecute();
	virtual QString getName() const;

    protected:
	MainWindow *m_mw;
	Pane *m_pane; // Main window owns this, but I determine its lifespan
	Pane *m_prevCurrentPane; // I don't own this
	bool m_added;
    };

    virtual void closeEvent(QCloseEvent *e);
    bool checkSaveModified();

    FileOpenStatus openSomeFile(QString path, QString location,
                                AudioFileOpenMode = AskUser);
    FileOpenStatus openAudioFile(QString path, QString location,
                                 AudioFileOpenMode = AskUser);
// Ivan Damnjanovic 09-10/2007 added video file import	
	FileOpenStatus openVideoFile(QString path, QString location,
                                 AudioFileOpenMode = AskUser);
//
    FileOpenStatus openLayerFile(QString path, QString location);
    FileOpenStatus openSessionFile(QString path, QString location);

    QString getOpenFileName(FileFinder::FileType type);
    QString getSaveFileName(FileFinder::FileType type);
    void registerLastOpenedFilePath(FileFinder::FileType type, QString path);

    void createPlayTarget();

    void openHelpUrl(QString url);

    void updateVisibleRangeDisplay(Pane *p) const;

    void toXml(QTextStream &stream);
	void toEasaierXml(QTextStream &stream);

	bool saveConfigFile();

	static MainWindow	*m_instance;

	ExpandWidget		*m_leftExpandWidget;
	ExpandWidget		*m_rightExpandWidget;

	InfoWidget			*m_infoWidget;
	SearchWidget		*m_searchWidget;
	QueryResultsWidget	*m_resultsWidget;

	QTabWidget			*m_qtabwidget;

	AdvancedToolBox         *m_toolBox; 

	WidgetGallery			m_gallery;

	HttpClient				*m_httpClient;

	EasaierSessionManager	*m_EasaierManager;

	MultiPaneLayerContainer					*m_multiPaneLayerContainer;

	RealTimeFilterPropertyStack	*m_filterPropertyStack;

private:
	void createMultiPaneLayerContainer();


};


#endif