annotate base/ViewManager.h @ 62:33285f426852

fixed some problems with building the latest revision on the mac
author Martin Gasser
date Tue, 28 Mar 2006 23:57:32 +0000
parents d397ea0a79f5
children e1aad27029e3
rev   line source
Chris@49 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@0 2
Chris@0 3 /*
Chris@52 4 Sonic Visualiser
Chris@52 5 An audio file viewer and annotation editor.
Chris@52 6 Centre for Digital Music, Queen Mary, University of London.
Chris@52 7 This file copyright 2006 Chris Cannam.
Chris@0 8
Chris@52 9 This program is free software; you can redistribute it and/or
Chris@52 10 modify it under the terms of the GNU General Public License as
Chris@52 11 published by the Free Software Foundation; either version 2 of the
Chris@52 12 License, or (at your option) any later version. See the file
Chris@52 13 COPYING included with this distribution for more information.
Chris@0 14 */
Chris@0 15
Chris@0 16 #ifndef _VIEW_MANAGER_H_
Chris@0 17 #define _VIEW_MANAGER_H_
Chris@0 18
Chris@0 19 #include <QObject>
Chris@0 20 #include <QTimer>
Chris@0 21
Chris@0 22 #include <map>
Chris@8 23
Chris@8 24 #include "Selection.h"
Chris@45 25 #include "Command.h"
Chris@0 26
Chris@0 27 class AudioPlaySource;
Chris@0 28 class Model;
Chris@0 29
Chris@0 30 /**
Chris@0 31 * The ViewManager manages properties that may need to be synchronised
Chris@0 32 * between separate Views. For example, it handles signals associated
Chris@48 33 * with changes to the global pan and zoom, and it handles selections.
Chris@0 34 *
Chris@0 35 * Views should be implemented in such a way as to work
Chris@0 36 * correctly whether they are supplied with a ViewManager or not.
Chris@0 37 */
Chris@0 38
Chris@0 39 class ViewManager : public QObject
Chris@0 40 {
Chris@0 41 Q_OBJECT
Chris@0 42
Chris@0 43 public:
Chris@0 44 ViewManager();
Chris@0 45
Chris@0 46 void setAudioPlaySource(AudioPlaySource *source);
Chris@0 47
Chris@8 48 bool isPlaying() const;
Chris@8 49
Chris@0 50 unsigned long getGlobalCentreFrame() const;
Chris@0 51 unsigned long getGlobalZoom() const;
Chris@0 52
Chris@24 53 unsigned long getPlaybackFrame() const;
Chris@24 54 void setPlaybackFrame(unsigned long frame);
Chris@8 55
Chris@8 56 bool haveInProgressSelection() const;
Chris@8 57 const Selection &getInProgressSelection(bool &exclusive) const;
Chris@8 58 void setInProgressSelection(const Selection &selection, bool exclusive);
Chris@8 59 void clearInProgressSelection();
Chris@8 60
Chris@24 61 const MultiSelection &getSelection() const;
Chris@24 62
Chris@24 63 const MultiSelection::SelectionList &getSelections() const;
Chris@8 64 void setSelection(const Selection &selection);
Chris@8 65 void addSelection(const Selection &selection);
Chris@8 66 void removeSelection(const Selection &selection);
Chris@8 67 void clearSelections();
Chris@8 68
Chris@9 69 /**
Chris@9 70 * Return the selection that contains a given frame.
Chris@9 71 * If defaultToFollowing is true, and if the frame is not in a
Chris@9 72 * selected area, return the next selection after the given frame.
Chris@9 73 * Return the empty selection if no appropriate selection is found.
Chris@9 74 */
Chris@36 75 Selection getContainingSelection(size_t frame, bool defaultToFollowing) const;
Chris@9 76
Chris@8 77 enum ToolMode {
Chris@8 78 NavigateMode,
Chris@8 79 SelectMode,
Chris@8 80 EditMode,
Chris@32 81 DrawMode
Chris@8 82 };
Chris@8 83 ToolMode getToolMode() const { return m_toolMode; }
Chris@8 84 void setToolMode(ToolMode mode);
Chris@8 85
Chris@9 86 bool getPlayLoopMode() const { return m_playLoopMode; }
Chris@9 87 void setPlayLoopMode(bool on);
Chris@9 88
Chris@9 89 bool getPlaySelectionMode() const { return m_playSelectionMode; }
Chris@9 90 void setPlaySelectionMode(bool on);
Chris@9 91
Chris@40 92 size_t getPlaybackSampleRate() const;
Chris@42 93 size_t getMainModelSampleRate() const { return m_mainModelSampleRate; }
Chris@42 94 void setMainModelSampleRate(size_t sr) { m_mainModelSampleRate = sr; }
Chris@40 95
Chris@0 96 signals:
Chris@0 97 /** Emitted when a widget pans. The originator identifies the widget. */
Chris@0 98 void centreFrameChanged(void *originator, unsigned long frame, bool locked);
Chris@0 99
Chris@0 100 /** Emitted when a widget zooms. The originator identifies the widget. */
Chris@0 101 void zoomLevelChanged(void *originator, unsigned long zoom, bool locked);
Chris@0 102
Chris@0 103 /** Emitted when the playback frame changes. */
Chris@0 104 void playbackFrameChanged(unsigned long frame);
Chris@0 105
Chris@0 106 /** Emitted when the output levels change. Values in range 0.0 -> 1.0. */
Chris@0 107 void outputLevelsChanged(float left, float right);
Chris@0 108
Chris@8 109 /** Emitted when the selection has changed. */
Chris@8 110 void selectionChanged();
Chris@8 111
Chris@9 112 /** Emitted when the in-progress (rubberbanding) selection has changed. */
Chris@9 113 void inProgressSelectionChanged();
Chris@9 114
Chris@8 115 /** Emitted when the tool mode has been changed. */
Chris@8 116 void toolModeChanged();
Chris@8 117
Chris@9 118 /** Emitted when the play loop mode has been changed. */
Chris@9 119 void playLoopModeChanged();
Chris@9 120
Chris@9 121 /** Emitted when the play selection mode has been changed. */
Chris@9 122 void playSelectionModeChanged();
Chris@9 123
Chris@0 124 protected slots:
Chris@0 125 void checkPlayStatus();
Chris@10 126 void playStatusChanged(bool playing);
Chris@0 127 void considerSeek(void *, unsigned long, bool);
Chris@0 128 void considerZoomChange(void *, unsigned long, bool);
Chris@0 129
Chris@0 130 protected:
Chris@0 131 AudioPlaySource *m_playSource;
Chris@0 132 unsigned long m_globalCentreFrame;
Chris@0 133 unsigned long m_globalZoom;
Chris@24 134 mutable unsigned long m_playbackFrame;
Chris@42 135 size_t m_mainModelSampleRate;
Chris@0 136
Chris@0 137 float m_lastLeft;
Chris@0 138 float m_lastRight;
Chris@0 139
Chris@24 140 MultiSelection m_selections;
Chris@8 141 Selection m_inProgressSelection;
Chris@8 142 bool m_inProgressExclusive;
Chris@8 143
Chris@8 144 ToolMode m_toolMode;
Chris@8 145
Chris@9 146 bool m_playLoopMode;
Chris@9 147 bool m_playSelectionMode;
Chris@45 148
Chris@45 149 void setSelections(const MultiSelection &ms);
Chris@45 150 void signalSelectionChange();
Chris@45 151
Chris@45 152 class SetSelectionCommand : public Command
Chris@45 153 {
Chris@45 154 public:
Chris@45 155 SetSelectionCommand(ViewManager *vm, const MultiSelection &ms);
Chris@45 156 virtual ~SetSelectionCommand();
Chris@45 157 virtual void execute();
Chris@45 158 virtual void unexecute();
Chris@45 159 virtual QString getName() const;
Chris@45 160
Chris@45 161 protected:
Chris@45 162 ViewManager *m_vm;
Chris@45 163 MultiSelection m_oldSelection;
Chris@45 164 MultiSelection m_newSelection;
Chris@45 165 };
Chris@0 166 };
Chris@0 167
Chris@0 168 #endif
Chris@0 169