NoteEvents.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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 <QJsonValue>
  21. #include <QMap>
  22. #include <QPoint>
  23. #include <QSize>
  24. #include <QVector>
  25. #include "Events.h"
  26. namespace ENoteEvents {
  27. enum { add = 100, resize, move, text, effect };
  28. }
  29. // add/remove note(s)
  30. class qtauEvent_NoteAddition : public qtauEvent {
  31. public:
  32. typedef struct {
  33. quint64 id;
  34. QString lyrics;
  35. int pulseOffset;
  36. int pulseLength;
  37. int keyNumber;
  38. QMap<QString, QJsonValue>
  39. optionalElements; // used by sinsy and other plugins
  40. QString toString() const {
  41. return QString("id: %1 offset: %2 length: %3 key number: %4 lyrics: %5")
  42. .arg(id)
  43. .arg(pulseOffset)
  44. .arg(pulseLength)
  45. .arg(keyNumber)
  46. .arg(lyrics);
  47. }
  48. } noteAddData;
  49. typedef QVector<noteAddData> noteAddVector;
  50. qtauEvent_NoteAddition(const noteAddVector& changeset, bool forward = true,
  51. bool deleteEvent = false)
  52. : qtauEvent(ENoteEvents::add, forward),
  53. added(changeset),
  54. deleteInstead(deleteEvent) {}
  55. const noteAddVector& getAdded() const {
  56. return added;
  57. }
  58. bool isDeleteEvent() const {
  59. return deleteInstead;
  60. }
  61. protected:
  62. noteAddVector added;
  63. bool deleteInstead; // if it really is a delete event, so its transformation
  64. // should be reversed
  65. qtauEvent_NoteAddition* allocCopy() const override {
  66. return new qtauEvent_NoteAddition(*this);
  67. }
  68. };
  69. class qtauEvent_NoteResize : public qtauEvent {
  70. public:
  71. typedef struct {
  72. quint64 id;
  73. int offset; // offset is delta of start of note
  74. int length;
  75. int prevOffset;
  76. int prevLength;
  77. QString toString() const {
  78. return QString(
  79. "id: %1 offset: %2 offset was: %3 length: %4 length was: %5")
  80. .arg(id)
  81. .arg(offset)
  82. .arg(prevOffset)
  83. .arg(length)
  84. .arg(prevLength);
  85. }
  86. } noteResizeData;
  87. typedef QVector<noteResizeData> noteResizeVector;
  88. qtauEvent_NoteResize(const noteResizeVector& changeset, bool forward = true)
  89. : qtauEvent(ENoteEvents::resize, forward), resized(changeset) {}
  90. const noteResizeVector& getResized() const {
  91. return resized;
  92. }
  93. protected:
  94. noteResizeVector resized;
  95. qtauEvent_NoteResize* allocCopy() const override {
  96. return new qtauEvent_NoteResize(*this);
  97. }
  98. };
  99. class qtauEvent_NoteMove : public qtauEvent {
  100. public:
  101. typedef struct {
  102. quint64 id;
  103. int pulseOffDelta;
  104. int keyNumber;
  105. int prevKeyNumber;
  106. QString toString() const {
  107. return QString(
  108. "id: %1 pulseOffDelta: %2 key number: %3 key number was: %4")
  109. .arg(id)
  110. .arg(pulseOffDelta)
  111. .arg(keyNumber)
  112. .arg(prevKeyNumber);
  113. }
  114. } noteMoveData;
  115. typedef QVector<noteMoveData> noteMoveVector;
  116. qtauEvent_NoteMove(const noteMoveVector& changeset, bool forward = true)
  117. : qtauEvent(ENoteEvents::move, forward), moved(changeset) {}
  118. const noteMoveVector& getMoved() const {
  119. return moved;
  120. }
  121. protected:
  122. noteMoveVector moved;
  123. qtauEvent_NoteMove* allocCopy() const override {
  124. return new qtauEvent_NoteMove(*this);
  125. }
  126. };
  127. class qtauEvent_NoteText : public qtauEvent {
  128. public:
  129. typedef struct {
  130. quint64 id;
  131. QString txt;
  132. QString prevTxt;
  133. QString toString() const {
  134. return QString("id: %1 text: %2 text was: %3")
  135. .arg(id)
  136. .arg(txt)
  137. .arg(prevTxt);
  138. }
  139. } noteTextData;
  140. typedef QVector<noteTextData> noteTextVector;
  141. qtauEvent_NoteText(const noteTextVector& changeset, bool forward = true)
  142. : qtauEvent(ENoteEvents::text, forward), text(changeset) {}
  143. const noteTextVector& getText() const {
  144. return text;
  145. }
  146. protected:
  147. noteTextVector text;
  148. qtauEvent_NoteText* allocCopy() const override {
  149. return new qtauEvent_NoteText(*this);
  150. }
  151. };
  152. class qtauEvent_NoteEffect : public qtauEvent {
  153. public:
  154. typedef struct {
  155. quint64 id;
  156. QMap<QString,QString> kv;
  157. QMap<QString,QString> prevKv;
  158. QString toString() const {
  159. return QString("id: %1").arg(id);
  160. }
  161. } noteEffectData;
  162. typedef QVector<noteEffectData> noteEffectVector;
  163. qtauEvent_NoteEffect(const noteEffectVector& changeset, bool forward = true)
  164. : qtauEvent(ENoteEvents::effect, forward), effect(changeset) {}
  165. const noteEffectVector& getEffect() const {
  166. return effect;
  167. }
  168. protected:
  169. noteEffectVector effect;
  170. qtauEvent_NoteEffect* allocCopy() const override {
  171. return new qtauEvent_NoteEffect(*this);
  172. }
  173. };
  174. #endif // NOTEEVENTS_H
  175. // Need INote interface
  176. // UTAUNote
  177. // USTJ format
  178. //