sinsyscoreconverter.cpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. void SinsyScoreConverter::genSetup()
  22. {
  23. QJsonObject setup;
  24. setup[TEMPO] = tempo;
  25. ust.push_back(setup);
  26. }
  27. SinsyScoreConverter::SinsyScoreConverter()
  28. {
  29. pos_pulses = 0;
  30. }
  31. bool SinsyScoreConverter::setEncoding(const std::__cxx11::string &encoding)
  32. {
  33. (void) encoding;
  34. //TODO shift jis
  35. return true;
  36. }
  37. bool SinsyScoreConverter::addKeyMark(sinsy::ModeType modeType, int fifths)
  38. {
  39. (void) modeType;
  40. (void) fifths;
  41. return true;
  42. }
  43. bool SinsyScoreConverter::addBeatMark(size_t beats, size_t beatType)
  44. {
  45. (void) beats;
  46. (void) beatType;
  47. return true;
  48. }
  49. bool SinsyScoreConverter::addTempoMark(double tempo)
  50. {
  51. tempo = tempo;
  52. //TODO: handle
  53. return true;
  54. }
  55. //untested
  56. bool SinsyScoreConverter::addSuddenDynamicsMark(sinsy::SuddenDynamicsType suddenDynamicsType)
  57. {
  58. QJsonObject mark;
  59. mark["suddenDynamicsType"] = (int)suddenDynamicsType;
  60. ust.push_back(mark);
  61. return true;
  62. }
  63. bool SinsyScoreConverter::addGradualDynamicsMark(sinsy::GradualDynamicsType gradualDynamicsType)
  64. {
  65. QJsonObject mark;
  66. mark["gradualDynamicsType"] = (int)gradualDynamicsType;
  67. ust.push_back(mark);
  68. return true;
  69. }
  70. QString TieType(sinsy::TieType tieType)
  71. {
  72. switch (tieType) {
  73. case sinsy::TIETYPE_BEGIN: return "TIETYPE_BEGIN";
  74. case sinsy::TIETYPE_END: return "TIETYPE_END";
  75. case sinsy::TIETYPE_NONE:
  76. default:
  77. return "TIETYPE_NONE";
  78. }
  79. }
  80. QString SlurType(sinsy::SlurType slurType)
  81. {
  82. switch (slurType) {
  83. case sinsy::SLURTYPE_BEGIN: return "SLURTYPE_BEGIN";
  84. case sinsy::SLURTYPE_END: return "SLURTYPE_BEGIN";
  85. case sinsy::SLURTYPE_NONE:
  86. default:
  87. return "SLURTYPE_NONE";
  88. }
  89. }
  90. QString SyllabicType(sinsy::SyllabicType syllabicType)
  91. {
  92. switch (syllabicType) {
  93. case sinsy::SYLLABICTYPE_BEGIN: return "SYLLABICTYPE_BEGIN";
  94. case sinsy::SYLLABICTYPE_END: return "SYLLABICTYPE_END";
  95. case sinsy::SYLLABICTYPE_MIDDLE: return "SYLLABICTYPE_MIDDLE";
  96. case sinsy::SYLLABICTYPE_SINGLE:
  97. default:
  98. return "SYLLABICTYPE_SINGLE";
  99. }
  100. }
  101. //FIXME: do not hardcode ppqn
  102. bool SinsyScoreConverter::addNote(size_t duration, const std::__cxx11::string &lyric, size_t pitch, bool accent, bool staccato, sinsy::TieType tieType, sinsy::SlurType slurType, sinsy::SyllabicType syllabicType, bool breath)
  103. {
  104. duration/=2; //sinsy uses a different ppqn than utau
  105. if(pos_pulses==0) genSetup();
  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. ust.push_back(note);
  120. pos_pulses += duration;
  121. return true;
  122. }
  123. bool SinsyScoreConverter::addRest(size_t duration)
  124. {
  125. duration/=2;
  126. if(pos_pulses==0) genSetup();
  127. pos_pulses += duration;
  128. return true;
  129. }