annotate view/ViewManager.h @ 1406:a18e78b9c78b fix-static-analysis

Use override throughout
author Chris Cannam
date Mon, 26 Nov 2018 13:52:27 +0000
parents 646e713a4632
children de41a11cabc2
rev   line source
Chris@127 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@127 2
Chris@127 3 /*
Chris@127 4 Sonic Visualiser
Chris@127 5 An audio file viewer and annotation editor.
Chris@127 6 Centre for Digital Music, Queen Mary, University of London.
Chris@182 7 This file copyright 2006 Chris Cannam and QMUL.
Chris@127 8
Chris@127 9 This program is free software; you can redistribute it and/or
Chris@127 10 modify it under the terms of the GNU General Public License as
Chris@127 11 published by the Free Software Foundation; either version 2 of the
Chris@127 12 License, or (at your option) any later version. See the file
Chris@127 13 COPYING included with this distribution for more information.
Chris@127 14 */
Chris@127 15
Chris@1270 16 #ifndef SV_VIEW_MANAGER_H
Chris@1270 17 #define SV_VIEW_MANAGER_H
Chris@127 18
Chris@127 19 #include <QObject>
Chris@127 20 #include <QTimer>
Chris@292 21 #include <QPalette>
Chris@127 22
Chris@127 23 #include <map>
Chris@127 24
Chris@376 25 #include "base/ViewManagerBase.h"
Chris@128 26 #include "base/Selection.h"
Chris@128 27 #include "base/Command.h"
Chris@128 28 #include "base/Clipboard.h"
Chris@902 29 #include "base/BaseTypes.h"
Chris@1327 30 #include "base/ZoomLevel.h"
Chris@127 31
Chris@127 32 class AudioPlaySource;
Chris@1210 33 class AudioRecordTarget;
Chris@127 34 class Model;
Chris@127 35
Chris@211 36 enum PlaybackFollowMode {
Chris@815 37
Chris@815 38 /**
Chris@815 39 * View scrolls continuously during playback, keeping the playback
Chris@815 40 * position at the centre.
Chris@815 41 */
Chris@211 42 PlaybackScrollContinuous,
Chris@815 43
Chris@815 44 /**
Chris@815 45 * View follows playback page-by-page, but dragging the view
Chris@815 46 * relocates playback to the centre frame. This is the classic
Chris@815 47 * Sonic Visualiser behaviour.
Chris@815 48 */
Chris@815 49 PlaybackScrollPageWithCentre,
Chris@815 50
Chris@815 51 /**
Chris@815 52 * View follows playback page-by-page, and the play head is moved
Chris@815 53 * (by the user) separately from dragging the view. This is
Chris@815 54 * roughly the behaviour of a typical DAW or audio editor.
Chris@815 55 */
Chris@211 56 PlaybackScrollPage,
Chris@815 57
Chris@815 58 /**
Chris@815 59 * View is detached from playback. It doesn't follow playback, and
Chris@815 60 * dragging the view does not affect the play head.
Chris@815 61 */
Chris@211 62 PlaybackIgnore
Chris@211 63 };
Chris@211 64
Chris@211 65 class View;
Chris@211 66
Chris@127 67 /**
Chris@127 68 * The ViewManager manages properties that may need to be synchronised
Chris@127 69 * between separate Views. For example, it handles signals associated
Chris@127 70 * with changes to the global pan and zoom, and it handles selections.
Chris@127 71 *
Chris@127 72 * Views should be implemented in such a way as to work
Chris@127 73 * correctly whether they are supplied with a ViewManager or not.
Chris@127 74 */
Chris@127 75
Chris@376 76 class ViewManager : public ViewManagerBase
Chris@127 77 {
Chris@127 78 Q_OBJECT
Chris@127 79
Chris@127 80 public:
Chris@127 81 ViewManager();
Chris@127 82 virtual ~ViewManager();
Chris@127 83
Chris@1406 84 void setAudioPlaySource(AudioPlaySource *source) override;
Chris@1406 85 void setAudioRecordTarget(AudioRecordTarget *target) override;
Chris@127 86
Chris@127 87 bool isPlaying() const;
Chris@1210 88 bool isRecording() const;
Chris@127 89
Chris@902 90 sv_frame_t getGlobalCentreFrame() const; // the set method is a slot
Chris@1327 91 ZoomLevel getGlobalZoom() const;
Chris@127 92
Chris@902 93 sv_frame_t getPlaybackFrame() const; // the set method is a slot
Chris@127 94
Chris@301 95 // Only meaningful in solo mode, and used for optional alignment feature
Chris@301 96 Model *getPlaybackModel() const;
Chris@301 97 void setPlaybackModel(Model *);
Chris@301 98
Chris@1406 99 sv_frame_t alignPlaybackFrameToReference(sv_frame_t) const override;
Chris@1406 100 sv_frame_t alignReferenceToPlaybackFrame(sv_frame_t) const override;
Chris@333 101
Chris@127 102 bool haveInProgressSelection() const;
Chris@127 103 const Selection &getInProgressSelection(bool &exclusive) const;
Chris@127 104 void setInProgressSelection(const Selection &selection, bool exclusive);
Chris@127 105 void clearInProgressSelection();
Chris@127 106
Chris@1406 107 const MultiSelection &getSelection() const override;
Chris@127 108
Chris@1406 109 const MultiSelection::SelectionList &getSelections() const override;
Chris@127 110 void setSelection(const Selection &selection);
Chris@127 111 void addSelection(const Selection &selection);
Chris@127 112 void removeSelection(const Selection &selection);
Chris@127 113 void clearSelections();
Chris@1406 114 sv_frame_t constrainFrameToSelection(sv_frame_t frame) const override;
Chris@127 115
Chris@127 116 /**
Chris@762 117 * Adding a selection normally emits the selectionChangedByUser
Chris@762 118 * signal. Call this to add a selection without emitting that signal.
Chris@762 119 * This is used in session file load, for example.
Chris@762 120 */
Chris@762 121 void addSelectionQuietly(const Selection &selection);
Chris@762 122
Chris@762 123 /**
Chris@127 124 * Return the selection that contains a given frame.
Chris@127 125 * If defaultToFollowing is true, and if the frame is not in a
Chris@127 126 * selected area, return the next selection after the given frame.
Chris@127 127 * Return the empty selection if no appropriate selection is found.
Chris@127 128 */
Chris@1406 129 Selection getContainingSelection(sv_frame_t frame, bool defaultToFollowing) const override;
Chris@127 130
Chris@127 131 Clipboard &getClipboard() { return m_clipboard; }
Chris@127 132
Chris@127 133 enum ToolMode {
Chris@1266 134 NavigateMode,
Chris@1266 135 SelectMode,
Chris@711 136 EditMode,
Chris@1266 137 DrawMode,
Chris@1266 138 EraseMode,
Chris@1266 139 MeasureMode,
Chris@1266 140 NoteEditMode //GF: Tonioni: this tool mode will be context sensitive.
Chris@127 141 };
Chris@127 142 ToolMode getToolMode() const { return m_toolMode; }
Chris@127 143 void setToolMode(ToolMode mode);
Chris@127 144
Chris@711 145 /// Override the tool mode for a specific view
Chris@711 146 void setToolModeFor(const View *v, ToolMode mode);
Chris@711 147 /// Return override mode if it exists for this view or global mode otherwise
Chris@711 148 ToolMode getToolModeFor(const View *v) const;
Chris@711 149 /// Clear all current view-specific overrides
Chris@711 150 void clearToolModeOverrides();
Chris@711 151
Chris@1406 152 bool getPlayLoopMode() const override { return m_playLoopMode; }
Chris@127 153 void setPlayLoopMode(bool on);
Chris@127 154
Chris@1406 155 bool getPlaySelectionMode() const override { return m_playSelectionMode; }
Chris@127 156 void setPlaySelectionMode(bool on);
Chris@127 157
Chris@1406 158 bool getPlaySoloMode() const override { return m_playSoloMode; }
Chris@301 159 void setPlaySoloMode(bool on);
Chris@301 160
Chris@1406 161 bool getAlignMode() const override { return m_alignMode; }
Chris@314 162 void setAlignMode(bool on);
Chris@314 163
Chris@326 164 void setIlluminateLocalFeatures(bool i) { m_illuminateLocalFeatures = i; }
Chris@326 165 void setShowWorkTitle(bool show) { m_showWorkTitle = show; }
matthiasm@822 166 void setShowDuration(bool show) { m_showDuration = show; }
Chris@326 167
Chris@224 168 /**
Chris@224 169 * The sample rate that is used for playback. This is usually the
Chris@224 170 * rate of the main model, but not always. Models whose rates
Chris@224 171 * differ from this will play back at the wrong speed -- there is
Chris@224 172 * no per-model resampler.
Chris@224 173 */
Chris@902 174 sv_samplerate_t getPlaybackSampleRate() const;
Chris@224 175
Chris@224 176 /**
Chris@224 177 * The sample rate of the audio output device. If the playback
Chris@224 178 * sample rate differs from this, everything will be resampled at
Chris@1181 179 * the output stage (but not before).
Chris@224 180 */
Chris@1181 181 sv_samplerate_t getDeviceSampleRate() const;
Chris@224 182
Chris@224 183 /**
Chris@224 184 * The sample rate of the current main model. This may in theory
Chris@224 185 * differ from the playback sample rate, in which case even the
Chris@224 186 * main model will play at the wrong speed.
Chris@224 187 */
Chris@902 188 sv_samplerate_t getMainModelSampleRate() const { return m_mainModelSampleRate; }
Chris@224 189
Chris@902 190 void setMainModelSampleRate(sv_samplerate_t sr) { m_mainModelSampleRate = sr; }
Chris@127 191
Chris@894 192 /**
Chris@894 193 * Take a "design pixel" size and scale it for the actual
Chris@894 194 * display. This is relevant to hi-dpi systems that do not do
Chris@894 195 * pixel doubling (i.e. Windows and Linux rather than OS/X).
Chris@894 196 */
Chris@1270 197 static int scalePixelSize(int pixels);
Chris@894 198
Chris@127 199 enum OverlayMode {
Chris@127 200 NoOverlays,
Chris@741 201 GlobalOverlays,
Chris@741 202 StandardOverlays,
Chris@127 203 AllOverlays
Chris@127 204 };
Chris@127 205 void setOverlayMode(OverlayMode mode);
Chris@127 206 OverlayMode getOverlayMode() const { return m_overlayMode; }
Chris@127 207
Chris@607 208 void setShowCentreLine(bool show);
Chris@607 209 bool shouldShowCentreLine() const { return m_showCentreLine; }
Chris@607 210
Chris@607 211 bool shouldShowDuration() const {
matthiasm@822 212 return m_overlayMode != NoOverlays && m_showDuration;
Chris@189 213 }
Chris@189 214 bool shouldShowFrameCount() const {
Chris@607 215 return m_showCentreLine && shouldShowDuration();
Chris@607 216 }
Chris@607 217 bool shouldShowVerticalScale() const {
Chris@189 218 return m_overlayMode != NoOverlays;
Chris@189 219 }
Chris@607 220 bool shouldShowVerticalColourScale() const {
Chris@607 221 return m_overlayMode == AllOverlays;
Chris@189 222 }
Chris@1281 223 bool shouldShowHorizontalValueScale() const { // for layers where x != time
Chris@1281 224 return m_overlayMode != NoOverlays;
Chris@1281 225 }
Chris@189 226 bool shouldShowSelectionExtents() const {
Chris@741 227 return m_overlayMode != NoOverlays && m_overlayMode != GlobalOverlays;
Chris@189 228 }
Chris@189 229 bool shouldShowLayerNames() const {
Chris@189 230 return m_overlayMode == AllOverlays;
Chris@189 231 }
Chris@195 232 bool shouldShowScaleGuides() const {
Chris@195 233 return m_overlayMode != NoOverlays;
Chris@195 234 }
Chris@326 235 bool shouldShowWorkTitle() const {
Chris@326 236 return m_showWorkTitle;
Chris@326 237 }
Chris@326 238 bool shouldIlluminateLocalFeatures() const {
Chris@326 239 return m_illuminateLocalFeatures;
Chris@326 240 }
Chris@741 241 bool shouldShowFeatureLabels() const {
Chris@741 242 return m_overlayMode != NoOverlays && m_overlayMode != GlobalOverlays;
Chris@741 243 }
Chris@189 244
Chris@133 245 void setZoomWheelsEnabled(bool enable);
Chris@133 246 bool getZoomWheelsEnabled() const { return m_zoomWheelsEnabled; }
Chris@133 247
Chris@292 248 void setGlobalDarkBackground(bool dark);
Chris@292 249 bool getGlobalDarkBackground() const;
Chris@292 250
Chris@127 251 signals:
Chris@211 252 /** Emitted when user causes the global centre frame to change. */
Chris@902 253 void globalCentreFrameChanged(sv_frame_t frame);
Chris@127 254
Chris@211 255 /** Emitted when user scrolls a view, but doesn't affect global centre. */
Chris@902 256 void viewCentreFrameChanged(View *v, sv_frame_t frame);
Chris@211 257
Chris@211 258 /** Emitted when a view zooms. */
Chris@1327 259 void viewZoomLevelChanged(View *v, ZoomLevel zoom, bool locked);
Chris@133 260
Chris@127 261 /** Emitted when the playback frame changes. */
Chris@902 262 void playbackFrameChanged(sv_frame_t frame);
Chris@127 263
Chris@1210 264 /** Emitted when the output or record levels change. Values in range 0.0 -> 1.0. */
Chris@1210 265 void monitoringLevelsChanged(float left, float right);
Chris@127 266
Chris@731 267 /** Emitted whenever the selection has changed. */
Chris@127 268 void selectionChanged();
Chris@127 269
Chris@731 270 /** Emitted when the selection has been changed through an
Chris@731 271 * explicit selection-editing action. *Not* emitted when the
Chris@731 272 * selection has been changed through undo or redo. */
Chris@731 273 void selectionChangedByUser();
Chris@731 274
Chris@127 275 /** Emitted when the in-progress (rubberbanding) selection has changed. */
Chris@127 276 void inProgressSelectionChanged();
Chris@127 277
Chris@127 278 /** Emitted when the tool mode has been changed. */
Chris@127 279 void toolModeChanged();
Chris@127 280
Chris@127 281 /** Emitted when the play loop mode has been changed. */
Chris@127 282 void playLoopModeChanged();
Chris@177 283 void playLoopModeChanged(bool);
Chris@127 284
Chris@127 285 /** Emitted when the play selection mode has been changed. */
Chris@127 286 void playSelectionModeChanged();
Chris@177 287 void playSelectionModeChanged(bool);
Chris@127 288
Chris@301 289 /** Emitted when the play solo mode has been changed. */
Chris@301 290 void playSoloModeChanged();
Chris@301 291 void playSoloModeChanged(bool);
Chris@301 292
Chris@314 293 /** Emitted when the alignment mode has been changed. */
Chris@314 294 void alignModeChanged();
Chris@314 295 void alignModeChanged(bool);
Chris@314 296
Chris@127 297 /** Emitted when the overlay mode has been changed. */
Chris@127 298 void overlayModeChanged();
Chris@127 299
Chris@607 300 /** Emitted when the centre line visibility has been changed. */
Chris@607 301 void showCentreLineChanged();
Chris@607 302
Chris@133 303 /** Emitted when the zoom wheels have been toggled. */
Chris@133 304 void zoomWheelsEnabledChanged();
Chris@133 305
Chris@502 306 /** Emitted when any loggable activity has occurred. */
Chris@502 307 void activity(QString);
Chris@502 308
Chris@211 309 public slots:
Chris@902 310 void viewCentreFrameChanged(sv_frame_t, bool, PlaybackFollowMode);
Chris@1327 311 void viewZoomLevelChanged(ZoomLevel, bool);
Chris@902 312 void setGlobalCentreFrame(sv_frame_t);
Chris@902 313 void setPlaybackFrame(sv_frame_t);
Chris@689 314 void playStatusChanged(bool playing);
Chris@1210 315 void recordStatusChanged(bool recording);
Chris@211 316
Chris@127 317 protected slots:
Chris@127 318 void checkPlayStatus();
Chris@902 319 void seek(sv_frame_t);
Chris@806 320 //!!! void considerZoomChange(void *, int, bool);
Chris@127 321
Chris@127 322 protected:
Chris@127 323 AudioPlaySource *m_playSource;
Chris@1210 324 AudioRecordTarget *m_recordTarget;
Chris@1210 325
Chris@902 326 sv_frame_t m_globalCentreFrame;
Chris@1327 327 ZoomLevel m_globalZoom;
Chris@902 328 mutable sv_frame_t m_playbackFrame;
Chris@301 329 Model *m_playbackModel; //!!!
Chris@902 330 sv_samplerate_t m_mainModelSampleRate;
Chris@127 331
Chris@127 332 float m_lastLeft;
Chris@127 333 float m_lastRight;
Chris@127 334
Chris@127 335 MultiSelection m_selections;
Chris@127 336 Selection m_inProgressSelection;
Chris@127 337 bool m_inProgressExclusive;
Chris@127 338
Chris@127 339 Clipboard m_clipboard;
Chris@127 340
Chris@127 341 ToolMode m_toolMode;
Chris@711 342 std::map<const View *, ToolMode> m_toolModeOverrides;
Chris@127 343
Chris@127 344 bool m_playLoopMode;
Chris@127 345 bool m_playSelectionMode;
Chris@301 346 bool m_playSoloMode;
Chris@314 347 bool m_alignMode;
Chris@127 348
Chris@762 349 void setSelections(const MultiSelection &ms, bool quietly = false);
Chris@127 350 void signalSelectionChange();
Chris@127 351
Chris@127 352 class SetSelectionCommand : public Command
Chris@127 353 {
Chris@127 354 public:
Chris@1266 355 SetSelectionCommand(ViewManager *vm, const MultiSelection &ms);
Chris@1266 356 virtual ~SetSelectionCommand();
Chris@1406 357 void execute() override;
Chris@1406 358 void unexecute() override;
Chris@1406 359 QString getName() const override;
Chris@127 360
Chris@127 361 protected:
Chris@1266 362 ViewManager *m_vm;
Chris@1266 363 MultiSelection m_oldSelection;
Chris@1266 364 MultiSelection m_newSelection;
Chris@127 365 };
Chris@127 366
Chris@127 367 OverlayMode m_overlayMode;
Chris@133 368 bool m_zoomWheelsEnabled;
Chris@607 369 bool m_showCentreLine;
Chris@326 370 bool m_illuminateLocalFeatures;
Chris@326 371 bool m_showWorkTitle;
matthiasm@822 372 bool m_showDuration;
Chris@292 373
Chris@292 374 QPalette m_lightPalette;
Chris@292 375 QPalette m_darkPalette;
Chris@127 376 };
Chris@127 377
Chris@127 378 #endif
Chris@127 379