svgui  1.9
ViewManager.h
Go to the documentation of this file.
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
2 
3 /*
4  Sonic Visualiser
5  An audio file viewer and annotation editor.
6  Centre for Digital Music, Queen Mary, University of London.
7  This file copyright 2006 Chris Cannam and QMUL.
8 
9  This program is free software; you can redistribute it and/or
10  modify it under the terms of the GNU General Public License as
11  published by the Free Software Foundation; either version 2 of the
12  License, or (at your option) any later version. See the file
13  COPYING included with this distribution for more information.
14 */
15 
16 #ifndef _VIEW_MANAGER_H_
17 #define _VIEW_MANAGER_H_
18 
19 #include <QObject>
20 #include <QTimer>
21 #include <QPalette>
22 
23 #include <map>
24 
25 #include "base/ViewManagerBase.h"
26 #include "base/Selection.h"
27 #include "base/Command.h"
28 #include "base/Clipboard.h"
29 
30 class AudioPlaySource;
31 class Model;
32 
34 
40 
47 
54 
60 };
61 
62 class View;
63 
73 class ViewManager : public ViewManagerBase
74 {
75  Q_OBJECT
76 
77 public:
78  ViewManager();
79  virtual ~ViewManager();
80 
81  void setAudioPlaySource(AudioPlaySource *source);
82 
83  bool isPlaying() const;
84 
85  int getGlobalCentreFrame() const; // the set method is a slot
86  int getGlobalZoom() const;
87 
88  int getPlaybackFrame() const; // the set method is a slot
89 
90  // Only meaningful in solo mode, and used for optional alignment feature
91  Model *getPlaybackModel() const;
92  void setPlaybackModel(Model *);
93 
94  int alignPlaybackFrameToReference(int) const;
95  int alignReferenceToPlaybackFrame(int) const;
96 
97  bool haveInProgressSelection() const;
98  const Selection &getInProgressSelection(bool &exclusive) const;
99  void setInProgressSelection(const Selection &selection, bool exclusive);
101 
102  const MultiSelection &getSelection() const;
103 
104  const MultiSelection::SelectionList &getSelections() const;
105  void setSelection(const Selection &selection);
106  void addSelection(const Selection &selection);
107  void removeSelection(const Selection &selection);
108  void clearSelections();
109  int constrainFrameToSelection(int frame) const;
110 
116  void addSelectionQuietly(const Selection &selection);
117 
124  Selection getContainingSelection(int frame, bool defaultToFollowing) const;
125 
126  Clipboard &getClipboard() { return m_clipboard; }
127 
128  enum ToolMode {
135  NoteEditMode //GF: Tonioni: this tool mode will be context sensitive.
136  };
137  ToolMode getToolMode() const { return m_toolMode; }
138  void setToolMode(ToolMode mode);
139 
141  void setToolModeFor(const View *v, ToolMode mode);
143  ToolMode getToolModeFor(const View *v) const;
145  void clearToolModeOverrides();
146 
147  bool getPlayLoopMode() const { return m_playLoopMode; }
148  void setPlayLoopMode(bool on);
149 
150  bool getPlaySelectionMode() const { return m_playSelectionMode; }
151  void setPlaySelectionMode(bool on);
152 
153  bool getPlaySoloMode() const { return m_playSoloMode; }
154  void setPlaySoloMode(bool on);
155 
156  bool getAlignMode() const { return m_alignMode; }
157  void setAlignMode(bool on);
158 
160  void setShowWorkTitle(bool show) { m_showWorkTitle = show; }
161  void setShowDuration(bool show) { m_showDuration = show; }
162 
169  int getPlaybackSampleRate() const;
170 
176  int getOutputSampleRate() const;
177 
184 
186 
187  enum OverlayMode {
192  };
193  void setOverlayMode(OverlayMode mode);
195 
196  void setShowCentreLine(bool show);
197  bool shouldShowCentreLine() const { return m_showCentreLine; }
198 
199  bool shouldShowDuration() const {
201  }
202  bool shouldShowFrameCount() const {
204  }
205  bool shouldShowVerticalScale() const {
206  return m_overlayMode != NoOverlays;
207  }
209  return m_overlayMode == AllOverlays;
210  }
213  }
214  bool shouldShowLayerNames() const {
215  return m_overlayMode == AllOverlays;
216  }
217  bool shouldShowScaleGuides() const {
218  return m_overlayMode != NoOverlays;
219  }
220  bool shouldShowWorkTitle() const {
221  return m_showWorkTitle;
222  }
225  }
226  bool shouldShowFeatureLabels() const {
228  }
229 
230  void setZoomWheelsEnabled(bool enable);
231  bool getZoomWheelsEnabled() const { return m_zoomWheelsEnabled; }
232 
233  void setGlobalDarkBackground(bool dark);
234  bool getGlobalDarkBackground() const;
235 
236 signals:
238  void globalCentreFrameChanged(int frame);
239 
241  void viewCentreFrameChanged(View *v, int frame);
242 
244  void viewZoomLevelChanged(View *v, int zoom, bool locked);
245 
247  void playbackFrameChanged(int frame);
248 
250  void outputLevelsChanged(float left, float right);
251 
253  void selectionChanged();
254 
258  void selectionChangedByUser();
259 
262 
264  void toolModeChanged();
265 
267  void playLoopModeChanged();
268  void playLoopModeChanged(bool);
269 
272  void playSelectionModeChanged(bool);
273 
275  void playSoloModeChanged();
276  void playSoloModeChanged(bool);
277 
279  void alignModeChanged();
280  void alignModeChanged(bool);
281 
283  void overlayModeChanged();
284 
286  void showCentreLineChanged();
287 
290 
292  void activity(QString);
293 
294 public slots:
296  void viewZoomLevelChanged(int, bool);
297  void setGlobalCentreFrame(int);
298  void setPlaybackFrame(int);
299  void playStatusChanged(bool playing);
300 
301 protected slots:
302  void checkPlayStatus();
303  void seek(int);
305 
306 protected:
307  AudioPlaySource *m_playSource;
310  mutable int m_playbackFrame;
313 
314  float m_lastLeft;
315  float m_lastRight;
316 
317  MultiSelection m_selections;
320 
321  Clipboard m_clipboard;
322 
324  std::map<const View *, ToolMode> m_toolModeOverrides;
325 
330 
331  void setSelections(const MultiSelection &ms, bool quietly = false);
332  void signalSelectionChange();
333 
334  class SetSelectionCommand : public Command
335  {
336  public:
337  SetSelectionCommand(ViewManager *vm, const MultiSelection &ms);
338  virtual ~SetSelectionCommand();
339  virtual void execute();
340  virtual void unexecute();
341  virtual QString getName() const;
342 
343  protected:
345  MultiSelection m_oldSelection;
346  MultiSelection m_newSelection;
347  };
348 
355 
356  QPalette m_lightPalette;
357  QPalette m_darkPalette;
358 };
359 
360 #endif
361 
void zoomWheelsEnabledChanged()
Emitted when the zoom wheels have been toggled.
void selectionChangedByUser()
Emitted when the selection has been changed through an explicit selection-editing action.
void playSelectionModeChanged()
Emitted when the play selection mode has been changed.
void setSelections(const MultiSelection &ms, bool quietly=false)
int getPlaybackFrame() const
int alignReferenceToPlaybackFrame(int) const
void viewCentreFrameChanged(View *v, int frame)
Emitted when user scrolls a view, but doesn't affect global centre.
bool shouldShowDuration() const
Definition: ViewManager.h:199
ToolMode getToolModeFor(const View *v) const
Return override mode if it exists for this view or global mode otherwise.
ToolMode m_toolMode
Definition: ViewManager.h:323
View scrolls continuously during playback, keeping the playback position at the centre.
Definition: ViewManager.h:39
void viewZoomLevelChanged(View *v, int zoom, bool locked)
Emitted when a view zooms.
void checkPlayStatus()
void toolModeChanged()
Emitted when the tool mode has been changed.
SetSelectionCommand(ViewManager *vm, const MultiSelection &ms)
void showCentreLineChanged()
Emitted when the centre line visibility has been changed.
int getGlobalZoom() const
bool haveInProgressSelection() const
int getMainModelSampleRate() const
The sample rate of the current main model.
Definition: ViewManager.h:183
void setGlobalDarkBackground(bool dark)
bool getPlayLoopMode() const
Definition: ViewManager.h:147
bool m_alignMode
Definition: ViewManager.h:329
ToolMode getToolMode() const
Definition: ViewManager.h:137
bool shouldShowVerticalScale() const
Definition: ViewManager.h:205
Model * getPlaybackModel() const
Model * m_playbackModel
Definition: ViewManager.h:311
int alignPlaybackFrameToReference(int) const
void setMainModelSampleRate(int sr)
Definition: ViewManager.h:185
void outputLevelsChanged(float left, float right)
Emitted when the output levels change.
void playStatusChanged(bool playing)
void inProgressSelectionChanged()
Emitted when the in-progress (rubberbanding) selection has changed.
bool shouldIlluminateLocalFeatures() const
Definition: ViewManager.h:223
bool isPlaying() const
bool shouldShowFeatureLabels() const
Definition: ViewManager.h:226
void setIlluminateLocalFeatures(bool i)
Definition: ViewManager.h:159
void removeSelection(const Selection &selection)
void addSelection(const Selection &selection)
void clearSelections()
bool shouldShowFrameCount() const
Definition: ViewManager.h:202
void seek(int)
void signalSelectionChange()
bool m_illuminateLocalFeatures
Definition: ViewManager.h:352
void setPlaySelectionMode(bool on)
virtual QString getName() const
bool shouldShowScaleGuides() const
Definition: ViewManager.h:217
Selection m_inProgressSelection
Definition: ViewManager.h:318
int m_globalCentreFrame
Definition: ViewManager.h:308
View follows playback page-by-page, but dragging the view relocates playback to the centre frame.
Definition: ViewManager.h:46
void overlayModeChanged()
Emitted when the overlay mode has been changed.
void setPlaybackFrame(int)
void globalCentreFrameChanged(int frame)
Emitted when user causes the global centre frame to change.
void setShowDuration(bool show)
Definition: ViewManager.h:161
const Selection & getInProgressSelection(bool &exclusive) const
void setInProgressSelection(const Selection &selection, bool exclusive)
void setAudioPlaySource(AudioPlaySource *source)
void setPlaySoloMode(bool on)
void selectionChanged()
Emitted whenever the selection has changed.
void setOverlayMode(OverlayMode mode)
PlaybackFollowMode
Definition: ViewManager.h:33
bool shouldShowLayerNames() const
Definition: ViewManager.h:214
View is detached from playback.
Definition: ViewManager.h:59
bool getPlaySelectionMode() const
Definition: ViewManager.h:150
void addSelectionQuietly(const Selection &selection)
Adding a selection normally emits the selectionChangedByUser signal.
bool m_inProgressExclusive
Definition: ViewManager.h:319
void playbackFrameChanged(int frame)
Emitted when the playback frame changes.
void setZoomWheelsEnabled(bool enable)
void alignModeChanged()
Emitted when the alignment mode has been changed.
bool shouldShowSelectionExtents() const
Definition: ViewManager.h:211
int getOutputSampleRate() const
The sample rate of the audio output device.
QPalette m_lightPalette
Definition: ViewManager.h:356
void setShowCentreLine(bool show)
MultiSelection m_selections
Definition: ViewManager.h:317
void playSoloModeChanged()
Emitted when the play solo mode has been changed.
bool shouldShowWorkTitle() const
Definition: ViewManager.h:220
OverlayMode m_overlayMode
Definition: ViewManager.h:349
AudioPlaySource * m_playSource
!! void considerZoomChange(void *, int, bool);
Definition: ViewManager.h:307
void setGlobalCentreFrame(int)
void clearInProgressSelection()
int constrainFrameToSelection(int frame) const
int m_playbackFrame
Definition: ViewManager.h:310
void setSelection(const Selection &selection)
View is the base class of widgets that display one or more overlaid views of data against a horizonta...
Definition: View.h:50
bool m_showDuration
Definition: ViewManager.h:354
void setToolModeFor(const View *v, ToolMode mode)
Override the tool mode for a specific view.
Clipboard & getClipboard()
Definition: ViewManager.h:126
int getPlaybackSampleRate() const
The sample rate that is used for playback.
float m_lastRight
Definition: ViewManager.h:315
The ViewManager manages properties that may need to be synchronised between separate Views.
Definition: ViewManager.h:73
bool m_playSelectionMode
Definition: ViewManager.h:327
Clipboard m_clipboard
Definition: ViewManager.h:321
QPalette m_darkPalette
Definition: ViewManager.h:357
int getGlobalCentreFrame() const
bool shouldShowCentreLine() const
Definition: ViewManager.h:197
const MultiSelection::SelectionList & getSelections() const
void setPlayLoopMode(bool on)
bool m_showCentreLine
Definition: ViewManager.h:351
void setShowWorkTitle(bool show)
Definition: ViewManager.h:160
bool m_showWorkTitle
Definition: ViewManager.h:353
bool m_playLoopMode
Definition: ViewManager.h:326
View follows playback page-by-page, and the play head is moved (by the user) separately from dragging...
Definition: ViewManager.h:53
int m_mainModelSampleRate
!!
Definition: ViewManager.h:312
void setAlignMode(bool on)
void activity(QString)
Emitted when any loggable activity has occurred.
void playLoopModeChanged()
Emitted when the play loop mode has been changed.
Selection getContainingSelection(int frame, bool defaultToFollowing) const
Return the selection that contains a given frame.
bool getAlignMode() const
Definition: ViewManager.h:156
OverlayMode getOverlayMode() const
Definition: ViewManager.h:194
virtual ~ViewManager()
int m_globalZoom
Definition: ViewManager.h:309
bool shouldShowVerticalColourScale() const
Definition: ViewManager.h:208
void setPlaybackModel(Model *)
void clearToolModeOverrides()
Clear all current view-specific overrides.
bool getPlaySoloMode() const
Definition: ViewManager.h:153
bool m_playSoloMode
Definition: ViewManager.h:328
float m_lastLeft
Definition: ViewManager.h:314
const MultiSelection & getSelection() const
bool m_zoomWheelsEnabled
Definition: ViewManager.h:350
std::map< const View *, ToolMode > m_toolModeOverrides
Definition: ViewManager.h:324
bool getZoomWheelsEnabled() const
Definition: ViewManager.h:231
void setToolMode(ToolMode mode)
bool getGlobalDarkBackground() const