MMLPlayer.h 878 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #pragma once
  2. #include <stdint.h>
  3. #include <stdlib.h>
  4. class MMLPlayer {
  5. public:
  6. void update();
  7. void play(const char* string);
  8. void stop();
  9. private:
  10. bool _playing;
  11. uint32_t _note_duration_us;
  12. uint32_t _note_start_us;
  13. const char* _string;
  14. uint8_t _tempo;
  15. uint8_t _default_note_length;
  16. uint8_t _volume;
  17. size_t _next;
  18. uint8_t _octave;
  19. float _silence_duration;
  20. bool _repeat;
  21. enum node_mode_t {
  22. MODE_NORMAL,
  23. MODE_LEGATO,
  24. MODE_STACCATO
  25. } _note_mode;
  26. void start_silence(float duration);
  27. void start_note(float duration, float frequency, float volume);
  28. char next_char();
  29. uint8_t next_number();
  30. size_t next_dots();
  31. float rest_duration(uint32_t rest_length, uint8_t dots);
  32. // Called when the MML player should start the next action
  33. void next_action();
  34. };