launchpad-screen.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include "RtMidi.h"
  4. #include "MidiMessage.h"
  5. #include "Launchpad.h"
  6. // Platform-dependent sleep routines.
  7. #if defined(__WINDOWS_MM__)
  8. #include <windows.h>
  9. #define SLEEP( milliseconds ) Sleep( (DWORD) milliseconds )
  10. #else // Unix variants
  11. #include <unistd.h>
  12. #define SLEEP( milliseconds ) usleep( (unsigned long) (milliseconds * 1000.0) )
  13. #endif
  14. struct DrawScreen : public LaunchpadScreen
  15. {
  16. virtual void keyPressed(unsigned char x, unsigned char y);
  17. void all(unsigned short a, unsigned short b)
  18. {
  19. setColorAll(LaunchpadColor(a, b));
  20. }
  21. };
  22. Launchpad l;
  23. DrawScreen s[8];
  24. void DrawScreen::keyPressed(unsigned char x, unsigned char y)
  25. {
  26. // std::cout << "(" << (int)x << ", " << (int)y << ")" << std::endl;
  27. if(y == 8) {
  28. std::cout << "switch to screen #" << (int)x << std::endl;
  29. disable();
  30. s[x].enable();
  31. } else {
  32. setColor(x, y, LaunchpadColor(3 - getColor(x, y).red, 3 - getColor(x, y).green));
  33. }
  34. }
  35. int main()
  36. {
  37. for(int i=0; i<8; i++) {
  38. s[i].setLaunchpad(l);
  39. s[i].all(i % 4, (int)((float)i/4));
  40. }
  41. s[4].enable();
  42. while(true)
  43. {
  44. SLEEP(1);
  45. }
  46. return 0;
  47. }