// https://github.com/Ableton/push-interface/blob/master/doc/AbletonPush2MIDIDisplayInterface.asc
MidiPush : MidiHandler {
- classvar buttonControls, padColors, padModes;
+ classvar buttonControls, padColors, padModes, butColors, butModes;
var <>but, <>press, <>pad, <>bend, <>rotLeft, <>rotRight, <>rot, <>butup, <>butlo;
var <>touchBend, <>touchRotLeft, <>touchRotRight, <>touchRot;
var <tempo=1, <syncTempo=false, prTickPlayer;
\blinkBeat -> 14,
\blink2th -> 15,
];
+
+ butColors = IdentityDictionary[
+ \off -> 0,
+ \dim -> -1,
+ \dimBlink2th -> -2,
+ \dimBlinkSlow -> -2,
+ \dimBlink4th -> -3,
+ \dimBlinkBeat -> -3,
+ \dimBlinkFast -> -3,
+ \dimBlink -> -3,
+ \bright -> -4,
+ \brightBlink2th -> -5,
+ \brightBlinkSlow -> -5,
+ \brightBlink4th -> -6,
+ \brightBlinkBeat -> -6,
+ \brightBlinkFast -> -6,
+ \brightBlink -> -6,
+ \red -> 1,
+ \amber -> 7,
+ \yellow -> 13,
+ \lime -> 19,
+ ];
+
+ butModes = IdentityDictionary[
+ \always -> 0,
+ \slow -> 1,
+ \fast -> 2,
+ ];
}
controlInit {
true.while{
midiout.midiClock;
(1.0/24).wait;
- thisThread.clock.beats.postln;
}
}.fork(TempoClock.default);
} {
};
}
- calcColor {|c=0, l=3, m=false|
+ calcPadColor {|c=0, l=3|
var color;
+ if (c==\off) {^0};
c = padColors[c] ? c;
- if (c > 60) {^c};
+ if (c < 0) {^c.neg};
if (c == 0, {
color = l;
},{
if (l == 0, {
color = 0;
}, {
- if (m, {
- color = c*4;
- }, {
- color = c*4 + 4 - l;
- });
+ color = c*4 + 4 - l;
});
});
^color;
}
- // 3 arguments version only works for the colors 0..14
- // c is color number, l is lightness from 0 to 3, m is whether blended color should be used
- // for colors 61..127 use one argument with color number
- ledPad {|row, col, light=3, color=0, mix=false, mode=1|
+ // 2 arguments version only works for the colors 0..14
+ // c is color number, l is lightness from 0 to 3
+ // for colors (4, 8..60) and (61..127) use one argument with color number negated
+ ledPad {|row, col, light=3, color=0, mode=1|
mode = padModes[mode] ? mode;
if ((col < 0) || (col > 7) || (row < 0) || (row > 7), {}, {
- midiout.noteOn(mode, 36+(row*8)+col, this.calcColor(color, light, mix));
+ midiout.noteOn(mode, 36+(row*8)+col, this.calcPadColor(color, light));
+ });
+ }
+
+ ledButlo {|col, light=3, color=0, mode=1|
+ mode = padModes[mode] ? mode;
+ if ((col < 0) || (col > 7), {}, {
+ midiout.control(mode, 102+col, this.calcPadColor(color, light));
});
}
+ ledButup {|col, color=\red, bright=true, mode=\always|
+ mode = butModes[mode] ? mode;
+ color = butColors[color] ? color;
+ if (color > 0) {
+ if (bright) {color = color + 3};
+ color = color + mode;
+ } {
+ color = color.neg;
+ };
+ if ((col < 0) || (col > 7), {}, {
+ midiout.control(mode, 20+col, color);
+ });
+ }
+
+ // 4 colors and bright/mode are only available for upper button row and right buttons next to pads
+ // for other buttons just use color with one of negative constants
+ ledButton {|buttonName, color=\red, bright=true, mode=\always|
+ mode = butModes[mode] ? mode;
+ color = butColors[color] ? color;
+ if (color > 1) {
+ if (bright) {color = color + 3};
+ color = color + mode;
+ } {
+ color = color.neg;
+ };
+ midiout.control(mode, buttonControls.findKeyForValue(buttonName), color);
+ }
+
ledPadOff {
for (0, 7, {|i|
for (0, 7, {|j|
~col.postln;
(0..127).do({|i|
~push.midiout.noteOn(1, i, ~col);
- ~push.midiout.control(1, i, ~col);
+ ~push.midiout.control(0, i, ~col);
});
};
)