comparison data/model/NoteModel.h @ 1647:29a20719796e single-point

Rework NoteModel commands (not entirely successfully); remove FlexiNoteModel as it has always been almost entirely identical to NoteModel (unlike its layer counterpart)
author Chris Cannam
date Thu, 14 Mar 2019 15:31:59 +0000
parents b429750e64a8
children 86bbccb79c9b
comparison
equal deleted inserted replaced
1646:b429750e64a8 1647:29a20719796e
35 public NoteExportable 35 public NoteExportable
36 { 36 {
37 Q_OBJECT 37 Q_OBJECT
38 38
39 public: 39 public:
40 enum Subtype {
41 NORMAL_NOTE,
42 FLEXI_NOTE
43 };
44
40 NoteModel(sv_samplerate_t sampleRate, 45 NoteModel(sv_samplerate_t sampleRate,
41 int resolution, 46 int resolution,
42 bool notifyOnAdd = true) : 47 bool notifyOnAdd = true,
48 Subtype subtype = NORMAL_NOTE) :
49 m_subtype(subtype),
43 m_sampleRate(sampleRate), 50 m_sampleRate(sampleRate),
44 m_resolution(resolution), 51 m_resolution(resolution),
45 m_valueMinimum(0.f), 52 m_valueMinimum(0.f),
46 m_valueMaximum(0.f), 53 m_valueMaximum(0.f),
47 m_haveExtents(false), 54 m_haveExtents(false),
50 m_extendTo(0), 57 m_extendTo(0),
51 m_notifyOnAdd(notifyOnAdd), 58 m_notifyOnAdd(notifyOnAdd),
52 m_sinceLastNotifyMin(-1), 59 m_sinceLastNotifyMin(-1),
53 m_sinceLastNotifyMax(-1), 60 m_sinceLastNotifyMax(-1),
54 m_completion(0) { 61 m_completion(0) {
62 if (subtype == FLEXI_NOTE) {
63 m_valueMinimum = 33.f;
64 m_valueMaximum = 88.f;
65 }
55 PlayParameterRepository::getInstance()->addPlayable(this); 66 PlayParameterRepository::getInstance()->addPlayable(this);
56 } 67 }
57 68
58 NoteModel(sv_samplerate_t sampleRate, int resolution, 69 NoteModel(sv_samplerate_t sampleRate, int resolution,
59 float valueMinimum, float valueMaximum, 70 float valueMinimum, float valueMaximum,
60 bool notifyOnAdd = true) : 71 bool notifyOnAdd = true,
72 Subtype subtype = NORMAL_NOTE) :
73 m_subtype(subtype),
61 m_sampleRate(sampleRate), 74 m_sampleRate(sampleRate),
62 m_resolution(resolution), 75 m_resolution(resolution),
63 m_valueMinimum(valueMinimum), 76 m_valueMinimum(valueMinimum),
64 m_valueMaximum(valueMaximum), 77 m_valueMaximum(valueMaximum),
65 m_haveExtents(true), 78 m_haveExtents(true),
74 } 87 }
75 88
76 virtual ~NoteModel() { 89 virtual ~NoteModel() {
77 PlayParameterRepository::getInstance()->removePlayable(this); 90 PlayParameterRepository::getInstance()->removePlayable(this);
78 } 91 }
79 92
80 QString getTypeName() const override { return tr("Note"); } 93 QString getTypeName() const override { return tr("Note"); }
94 Subtype getSubtype() const { return m_subtype; }
81 95
82 bool isOK() const override { return true; } 96 bool isOK() const override { return true; }
83 sv_frame_t getStartFrame() const override { return m_events.getStartFrame(); } 97 sv_frame_t getStartFrame() const override { return m_events.getStartFrame(); }
84 sv_frame_t getEndFrame() const override { return m_events.getEndFrame(); } 98 sv_frame_t getEndFrame() const override { return m_events.getEndFrame(); }
85 sv_samplerate_t getSampleRate() const override { return m_sampleRate; } 99 sv_samplerate_t getSampleRate() const override { return m_sampleRate; }
184 class EditCommand : public Command 198 class EditCommand : public Command
185 { 199 {
186 public: 200 public:
187 //!!! borrowed ptr 201 //!!! borrowed ptr
188 EditCommand(NoteModel *model, QString name) : 202 EditCommand(NoteModel *model, QString name) :
189 m_model(model), m_name(name) { } 203 m_model(model), m_executed(false), m_name(name) { }
190 204
191 QString getName() const override { 205 QString getName() const override {
192 return m_name; 206 return m_name;
193 } 207 }
194 208
195 void setName(QString name) { 209 void setName(QString name) {
196 m_name = name; 210 m_name = name;
197 } 211 }
198 212
199 void add(Event e) { 213 void add(Event e) {
200 m_add.insert(e); 214 m_adding.insert(e);
215 m_model->add(e);
216 m_executed = true;
201 } 217 }
202 218
203 void remove(Event e) { 219 void remove(Event e) {
204 m_remove.insert(e); 220 m_removing.insert(e);
221 m_model->remove(e);
222 m_executed = true;
205 } 223 }
206 224
207 void execute() override { 225 void execute() override {
208 for (const Event &e: m_add) { 226 if (m_executed) return;
209 m_model->add(e); 227 for (const Event &e: m_adding) m_model->add(e);
210 } 228 for (const Event &e: m_removing) m_model->remove(e);
211 for (const Event &e: m_remove) { 229 m_executed = true;
212 m_model->remove(e);
213 }
214 } 230 }
215 231
216 void unexecute() override { 232 void unexecute() override {
217 for (const Event &e: m_remove) { 233 for (const Event &e: m_removing) m_model->add(e);
218 m_model->add(e); 234 for (const Event &e: m_adding) m_model->remove(e);
219 } 235 m_executed = false;
220 for (const Event &e: m_add) {
221 m_model->remove(e);
222 }
223 } 236 }
224 237
225 EditCommand *finish() { 238 EditCommand *finish() {
226 if (m_add.empty() && m_remove.empty()) { 239 if (m_adding.empty() && m_removing.empty()) {
227 delete this; 240 delete this;
228 return nullptr; 241 return nullptr;
229 } else { 242 } else {
230 execute();
231 return this; 243 return this;
232 } 244 }
233 } 245 }
234 246
235 private: 247 private:
236 NoteModel *m_model; 248 NoteModel *m_model;
237 std::set<Event> m_add; 249 bool m_executed;
238 std::set<Event> m_remove; 250 std::set<Event> m_adding;
251 std::set<Event> m_removing;
239 QString m_name; 252 QString m_name;
240 }; 253 };
241 254
242 void add(Event e) { 255 void add(Event e) {
243 256
424 437
425 Model::toXml 438 Model::toXml
426 (out, 439 (out,
427 indent, 440 indent,
428 QString("type=\"sparse\" dimensions=\"3\" resolution=\"%1\" " 441 QString("type=\"sparse\" dimensions=\"3\" resolution=\"%1\" "
429 "notifyOnAdd=\"%2\" dataset=\"%3\" subtype=\"note\" " 442 "notifyOnAdd=\"%2\" dataset=\"%3\" subtype=\"%4\" "
430 "valueQuantization=\"%4\" minimum=\"%5\" maximum=\"%6\" " 443 "valueQuantization=\"%5\" minimum=\"%6\" maximum=\"%7\" "
431 "units=\"%7\" %8") 444 "units=\"%8\" %9")
432 .arg(m_resolution) 445 .arg(m_resolution)
433 .arg(m_notifyOnAdd ? "true" : "false") 446 .arg(m_notifyOnAdd ? "true" : "false")
434 .arg(getObjectExportId(&m_events)) 447 .arg(getObjectExportId(&m_events))
448 .arg(m_subtype == FLEXI_NOTE ? "flexinote" : "note")
435 .arg(m_valueQuantization) 449 .arg(m_valueQuantization)
436 .arg(m_valueMinimum) 450 .arg(m_valueMinimum)
437 .arg(m_valueMaximum) 451 .arg(m_valueMaximum)
438 .arg(m_units) 452 .arg(m_units)
439 .arg(extraAttributes)); 453 .arg(extraAttributes));
440 454
441 m_events.toXml(out, indent, QString("dimensions=\"3\"")); 455 m_events.toXml(out, indent, QString("dimensions=\"3\""));
442 } 456 }
443 457
444 protected: 458 protected:
459 Subtype m_subtype;
445 sv_samplerate_t m_sampleRate; 460 sv_samplerate_t m_sampleRate;
446 int m_resolution; 461 int m_resolution;
447 462
448 float m_valueMinimum; 463 float m_valueMinimum;
449 float m_valueMaximum; 464 float m_valueMaximum;