From 609aed4a53148b2abf6e480d4d435ed79967e7ad Mon Sep 17 00:00:00 2001 From: Eugene Petkevich Date: Mon, 6 Jun 2022 22:09:19 +0300 Subject: [PATCH] Add button led control --- extensions/classes/midipush.sc | 89 +++++++++++++++---- .../test.scd" | 6 ++ 2 files changed, 80 insertions(+), 15 deletions(-) diff --git a/extensions/classes/midipush.sc b/extensions/classes/midipush.sc index 33a97a5..30f54df 100644 --- a/extensions/classes/midipush.sc +++ b/extensions/classes/midipush.sc @@ -5,7 +5,7 @@ // 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 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 { @@ -242,7 +270,6 @@ MidiPush : MidiHandler { true.while{ midiout.midiClock; (1.0/24).wait; - thisThread.clock.beats.postln; } }.fork(TempoClock.default); } { @@ -263,36 +290,68 @@ MidiPush : MidiHandler { }; } - 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| @@ -320,7 +379,7 @@ MidiPush : MidiHandler { ~col.postln; (0..127).do({|i| ~push.midiout.noteOn(1, i, ~col); - ~push.midiout.control(1, i, ~col); + ~push.midiout.control(0, i, ~col); }); }; ) diff --git "a/\320\245\321\215\320\267\320\270\321\204\321\203/test.scd" "b/\320\245\321\215\320\267\320\270\321\204\321\203/test.scd" index 725331a..4d42332 100644 --- "a/\320\245\321\215\320\267\320\270\321\204\321\203/test.scd" +++ "b/\320\245\321\215\320\267\320\270\321\204\321\203/test.scd" @@ -27,6 +27,12 @@ TempoClock.play({|beats, time, clock| }; ) +~push.ledPad(0, 0, color: -60); +~push.ledPadOff; +~push.ledButlo(2, color: 5, light: 3, mode: 0); +~push.ledButup(2, \off, true, \always); +~push.ledButton(\play, \off); +~push.ledButton(\d14t, \lime, true); //============================================================================= -- 2.17.1