Changes to make DPat able to run multiple instances
[SugarCubes.git] / MarkSlee.pde
index 9804b5cf705f026040b663f6e4211ae0fa36d559..3a9b530cc4d44ddef86afe6c4e9b6c311a1fe232 100644 (file)
@@ -391,11 +391,7 @@ public class PianoKeyPattern extends SCPattern {
   
   PianoKeyPattern(GLucose glucose) {
     super(glucose);
-    
-    for (MidiInputDevice input : RWMidi.getInputDevices()) {
-      input.createInput(this);
-    }
-    
+        
     addParameter(attack);
     addParameter(release);
     addParameter(level);
@@ -425,13 +421,15 @@ public class PianoKeyPattern extends SCPattern {
     return base[index % base.length];
   }
     
-  public void noteOnReceived(Note note) {
+  public boolean noteOnReceived(Note note) {
     LinearEnvelope env = getEnvelope(note.getPitch());
     env.setEndVal(min(1, env.getValuef() + (note.getVelocity() / 127.)), getAttackTime()).start();
+    return true;
   }
   
-  public void noteOffReceived(Note note) {
+  public boolean noteOffReceived(Note note) {
     getEnvelope(note.getPitch()).setEndVal(0, getReleaseTime()).start();
+    return true;
   }
   
   public void run(double deltaMs) {
@@ -815,3 +813,44 @@ class ColorFuckerEffect extends SCEffect {
     }
   }
 }
+
+class BlurEffect extends SCEffect {
+  
+  final LXParameter amount = new BasicParameter("AMT", 0);
+  final int[] frame;
+  final LinearEnvelope env = new LinearEnvelope(0, 1, 100);
+  
+  BlurEffect(GLucose glucose) {
+    super(glucose);
+    addParameter(amount);
+    addModulator(env);
+    frame = new int[lx.total];
+    for (int i = 0; i < frame.length; ++i) {
+      frame[i] = #000000;
+    }
+  }
+  
+  public void onEnable() {
+    env.setRangeFromHereTo(1, 400).start();
+    for (int i = 0; i < frame.length; ++i) {
+      frame[i] = #000000;
+    }
+  }
+  
+  public void onDisable() {
+    env.setRangeFromHereTo(0, 1000).start();
+  }
+  
+  public void doApply(int[] colors) {
+    float amt = env.getValuef() * amount.getValuef();
+    if (amt > 0) {    
+      amt = (1 - amt);
+      amt = 1 - (amt*amt*amt);
+      for (int i = 0; i < colors.length; ++i) {
+        // frame[i] = colors[i] = blendColor(colors[i], lerpColor(#000000, frame[i], amt, RGB), SCREEN);
+        frame[i] = colors[i] = lerpColor(colors[i], blendColor(colors[i], frame[i], SCREEN), amt, RGB);
+      }
+    }
+      
+  }  
+}