NoteEvents.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. /*
  2. This file is part of QTau
  3. Copyright (C) 2013-2018 Tobias "Tomoko" Platen <tplaten@posteo.de>
  4. Copyright (C) 2013 digited <https://github.com/digited>
  5. Copyright (C) 2010-2013 HAL@ShurabaP <https://github.com/haruneko>
  6. QTau is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. SPDX-License-Identifier: GPL-3.0+
  17. */
  18. #ifndef NOTEEVENTS_H
  19. #define NOTEEVENTS_H
  20. #include <QVector>
  21. #include <QPoint>
  22. #include <QSize>
  23. #include "Events.h"
  24. namespace ENoteEvents
  25. {
  26. enum {
  27. add = 100,
  28. resize,
  29. move,
  30. text,
  31. effect
  32. };
  33. }
  34. // add/remove note(s)
  35. class qtauEvent_NoteAddition : public qtauEvent
  36. {
  37. public:
  38. typedef struct {
  39. quint64 id;
  40. QString lyrics;
  41. int pulseOffset;
  42. int pulseLength;
  43. int keyNumber;
  44. QMap<QString,QJsonValue> optionalElements;//used by sinsy and other plugins
  45. QString toString() const { return QString("id: %1 offset: %2 length: %3 key number: %4 lyrics: %5")
  46. .arg(id).arg(pulseOffset).arg(pulseLength).arg(keyNumber).arg(lyrics); }
  47. } noteAddData;
  48. typedef QVector<noteAddData> noteAddVector;
  49. qtauEvent_NoteAddition(const noteAddVector &changeset, bool forward = true, bool deleteEvent = false) :
  50. qtauEvent(ENoteEvents::add, forward), added(changeset), deleteInstead(deleteEvent) {}
  51. const noteAddVector& getAdded() const { return added; }
  52. bool isDeleteEvent() const { return deleteInstead; }
  53. protected:
  54. noteAddVector added;
  55. bool deleteInstead; // if it really is a delete event, so its transformation should be reversed
  56. qtauEvent_NoteAddition* allocCopy() const override { return new qtauEvent_NoteAddition(*this); }
  57. };
  58. class qtauEvent_NoteResize : public qtauEvent
  59. {
  60. public:
  61. typedef struct {
  62. quint64 id;
  63. int offset; // offset is delta of start of note
  64. int length;
  65. int prevOffset;
  66. int prevLength;
  67. QString toString() const { return QString("id: %1 offset: %2 offset was: %3 length: %4 length was: %5")
  68. .arg(id).arg(offset).arg(prevOffset).arg(length).arg(prevLength); }
  69. } noteResizeData;
  70. typedef QVector<noteResizeData> noteResizeVector;
  71. qtauEvent_NoteResize(const noteResizeVector &changeset, bool forward = true) :
  72. qtauEvent(ENoteEvents::resize, forward), resized(changeset) {}
  73. const noteResizeVector& getResized() const { return resized; }
  74. protected:
  75. noteResizeVector resized;
  76. qtauEvent_NoteResize* allocCopy() const override { return new qtauEvent_NoteResize(*this); }
  77. };
  78. class qtauEvent_NoteMove : public qtauEvent
  79. {
  80. public:
  81. typedef struct {
  82. quint64 id;
  83. int pulseOffDelta;
  84. int keyNumber;
  85. int prevKeyNumber;
  86. QString toString() const { return QString("id: %1 pulseOffDelta: %2 key number: %3 key number was: %4")
  87. .arg(id).arg(pulseOffDelta).arg(keyNumber).arg(prevKeyNumber); }
  88. } noteMoveData;
  89. typedef QVector<noteMoveData> noteMoveVector;
  90. qtauEvent_NoteMove(const noteMoveVector &changeset, bool forward = true) :
  91. qtauEvent(ENoteEvents::move, forward), moved(changeset) {}
  92. const noteMoveVector& getMoved() const { return moved; }
  93. protected:
  94. noteMoveVector moved;
  95. qtauEvent_NoteMove* allocCopy() const override { return new qtauEvent_NoteMove(*this); }
  96. };
  97. class qtauEvent_NoteText : public qtauEvent
  98. {
  99. public:
  100. typedef struct {
  101. quint64 id;
  102. QString txt;
  103. QString prevTxt;
  104. QString toString() const { return QString("id: %1 text: %2 text was: %3").arg(id).arg(txt).arg(prevTxt); }
  105. } noteTextData;
  106. typedef QVector<noteTextData> noteTextVector;
  107. qtauEvent_NoteText(const noteTextVector &changeset, bool forward = true) :
  108. qtauEvent(ENoteEvents::text, forward), text(changeset) {}
  109. const noteTextVector& getText() const { return text; }
  110. protected:
  111. noteTextVector text;
  112. qtauEvent_NoteText* allocCopy() const override { return new qtauEvent_NoteText(*this); }
  113. };
  114. class qtauEvent_NoteEffect : public qtauEvent
  115. {
  116. public:
  117. typedef struct {
  118. quint64 id;
  119. //TODO: implement this (ignore for now)
  120. QString toString() const { return QString("id: %1").arg(id); }
  121. } noteEffectData;
  122. typedef QVector<noteEffectData> noteEffectVector;
  123. qtauEvent_NoteEffect(const noteEffectVector &changeset, bool forward = true) :
  124. qtauEvent(ENoteEvents::effect, forward), effect(changeset) {}
  125. const noteEffectVector& getEffect() const { return effect; }
  126. protected:
  127. noteEffectVector effect;
  128. qtauEvent_NoteEffect* allocCopy() const override { return new qtauEvent_NoteEffect(*this); }
  129. };
  130. #endif // NOTEEVENTS_H
  131. //Need INote interface
  132. //UTAUNote
  133. //USTJ format
  134. //