annotate view/ViewManager.h @ 1189:7609580fb05a levelpanwidget

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