annotate view/ViewManager.h @ 833:57d943a61943

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