Launchpad.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #pragma once
  2. #include "Input.h"
  3. #include "Output.h"
  4. #include "LaunchpadColor.h"
  5. #include <utility>
  6. #include <atomic>
  7. namespace midi {
  8. class Launchpad
  9. {
  10. public:
  11. typedef unsigned char KeyCoordinate;
  12. typedef void (*KeyEventCallback)(unsigned char x, unsigned char y, void* data);
  13. static const unsigned char width = 9;
  14. static const unsigned char height = 9;
  15. private:
  16. LaunchpadColor colors[width][height];
  17. bool colorSet[width][height];
  18. std::atomic<bool> keyBeingPressed[width][height];
  19. protected:
  20. Input midiin;
  21. Output midiout;
  22. public:
  23. KeyEventCallback keyPressedCallback;
  24. KeyEventCallback keyReleasedCallback;
  25. void* keyEventCallbackData;
  26. Launchpad();
  27. bool issetColor(unsigned char x, unsigned char y) const;
  28. const LaunchpadColor& getColor(unsigned char x, unsigned char y) const;
  29. void setColor(unsigned char x, unsigned char y, const LaunchpadColor& color);
  30. void setColorAll(const LaunchpadColor& color);
  31. bool getKeyPressed(KeyCoordinate x, KeyCoordinate y);
  32. protected:
  33. void keyPressed(unsigned char x, unsigned char y);
  34. void keyReleased(unsigned char x, unsigned char y);
  35. private:
  36. static void midiMessageCallback(double timeStamp, Message &message, void *launchpad);
  37. void setKeyPressed(KeyCoordinate x, KeyCoordinate y, bool pressed);
  38. };
  39. };