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