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 SV_VIEW_MANAGER_H
17 #define SV_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 #include "base/BaseTypes.h"
30 #include "base/ZoomLevel.h"
31 
32 #include "data/model/Model.h"
33 
34 class AudioPlaySource;
35 class AudioRecordTarget;
36 class Model;
37 
39 
45 
52 
59 
65 };
66 
67 class View;
68 
78 class ViewManager : public ViewManagerBase
79 {
80  Q_OBJECT
81 
82 public:
83  ViewManager();
84  virtual ~ViewManager();
85 
86  void setAudioPlaySource(AudioPlaySource *source) override;
87  void setAudioRecordTarget(AudioRecordTarget *target) override;
88 
89  bool isPlaying() const;
90  bool isRecording() const;
91 
92  sv_frame_t getGlobalCentreFrame() const; // the set method is a slot
93  ZoomLevel getGlobalZoom() const;
94 
95  sv_frame_t getPlaybackFrame() const; // the set method is a slot
96 
97  // Only meaningful in solo mode, and used for optional alignment feature
98  ModelId getPlaybackModel() const;
99  void setPlaybackModel(ModelId);
100 
101  sv_frame_t alignPlaybackFrameToReference(sv_frame_t) const override;
102  sv_frame_t alignReferenceToPlaybackFrame(sv_frame_t) const override;
103 
104  bool haveInProgressSelection() const;
105  const Selection &getInProgressSelection(bool &exclusive) const;
106  void setInProgressSelection(const Selection &selection, bool exclusive);
108 
109  const MultiSelection &getSelection() const override;
110 
111  const MultiSelection::SelectionList &getSelections() const override;
112  void setSelection(const Selection &selection);
113  void addSelection(const Selection &selection);
114  void removeSelection(const Selection &selection);
115  void clearSelections();
116  sv_frame_t constrainFrameToSelection(sv_frame_t frame) const override;
117 
123  void addSelectionQuietly(const Selection &selection);
124 
131  Selection getContainingSelection(sv_frame_t frame, bool defaultToFollowing) const override;
132 
133  Clipboard &getClipboard() { return m_clipboard; }
134 
135  enum ToolMode {
142  NoteEditMode //GF: Tonioni: this tool mode will be context sensitive.
143  };
144  ToolMode getToolMode() const { return m_toolMode; }
145  void setToolMode(ToolMode mode);
146 
148  void setToolModeFor(const View *v, ToolMode mode);
150  ToolMode getToolModeFor(const View *v) const;
152  void clearToolModeOverrides();
153 
154  bool getPlayLoopMode() const override { return m_playLoopMode; }
155  void setPlayLoopMode(bool on);
156 
157  bool getPlaySelectionMode() const override { return m_playSelectionMode; }
158  void setPlaySelectionMode(bool on);
159 
160  bool getPlaySoloMode() const override { return m_playSoloMode; }
161  void setPlaySoloMode(bool on);
162 
163  bool getAlignMode() const override { return m_alignMode; }
164  void setAlignMode(bool on);
165 
167  void setShowWorkTitle(bool show) { m_showWorkTitle = show; }
168  void setShowDuration(bool show) { m_showDuration = show; }
169 
176  sv_samplerate_t getPlaybackSampleRate() const;
177 
183  sv_samplerate_t getDeviceSampleRate() const;
184 
190  sv_samplerate_t getMainModelSampleRate() const { return m_mainModelSampleRate; }
191 
192  void setMainModelSampleRate(sv_samplerate_t sr) { m_mainModelSampleRate = sr; }
193 
199  static int scalePixelSize(int pixels);
200 
201  enum OverlayMode {
206  };
207  void setOverlayMode(OverlayMode mode);
209 
210  void setShowCentreLine(bool show);
211  bool shouldShowCentreLine() const { return m_showCentreLine; }
212 
213  bool shouldShowDuration() const {
215  }
216  bool shouldShowFrameCount() const {
218  }
219  bool shouldShowVerticalScale() const {
220  return m_overlayMode != NoOverlays;
221  }
223  return m_overlayMode == AllOverlays;
224  }
225  bool shouldShowHorizontalValueScale() const { // for layers where x != time
226  return m_overlayMode != NoOverlays;
227  }
230  }
231  bool shouldShowLayerNames() const {
232  return m_overlayMode == AllOverlays;
233  }
234  bool shouldShowScaleGuides() const {
235  return m_overlayMode != NoOverlays;
236  }
237  bool shouldShowWorkTitle() const {
238  return m_showWorkTitle;
239  }
242  }
243  bool shouldShowFeatureLabels() const {
245  }
246 
247  void setZoomWheelsEnabled(bool enable);
248  bool getZoomWheelsEnabled() const { return m_zoomWheelsEnabled; }
249 
263  void setOpportunisticEditingEnabled(bool enable);
266  }
267 
268  void setGlobalDarkBackground(bool dark);
269  bool getGlobalDarkBackground() const;
270 
271 signals:
273  void globalCentreFrameChanged(sv_frame_t frame);
274 
276  void viewCentreFrameChanged(View *v, sv_frame_t frame);
277 
279  void viewZoomLevelChanged(View *v, ZoomLevel zoom, bool locked);
280 
282  void playbackFrameChanged(sv_frame_t frame);
283 
285  void monitoringLevelsChanged(float left, float right);
286 
288  void selectionChanged();
289 
293  void selectionChangedByUser();
294 
297 
299  void toolModeChanged();
300 
302  void playLoopModeChanged();
303  void playLoopModeChanged(bool);
304 
307  void playSelectionModeChanged(bool);
308 
310  void playSoloModeChanged();
311  void playSoloModeChanged(bool);
312 
314  void alignModeChanged();
315  void alignModeChanged(bool);
316 
318  void overlayModeChanged();
319 
321  void showCentreLineChanged();
322 
325 
328 
330  void activity(QString);
331 
332 public slots:
333  void viewCentreFrameChanged(sv_frame_t, bool, PlaybackFollowMode);
334  void viewZoomLevelChanged(ZoomLevel, bool);
335  void setGlobalCentreFrame(sv_frame_t);
336  void setPlaybackFrame(sv_frame_t);
337  void playStatusChanged(bool playing);
338  void recordStatusChanged(bool recording);
339 
340 protected slots:
341  void checkPlayStatus();
342  void seek(sv_frame_t);
344 
345 protected:
346  AudioPlaySource *m_playSource;
347  AudioRecordTarget *m_recordTarget;
348 
350  ZoomLevel m_globalZoom;
351  mutable sv_frame_t m_playbackFrame;
353  sv_samplerate_t m_mainModelSampleRate;
354 
355  float m_lastLeft;
356  float m_lastRight;
357 
358  MultiSelection m_selections;
361 
362  Clipboard m_clipboard;
363 
365  std::map<const View *, ToolMode> m_toolModeOverrides;
366 
371 
372  void setSelections(const MultiSelection &ms, bool quietly = false);
373  void signalSelectionChange();
374 
375  class SetSelectionCommand : public Command
376  {
377  public:
378  SetSelectionCommand(ViewManager *vm, const MultiSelection &ms);
379  virtual ~SetSelectionCommand();
380  void execute() override;
381  void unexecute() override;
382  QString getName() const override;
383 
384  protected:
386  MultiSelection m_oldSelection;
387  MultiSelection m_newSelection;
388  };
389 
397 
398  QPalette m_lightPalette;
399  QPalette m_darkPalette;
400 };
401 
402 #endif
403 
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...
bool haveInProgressSelection() const
void playSelectionModeChanged()
Emitted when the play selection mode has been changed.
void setSelections(const MultiSelection &ms, bool quietly=false)
ModelId m_playbackModel
Definition: ViewManager.h:352
ToolMode m_toolMode
Definition: ViewManager.h:364
View scrolls continuously during playback, keeping the playback position at the centre.
Definition: ViewManager.h:44
void checkPlayStatus()
void toolModeChanged()
Emitted when the tool mode has been changed.
bool getGlobalDarkBackground() const
SetSelectionCommand(ViewManager *vm, const MultiSelection &ms)
bool shouldShowWorkTitle() const
Definition: ViewManager.h:237
void showCentreLineChanged()
Emitted when the centre line visibility has been changed.
bool getPlayLoopMode() const override
Definition: ViewManager.h:154
Selection getContainingSelection(sv_frame_t frame, bool defaultToFollowing) const override
Return the selection that contains a given frame.
void setMainModelSampleRate(sv_samplerate_t sr)
Definition: ViewManager.h:192
static int scalePixelSize(int pixels)
Take a "design pixel" size and scale it for the actual display.
bool getAlignMode() const override
Definition: ViewManager.h:163
void viewCentreFrameChanged(View *v, sv_frame_t frame)
Emitted when user scrolls a view, but doesn&#39;t affect global centre.
void setGlobalDarkBackground(bool dark)
bool m_alignMode
Definition: ViewManager.h:370
sv_frame_t getGlobalCentreFrame() const
sv_frame_t alignPlaybackFrameToReference(sv_frame_t) const override
sv_samplerate_t m_mainModelSampleRate
Definition: ViewManager.h:353
void viewZoomLevelChanged(View *v, ZoomLevel zoom, bool locked)
Emitted when a view zooms.
bool shouldIlluminateLocalFeatures() const
Definition: ViewManager.h:240
const MultiSelection & getSelection() const override
void setAudioPlaySource(AudioPlaySource *source) override
bool shouldShowFeatureLabels() const
Definition: ViewManager.h:243
void setPlaybackModel(ModelId)
sv_samplerate_t getMainModelSampleRate() const
The sample rate of the current main model.
Definition: ViewManager.h:190
const Selection & getInProgressSelection(bool &exclusive) const
void playStatusChanged(bool playing)
void inProgressSelectionChanged()
Emitted when the in-progress (rubberbanding) selection has changed.
sv_frame_t m_globalCentreFrame
Definition: ViewManager.h:349
void setIlluminateLocalFeatures(bool i)
Definition: ViewManager.h:166
void removeSelection(const Selection &selection)
void addSelection(const Selection &selection)
sv_frame_t getPlaybackFrame() const
void clearSelections()
bool getPlaySelectionMode() const override
Definition: ViewManager.h:157
ToolMode getToolMode() const
Definition: ViewManager.h:144
AudioRecordTarget * m_recordTarget
Definition: ViewManager.h:347
sv_frame_t alignReferenceToPlaybackFrame(sv_frame_t) const override
void signalSelectionChange()
sv_samplerate_t getPlaybackSampleRate() const
The sample rate that is used for playback.
bool m_illuminateLocalFeatures
Definition: ViewManager.h:394
void setPlaySelectionMode(bool on)
ToolMode getToolModeFor(const View *v) const
Return override mode if it exists for this view or global mode otherwise.
sv_samplerate_t getDeviceSampleRate() const
The sample rate of the audio output device.
Selection m_inProgressSelection
Definition: ViewManager.h:359
void setOpportunisticEditingEnabled(bool enable)
Enable or disable opportunistic editing.
View follows playback page-by-page, but dragging the view relocates playback to the centre frame...
Definition: ViewManager.h:51
ZoomLevel getGlobalZoom() const
void overlayModeChanged()
Emitted when the overlay mode has been changed.
void monitoringLevelsChanged(float left, float right)
Emitted when the output or record levels change.
void setShowDuration(bool show)
Definition: ViewManager.h:168
void setInProgressSelection(const Selection &selection, bool exclusive)
void recordStatusChanged(bool recording)
void setPlaybackFrame(sv_frame_t)
void setPlaySoloMode(bool on)
void selectionChanged()
Emitted whenever the selection has changed.
void setOverlayMode(OverlayMode mode)
PlaybackFollowMode
Definition: ViewManager.h:38
bool shouldShowFrameCount() const
Definition: ViewManager.h:216
View is detached from playback.
Definition: ViewManager.h:64
bool isRecording() const
ZoomLevel m_globalZoom
Definition: ViewManager.h:350
bool shouldShowHorizontalValueScale() const
Definition: ViewManager.h:225
void addSelectionQuietly(const Selection &selection)
Adding a selection normally emits the selectionChangedByUser signal.
bool m_inProgressExclusive
Definition: ViewManager.h:360
QString getName() const override
void setZoomWheelsEnabled(bool enable)
void alignModeChanged()
Emitted when the alignment mode has been changed.
bool shouldShowVerticalColourScale() const
Definition: ViewManager.h:222
QPalette m_lightPalette
Definition: ViewManager.h:398
void setShowCentreLine(bool show)
sv_frame_t constrainFrameToSelection(sv_frame_t frame) const override
bool getPlaySoloMode() const override
Definition: ViewManager.h:160
MultiSelection m_selections
Definition: ViewManager.h:358
bool shouldShowVerticalScale() const
Definition: ViewManager.h:219
void playSoloModeChanged()
Emitted when the play solo mode has been changed.
OverlayMode m_overlayMode
Definition: ViewManager.h:390
void opportunisticEditingEnabledChanged()
Emitted when editing-enabled has been toggled.
void playbackFrameChanged(sv_frame_t frame)
Emitted when the playback frame changes.
AudioPlaySource * m_playSource
!! void considerZoomChange(void *, int, bool);
Definition: ViewManager.h:346
bool shouldShowCentreLine() const
Definition: ViewManager.h:211
void setAudioRecordTarget(AudioRecordTarget *target) override
void clearInProgressSelection()
ModelId getPlaybackModel() const
bool shouldShowDuration() const
Definition: ViewManager.h:213
bool shouldShowLayerNames() const
Definition: ViewManager.h:231
void setSelection(const Selection &selection)
bool m_opportunisticEditingEnabled
Definition: ViewManager.h:392
View is the base class of widgets that display one or more overlaid views of data against a horizonta...
Definition: View.h:55
bool m_showDuration
Definition: ViewManager.h:396
void setToolModeFor(const View *v, ToolMode mode)
Override the tool mode for a specific view.
Clipboard & getClipboard()
Definition: ViewManager.h:133
float m_lastRight
Definition: ViewManager.h:356
The ViewManager manages properties that may need to be synchronised between separate Views...
Definition: ViewManager.h:78
bool m_playSelectionMode
Definition: ViewManager.h:368
bool shouldShowScaleGuides() const
Definition: ViewManager.h:234
Clipboard m_clipboard
Definition: ViewManager.h:362
QPalette m_darkPalette
Definition: ViewManager.h:399
const MultiSelection::SelectionList & getSelections() const override
bool shouldShowSelectionExtents() const
Definition: ViewManager.h:228
OverlayMode getOverlayMode() const
Definition: ViewManager.h:208
void seek(sv_frame_t)
void globalCentreFrameChanged(sv_frame_t frame)
Emitted when user causes the global centre frame to change.
void setPlayLoopMode(bool on)
bool m_showCentreLine
Definition: ViewManager.h:393
void setShowWorkTitle(bool show)
Definition: ViewManager.h:167
bool getZoomWheelsEnabled() const
Definition: ViewManager.h:248
bool m_showWorkTitle
Definition: ViewManager.h:395
bool m_playLoopMode
Definition: ViewManager.h:367
View follows playback page-by-page, and the play head is moved (by the user) separately from dragging...
Definition: ViewManager.h:58
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.
virtual ~ViewManager()
bool getOpportunisticEditingEnabled() const
Definition: ViewManager.h:264
bool isPlaying() const
void clearToolModeOverrides()
Clear all current view-specific overrides.
bool m_playSoloMode
Definition: ViewManager.h:369
float m_lastLeft
Definition: ViewManager.h:355
bool m_zoomWheelsEnabled
Definition: ViewManager.h:391
std::map< const View *, ToolMode > m_toolModeOverrides
Definition: ViewManager.h:365
void setToolMode(ToolMode mode)
void setGlobalCentreFrame(sv_frame_t)
sv_frame_t m_playbackFrame
Definition: ViewManager.h:351