Chris@49: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@0: Chris@0: /* Chris@0: A waveform viewer and audio annotation editor. Chris@2: Chris Cannam, Queen Mary University of London, 2005-2006 Chris@0: Chris@0: This is experimental software. Not for distribution. Chris@0: */ Chris@0: Chris@0: #ifndef _VIEW_MANAGER_H_ Chris@0: #define _VIEW_MANAGER_H_ Chris@0: Chris@0: #include Chris@0: #include Chris@0: Chris@0: #include Chris@8: Chris@8: #include "Selection.h" Chris@45: #include "Command.h" Chris@0: Chris@0: class AudioPlaySource; Chris@0: class Model; Chris@0: Chris@0: /** Chris@0: * The ViewManager manages properties that may need to be synchronised Chris@0: * between separate Views. For example, it handles signals associated Chris@48: * with changes to the global pan and zoom, and it handles selections. Chris@0: * Chris@0: * Views should be implemented in such a way as to work Chris@0: * correctly whether they are supplied with a ViewManager or not. Chris@0: */ Chris@0: Chris@0: class ViewManager : public QObject Chris@0: { Chris@0: Q_OBJECT Chris@0: Chris@0: public: Chris@0: ViewManager(); Chris@0: Chris@0: void setAudioPlaySource(AudioPlaySource *source); Chris@0: Chris@8: bool isPlaying() const; Chris@8: Chris@0: unsigned long getGlobalCentreFrame() const; Chris@0: unsigned long getGlobalZoom() const; Chris@0: Chris@24: unsigned long getPlaybackFrame() const; Chris@24: void setPlaybackFrame(unsigned long frame); Chris@8: Chris@8: bool haveInProgressSelection() const; Chris@8: const Selection &getInProgressSelection(bool &exclusive) const; Chris@8: void setInProgressSelection(const Selection &selection, bool exclusive); Chris@8: void clearInProgressSelection(); Chris@8: Chris@24: const MultiSelection &getSelection() const; Chris@24: Chris@24: const MultiSelection::SelectionList &getSelections() const; Chris@8: void setSelection(const Selection &selection); Chris@8: void addSelection(const Selection &selection); Chris@8: void removeSelection(const Selection &selection); Chris@8: void clearSelections(); Chris@8: Chris@9: /** Chris@9: * Return the selection that contains a given frame. Chris@9: * If defaultToFollowing is true, and if the frame is not in a Chris@9: * selected area, return the next selection after the given frame. Chris@9: * Return the empty selection if no appropriate selection is found. Chris@9: */ Chris@36: Selection getContainingSelection(size_t frame, bool defaultToFollowing) const; Chris@9: Chris@8: enum ToolMode { Chris@8: NavigateMode, Chris@8: SelectMode, Chris@8: EditMode, Chris@32: DrawMode Chris@8: }; Chris@8: ToolMode getToolMode() const { return m_toolMode; } Chris@8: void setToolMode(ToolMode mode); Chris@8: Chris@9: bool getPlayLoopMode() const { return m_playLoopMode; } Chris@9: void setPlayLoopMode(bool on); Chris@9: Chris@9: bool getPlaySelectionMode() const { return m_playSelectionMode; } Chris@9: void setPlaySelectionMode(bool on); Chris@9: Chris@40: size_t getPlaybackSampleRate() const; Chris@42: size_t getMainModelSampleRate() const { return m_mainModelSampleRate; } Chris@42: void setMainModelSampleRate(size_t sr) { m_mainModelSampleRate = sr; } Chris@40: Chris@0: signals: Chris@0: /** Emitted when a widget pans. The originator identifies the widget. */ Chris@0: void centreFrameChanged(void *originator, unsigned long frame, bool locked); Chris@0: Chris@0: /** Emitted when a widget zooms. The originator identifies the widget. */ Chris@0: void zoomLevelChanged(void *originator, unsigned long zoom, bool locked); Chris@0: Chris@0: /** Emitted when the playback frame changes. */ Chris@0: void playbackFrameChanged(unsigned long frame); Chris@0: Chris@0: /** Emitted when the output levels change. Values in range 0.0 -> 1.0. */ Chris@0: void outputLevelsChanged(float left, float right); Chris@0: Chris@8: /** Emitted when the selection has changed. */ Chris@8: void selectionChanged(); Chris@8: Chris@9: /** Emitted when the in-progress (rubberbanding) selection has changed. */ Chris@9: void inProgressSelectionChanged(); Chris@9: Chris@8: /** Emitted when the tool mode has been changed. */ Chris@8: void toolModeChanged(); Chris@8: Chris@9: /** Emitted when the play loop mode has been changed. */ Chris@9: void playLoopModeChanged(); Chris@9: Chris@9: /** Emitted when the play selection mode has been changed. */ Chris@9: void playSelectionModeChanged(); Chris@9: Chris@0: protected slots: Chris@0: void checkPlayStatus(); Chris@10: void playStatusChanged(bool playing); Chris@0: void considerSeek(void *, unsigned long, bool); Chris@0: void considerZoomChange(void *, unsigned long, bool); Chris@0: Chris@0: protected: Chris@0: AudioPlaySource *m_playSource; Chris@0: unsigned long m_globalCentreFrame; Chris@0: unsigned long m_globalZoom; Chris@24: mutable unsigned long m_playbackFrame; Chris@42: size_t m_mainModelSampleRate; Chris@0: Chris@0: float m_lastLeft; Chris@0: float m_lastRight; Chris@0: Chris@24: MultiSelection m_selections; Chris@8: Selection m_inProgressSelection; Chris@8: bool m_inProgressExclusive; Chris@8: Chris@8: ToolMode m_toolMode; Chris@8: Chris@9: bool m_playLoopMode; Chris@9: bool m_playSelectionMode; Chris@45: Chris@45: void setSelections(const MultiSelection &ms); Chris@45: void signalSelectionChange(); Chris@45: Chris@45: class SetSelectionCommand : public Command Chris@45: { Chris@45: public: Chris@45: SetSelectionCommand(ViewManager *vm, const MultiSelection &ms); Chris@45: virtual ~SetSelectionCommand(); Chris@45: virtual void execute(); Chris@45: virtual void unexecute(); Chris@45: virtual QString getName() const; Chris@45: Chris@45: protected: Chris@45: ViewManager *m_vm; Chris@45: MultiSelection m_oldSelection; Chris@45: MultiSelection m_newSelection; Chris@45: }; Chris@0: }; Chris@0: Chris@0: #endif Chris@0: