comparison data/model/Labeller.h @ 1742:52705a328b34 by-id

Rejig ById so as to put everything in a single pool, so that at the core you can go from numeric id (untyped) to anything the object can be dynamic_cast to. Useful for building other abstractions like PlayParameter-type registrations that don't know about e.g. Models. Probably some more tweaking needed. Also add tests
author Chris Cannam
date Fri, 28 Jun 2019 17:36:30 +0100
parents 9d82b164f264
children
comparison
equal deleted inserted replaced
1741:9d82b164f264 1742:52705a328b34
223 223
224 /** 224 /**
225 * Relabel all events in the given event vector that lie within 225 * Relabel all events in the given event vector that lie within
226 * the given multi-selection, according to the labelling 226 * the given multi-selection, according to the labelling
227 * properties of this labeller. Return a command that has been 227 * properties of this labeller. Return a command that has been
228 * executed but not yet added to the history. The template 228 * executed but not yet added to the history. The id must be that
229 * parameter must be a type that can be dynamic_cast to 229 * of a type that can be retrieved from the AnyById store and
230 * EventEditable and that has a ById store. 230 * dynamic_cast to EventEditable.
231 */ 231 */
232 template <typename EditableBase> 232 Command *labelAll(int editableId,
233 Command *labelAll(typename EditableBase::Id editable,
234 MultiSelection *ms, 233 MultiSelection *ms,
235 const EventVector &allEvents) { 234 const EventVector &allEvents) {
236 235
237 auto command = new ChangeEventsCommand<EditableBase> 236 auto command = new ChangeEventsCommand
238 (editable, tr("Label Points")); 237 (editableId, tr("Label Points"));
239 238
240 Event prev; 239 Event prev;
241 bool havePrev = false; 240 bool havePrev = false;
242 241
243 for (auto p: allEvents) { 242 for (auto p: allEvents) {
271 /** 270 /**
272 * For each event in the given event vector (except the last), if 271 * For each event in the given event vector (except the last), if
273 * that event lies within the given multi-selection, add n-1 new 272 * that event lies within the given multi-selection, add n-1 new
274 * events at equally spaced intervals between it and the following 273 * events at equally spaced intervals between it and the following
275 * event. Return a command that has been executed but not yet 274 * event. Return a command that has been executed but not yet
276 * added to the history. The template parameter must be a type 275 * added to the history. The id must be that of a type that can
277 * that can be dynamic_cast to EventEditable and that has a ById 276 * be retrieved from the AnyById store and dynamic_cast to
278 * store. 277 * EventEditable.
279 */ 278 */
280 template <typename EditableBase> 279 Command *subdivide(int editableId,
281 Command *subdivide(typename EditableBase::Id editable,
282 MultiSelection *ms, 280 MultiSelection *ms,
283 const EventVector &allEvents, 281 const EventVector &allEvents,
284 int n) { 282 int n) {
285 283
286 auto command = new ChangeEventsCommand<EditableBase> 284 auto command = new ChangeEventsCommand
287 (editable, tr("Subdivide Points")); 285 (editableId, tr("Subdivide Points"));
288 286
289 for (auto i = allEvents.begin(); i != allEvents.end(); ++i) { 287 for (auto i = allEvents.begin(); i != allEvents.end(); ++i) {
290 288
291 auto j = i; 289 auto j = i;
292 // require a "next point" even if it's not in selection 290 // require a "next point" even if it's not in selection
323 /** 321 /**
324 * The opposite of subdivide. Given an event vector, a 322 * The opposite of subdivide. Given an event vector, a
325 * multi-selection, and a number n, remove all but every nth event 323 * multi-selection, and a number n, remove all but every nth event
326 * from the vector within the extents of the multi-selection. 324 * from the vector within the extents of the multi-selection.
327 * Return a command that has been executed but not yet added to 325 * Return a command that has been executed but not yet added to
328 * the history. The template parameter must be a type 326 * the history. The id must be that of a type that can be
329 * that can be dynamic_cast to EventEditable and that has a ById 327 * retrieved from the AnyById store and dynamic_cast to
330 * store. 328 * EventEditable.
331 */ 329 */
332 template <typename EditableBase> 330 Command *winnow(int editableId,
333 Command *winnow(typename EditableBase::Id editable,
334 MultiSelection *ms, 331 MultiSelection *ms,
335 const EventVector &allEvents, 332 const EventVector &allEvents,
336 int n) { 333 int n) {
337 334
338 auto command = new ChangeEventsCommand<EditableBase> 335 auto command = new ChangeEventsCommand
339 (editable, tr("Winnow Points")); 336 (editableId, tr("Winnow Points"));
340 337
341 int counter = 0; 338 int counter = 0;
342 339
343 for (auto p: allEvents) { 340 for (auto p: allEvents) {
344 341