Mercurial > hg > svcore
comparison data/model/AlignmentModel.cpp @ 339:ba30f4a3e3be
* Some work on correct alignment when moving panes during playback
* Overhaul alignment for playback frame values (view manager now always
refers to reference-timeline values, only the play source deals in
playback model timeline values)
* When making a selection, ensure the selection regions shown in other
panes (and used for playback constraints if appropriate) are aligned
correctly. This may be the coolest feature ever implemented in any
program ever.
author | Chris Cannam |
---|---|
date | Thu, 22 Nov 2007 14:17:19 +0000 |
parents | f14e2f7b24f7 |
children | d77e1fa49e26 94fc0591ea43 |
comparison
equal
deleted
inserted
replaced
338:f14e2f7b24f7 | 339:ba30f4a3e3be |
---|---|
123 | 123 |
124 size_t | 124 size_t |
125 AlignmentModel::toReference(size_t frame) const | 125 AlignmentModel::toReference(size_t frame) const |
126 { | 126 { |
127 // std::cerr << "AlignmentModel::toReference(" << frame << ")" << std::endl; | 127 // std::cerr << "AlignmentModel::toReference(" << frame << ")" << std::endl; |
128 if (!m_path) constructPath(); | |
129 return align(m_path, frame); | |
130 } | |
131 | |
132 size_t | |
133 AlignmentModel::fromReference(size_t frame) const | |
134 { | |
135 // std::cerr << "AlignmentModel::fromReference(" << frame << ")" << std::endl; | |
128 if (!m_reversePath) constructReversePath(); | 136 if (!m_reversePath) constructReversePath(); |
129 return align(m_reversePath, frame); | 137 return align(m_reversePath, frame); |
130 } | 138 } |
131 | 139 |
132 size_t | |
133 AlignmentModel::fromReference(size_t frame) const | |
134 { | |
135 // std::cerr << "AlignmentModel::fromReference(" << frame << ")" << std::endl; | |
136 if (!m_path) constructPath(); | |
137 return align(m_path, frame); | |
138 } | |
139 | |
140 void | 140 void |
141 AlignmentModel::pathChanged() | 141 AlignmentModel::pathChanged() |
142 { | 142 { |
143 if (m_pathComplete) { | |
144 std::cerr << "AlignmentModel: deleting raw path model" << std::endl; | |
145 delete m_rawPath; | |
146 m_rawPath = 0; | |
147 } | |
143 } | 148 } |
144 | 149 |
145 void | 150 void |
146 AlignmentModel::pathChanged(size_t, size_t) | 151 AlignmentModel::pathChanged(size_t, size_t) |
147 { | 152 { |
151 } | 156 } |
152 | 157 |
153 void | 158 void |
154 AlignmentModel::pathCompletionChanged() | 159 AlignmentModel::pathCompletionChanged() |
155 { | 160 { |
161 if (!m_rawPath) return; | |
156 m_pathBegun = true; | 162 m_pathBegun = true; |
157 | 163 |
158 if (!m_pathComplete) { | 164 if (!m_pathComplete) { |
159 | 165 |
160 int completion = 0; | 166 int completion = 0; |
167 | 173 |
168 if (m_pathComplete) { | 174 if (m_pathComplete) { |
169 | 175 |
170 constructPath(); | 176 constructPath(); |
171 constructReversePath(); | 177 constructReversePath(); |
172 | |
173 delete m_rawPath; | |
174 m_rawPath = 0; | |
175 | 178 |
176 delete m_inputModel; | 179 delete m_inputModel; |
177 m_inputModel = 0; | 180 m_inputModel = 0; |
178 } | 181 } |
179 } | 182 } |
206 float value = i->value; | 209 float value = i->value; |
207 long rframe = lrintf(value * m_aligned->getSampleRate()); | 210 long rframe = lrintf(value * m_aligned->getSampleRate()); |
208 m_path->addPoint(PathPoint(frame, rframe)); | 211 m_path->addPoint(PathPoint(frame, rframe)); |
209 } | 212 } |
210 | 213 |
211 std::cerr << "AlignmentModel::constructPath: " << m_path->getPointCount() << " points, at least " << (2 * m_path->getPointCount() * (3 * sizeof(void *) + sizeof(int) + sizeof(PathPoint))) << " bytes" << std::endl; | 214 // std::cerr << "AlignmentModel::constructPath: " << m_path->getPointCount() << " points, at least " << (2 * m_path->getPointCount() * (3 * sizeof(void *) + sizeof(int) + sizeof(PathPoint))) << " bytes" << std::endl; |
212 } | 215 } |
213 | 216 |
214 void | 217 void |
215 AlignmentModel::constructReversePath() const | 218 AlignmentModel::constructReversePath() const |
216 { | 219 { |
236 float value = i->value; | 239 float value = i->value; |
237 long rframe = lrintf(value * m_aligned->getSampleRate()); | 240 long rframe = lrintf(value * m_aligned->getSampleRate()); |
238 m_reversePath->addPoint(PathPoint(rframe, frame)); | 241 m_reversePath->addPoint(PathPoint(rframe, frame)); |
239 } | 242 } |
240 | 243 |
241 std::cerr << "AlignmentModel::constructReversePath: " << m_reversePath->getPointCount() << " points, at least " << (2 * m_reversePath->getPointCount() * (3 * sizeof(void *) + sizeof(int) + sizeof(PathPoint))) << " bytes" << std::endl; | 244 // std::cerr << "AlignmentModel::constructReversePath: " << m_reversePath->getPointCount() << " points, at least " << (2 * m_reversePath->getPointCount() * (3 * sizeof(void *) + sizeof(int) + sizeof(PathPoint))) << " bytes" << std::endl; |
242 } | 245 } |
243 | 246 |
244 size_t | 247 size_t |
245 AlignmentModel::align(PathModel *path, size_t frame) const | 248 AlignmentModel::align(PathModel *path, size_t frame) const |
246 { | 249 { |
250 if (!path) return frame; | |
251 | |
247 // The path consists of a series of points, each with frame equal | 252 // The path consists of a series of points, each with frame equal |
248 // to the frame on the source model and mapframe equal to the | 253 // to the frame on the source model and mapframe equal to the |
249 // frame on the target model. Both should be monotonically | 254 // frame on the target model. Both should be monotonically |
250 // increasing. | 255 // increasing. |
251 | 256 |
281 float(frame - foundFrame) / | 286 float(frame - foundFrame) / |
282 float(followingFrame - foundFrame); | 287 float(followingFrame - foundFrame); |
283 resultFrame += lrintf((followingMapFrame - foundMapFrame) * interp); | 288 resultFrame += lrintf((followingMapFrame - foundMapFrame) * interp); |
284 } | 289 } |
285 | 290 |
286 std::cerr << "AlignmentModel::align: resultFrame = " << resultFrame << std::endl; | 291 // std::cerr << "AlignmentModel::align: resultFrame = " << resultFrame << std::endl; |
287 | 292 |
288 return resultFrame; | 293 return resultFrame; |
289 } | 294 } |
290 | 295 |