瀏覽代碼

LaunchpadScreen::getColor() implemented

Fabian Peter Hammerle 10 年之前
父節點
當前提交
cfad2ef83a
共有 3 個文件被更改,包括 62 次插入0 次删除
  1. 5 0
      Launchpad.cpp
  2. 1 0
      Launchpad.h
  3. 56 0
      tests/launchpad-screen.cpp

+ 5 - 0
Launchpad.cpp

@@ -191,6 +191,11 @@ 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)) {

+ 1 - 0
Launchpad.h

@@ -66,6 +66,7 @@ public:
 protected:
 	virtual void keyPressed(unsigned char x, unsigned char y);
 	virtual void keyReleased(unsigned char x, unsigned char y);
+	const LaunchpadColor& getColor(unsigned char x, unsigned char y) const;
 	void setColor(unsigned char x, unsigned char y, const LaunchpadColor& color);
 	void setColorAll(const LaunchpadColor& color);
     void sync();

+ 56 - 0
tests/launchpad-screen.cpp

@@ -0,0 +1,56 @@
+#include <iostream>
+#include <cstdlib>
+#include "RtMidi.h"
+#include "MidiMessage.h"
+#include "Launchpad.h"
+
+// Platform-dependent sleep routines.
+#if defined(__WINDOWS_MM__)
+  #include <windows.h>
+  #define SLEEP( milliseconds ) Sleep( (DWORD) milliseconds ) 
+#else // Unix variants
+  #include <unistd.h>
+  #define SLEEP( milliseconds ) usleep( (unsigned long) (milliseconds * 1000.0) )
+#endif
+
+struct DrawScreen : public LaunchpadScreen
+{
+    virtual void keyPressed(unsigned char x, unsigned char y);
+
+    void all(unsigned short a, unsigned short b)
+    {
+        setColorAll(LaunchpadColor(a, b));
+    }
+};
+
+Launchpad l;
+DrawScreen s[8];
+    
+void DrawScreen::keyPressed(unsigned char x, unsigned char y)
+{
+    // std::cout << "(" << (int)x << ", " << (int)y << ")" << std::endl;
+
+    if(y == 8) {
+        std::cout << "switch to screen #" << (int)x << std::endl;
+        disable();
+        s[x].enable();
+    } else {
+        setColor(x, y, LaunchpadColor(3 - getColor(x, y).red, 3 - getColor(x, y).green));
+    }
+}
+
+int main()
+{
+    for(int i=0; i<8; i++) {
+        s[i].setLaunchpad(l);
+        s[i].all(i % 4, (int)((float)i/4));
+    }
+    s[4].enable();
+
+    while(true) 
+    {
+        SLEEP(1);
+    }
+
+    return 0;
+}