|
| 1 | +desc: APC Pad Blinker (Sync to Transport) |
| 2 | +author: tomaszpio |
| 3 | +version: 1.0.0 |
| 4 | +about: |
| 5 | + APC Mini mk2: blink a chosen pad LED **once per quarter note** while the DAW is **playing**. |
| 6 | + - Output is via **Note On velocity** (single-color LED). |
| 7 | + - Tempo comes from host `tempo` (falls back to 120 BPM). |
| 8 | + - Uses pad note numbers (APC pads are typically 0–63; script slider allows up to 77). |
| 9 | + |
| 10 | + Sliders: |
| 11 | + 1) Pad MIDI Note (0–77) — which pad to blink |
| 12 | + 2) Enable Blinking (Off/On) |
| 13 | + 3) Pad Color (0–127) — velocity used when LED is ON |
| 14 | + |
| 15 | + MIDI out (LED): status `0x96` (Note On, ch. 7), data1 = pad note, data2 = color or 0. |
| 16 | + |
| 17 | +slider1:0<0,77,1>Pad MIDI Note (0-63) |
| 18 | +slider2:1<0,1,1{Off,On}>Enable Blinking |
| 19 | +slider3:3<0,127,1>Pad Color (0-127) |
| 20 | + |
| 21 | +@init |
| 22 | +note = 0; |
| 23 | +interval = 0.5; // seconds per beat (updated from tempo) |
| 24 | +beat_timer = 0.0; |
| 25 | +is_on = 0; // LED state toggle |
| 26 | +should_blink = 1; // from slider2 |
| 27 | +play_state = 0; // host transport state (read by JSFX) |
| 28 | +color = 0; // from slider3 |
| 29 | + |
| 30 | +@slider |
| 31 | +note = slider1; |
| 32 | +should_blink = slider2; |
| 33 | +color = slider3; |
| 34 | + |
| 35 | +@block |
| 36 | +// Read host tempo (BPM); use 120 if unavailable |
| 37 | +tempo = tempo > 0 ? tempo : 120; |
| 38 | +interval = 60 / tempo; // quarter-note period |
| 39 | + |
| 40 | +// `play_state` is provided by host (nonzero when playing/recording) |
| 41 | + |
| 42 | +@sample |
| 43 | +beat_timer += 1 / srate; |
| 44 | + |
| 45 | +velocity = 0; |
| 46 | + |
| 47 | +// Blink only when transport is active and blinking is enabled |
| 48 | +(play_state ? ( |
| 49 | + should_blink == 1 ? ( |
| 50 | + beat_timer >= interval ? ( |
| 51 | + beat_timer -= interval; |
| 52 | + is_on = is_on == 0 ? 1 : 0; |
| 53 | + velocity = is_on ? color : 0; |
| 54 | + midisend(0, 0x96, note, velocity); // Note On LED update (ch. 7) |
| 55 | + ); |
| 56 | + ); |
| 57 | +) : 0); |
0 commit comments