comparison base/ViewManager.cpp @ 9:73d85d19919f

* Add play-selection and looping modes. Looping seems to work OK, but the plain play-selection is miscalculating current frame number to feed back to the GUI. * Cache selection rectanges wherever possible in View::paintEvent.
author Chris Cannam
date Tue, 24 Jan 2006 16:20:58 +0000
parents 214054a0d8b8
children ec6886f0e673
comparison
equal deleted inserted replaced
8:214054a0d8b8 9:73d85d19919f
21 m_globalCentreFrame(0), 21 m_globalCentreFrame(0),
22 m_globalZoom(1024), 22 m_globalZoom(1024),
23 m_lastLeft(0), 23 m_lastLeft(0),
24 m_lastRight(0), 24 m_lastRight(0),
25 m_inProgressExclusive(true), 25 m_inProgressExclusive(true),
26 m_toolMode(NavigateMode) 26 m_toolMode(NavigateMode),
27 m_playLoopMode(false),
28 m_playSelectionMode(true)
27 { 29 {
28 connect(this, 30 connect(this,
29 SIGNAL(centreFrameChanged(void *, unsigned long, bool)), 31 SIGNAL(centreFrameChanged(void *, unsigned long, bool)),
30 SLOT(considerSeek(void *, unsigned long, bool))); 32 SLOT(considerSeek(void *, unsigned long, bool)));
31 33
69 ViewManager::setInProgressSelection(const Selection &selection, bool exclusive) 71 ViewManager::setInProgressSelection(const Selection &selection, bool exclusive)
70 { 72 {
71 m_inProgressExclusive = exclusive; 73 m_inProgressExclusive = exclusive;
72 m_inProgressSelection = selection; 74 m_inProgressSelection = selection;
73 if (exclusive) clearSelections(); 75 if (exclusive) clearSelections();
74 emit selectionChanged(); 76 emit inProgressSelectionChanged();
75 } 77 }
76 78
77 void 79 void
78 ViewManager::clearInProgressSelection() 80 ViewManager::clearInProgressSelection()
79 { 81 {
80 m_inProgressSelection = Selection(); 82 m_inProgressSelection = Selection();
81 emit selectionChanged(); 83 emit inProgressSelectionChanged();
82 } 84 }
83 85
84 const ViewManager::SelectionList & 86 const ViewManager::SelectionList &
85 ViewManager::getSelections() const 87 ViewManager::getSelections() const
86 { 88 {
101 103
102 // Cope with a sitation where the new selection overlaps one or 104 // Cope with a sitation where the new selection overlaps one or
103 // more existing ones. This is a terribly inefficient way to do 105 // more existing ones. This is a terribly inefficient way to do
104 // this, but that probably isn't significant in real life. 106 // this, but that probably isn't significant in real life.
105 107
106 for (SelectionList::iterator i = m_selections.begin(); 108 // It's essential for the correct operation of
109 // getContainingSelection that the selections do not overlap, so
110 // this is not just a frill.
111
112 for (SelectionList::iterator i = m_selections.begin();
107 i != m_selections.end(); ) { 113 i != m_selections.end(); ) {
108 114
109 SelectionList::iterator j = i; 115 SelectionList::iterator j = i;
110 if (++j == m_selections.end()) break; 116 if (++j == m_selections.end()) break;
111 117
143 m_selections.clear(); 149 m_selections.clear();
144 150
145 emit selectionChanged(); 151 emit selectionChanged();
146 } 152 }
147 153
154 Selection
155 ViewManager::getContainingSelection(size_t frame, bool defaultToFollowing)
156 {
157 // This scales very badly with the number of selections, but it's
158 // more efficient for very small numbers of selections than a more
159 // scalable method, and I think that may be what we need
160
161 for (SelectionList::const_iterator i = m_selections.begin();
162 i != m_selections.end(); ++i) {
163
164 if (i->contains(frame)) return *i;
165
166 if (i->getStartFrame() > frame) {
167 if (defaultToFollowing) return *i;
168 else return Selection();
169 }
170 }
171
172 return Selection();
173 }
174
148 void 175 void
149 ViewManager::setToolMode(ToolMode mode) 176 ViewManager::setToolMode(ToolMode mode)
150 { 177 {
151 m_toolMode = mode; 178 m_toolMode = mode;
152 179
153 emit toolModeChanged(); 180 emit toolModeChanged();
181 }
182
183 void
184 ViewManager::setPlayLoopMode(bool mode)
185 {
186 m_playLoopMode = mode;
187
188 emit playLoopModeChanged();
189 }
190
191 void
192 ViewManager::setPlaySelectionMode(bool mode)
193 {
194 m_playSelectionMode = mode;
195
196 emit playSelectionModeChanged();
154 } 197 }
155 198
156 void 199 void
157 ViewManager::setAudioPlaySource(AudioPlaySource *source) 200 ViewManager::setAudioPlaySource(AudioPlaySource *source)
158 { 201 {