comparison data/model/SparseTimeValueModel.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 77543124651b
comparison
equal deleted inserted replaced
1741:9d82b164f264 1742:52705a328b34
52 DeferredNotifier::NOTIFY_ALWAYS : 52 DeferredNotifier::NOTIFY_ALWAYS :
53 DeferredNotifier::NOTIFY_DEFERRED), 53 DeferredNotifier::NOTIFY_DEFERRED),
54 m_completion(100) { 54 m_completion(100) {
55 // Model is playable, but may not sound (if units not Hz or 55 // Model is playable, but may not sound (if units not Hz or
56 // range unsuitable) 56 // range unsuitable)
57 PlayParameterRepository::getInstance()->addPlayable(this); 57 PlayParameterRepository::getInstance()->addPlayable(getId().untyped);
58 } 58 }
59 59
60 SparseTimeValueModel(sv_samplerate_t sampleRate, int resolution, 60 SparseTimeValueModel(sv_samplerate_t sampleRate, int resolution,
61 float valueMinimum, float valueMaximum, 61 float valueMinimum, float valueMaximum,
62 bool notifyOnAdd = true) : 62 bool notifyOnAdd = true) :
71 DeferredNotifier::NOTIFY_ALWAYS : 71 DeferredNotifier::NOTIFY_ALWAYS :
72 DeferredNotifier::NOTIFY_DEFERRED), 72 DeferredNotifier::NOTIFY_DEFERRED),
73 m_completion(100) { 73 m_completion(100) {
74 // Model is playable, but may not sound (if units not Hz or 74 // Model is playable, but may not sound (if units not Hz or
75 // range unsuitable) 75 // range unsuitable)
76 PlayParameterRepository::getInstance()->addPlayable(this); 76 PlayParameterRepository::getInstance()->addPlayable(getId().untyped);
77 } 77 }
78 78
79 virtual ~SparseTimeValueModel() { 79 virtual ~SparseTimeValueModel() {
80 PlayParameterRepository::getInstance()->removePlayable(this); 80 PlayParameterRepository::getInstance()->removePlayable(getId().untyped);
81 } 81 }
82 82
83 QString getTypeName() const override { return tr("Sparse Time-Value"); } 83 QString getTypeName() const override { return tr("Sparse Time-Value"); }
84 bool isSparse() const override { return true; } 84 bool isSparse() const override { return true; }
85 bool isOK() const override { return true; } 85 bool isOK() const override { return true; }
287 case 1: e1 = e0.withFrame(value.toInt()); break; 287 case 1: e1 = e0.withFrame(value.toInt()); break;
288 case 2: e1 = e0.withValue(float(value.toDouble())); break; 288 case 2: e1 = e0.withValue(float(value.toDouble())); break;
289 case 3: e1 = e0.withLabel(value.toString()); break; 289 case 3: e1 = e0.withLabel(value.toString()); break;
290 } 290 }
291 291
292 auto command = new ChangeEventsCommand<Model>(getId(), tr("Edit Data")); 292 auto command = new ChangeEventsCommand(getId().untyped, tr("Edit Data"));
293 command->remove(e0); 293 command->remove(e0);
294 command->add(e1); 294 command->add(e1);
295 return command->finish(); 295 return command->finish();
296 } 296 }
297 297