score.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #define __devloglevel__ 4
  2. #include "score.h"
  3. #include "ustjkeys.h"
  4. QtauScore::QtauScore(const QJsonArray& ust,TempoMap* tmap)
  5. {
  6. float lastNoteEndTime=0;
  7. for (int i = 0; i < ust.count(); ++i)
  8. {
  9. auto o = ust[i].toObject();
  10. if(!o.contains(NOTE_KEY_NUMBER)) {
  11. continue;
  12. }
  13. synthNote note;
  14. int noteOffset = o[NOTE_PULSE_OFFSET].toInt();
  15. int noteLength = o[NOTE_PULSE_LENGTH].toInt();
  16. QString lyric = o[NOTE_LYRIC].toString();
  17. int pitch = o[NOTE_KEY_NUMBER].toInt();
  18. float timeSt;
  19. float timeEd;
  20. int barSt;
  21. int barEd;
  22. int st = noteOffset;
  23. int ed = noteOffset+noteLength-1;
  24. tmap->getBar(st,timeSt,barSt,0);
  25. tmap->getBar(ed,timeEd,barEd,1);
  26. //int rest = noteOffset-lastNoteEnd;
  27. float rest = timeSt-lastNoteEndTime;
  28. if(rest<0) {
  29. // invalid=true;
  30. break;
  31. }
  32. note.rest = rest;
  33. note.start = timeSt;
  34. note.lenght = timeEd-timeSt;
  35. note.pitch = pitch;
  36. note.lyric = lyric;
  37. lastNoteEndTime = timeEd;
  38. notes.push_back(note);
  39. // noteCount++;
  40. }
  41. }
  42. int QtauScore::getNoteCount()
  43. {
  44. return notes.size();
  45. }
  46. synthNote QtauScore::getNote(int index)
  47. {
  48. return notes[index];
  49. }