123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- #include "LaunchpadScreen.h"
- #include <string>
- namespace midi {
- void LaunchpadScreen::keyPressed(unsigned char x, unsigned char y)
- {
- }
- void LaunchpadScreen::keyReleased(unsigned char x, unsigned char y)
- {
- }
- const LaunchpadColor& LaunchpadScreen::getColor(unsigned char x, unsigned char y) const
- {
- return colors[x][y];
- }
- void LaunchpadScreen::setColor(unsigned char x, unsigned char y, const LaunchpadColor& color)
- {
- if(active && (!launchpad->issetColor(x, y) || launchpad->getColor(x, y) != color)) {
- launchpad->setColor(x, y, color);
- }
- colors[x][y] = color;
- }
- void LaunchpadScreen::setColorAll(const LaunchpadColor& color)
- {
- for(unsigned char x = 0; x < Launchpad::width; x++) {
- for(unsigned char y = 0; y < Launchpad::height; y++) {
- if(x != 8 || y != 8)
- {
- setColor(x, y, color);
- }
- }
- }
- }
- void LaunchpadScreen::sync()
- {
- for(unsigned char x = 0; x < Launchpad::width; x++) {
- for(unsigned char y = 0; y < Launchpad::height; y++) {
- if((x != 8 || y != 8)
- && (!launchpad->issetColor(x, y) || launchpad->getColor(x, y) != colors[x][y])) {
- launchpad->setColor(x, y, colors[x][y]);
- }
- }
- }
- }
- bool LaunchpadScreen::getKeyPressed(KeyCoordinate x, KeyCoordinate y)
- {
- return enabled() && launchpad->getKeyPressed(x, y);
- }
- LaunchpadScreen::LaunchpadScreen()
- : launchpad(0), active(false)
- {
- }
- void LaunchpadScreen::enable()
- {
- if(!launchpad) {
- throw "no launchpad set";
- }
- launchpad->keyEventCallbackData = (void*)this;
- launchpad->keyPressedCallback = keyPressedCallback;
- launchpad->keyReleasedCallback = keyReleasedCallback;
- sync();
- active = true;
- }
- void LaunchpadScreen::disable()
- {
- launchpad->keyPressedCallback = 0;
- launchpad->keyReleasedCallback = 0;
- launchpad->keyEventCallbackData = 0;
- active = false;
- }
- bool LaunchpadScreen::enabled() const
- {
- return active;
- }
- void LaunchpadScreen::setLaunchpad(Launchpad& l)
- {
- if(enabled()) {
- disable();
- launchpad = &l;
- enable();
- } else {
- launchpad = &l;
- }
- }
- void LaunchpadScreen::keyPressedCallback(unsigned char x, unsigned char y, void* screen)
- {
- ((LaunchpadScreen*)screen)->keyPressed(x, y);
- }
- void LaunchpadScreen::keyReleasedCallback(unsigned char x, unsigned char y, void* screen)
- {
- ((LaunchpadScreen*)screen)->keyReleased(x, y);
- }
- } // namespace
|