You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.5KB

  1. #include "NoteScreenScale.h"
  2. #include "MidiEditorContext.h"
  3. NoteScreenScale::NoteScreenScale(MidiEditorContextPtr vp, float screenWidth, float screenHeight) : viewport(vp)
  4. {
  5. assert(screenWidth > 0);
  6. assert(screenHeight > 0);
  7. viewport->assertValid();
  8. ax = screenWidth / (viewport->endTime() - viewport->startTime());
  9. // min and max the same is fine - it's just one note bar full screen
  10. float dbg = ((viewport->pitchHi() + 1 / 12.f) - viewport->pitchLow());
  11. ay = screenHeight / ((viewport->pitchHi() + 1 / 12.f) - viewport->pitchLow());
  12. //printf("in init ax=%f ay=%f screenx=%f screeny=%f\n", ax, ay, screenWidth, screenHeight);
  13. //fflush(stdout);
  14. }
  15. float NoteScreenScale::midiTimeToX(const MidiEvent& ev)
  16. {
  17. return midiTimeToX(ev.startTime);
  18. }
  19. float NoteScreenScale::midiTimeToX(MidiEvent::time_t t)
  20. {
  21. return (t - viewport->startTime()) * ax;
  22. }
  23. float NoteScreenScale::midiTimeTodX(MidiEvent::time_t dt)
  24. {
  25. return dt * ax;
  26. }
  27. float NoteScreenScale::midiPitchToY(const MidiNoteEvent& note)
  28. {
  29. return (viewport->pitchHi() - note.pitchCV) * ay;
  30. }
  31. float NoteScreenScale::midiCvToY(float cv)
  32. {
  33. return (viewport->pitchHi() - cv) * ay;
  34. }
  35. float NoteScreenScale::noteHeight()
  36. {
  37. return (1 / 12.f) * ay;
  38. }
  39. std::pair<float, float> NoteScreenScale::midiTimeToHBounds(const MidiNoteEvent& note)
  40. {
  41. float x = (note.startTime - viewport->startTime()) * ax;
  42. float y = (note.startTime + note.duration - viewport->startTime()) * ax;
  43. return std::pair<float, float>(x, y);
  44. }