annotate view/ViewManager.h @ 786:c58569bd952e tonioni

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