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.

41 lines
1.1KB

  1. #pragma once
  2. class MidiEditorContext;
  3. #include "MidiEvent.h"
  4. /**
  5. * This class know how to map between pitch, time, and screen coordinates.
  6. * notes on the screen have:
  7. * height in pixels - determined by vertical zoom
  8. * width in pixels - determined by duration and horizontal zoom
  9. * x position where the note starts.
  10. * y position of the upper edge of the notes.
  11. *
  12. * Coordinate conventions:
  13. * if viewport hi and low pitches are the same, it maps a note of that pitch to full screen.
  14. * y==0 it the top edge, increasing y goes down the screen
  15. */
  16. class NoteScreenScale
  17. {
  18. public:
  19. NoteScreenScale(std::shared_ptr<MidiEditorContext> vp, float screenWidth, float screenHeight);
  20. float midiTimeToX(const MidiEvent& ev);
  21. float midiTimeToX(MidiEvent::time_t ev);
  22. float midiTimeTodX(MidiEvent::time_t dt);
  23. std::pair<float, float> midiTimeToHBounds(const MidiNoteEvent& note);
  24. float midiPitchToY(const MidiNoteEvent& note);
  25. float midiCvToY(float cv);
  26. float noteHeight();
  27. private:
  28. float ax = 0;
  29. float ay = 0;
  30. std::shared_ptr<MidiEditorContext> viewport;
  31. };