annotate view/ViewManager.h @ 1273:61418c112281

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