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/Selection.h"
00026 #include "base/Command.h"
00027 #include "base/Clipboard.h"
00028 
00029 class AudioPlaySource;
00030 class Model;
00031 
00032 enum PlaybackFollowMode {
00033     PlaybackScrollContinuous,
00034     PlaybackScrollPage,
00035     PlaybackIgnore
00036 };
00037 
00038 class View;
00039 
00049 class ViewManager : public QObject
00050 {
00051     Q_OBJECT
00052 
00053 public:
00054     ViewManager();
00055     virtual ~ViewManager();
00056 
00057     void setAudioPlaySource(AudioPlaySource *source);
00058 
00059     bool isPlaying() const;
00060 
00061     unsigned long getGlobalCentreFrame() const;
00062     void setGlobalCentreFrame(unsigned long);
00063     unsigned long getGlobalZoom() const;
00064 
00065     unsigned long getPlaybackFrame() const;
00066     void setPlaybackFrame(unsigned long frame);
00067 
00068     // Only meaningful in solo mode, and used for optional alignment feature
00069     Model *getPlaybackModel() const;
00070     void setPlaybackModel(Model *);
00071 
00072     size_t alignPlaybackFrameToReference(size_t) const;
00073     size_t alignReferenceToPlaybackFrame(size_t) const;
00074 
00075     bool haveInProgressSelection() const;
00076     const Selection &getInProgressSelection(bool &exclusive) const;
00077     void setInProgressSelection(const Selection &selection, bool exclusive);
00078     void clearInProgressSelection();
00079 
00080     const MultiSelection &getSelection() const;
00081 
00082     const MultiSelection::SelectionList &getSelections() const;
00083     void setSelection(const Selection &selection);
00084     void addSelection(const Selection &selection);
00085     void removeSelection(const Selection &selection);
00086     void clearSelections();
00087     size_t constrainFrameToSelection(size_t frame) const;
00088 
00095     Selection getContainingSelection(size_t frame, bool defaultToFollowing) const;
00096 
00097     Clipboard &getClipboard() { return m_clipboard; }
00098 
00099     enum ToolMode {
00100         NavigateMode,
00101         SelectMode,
00102         EditMode,
00103         DrawMode,
00104         EraseMode,
00105         MeasureMode
00106     };
00107     ToolMode getToolMode() const { return m_toolMode; }
00108     void setToolMode(ToolMode mode);
00109 
00110     bool getPlayLoopMode() const { return m_playLoopMode; }
00111     void setPlayLoopMode(bool on);
00112 
00113     bool getPlaySelectionMode() const { return m_playSelectionMode; }
00114     void setPlaySelectionMode(bool on);
00115 
00116     bool getPlaySoloMode() const { return m_playSoloMode; }
00117     void setPlaySoloMode(bool on);
00118 
00119     bool getAlignMode() const { return m_alignMode; }
00120     void setAlignMode(bool on);
00121 
00122     void setIlluminateLocalFeatures(bool i) { m_illuminateLocalFeatures = i; }
00123     void setShowWorkTitle(bool show) { m_showWorkTitle = show; }
00124 
00131     size_t getPlaybackSampleRate() const;
00132 
00138     size_t getOutputSampleRate() const;
00139 
00145     size_t getMainModelSampleRate() const { return m_mainModelSampleRate; }
00146 
00147     void setMainModelSampleRate(size_t sr) { m_mainModelSampleRate = sr; }
00148 
00149     enum OverlayMode {
00150         NoOverlays,
00151         MinimalOverlays,
00152         StandardOverlays,
00153         AllOverlays
00154     };
00155     void setOverlayMode(OverlayMode mode);
00156     OverlayMode getOverlayMode() const { return m_overlayMode; }
00157 
00158     bool shouldShowCentreLine() const {
00159         return m_overlayMode != NoOverlays;
00160     }
00161     bool shouldShowFrameCount() const {
00162         return m_overlayMode != NoOverlays;
00163     }
00164     bool shouldShowDuration() const {
00165         return m_overlayMode > MinimalOverlays;
00166     }
00167     bool shouldShowVerticalScale() const {
00168         return m_overlayMode > MinimalOverlays;
00169     }
00170     bool shouldShowSelectionExtents() const {
00171         return m_overlayMode > MinimalOverlays;
00172     }
00173     bool shouldShowLayerNames() const {
00174         return m_overlayMode == AllOverlays;
00175     }
00176     bool shouldShowScaleGuides() const {
00177         return m_overlayMode != NoOverlays;
00178     }
00179     bool shouldShowWorkTitle() const {
00180         return m_showWorkTitle;
00181     }
00182     bool shouldIlluminateLocalFeatures() const {
00183         return m_illuminateLocalFeatures;
00184     }
00185 
00186     void setZoomWheelsEnabled(bool enable);
00187     bool getZoomWheelsEnabled() const { return m_zoomWheelsEnabled; }
00188 
00189     void setGlobalDarkBackground(bool dark);
00190     bool getGlobalDarkBackground() const;
00191 
00192 signals:
00194     void globalCentreFrameChanged(unsigned long frame);
00195 
00197     void viewCentreFrameChanged(View *v, unsigned long frame);
00198 
00200     void viewZoomLevelChanged(View *v, unsigned long zoom, bool locked);
00201 
00203     void playbackFrameChanged(unsigned long frame);
00204 
00206     void outputLevelsChanged(float left, float right);
00207 
00209     void selectionChanged();
00210 
00212     void inProgressSelectionChanged();
00213 
00215     void toolModeChanged();
00216 
00218     void playLoopModeChanged();
00219     void playLoopModeChanged(bool);
00220 
00222     void playSelectionModeChanged();
00223     void playSelectionModeChanged(bool);
00224 
00226     void playSoloModeChanged();
00227     void playSoloModeChanged(bool);
00228 
00230     void alignModeChanged();
00231     void alignModeChanged(bool);
00232 
00234     void overlayModeChanged();
00235 
00237     void zoomWheelsEnabledChanged();
00238 
00239 public slots:
00240     void viewCentreFrameChanged(unsigned long, bool, PlaybackFollowMode);
00241     void viewZoomLevelChanged(unsigned long, bool);
00242 
00243 protected slots:
00244     void checkPlayStatus();
00245     void playStatusChanged(bool playing);
00246     void seek(unsigned long);
00248 
00249 protected:
00250     AudioPlaySource *m_playSource;
00251     unsigned long m_globalCentreFrame;
00252     unsigned long m_globalZoom;
00253     mutable unsigned long m_playbackFrame;
00254     Model *m_playbackModel; 
00255     size_t m_mainModelSampleRate;
00256 
00257     float m_lastLeft;
00258     float m_lastRight;
00259 
00260     MultiSelection m_selections;
00261     Selection m_inProgressSelection;
00262     bool m_inProgressExclusive;
00263 
00264     Clipboard m_clipboard;
00265 
00266     ToolMode m_toolMode;
00267 
00268     bool m_playLoopMode;
00269     bool m_playSelectionMode;
00270     bool m_playSoloMode;
00271     bool m_alignMode;
00272 
00273     void setSelections(const MultiSelection &ms);
00274     void signalSelectionChange();
00275 
00276     class SetSelectionCommand : public Command
00277     {
00278     public:
00279         SetSelectionCommand(ViewManager *vm, const MultiSelection &ms);
00280         virtual ~SetSelectionCommand();
00281         virtual void execute();
00282         virtual void unexecute();
00283         virtual QString getName() const;
00284 
00285     protected:
00286         ViewManager *m_vm;
00287         MultiSelection m_oldSelection;
00288         MultiSelection m_newSelection;
00289     };
00290 
00291     OverlayMode m_overlayMode;
00292     bool m_zoomWheelsEnabled;
00293     bool m_illuminateLocalFeatures;
00294     bool m_showWorkTitle;
00295 
00296     QPalette m_lightPalette;
00297     QPalette m_darkPalette;
00298 };
00299 
00300 #endif
00301 

Generated on Wed Feb 20 15:45:30 2008 for SonicVisualiser by  doxygen 1.5.1