Chris@127: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@127: Chris@127: /* Chris@127: Sonic Visualiser Chris@127: An audio file viewer and annotation editor. Chris@127: Centre for Digital Music, Queen Mary, University of London. Chris@127: This file copyright 2006 Chris Cannam. Chris@127: Chris@127: This program is free software; you can redistribute it and/or Chris@127: modify it under the terms of the GNU General Public License as Chris@127: published by the Free Software Foundation; either version 2 of the Chris@127: License, or (at your option) any later version. See the file Chris@127: COPYING included with this distribution for more information. Chris@127: */ Chris@127: Chris@127: #ifndef _VIEW_MANAGER_H_ Chris@127: #define _VIEW_MANAGER_H_ Chris@127: Chris@127: #include Chris@127: #include Chris@127: Chris@127: #include Chris@127: Chris@128: #include "base/Selection.h" Chris@128: #include "base/Command.h" Chris@128: #include "base/Clipboard.h" Chris@127: Chris@127: class AudioPlaySource; Chris@127: class Model; Chris@127: Chris@127: /** Chris@127: * The ViewManager manages properties that may need to be synchronised Chris@127: * between separate Views. For example, it handles signals associated Chris@127: * with changes to the global pan and zoom, and it handles selections. Chris@127: * Chris@127: * Views should be implemented in such a way as to work Chris@127: * correctly whether they are supplied with a ViewManager or not. Chris@127: */ Chris@127: Chris@127: class ViewManager : public QObject Chris@127: { Chris@127: Q_OBJECT Chris@127: Chris@127: public: Chris@127: ViewManager(); Chris@127: virtual ~ViewManager(); Chris@127: Chris@127: void setAudioPlaySource(AudioPlaySource *source); Chris@127: Chris@127: bool isPlaying() const; Chris@127: Chris@127: unsigned long getGlobalCentreFrame() const; Chris@127: unsigned long getGlobalZoom() const; Chris@127: Chris@127: unsigned long getPlaybackFrame() const; Chris@127: void setPlaybackFrame(unsigned long frame); Chris@127: Chris@127: bool haveInProgressSelection() const; Chris@127: const Selection &getInProgressSelection(bool &exclusive) const; Chris@127: void setInProgressSelection(const Selection &selection, bool exclusive); Chris@127: void clearInProgressSelection(); Chris@127: Chris@127: const MultiSelection &getSelection() const; Chris@127: Chris@127: const MultiSelection::SelectionList &getSelections() const; Chris@127: void setSelection(const Selection &selection); Chris@127: void addSelection(const Selection &selection); Chris@127: void removeSelection(const Selection &selection); Chris@127: void clearSelections(); Chris@127: Chris@127: /** Chris@127: * Return the selection that contains a given frame. Chris@127: * If defaultToFollowing is true, and if the frame is not in a Chris@127: * selected area, return the next selection after the given frame. Chris@127: * Return the empty selection if no appropriate selection is found. Chris@127: */ Chris@127: Selection getContainingSelection(size_t frame, bool defaultToFollowing) const; Chris@127: Chris@127: Clipboard &getClipboard() { return m_clipboard; } Chris@127: Chris@127: enum ToolMode { Chris@127: NavigateMode, Chris@127: SelectMode, Chris@127: EditMode, Chris@127: DrawMode Chris@127: }; Chris@127: ToolMode getToolMode() const { return m_toolMode; } Chris@127: void setToolMode(ToolMode mode); Chris@127: Chris@127: bool getPlayLoopMode() const { return m_playLoopMode; } Chris@127: void setPlayLoopMode(bool on); Chris@127: Chris@127: bool getPlaySelectionMode() const { return m_playSelectionMode; } Chris@127: void setPlaySelectionMode(bool on); Chris@127: Chris@127: size_t getPlaybackSampleRate() const; Chris@127: size_t getMainModelSampleRate() const { return m_mainModelSampleRate; } Chris@127: void setMainModelSampleRate(size_t sr) { m_mainModelSampleRate = sr; } Chris@127: Chris@127: enum OverlayMode { Chris@127: NoOverlays, Chris@127: BasicOverlays, Chris@127: AllOverlays Chris@127: }; Chris@127: void setOverlayMode(OverlayMode mode); Chris@127: OverlayMode getOverlayMode() const { return m_overlayMode; } Chris@127: Chris@127: signals: Chris@127: /** Emitted when a widget pans. The originator identifies the widget. */ Chris@127: void centreFrameChanged(void *originator, unsigned long frame, bool locked); Chris@127: Chris@127: /** Emitted when a widget zooms. The originator identifies the widget. */ Chris@127: void zoomLevelChanged(void *originator, unsigned long zoom, bool locked); Chris@127: Chris@127: /** Emitted when the playback frame changes. */ Chris@127: void playbackFrameChanged(unsigned long frame); Chris@127: Chris@127: /** Emitted when the output levels change. Values in range 0.0 -> 1.0. */ Chris@127: void outputLevelsChanged(float left, float right); Chris@127: Chris@127: /** Emitted when the selection has changed. */ Chris@127: void selectionChanged(); Chris@127: Chris@127: /** Emitted when the in-progress (rubberbanding) selection has changed. */ Chris@127: void inProgressSelectionChanged(); Chris@127: Chris@127: /** Emitted when the tool mode has been changed. */ Chris@127: void toolModeChanged(); Chris@127: Chris@127: /** Emitted when the play loop mode has been changed. */ Chris@127: void playLoopModeChanged(); Chris@127: Chris@127: /** Emitted when the play selection mode has been changed. */ Chris@127: void playSelectionModeChanged(); Chris@127: Chris@127: /** Emitted when the overlay mode has been changed. */ Chris@127: void overlayModeChanged(); Chris@127: Chris@127: protected slots: Chris@127: void checkPlayStatus(); Chris@127: void playStatusChanged(bool playing); Chris@127: void considerSeek(void *, unsigned long, bool); Chris@127: void considerZoomChange(void *, unsigned long, bool); Chris@127: Chris@127: protected: Chris@127: AudioPlaySource *m_playSource; Chris@127: unsigned long m_globalCentreFrame; Chris@127: unsigned long m_globalZoom; Chris@127: mutable unsigned long m_playbackFrame; Chris@127: size_t m_mainModelSampleRate; Chris@127: Chris@127: float m_lastLeft; Chris@127: float m_lastRight; Chris@127: Chris@127: MultiSelection m_selections; Chris@127: Selection m_inProgressSelection; Chris@127: bool m_inProgressExclusive; Chris@127: Chris@127: Clipboard m_clipboard; Chris@127: Chris@127: ToolMode m_toolMode; Chris@127: Chris@127: bool m_playLoopMode; Chris@127: bool m_playSelectionMode; Chris@127: Chris@127: void setSelections(const MultiSelection &ms); Chris@127: void signalSelectionChange(); Chris@127: Chris@127: class SetSelectionCommand : public Command Chris@127: { Chris@127: public: Chris@127: SetSelectionCommand(ViewManager *vm, const MultiSelection &ms); Chris@127: virtual ~SetSelectionCommand(); Chris@127: virtual void execute(); Chris@127: virtual void unexecute(); Chris@127: virtual QString getName() const; Chris@127: Chris@127: protected: Chris@127: ViewManager *m_vm; Chris@127: MultiSelection m_oldSelection; Chris@127: MultiSelection m_newSelection; Chris@127: }; Chris@127: Chris@127: OverlayMode m_overlayMode; Chris@127: }; Chris@127: Chris@127: #endif Chris@127: