annotate view/ViewManager.h @ 1473:886c1cd48f9d by-id

Further layer updates for ModelById
author Chris Cannam
date Tue, 02 Jul 2019 11:49:52 +0100
parents de41a11cabc2
children 9bf8aa2916e9
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@1468 248 /**
Chris@1468 249 * Enable or disable opportunistic editing. This allows certain
Chris@1468 250 * edits while not in edit modes - e.g. double-click on an item
Chris@1468 251 * while in navigate mode to open an edit dialog. It is enabled by
Chris@1468 252 * default, but it may be undesirable if the application is
Chris@1468 253 * intended to be "read-only".
Chris@1468 254 *
Chris@1468 255 * This setting makes no difference to behaviour when actually in
Chris@1468 256 * editing modes.
Chris@1468 257 *
Chris@1468 258 * Unlike some other options, this is considered to be
Chris@1468 259 * application-build-specific and is not restored from settings.
Chris@1468 260 */
Chris@1468 261 void setOpportunisticEditingEnabled(bool enable);
Chris@1468 262 bool getOpportunisticEditingEnabled() const {
Chris@1468 263 return m_opportunisticEditingEnabled;
Chris@1468 264 }
Chris@1468 265
Chris@292 266 void setGlobalDarkBackground(bool dark);
Chris@292 267 bool getGlobalDarkBackground() const;
Chris@292 268
Chris@127 269 signals:
Chris@211 270 /** Emitted when user causes the global centre frame to change. */
Chris@902 271 void globalCentreFrameChanged(sv_frame_t frame);
Chris@127 272
Chris@211 273 /** Emitted when user scrolls a view, but doesn't affect global centre. */
Chris@902 274 void viewCentreFrameChanged(View *v, sv_frame_t frame);
Chris@211 275
Chris@211 276 /** Emitted when a view zooms. */
Chris@1327 277 void viewZoomLevelChanged(View *v, ZoomLevel zoom, bool locked);
Chris@133 278
Chris@127 279 /** Emitted when the playback frame changes. */
Chris@902 280 void playbackFrameChanged(sv_frame_t frame);
Chris@127 281
Chris@1210 282 /** Emitted when the output or record levels change. Values in range 0.0 -> 1.0. */
Chris@1210 283 void monitoringLevelsChanged(float left, float right);
Chris@127 284
Chris@731 285 /** Emitted whenever the selection has changed. */
Chris@127 286 void selectionChanged();
Chris@127 287
Chris@731 288 /** Emitted when the selection has been changed through an
Chris@731 289 * explicit selection-editing action. *Not* emitted when the
Chris@731 290 * selection has been changed through undo or redo. */
Chris@731 291 void selectionChangedByUser();
Chris@731 292
Chris@127 293 /** Emitted when the in-progress (rubberbanding) selection has changed. */
Chris@127 294 void inProgressSelectionChanged();
Chris@127 295
Chris@127 296 /** Emitted when the tool mode has been changed. */
Chris@127 297 void toolModeChanged();
Chris@127 298
Chris@127 299 /** Emitted when the play loop mode has been changed. */
Chris@127 300 void playLoopModeChanged();
Chris@177 301 void playLoopModeChanged(bool);
Chris@127 302
Chris@127 303 /** Emitted when the play selection mode has been changed. */
Chris@127 304 void playSelectionModeChanged();
Chris@177 305 void playSelectionModeChanged(bool);
Chris@127 306
Chris@301 307 /** Emitted when the play solo mode has been changed. */
Chris@301 308 void playSoloModeChanged();
Chris@301 309 void playSoloModeChanged(bool);
Chris@301 310
Chris@314 311 /** Emitted when the alignment mode has been changed. */
Chris@314 312 void alignModeChanged();
Chris@314 313 void alignModeChanged(bool);
Chris@314 314
Chris@127 315 /** Emitted when the overlay mode has been changed. */
Chris@127 316 void overlayModeChanged();
Chris@127 317
Chris@607 318 /** Emitted when the centre line visibility has been changed. */
Chris@607 319 void showCentreLineChanged();
Chris@607 320
Chris@133 321 /** Emitted when the zoom wheels have been toggled. */
Chris@133 322 void zoomWheelsEnabledChanged();
Chris@133 323
Chris@1468 324 /** Emitted when editing-enabled has been toggled. */
Chris@1468 325 void opportunisticEditingEnabledChanged();
Chris@1468 326
Chris@502 327 /** Emitted when any loggable activity has occurred. */
Chris@502 328 void activity(QString);
Chris@502 329
Chris@211 330 public slots:
Chris@902 331 void viewCentreFrameChanged(sv_frame_t, bool, PlaybackFollowMode);
Chris@1327 332 void viewZoomLevelChanged(ZoomLevel, bool);
Chris@902 333 void setGlobalCentreFrame(sv_frame_t);
Chris@902 334 void setPlaybackFrame(sv_frame_t);
Chris@689 335 void playStatusChanged(bool playing);
Chris@1210 336 void recordStatusChanged(bool recording);
Chris@211 337
Chris@127 338 protected slots:
Chris@127 339 void checkPlayStatus();
Chris@902 340 void seek(sv_frame_t);
Chris@806 341 //!!! void considerZoomChange(void *, int, bool);
Chris@127 342
Chris@127 343 protected:
Chris@127 344 AudioPlaySource *m_playSource;
Chris@1210 345 AudioRecordTarget *m_recordTarget;
Chris@1210 346
Chris@902 347 sv_frame_t m_globalCentreFrame;
Chris@1327 348 ZoomLevel m_globalZoom;
Chris@902 349 mutable sv_frame_t m_playbackFrame;
Chris@301 350 Model *m_playbackModel; //!!!
Chris@902 351 sv_samplerate_t m_mainModelSampleRate;
Chris@127 352
Chris@127 353 float m_lastLeft;
Chris@127 354 float m_lastRight;
Chris@127 355
Chris@127 356 MultiSelection m_selections;
Chris@127 357 Selection m_inProgressSelection;
Chris@127 358 bool m_inProgressExclusive;
Chris@127 359
Chris@127 360 Clipboard m_clipboard;
Chris@127 361
Chris@127 362 ToolMode m_toolMode;
Chris@711 363 std::map<const View *, ToolMode> m_toolModeOverrides;
Chris@127 364
Chris@127 365 bool m_playLoopMode;
Chris@127 366 bool m_playSelectionMode;
Chris@301 367 bool m_playSoloMode;
Chris@314 368 bool m_alignMode;
Chris@127 369
Chris@762 370 void setSelections(const MultiSelection &ms, bool quietly = false);
Chris@127 371 void signalSelectionChange();
Chris@127 372
Chris@127 373 class SetSelectionCommand : public Command
Chris@127 374 {
Chris@127 375 public:
Chris@1266 376 SetSelectionCommand(ViewManager *vm, const MultiSelection &ms);
Chris@1266 377 virtual ~SetSelectionCommand();
Chris@1406 378 void execute() override;
Chris@1406 379 void unexecute() override;
Chris@1406 380 QString getName() const override;
Chris@127 381
Chris@127 382 protected:
Chris@1266 383 ViewManager *m_vm;
Chris@1266 384 MultiSelection m_oldSelection;
Chris@1266 385 MultiSelection m_newSelection;
Chris@127 386 };
Chris@127 387
Chris@127 388 OverlayMode m_overlayMode;
Chris@133 389 bool m_zoomWheelsEnabled;
Chris@1468 390 bool m_opportunisticEditingEnabled;
Chris@607 391 bool m_showCentreLine;
Chris@326 392 bool m_illuminateLocalFeatures;
Chris@326 393 bool m_showWorkTitle;
matthiasm@822 394 bool m_showDuration;
Chris@292 395
Chris@292 396 QPalette m_lightPalette;
Chris@292 397 QPalette m_darkPalette;
Chris@127 398 };
Chris@127 399
Chris@127 400 #endif
Chris@127 401