annotate base/ViewManager.h @ 74:47fd14e29813

* Fix long-standing off-by-1 bug in WaveFileModel that was getting us the wrong values for almost all audio data when merging channels (channel == -1) * Implement cut, copy and paste * Make draw mode work properly in time value layer * Minor fixes to CSV import
author Chris Cannam
date Fri, 07 Apr 2006 17:50:33 +0000
parents e1aad27029e3
children 163f3428bbe0
rev   line source
Chris@49 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@0 2
Chris@0 3 /*
Chris@52 4 Sonic Visualiser
Chris@52 5 An audio file viewer and annotation editor.
Chris@52 6 Centre for Digital Music, Queen Mary, University of London.
Chris@52 7 This file copyright 2006 Chris Cannam.
Chris@0 8
Chris@52 9 This program is free software; you can redistribute it and/or
Chris@52 10 modify it under the terms of the GNU General Public License as
Chris@52 11 published by the Free Software Foundation; either version 2 of the
Chris@52 12 License, or (at your option) any later version. See the file
Chris@52 13 COPYING included with this distribution for more information.
Chris@0 14 */
Chris@0 15
Chris@0 16 #ifndef _VIEW_MANAGER_H_
Chris@0 17 #define _VIEW_MANAGER_H_
Chris@0 18
Chris@0 19 #include <QObject>
Chris@0 20 #include <QTimer>
Chris@0 21
Chris@0 22 #include <map>
Chris@8 23
Chris@8 24 #include "Selection.h"
Chris@45 25 #include "Command.h"
Chris@74 26 #include "Clipboard.h"
Chris@0 27
Chris@0 28 class AudioPlaySource;
Chris@0 29 class Model;
Chris@0 30
Chris@0 31 /**
Chris@0 32 * The ViewManager manages properties that may need to be synchronised
Chris@0 33 * between separate Views. For example, it handles signals associated
Chris@48 34 * with changes to the global pan and zoom, and it handles selections.
Chris@0 35 *
Chris@0 36 * Views should be implemented in such a way as to work
Chris@0 37 * correctly whether they are supplied with a ViewManager or not.
Chris@0 38 */
Chris@0 39
Chris@0 40 class ViewManager : public QObject
Chris@0 41 {
Chris@0 42 Q_OBJECT
Chris@0 43
Chris@0 44 public:
Chris@0 45 ViewManager();
Chris@0 46
Chris@0 47 void setAudioPlaySource(AudioPlaySource *source);
Chris@0 48
Chris@8 49 bool isPlaying() const;
Chris@8 50
Chris@0 51 unsigned long getGlobalCentreFrame() const;
Chris@0 52 unsigned long getGlobalZoom() const;
Chris@0 53
Chris@24 54 unsigned long getPlaybackFrame() const;
Chris@24 55 void setPlaybackFrame(unsigned long frame);
Chris@8 56
Chris@8 57 bool haveInProgressSelection() const;
Chris@8 58 const Selection &getInProgressSelection(bool &exclusive) const;
Chris@8 59 void setInProgressSelection(const Selection &selection, bool exclusive);
Chris@8 60 void clearInProgressSelection();
Chris@8 61
Chris@24 62 const MultiSelection &getSelection() const;
Chris@24 63
Chris@24 64 const MultiSelection::SelectionList &getSelections() const;
Chris@8 65 void setSelection(const Selection &selection);
Chris@8 66 void addSelection(const Selection &selection);
Chris@8 67 void removeSelection(const Selection &selection);
Chris@8 68 void clearSelections();
Chris@8 69
Chris@9 70 /**
Chris@9 71 * Return the selection that contains a given frame.
Chris@9 72 * If defaultToFollowing is true, and if the frame is not in a
Chris@9 73 * selected area, return the next selection after the given frame.
Chris@9 74 * Return the empty selection if no appropriate selection is found.
Chris@9 75 */
Chris@36 76 Selection getContainingSelection(size_t frame, bool defaultToFollowing) const;
Chris@9 77
Chris@74 78 Clipboard &getClipboard() { return m_clipboard; }
Chris@74 79
Chris@8 80 enum ToolMode {
Chris@8 81 NavigateMode,
Chris@8 82 SelectMode,
Chris@8 83 EditMode,
Chris@32 84 DrawMode
Chris@8 85 };
Chris@8 86 ToolMode getToolMode() const { return m_toolMode; }
Chris@8 87 void setToolMode(ToolMode mode);
Chris@8 88
Chris@9 89 bool getPlayLoopMode() const { return m_playLoopMode; }
Chris@9 90 void setPlayLoopMode(bool on);
Chris@9 91
Chris@9 92 bool getPlaySelectionMode() const { return m_playSelectionMode; }
Chris@9 93 void setPlaySelectionMode(bool on);
Chris@9 94
Chris@40 95 size_t getPlaybackSampleRate() const;
Chris@42 96 size_t getMainModelSampleRate() const { return m_mainModelSampleRate; }
Chris@42 97 void setMainModelSampleRate(size_t sr) { m_mainModelSampleRate = sr; }
Chris@40 98
Chris@65 99 enum OverlayMode {
Chris@65 100 NoOverlays,
Chris@65 101 BasicOverlays,
Chris@65 102 AllOverlays
Chris@65 103 };
Chris@65 104 void setOverlayMode(OverlayMode mode);
Chris@65 105 OverlayMode getOverlayMode() const { return m_overlayMode; }
Chris@65 106
Chris@0 107 signals:
Chris@0 108 /** Emitted when a widget pans. The originator identifies the widget. */
Chris@0 109 void centreFrameChanged(void *originator, unsigned long frame, bool locked);
Chris@0 110
Chris@0 111 /** Emitted when a widget zooms. The originator identifies the widget. */
Chris@0 112 void zoomLevelChanged(void *originator, unsigned long zoom, bool locked);
Chris@0 113
Chris@0 114 /** Emitted when the playback frame changes. */
Chris@0 115 void playbackFrameChanged(unsigned long frame);
Chris@0 116
Chris@0 117 /** Emitted when the output levels change. Values in range 0.0 -> 1.0. */
Chris@0 118 void outputLevelsChanged(float left, float right);
Chris@0 119
Chris@8 120 /** Emitted when the selection has changed. */
Chris@8 121 void selectionChanged();
Chris@8 122
Chris@9 123 /** Emitted when the in-progress (rubberbanding) selection has changed. */
Chris@9 124 void inProgressSelectionChanged();
Chris@9 125
Chris@8 126 /** Emitted when the tool mode has been changed. */
Chris@8 127 void toolModeChanged();
Chris@8 128
Chris@9 129 /** Emitted when the play loop mode has been changed. */
Chris@9 130 void playLoopModeChanged();
Chris@9 131
Chris@9 132 /** Emitted when the play selection mode has been changed. */
Chris@9 133 void playSelectionModeChanged();
Chris@9 134
Chris@65 135 /** Emitted when the overlay mode has been changed. */
Chris@65 136 void overlayModeChanged();
Chris@65 137
Chris@0 138 protected slots:
Chris@0 139 void checkPlayStatus();
Chris@10 140 void playStatusChanged(bool playing);
Chris@0 141 void considerSeek(void *, unsigned long, bool);
Chris@0 142 void considerZoomChange(void *, unsigned long, bool);
Chris@0 143
Chris@0 144 protected:
Chris@0 145 AudioPlaySource *m_playSource;
Chris@0 146 unsigned long m_globalCentreFrame;
Chris@0 147 unsigned long m_globalZoom;
Chris@24 148 mutable unsigned long m_playbackFrame;
Chris@42 149 size_t m_mainModelSampleRate;
Chris@0 150
Chris@0 151 float m_lastLeft;
Chris@0 152 float m_lastRight;
Chris@0 153
Chris@24 154 MultiSelection m_selections;
Chris@8 155 Selection m_inProgressSelection;
Chris@8 156 bool m_inProgressExclusive;
Chris@8 157
Chris@74 158 Clipboard m_clipboard;
Chris@74 159
Chris@8 160 ToolMode m_toolMode;
Chris@8 161
Chris@9 162 bool m_playLoopMode;
Chris@9 163 bool m_playSelectionMode;
Chris@45 164
Chris@45 165 void setSelections(const MultiSelection &ms);
Chris@45 166 void signalSelectionChange();
Chris@45 167
Chris@45 168 class SetSelectionCommand : public Command
Chris@45 169 {
Chris@45 170 public:
Chris@45 171 SetSelectionCommand(ViewManager *vm, const MultiSelection &ms);
Chris@45 172 virtual ~SetSelectionCommand();
Chris@45 173 virtual void execute();
Chris@45 174 virtual void unexecute();
Chris@45 175 virtual QString getName() const;
Chris@45 176
Chris@45 177 protected:
Chris@45 178 ViewManager *m_vm;
Chris@45 179 MultiSelection m_oldSelection;
Chris@45 180 MultiSelection m_newSelection;
Chris@45 181 };
Chris@65 182
Chris@65 183 OverlayMode m_overlayMode;
Chris@0 184 };
Chris@0 185
Chris@0 186 #endif
Chris@0 187