annotate base/ViewManager.h @ 76:af2725b5d6fe

* Implement harmonic cursor in spectrogram * Implement layer export. This doesn't quite do the right thing for the SV XML layer export yet -- it doesn't include layer display information, so when imported, it only creates an invisible model. Could also do with fixing CSV file import so as to work correctly for note and text layers.
author Chris Cannam
date Mon, 10 Apr 2006 17:22:59 +0000
parents 163f3428bbe0
children f277a171749d
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@75 46 virtual ~ViewManager();
Chris@0 47
Chris@0 48 void setAudioPlaySource(AudioPlaySource *source);
Chris@0 49
Chris@8 50 bool isPlaying() const;
Chris@8 51
Chris@0 52 unsigned long getGlobalCentreFrame() const;
Chris@0 53 unsigned long getGlobalZoom() const;
Chris@0 54
Chris@24 55 unsigned long getPlaybackFrame() const;
Chris@24 56 void setPlaybackFrame(unsigned long frame);
Chris@8 57
Chris@8 58 bool haveInProgressSelection() const;
Chris@8 59 const Selection &getInProgressSelection(bool &exclusive) const;
Chris@8 60 void setInProgressSelection(const Selection &selection, bool exclusive);
Chris@8 61 void clearInProgressSelection();
Chris@8 62
Chris@24 63 const MultiSelection &getSelection() const;
Chris@24 64
Chris@24 65 const MultiSelection::SelectionList &getSelections() const;
Chris@8 66 void setSelection(const Selection &selection);
Chris@8 67 void addSelection(const Selection &selection);
Chris@8 68 void removeSelection(const Selection &selection);
Chris@8 69 void clearSelections();
Chris@8 70
Chris@9 71 /**
Chris@9 72 * Return the selection that contains a given frame.
Chris@9 73 * If defaultToFollowing is true, and if the frame is not in a
Chris@9 74 * selected area, return the next selection after the given frame.
Chris@9 75 * Return the empty selection if no appropriate selection is found.
Chris@9 76 */
Chris@36 77 Selection getContainingSelection(size_t frame, bool defaultToFollowing) const;
Chris@9 78
Chris@74 79 Clipboard &getClipboard() { return m_clipboard; }
Chris@74 80
Chris@8 81 enum ToolMode {
Chris@8 82 NavigateMode,
Chris@8 83 SelectMode,
Chris@8 84 EditMode,
Chris@32 85 DrawMode
Chris@8 86 };
Chris@8 87 ToolMode getToolMode() const { return m_toolMode; }
Chris@8 88 void setToolMode(ToolMode mode);
Chris@8 89
Chris@9 90 bool getPlayLoopMode() const { return m_playLoopMode; }
Chris@9 91 void setPlayLoopMode(bool on);
Chris@9 92
Chris@9 93 bool getPlaySelectionMode() const { return m_playSelectionMode; }
Chris@9 94 void setPlaySelectionMode(bool on);
Chris@9 95
Chris@40 96 size_t getPlaybackSampleRate() const;
Chris@42 97 size_t getMainModelSampleRate() const { return m_mainModelSampleRate; }
Chris@42 98 void setMainModelSampleRate(size_t sr) { m_mainModelSampleRate = sr; }
Chris@40 99
Chris@65 100 enum OverlayMode {
Chris@65 101 NoOverlays,
Chris@65 102 BasicOverlays,
Chris@65 103 AllOverlays
Chris@65 104 };
Chris@65 105 void setOverlayMode(OverlayMode mode);
Chris@65 106 OverlayMode getOverlayMode() const { return m_overlayMode; }
Chris@65 107
Chris@75 108 QString getTemporaryDirectory();
Chris@75 109
Chris@0 110 signals:
Chris@0 111 /** Emitted when a widget pans. The originator identifies the widget. */
Chris@0 112 void centreFrameChanged(void *originator, unsigned long frame, bool locked);
Chris@0 113
Chris@0 114 /** Emitted when a widget zooms. The originator identifies the widget. */
Chris@0 115 void zoomLevelChanged(void *originator, unsigned long zoom, bool locked);
Chris@0 116
Chris@0 117 /** Emitted when the playback frame changes. */
Chris@0 118 void playbackFrameChanged(unsigned long frame);
Chris@0 119
Chris@0 120 /** Emitted when the output levels change. Values in range 0.0 -> 1.0. */
Chris@0 121 void outputLevelsChanged(float left, float right);
Chris@0 122
Chris@8 123 /** Emitted when the selection has changed. */
Chris@8 124 void selectionChanged();
Chris@8 125
Chris@9 126 /** Emitted when the in-progress (rubberbanding) selection has changed. */
Chris@9 127 void inProgressSelectionChanged();
Chris@9 128
Chris@8 129 /** Emitted when the tool mode has been changed. */
Chris@8 130 void toolModeChanged();
Chris@8 131
Chris@9 132 /** Emitted when the play loop mode has been changed. */
Chris@9 133 void playLoopModeChanged();
Chris@9 134
Chris@9 135 /** Emitted when the play selection mode has been changed. */
Chris@9 136 void playSelectionModeChanged();
Chris@9 137
Chris@65 138 /** Emitted when the overlay mode has been changed. */
Chris@65 139 void overlayModeChanged();
Chris@65 140
Chris@0 141 protected slots:
Chris@0 142 void checkPlayStatus();
Chris@10 143 void playStatusChanged(bool playing);
Chris@0 144 void considerSeek(void *, unsigned long, bool);
Chris@0 145 void considerZoomChange(void *, unsigned long, bool);
Chris@0 146
Chris@0 147 protected:
Chris@0 148 AudioPlaySource *m_playSource;
Chris@0 149 unsigned long m_globalCentreFrame;
Chris@0 150 unsigned long m_globalZoom;
Chris@24 151 mutable unsigned long m_playbackFrame;
Chris@42 152 size_t m_mainModelSampleRate;
Chris@0 153
Chris@0 154 float m_lastLeft;
Chris@0 155 float m_lastRight;
Chris@0 156
Chris@24 157 MultiSelection m_selections;
Chris@8 158 Selection m_inProgressSelection;
Chris@8 159 bool m_inProgressExclusive;
Chris@8 160
Chris@74 161 Clipboard m_clipboard;
Chris@74 162
Chris@8 163 ToolMode m_toolMode;
Chris@8 164
Chris@9 165 bool m_playLoopMode;
Chris@9 166 bool m_playSelectionMode;
Chris@45 167
Chris@45 168 void setSelections(const MultiSelection &ms);
Chris@45 169 void signalSelectionChange();
Chris@45 170
Chris@45 171 class SetSelectionCommand : public Command
Chris@45 172 {
Chris@45 173 public:
Chris@45 174 SetSelectionCommand(ViewManager *vm, const MultiSelection &ms);
Chris@45 175 virtual ~SetSelectionCommand();
Chris@45 176 virtual void execute();
Chris@45 177 virtual void unexecute();
Chris@45 178 virtual QString getName() const;
Chris@45 179
Chris@45 180 protected:
Chris@45 181 ViewManager *m_vm;
Chris@45 182 MultiSelection m_oldSelection;
Chris@45 183 MultiSelection m_newSelection;
Chris@45 184 };
Chris@65 185
Chris@65 186 OverlayMode m_overlayMode;
Chris@75 187
Chris@75 188 void deleteTemporaryDirectory(QString);
Chris@75 189 QString m_tmpdir;
Chris@0 190 };
Chris@0 191
Chris@0 192 #endif
Chris@0 193