annotate view/ViewManager.h @ 1281:fc9d9f1103fa horizontal-scale

Provide linear horizontal scale in spectrum as well as log; fix bin positioning and colour scale property box updating; ensure proper background colour and visibility of peak lines
author Chris Cannam
date Thu, 03 May 2018 15:15:15 +0100
parents 7527701c8076
children 646e713a4632
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@1281 222 bool shouldShowHorizontalValueScale() const { // for layers where x != time
Chris@1281 223 return m_overlayMode != NoOverlays;
Chris@1281 224 }
Chris@189 225 bool shouldShowSelectionExtents() const {
Chris@741 226 return m_overlayMode != NoOverlays && m_overlayMode != GlobalOverlays;
Chris@189 227 }
Chris@189 228 bool shouldShowLayerNames() const {
Chris@189 229 return m_overlayMode == AllOverlays;
Chris@189 230 }
Chris@195 231 bool shouldShowScaleGuides() const {
Chris@195 232 return m_overlayMode != NoOverlays;
Chris@195 233 }
Chris@326 234 bool shouldShowWorkTitle() const {
Chris@326 235 return m_showWorkTitle;
Chris@326 236 }
Chris@326 237 bool shouldIlluminateLocalFeatures() const {
Chris@326 238 return m_illuminateLocalFeatures;
Chris@326 239 }
Chris@741 240 bool shouldShowFeatureLabels() const {
Chris@741 241 return m_overlayMode != NoOverlays && m_overlayMode != GlobalOverlays;
Chris@741 242 }
Chris@189 243
Chris@133 244 void setZoomWheelsEnabled(bool enable);
Chris@133 245 bool getZoomWheelsEnabled() const { return m_zoomWheelsEnabled; }
Chris@133 246
Chris@292 247 void setGlobalDarkBackground(bool dark);
Chris@292 248 bool getGlobalDarkBackground() const;
Chris@292 249
Chris@127 250 signals:
Chris@211 251 /** Emitted when user causes the global centre frame to change. */
Chris@902 252 void globalCentreFrameChanged(sv_frame_t frame);
Chris@127 253
Chris@211 254 /** Emitted when user scrolls a view, but doesn't affect global centre. */
Chris@902 255 void viewCentreFrameChanged(View *v, sv_frame_t frame);
Chris@211 256
Chris@211 257 /** Emitted when a view zooms. */
Chris@806 258 void viewZoomLevelChanged(View *v, int zoom, bool locked);
Chris@133 259
Chris@127 260 /** Emitted when the playback frame changes. */
Chris@902 261 void playbackFrameChanged(sv_frame_t frame);
Chris@127 262
Chris@1210 263 /** Emitted when the output or record levels change. Values in range 0.0 -> 1.0. */
Chris@1210 264 void monitoringLevelsChanged(float left, float right);
Chris@127 265
Chris@731 266 /** Emitted whenever the selection has changed. */
Chris@127 267 void selectionChanged();
Chris@127 268
Chris@731 269 /** Emitted when the selection has been changed through an
Chris@731 270 * explicit selection-editing action. *Not* emitted when the
Chris@731 271 * selection has been changed through undo or redo. */
Chris@731 272 void selectionChangedByUser();
Chris@731 273
Chris@127 274 /** Emitted when the in-progress (rubberbanding) selection has changed. */
Chris@127 275 void inProgressSelectionChanged();
Chris@127 276
Chris@127 277 /** Emitted when the tool mode has been changed. */
Chris@127 278 void toolModeChanged();
Chris@127 279
Chris@127 280 /** Emitted when the play loop mode has been changed. */
Chris@127 281 void playLoopModeChanged();
Chris@177 282 void playLoopModeChanged(bool);
Chris@127 283
Chris@127 284 /** Emitted when the play selection mode has been changed. */
Chris@127 285 void playSelectionModeChanged();
Chris@177 286 void playSelectionModeChanged(bool);
Chris@127 287
Chris@301 288 /** Emitted when the play solo mode has been changed. */
Chris@301 289 void playSoloModeChanged();
Chris@301 290 void playSoloModeChanged(bool);
Chris@301 291
Chris@314 292 /** Emitted when the alignment mode has been changed. */
Chris@314 293 void alignModeChanged();
Chris@314 294 void alignModeChanged(bool);
Chris@314 295
Chris@127 296 /** Emitted when the overlay mode has been changed. */
Chris@127 297 void overlayModeChanged();
Chris@127 298
Chris@607 299 /** Emitted when the centre line visibility has been changed. */
Chris@607 300 void showCentreLineChanged();
Chris@607 301
Chris@133 302 /** Emitted when the zoom wheels have been toggled. */
Chris@133 303 void zoomWheelsEnabledChanged();
Chris@133 304
Chris@502 305 /** Emitted when any loggable activity has occurred. */
Chris@502 306 void activity(QString);
Chris@502 307
Chris@211 308 public slots:
Chris@902 309 void viewCentreFrameChanged(sv_frame_t, bool, PlaybackFollowMode);
Chris@806 310 void viewZoomLevelChanged(int, bool);
Chris@902 311 void setGlobalCentreFrame(sv_frame_t);
Chris@902 312 void setPlaybackFrame(sv_frame_t);
Chris@689 313 void playStatusChanged(bool playing);
Chris@1210 314 void recordStatusChanged(bool recording);
Chris@211 315
Chris@127 316 protected slots:
Chris@127 317 void checkPlayStatus();
Chris@902 318 void seek(sv_frame_t);
Chris@806 319 //!!! void considerZoomChange(void *, int, bool);
Chris@127 320
Chris@127 321 protected:
Chris@127 322 AudioPlaySource *m_playSource;
Chris@1210 323 AudioRecordTarget *m_recordTarget;
Chris@1210 324
Chris@902 325 sv_frame_t m_globalCentreFrame;
Chris@806 326 int m_globalZoom;
Chris@902 327 mutable sv_frame_t m_playbackFrame;
Chris@301 328 Model *m_playbackModel; //!!!
Chris@902 329 sv_samplerate_t m_mainModelSampleRate;
Chris@127 330
Chris@127 331 float m_lastLeft;
Chris@127 332 float m_lastRight;
Chris@127 333
Chris@127 334 MultiSelection m_selections;
Chris@127 335 Selection m_inProgressSelection;
Chris@127 336 bool m_inProgressExclusive;
Chris@127 337
Chris@127 338 Clipboard m_clipboard;
Chris@127 339
Chris@127 340 ToolMode m_toolMode;
Chris@711 341 std::map<const View *, ToolMode> m_toolModeOverrides;
Chris@127 342
Chris@127 343 bool m_playLoopMode;
Chris@127 344 bool m_playSelectionMode;
Chris@301 345 bool m_playSoloMode;
Chris@314 346 bool m_alignMode;
Chris@127 347
Chris@762 348 void setSelections(const MultiSelection &ms, bool quietly = false);
Chris@127 349 void signalSelectionChange();
Chris@127 350
Chris@127 351 class SetSelectionCommand : public Command
Chris@127 352 {
Chris@127 353 public:
Chris@1266 354 SetSelectionCommand(ViewManager *vm, const MultiSelection &ms);
Chris@1266 355 virtual ~SetSelectionCommand();
Chris@1266 356 virtual void execute();
Chris@1266 357 virtual void unexecute();
Chris@1266 358 virtual QString getName() const;
Chris@127 359
Chris@127 360 protected:
Chris@1266 361 ViewManager *m_vm;
Chris@1266 362 MultiSelection m_oldSelection;
Chris@1266 363 MultiSelection m_newSelection;
Chris@127 364 };
Chris@127 365
Chris@127 366 OverlayMode m_overlayMode;
Chris@133 367 bool m_zoomWheelsEnabled;
Chris@607 368 bool m_showCentreLine;
Chris@326 369 bool m_illuminateLocalFeatures;
Chris@326 370 bool m_showWorkTitle;
matthiasm@822 371 bool m_showDuration;
Chris@292 372
Chris@292 373 QPalette m_lightPalette;
Chris@292 374 QPalette m_darkPalette;
Chris@127 375 };
Chris@127 376
Chris@127 377 #endif
Chris@127 378