svgui  1.9
ViewManager.h
Go to the documentation of this file.
00001 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
00002 
00003 /*
00004     Sonic Visualiser
00005     An audio file viewer and annotation editor.
00006     Centre for Digital Music, Queen Mary, University of London.
00007     This file copyright 2006 Chris Cannam and QMUL.
00008     
00009     This program is free software; you can redistribute it and/or
00010     modify it under the terms of the GNU General Public License as
00011     published by the Free Software Foundation; either version 2 of the
00012     License, or (at your option) any later version.  See the file
00013     COPYING included with this distribution for more information.
00014 */
00015 
00016 #ifndef _VIEW_MANAGER_H_
00017 #define _VIEW_MANAGER_H_
00018 
00019 #include <QObject>
00020 #include <QTimer>
00021 #include <QPalette>
00022 
00023 #include <map>
00024 
00025 #include "base/ViewManagerBase.h"
00026 #include "base/Selection.h"
00027 #include "base/Command.h"
00028 #include "base/Clipboard.h"
00029 
00030 class AudioPlaySource;
00031 class Model;
00032 
00033 enum PlaybackFollowMode {
00034 
00039     PlaybackScrollContinuous,
00040 
00046     PlaybackScrollPageWithCentre,
00047 
00053     PlaybackScrollPage,
00054 
00059     PlaybackIgnore
00060 };
00061 
00062 class View;
00063 
00073 class ViewManager : public ViewManagerBase
00074 {
00075     Q_OBJECT
00076 
00077 public:
00078     ViewManager();
00079     virtual ~ViewManager();
00080 
00081     void setAudioPlaySource(AudioPlaySource *source);
00082 
00083     bool isPlaying() const;
00084 
00085     int getGlobalCentreFrame() const; // the set method is a slot
00086     int getGlobalZoom() const;
00087 
00088     int getPlaybackFrame() const; // the set method is a slot
00089 
00090     // Only meaningful in solo mode, and used for optional alignment feature
00091     Model *getPlaybackModel() const;
00092     void setPlaybackModel(Model *);
00093 
00094     int alignPlaybackFrameToReference(int) const;
00095     int alignReferenceToPlaybackFrame(int) const;
00096 
00097     bool haveInProgressSelection() const;
00098     const Selection &getInProgressSelection(bool &exclusive) const;
00099     void setInProgressSelection(const Selection &selection, bool exclusive);
00100     void clearInProgressSelection();
00101 
00102     const MultiSelection &getSelection() const;
00103 
00104     const MultiSelection::SelectionList &getSelections() const;
00105     void setSelection(const Selection &selection);
00106     void addSelection(const Selection &selection);
00107     void removeSelection(const Selection &selection);
00108     void clearSelections();
00109     int constrainFrameToSelection(int frame) const;
00110 
00116     void addSelectionQuietly(const Selection &selection);
00117 
00124     Selection getContainingSelection(int frame, bool defaultToFollowing) const;
00125 
00126     Clipboard &getClipboard() { return m_clipboard; }
00127 
00128     enum ToolMode {
00129         NavigateMode,
00130         SelectMode,
00131         EditMode,
00132         DrawMode,
00133         EraseMode,
00134         MeasureMode,
00135         NoteEditMode //GF: Tonioni: this tool mode will be context sensitive.
00136     };
00137     ToolMode getToolMode() const { return m_toolMode; }
00138     void setToolMode(ToolMode mode);
00139 
00141     void setToolModeFor(const View *v, ToolMode mode);
00143     ToolMode getToolModeFor(const View *v) const;
00145     void clearToolModeOverrides();
00146 
00147     bool getPlayLoopMode() const { return m_playLoopMode; }
00148     void setPlayLoopMode(bool on);
00149 
00150     bool getPlaySelectionMode() const { return m_playSelectionMode; }
00151     void setPlaySelectionMode(bool on);
00152 
00153     bool getPlaySoloMode() const { return m_playSoloMode; }
00154     void setPlaySoloMode(bool on);
00155 
00156     bool getAlignMode() const { return m_alignMode; }
00157     void setAlignMode(bool on);
00158 
00159     void setIlluminateLocalFeatures(bool i) { m_illuminateLocalFeatures = i; }
00160     void setShowWorkTitle(bool show) { m_showWorkTitle = show; }
00161     void setShowDuration(bool show) { m_showDuration = show; }
00162 
00169     int getPlaybackSampleRate() const;
00170 
00176     int getOutputSampleRate() const;
00177 
00183     int getMainModelSampleRate() const { return m_mainModelSampleRate; }
00184 
00185     void setMainModelSampleRate(int sr) { m_mainModelSampleRate = sr; }
00186 
00187     enum OverlayMode {
00188         NoOverlays,
00189         GlobalOverlays,
00190         StandardOverlays,
00191         AllOverlays
00192     };
00193     void setOverlayMode(OverlayMode mode);
00194     OverlayMode getOverlayMode() const { return m_overlayMode; }
00195 
00196     void setShowCentreLine(bool show);
00197     bool shouldShowCentreLine() const { return m_showCentreLine; }
00198 
00199     bool shouldShowDuration() const {
00200         return m_overlayMode != NoOverlays && m_showDuration;
00201     }
00202     bool shouldShowFrameCount() const {
00203         return m_showCentreLine && shouldShowDuration();
00204     }
00205     bool shouldShowVerticalScale() const {
00206         return m_overlayMode != NoOverlays;
00207     }
00208     bool shouldShowVerticalColourScale() const {
00209         return m_overlayMode == AllOverlays;
00210     }
00211     bool shouldShowSelectionExtents() const {
00212         return m_overlayMode != NoOverlays && m_overlayMode != GlobalOverlays;
00213     }
00214     bool shouldShowLayerNames() const {
00215         return m_overlayMode == AllOverlays;
00216     }
00217     bool shouldShowScaleGuides() const {
00218         return m_overlayMode != NoOverlays;
00219     }
00220     bool shouldShowWorkTitle() const {
00221         return m_showWorkTitle;
00222     }
00223     bool shouldIlluminateLocalFeatures() const {
00224         return m_illuminateLocalFeatures;
00225     }
00226     bool shouldShowFeatureLabels() const {
00227         return m_overlayMode != NoOverlays && m_overlayMode != GlobalOverlays;
00228     }
00229 
00230     void setZoomWheelsEnabled(bool enable);
00231     bool getZoomWheelsEnabled() const { return m_zoomWheelsEnabled; }
00232 
00233     void setGlobalDarkBackground(bool dark);
00234     bool getGlobalDarkBackground() const;
00235 
00236 signals:
00238     void globalCentreFrameChanged(int frame);
00239 
00241     void viewCentreFrameChanged(View *v, int frame);
00242 
00244     void viewZoomLevelChanged(View *v, int zoom, bool locked);
00245 
00247     void playbackFrameChanged(int frame);
00248 
00250     void outputLevelsChanged(float left, float right);
00251 
00253     void selectionChanged();
00254 
00258     void selectionChangedByUser();
00259 
00261     void inProgressSelectionChanged();
00262 
00264     void toolModeChanged();
00265 
00267     void playLoopModeChanged();
00268     void playLoopModeChanged(bool);
00269 
00271     void playSelectionModeChanged();
00272     void playSelectionModeChanged(bool);
00273 
00275     void playSoloModeChanged();
00276     void playSoloModeChanged(bool);
00277 
00279     void alignModeChanged();
00280     void alignModeChanged(bool);
00281 
00283     void overlayModeChanged();
00284 
00286     void showCentreLineChanged();
00287 
00289     void zoomWheelsEnabledChanged();
00290 
00292     void activity(QString);
00293 
00294 public slots:
00295     void viewCentreFrameChanged(int, bool, PlaybackFollowMode);
00296     void viewZoomLevelChanged(int, bool);
00297     void setGlobalCentreFrame(int);
00298     void setPlaybackFrame(int);
00299     void playStatusChanged(bool playing);
00300 
00301 protected slots:
00302     void checkPlayStatus();
00303     void seek(int);
00305 
00306 protected:
00307     AudioPlaySource *m_playSource;
00308     int m_globalCentreFrame;
00309     int m_globalZoom;
00310     mutable int m_playbackFrame;
00311     Model *m_playbackModel; 
00312     int m_mainModelSampleRate;
00313 
00314     float m_lastLeft;
00315     float m_lastRight;
00316 
00317     MultiSelection m_selections;
00318     Selection m_inProgressSelection;
00319     bool m_inProgressExclusive;
00320 
00321     Clipboard m_clipboard;
00322 
00323     ToolMode m_toolMode;
00324     std::map<const View *, ToolMode> m_toolModeOverrides;
00325 
00326     bool m_playLoopMode;
00327     bool m_playSelectionMode;
00328     bool m_playSoloMode;
00329     bool m_alignMode;
00330 
00331     void setSelections(const MultiSelection &ms, bool quietly = false);
00332     void signalSelectionChange();
00333 
00334     class SetSelectionCommand : public Command
00335     {
00336     public:
00337         SetSelectionCommand(ViewManager *vm, const MultiSelection &ms);
00338         virtual ~SetSelectionCommand();
00339         virtual void execute();
00340         virtual void unexecute();
00341         virtual QString getName() const;
00342 
00343     protected:
00344         ViewManager *m_vm;
00345         MultiSelection m_oldSelection;
00346         MultiSelection m_newSelection;
00347     };
00348 
00349     OverlayMode m_overlayMode;
00350     bool m_zoomWheelsEnabled;
00351     bool m_showCentreLine;
00352     bool m_illuminateLocalFeatures;
00353     bool m_showWorkTitle;
00354     bool m_showDuration;
00355 
00356     QPalette m_lightPalette;
00357     QPalette m_darkPalette;
00358 };
00359 
00360 #endif
00361