ustfile.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #include "ustfile.h"
  2. #include "Utils.h"
  3. #include "ustjkeys.h"
  4. #include "tempomap.h"
  5. #define __devloglevel__ 4
  6. USTFile::USTFile() {}
  7. void USTFile::handleKey(QString key, QString value) {
  8. (void)key;
  9. (void)value;
  10. if (_isSetting) {
  11. if (key == "Tempo") _tempo = QVariant(value).toFloat();
  12. }
  13. // Tempo : default value = 120.00
  14. if (_isNote) {
  15. if (key == "Length") {
  16. int duration = QVariant(value).toInt();
  17. _note[NOTE_PULSE_LENGTH] = duration;
  18. _note[NOTE_PULSE_OFFSET] = _posPulses;
  19. _posPulses += duration;
  20. } else if (key == "Lyric")
  21. _note[NOTE_LYRIC] = value;
  22. else if (key == "NoteNum")
  23. _note[NOTE_KEY_NUMBER] = QVariant(value).toInt();
  24. else if (key == "Intensity")
  25. _note[NOTE_INTENSITY] = QVariant(value).toInt();
  26. else if (key == "Modulation")
  27. _note[NOTE_MODULATION] = QVariant(value).toInt();
  28. else
  29. _note["UST:" + key] = value;
  30. }
  31. // notes:
  32. // Length value:480
  33. // Lyric value:do
  34. // NoteNum value:60
  35. // Intensity value:100
  36. // Modulation value:0
  37. }
  38. void USTFile::genSetup() {
  39. QJsonObject setup;
  40. TempoMap tmap;
  41. QJsonArray json;
  42. tmap.addTempo(0,_tempo);
  43. tmap.addTimeSignature(0,4,4);
  44. tmap.toJson(json);
  45. setup[TEMPOMAP] = json;
  46. setup[USER_AGENT] = "QTAU::USTFile";
  47. _ust.push_back(setup);
  48. }
  49. void USTFile::handleSection(QString section) {
  50. if (_isSetting) {
  51. DEVLOG_DEBUG("genSetup");
  52. genSetup();
  53. }
  54. if (_isNote && _note[NOTE_LYRIC] != "R") {
  55. if (_note[NOTE_LYRIC] == "") _note[NOTE_LYRIC] = "a";
  56. // do not add rests
  57. _ust.push_back(_note);
  58. }
  59. if (section == "#SETTING") {
  60. _noteCounter = -1;
  61. _isSetting = true;
  62. }
  63. QString number = QString("#%1").arg(_noteCounter, 4, 10, QChar('0'));
  64. _isNote = (number == section);
  65. _noteCounter++;
  66. if (_isNote) _isSetting = false;
  67. }
  68. bool USTFile::writeOutputToStream() {
  69. return false;
  70. }