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@65
|
96 enum OverlayMode {
|
Chris@65
|
97 NoOverlays,
|
Chris@65
|
98 BasicOverlays,
|
Chris@65
|
99 AllOverlays
|
Chris@65
|
100 };
|
Chris@65
|
101 void setOverlayMode(OverlayMode mode);
|
Chris@65
|
102 OverlayMode getOverlayMode() const { return m_overlayMode; }
|
Chris@65
|
103
|
Chris@0
|
104 signals:
|
Chris@0
|
105 /** Emitted when a widget pans. The originator identifies the widget. */
|
Chris@0
|
106 void centreFrameChanged(void *originator, unsigned long frame, bool locked);
|
Chris@0
|
107
|
Chris@0
|
108 /** Emitted when a widget zooms. The originator identifies the widget. */
|
Chris@0
|
109 void zoomLevelChanged(void *originator, unsigned long zoom, bool locked);
|
Chris@0
|
110
|
Chris@0
|
111 /** Emitted when the playback frame changes. */
|
Chris@0
|
112 void playbackFrameChanged(unsigned long frame);
|
Chris@0
|
113
|
Chris@0
|
114 /** Emitted when the output levels change. Values in range 0.0 -> 1.0. */
|
Chris@0
|
115 void outputLevelsChanged(float left, float right);
|
Chris@0
|
116
|
Chris@8
|
117 /** Emitted when the selection has changed. */
|
Chris@8
|
118 void selectionChanged();
|
Chris@8
|
119
|
Chris@9
|
120 /** Emitted when the in-progress (rubberbanding) selection has changed. */
|
Chris@9
|
121 void inProgressSelectionChanged();
|
Chris@9
|
122
|
Chris@8
|
123 /** Emitted when the tool mode has been changed. */
|
Chris@8
|
124 void toolModeChanged();
|
Chris@8
|
125
|
Chris@9
|
126 /** Emitted when the play loop mode has been changed. */
|
Chris@9
|
127 void playLoopModeChanged();
|
Chris@9
|
128
|
Chris@9
|
129 /** Emitted when the play selection mode has been changed. */
|
Chris@9
|
130 void playSelectionModeChanged();
|
Chris@9
|
131
|
Chris@65
|
132 /** Emitted when the overlay mode has been changed. */
|
Chris@65
|
133 void overlayModeChanged();
|
Chris@65
|
134
|
Chris@0
|
135 protected slots:
|
Chris@0
|
136 void checkPlayStatus();
|
Chris@10
|
137 void playStatusChanged(bool playing);
|
Chris@0
|
138 void considerSeek(void *, unsigned long, bool);
|
Chris@0
|
139 void considerZoomChange(void *, unsigned long, bool);
|
Chris@0
|
140
|
Chris@0
|
141 protected:
|
Chris@0
|
142 AudioPlaySource *m_playSource;
|
Chris@0
|
143 unsigned long m_globalCentreFrame;
|
Chris@0
|
144 unsigned long m_globalZoom;
|
Chris@24
|
145 mutable unsigned long m_playbackFrame;
|
Chris@42
|
146 size_t m_mainModelSampleRate;
|
Chris@0
|
147
|
Chris@0
|
148 float m_lastLeft;
|
Chris@0
|
149 float m_lastRight;
|
Chris@0
|
150
|
Chris@24
|
151 MultiSelection m_selections;
|
Chris@8
|
152 Selection m_inProgressSelection;
|
Chris@8
|
153 bool m_inProgressExclusive;
|
Chris@8
|
154
|
Chris@8
|
155 ToolMode m_toolMode;
|
Chris@8
|
156
|
Chris@9
|
157 bool m_playLoopMode;
|
Chris@9
|
158 bool m_playSelectionMode;
|
Chris@45
|
159
|
Chris@45
|
160 void setSelections(const MultiSelection &ms);
|
Chris@45
|
161 void signalSelectionChange();
|
Chris@45
|
162
|
Chris@45
|
163 class SetSelectionCommand : public Command
|
Chris@45
|
164 {
|
Chris@45
|
165 public:
|
Chris@45
|
166 SetSelectionCommand(ViewManager *vm, const MultiSelection &ms);
|
Chris@45
|
167 virtual ~SetSelectionCommand();
|
Chris@45
|
168 virtual void execute();
|
Chris@45
|
169 virtual void unexecute();
|
Chris@45
|
170 virtual QString getName() const;
|
Chris@45
|
171
|
Chris@45
|
172 protected:
|
Chris@45
|
173 ViewManager *m_vm;
|
Chris@45
|
174 MultiSelection m_oldSelection;
|
Chris@45
|
175 MultiSelection m_newSelection;
|
Chris@45
|
176 };
|
Chris@65
|
177
|
Chris@65
|
178 OverlayMode m_overlayMode;
|
Chris@0
|
179 };
|
Chris@0
|
180
|
Chris@0
|
181 #endif
|
Chris@0
|
182
|