|
@@ -0,0 +1,104 @@
|
|
|
|
+#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]);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+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
|