sinsyscoreconverter.cpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. #include "sinsyscoreconverter.h"
  19. #include <QJsonObject>
  20. #include "ustjkeys.h"
  21. #define PPQN (480)
  22. #define INCREMENT(delta) (delta/numerator/PPQN*denominator/4);
  23. SinsyScoreConverter::SinsyScoreConverter() {
  24. pos_pulses = 0;//FIXME
  25. QJsonObject setup;
  26. setup[USER_AGENT] = "QTAU::SinsyScoreConverter";
  27. notes.push_back(setup);
  28. }
  29. bool SinsyScoreConverter::setEncoding(const std::string &encoding) {
  30. (void)encoding;
  31. // only sane encoding is utf8
  32. return true;
  33. }
  34. bool SinsyScoreConverter::addKeyMark(sinsy::ModeType modeType, int fifths) {
  35. (void)modeType;
  36. (void)fifths;
  37. //currently ignored in qtau -- keymap needed for key change events
  38. return true;
  39. }
  40. bool SinsyScoreConverter::addBeatMark(size_t beats, size_t beatType) {
  41. tmap.addTimeSignature(current_measure,beats,beatType);
  42. numerator = beats;
  43. denominator = beatType;
  44. return true;
  45. }
  46. bool SinsyScoreConverter::addTempoMark(double tempo) {
  47. tmap.addTempo(current_measure,tempo);
  48. return true;
  49. }
  50. // untested
  51. bool SinsyScoreConverter::addSuddenDynamicsMark(
  52. sinsy::SuddenDynamicsType suddenDynamicsType) {
  53. // QJsonObject mark;
  54. // mark["suddenDynamicsType"] = (int)suddenDynamicsType;
  55. // ust.push_back(mark);
  56. return true;
  57. }
  58. bool SinsyScoreConverter::addGradualDynamicsMark(
  59. sinsy::GradualDynamicsType gradualDynamicsType) {
  60. //QJsonObject mark;
  61. //mark["gradualDynamicsType"] = (int)gradualDynamicsType;
  62. //ust.push_back(mark);
  63. return true;
  64. }
  65. QString TieType(sinsy::TieType tieType) {
  66. switch (tieType) {
  67. case sinsy::TIETYPE_BEGIN:
  68. return "TIETYPE_BEGIN";
  69. case sinsy::TIETYPE_END:
  70. return "TIETYPE_END";
  71. case sinsy::TIETYPE_NONE:
  72. default:
  73. return "TIETYPE_NONE";
  74. }
  75. }
  76. QString SlurType(sinsy::SlurType slurType) {
  77. switch (slurType) {
  78. case sinsy::SLURTYPE_BEGIN:
  79. return "SLURTYPE_BEGIN";
  80. case sinsy::SLURTYPE_END:
  81. return "SLURTYPE_BEGIN";
  82. case sinsy::SLURTYPE_NONE:
  83. default:
  84. return "SLURTYPE_NONE";
  85. }
  86. }
  87. QString SyllabicType(sinsy::SyllabicType syllabicType) {
  88. switch (syllabicType) {
  89. case sinsy::SYLLABICTYPE_BEGIN:
  90. return "SYLLABICTYPE_BEGIN";
  91. case sinsy::SYLLABICTYPE_END:
  92. return "SYLLABICTYPE_END";
  93. case sinsy::SYLLABICTYPE_MIDDLE:
  94. return "SYLLABICTYPE_MIDDLE";
  95. case sinsy::SYLLABICTYPE_SINGLE:
  96. default:
  97. return "SYLLABICTYPE_SINGLE";
  98. }
  99. }
  100. // FIXME: do not hardcode ppqn
  101. bool SinsyScoreConverter::addNote(
  102. size_t duration, const std::string &lyric, size_t pitch,
  103. bool accent, bool staccato, sinsy::TieType tieType,
  104. sinsy::SlurType slurType, sinsy::SyllabicType syllabicType, bool breath) {
  105. duration /= 2; // sinsy uses a different ppqn than utau
  106. QJsonObject note;
  107. QString tmp = QString::fromStdString(lyric);
  108. if (tmp == "") tmp = "a";
  109. note[NOTE_LYRIC] = tmp;
  110. note[NOTE_PULSE_LENGTH] = (int)duration;
  111. note[NOTE_PULSE_OFFSET] = pos_pulses;
  112. note[NOTE_KEY_NUMBER] = (int)pitch;
  113. note[XML_ACCENT] = accent;
  114. note[XML_STACATTO] = staccato;
  115. note[XML_TIETYPE] = TieType(tieType);
  116. note[XML_SLURTYPE] = SlurType(slurType);
  117. note[XML_SYLLABICTYPE] = SyllabicType(syllabicType);
  118. note[XML_BREATH] = breath;
  119. notes.push_back(note);
  120. pos_pulses += duration;
  121. current_measure += INCREMENT(duration);
  122. return true;
  123. }
  124. bool SinsyScoreConverter::addRest(size_t duration) {
  125. duration /= 2;
  126. //if (pos_pulses == 0) genSetup();
  127. pos_pulses += duration;
  128. current_measure += INCREMENT(duration);
  129. return true;
  130. }
  131. void SinsyScoreConverter::toJSON(QJsonArray& ust)
  132. {
  133. QJsonArray json;
  134. tmap.toJson(json);
  135. QJsonObject obj = notes[0].toObject();
  136. obj.insert(TEMPOMAP,json);
  137. notes[0] = obj;
  138. ust = notes;
  139. }