Skip to content

Commit

Permalink
disting ex channel note ops (#327)
Browse files Browse the repository at this point in the history
* disting ex channel note ops

* fixes

* fix merge conflicts

* clang-format
  • Loading branch information
scanner-darkly authored Aug 29, 2023
1 parent 2779adb commit d1de34e
Show file tree
Hide file tree
Showing 9 changed files with 104 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
- **NEW**: new ops: `CV.CAL` and `CV.CAL.RESET` to calibrate CV outputs
- **FIX**: N.CS scales 7 & 8 were incorrectly swapped; make them consistent with N.S and docs
- **FIX**: libavr32 update: support CDC grid size detection (e.g. zero), increase HID message buffer
- **NEW**: new Disting EX ops: `EX.CH`, `EX.#`, `EX.N#`, `EX.NO#`
- **NEW**: apply VCV Rack compatibility patches, so branches off main can be used in both hardware and software

## v4.0.0
Expand Down
13 changes: 13 additions & 0 deletions docs/ops/disting.toml
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,29 @@ prototype = "EX.VOX.O x"
aliases = ["EX.VO"]
short = "send a note off to voice `x`"

["EX.CH"]
prototype = "EX.CH x"
aliases = ["EX.#"]
short = "select default note channel (for multi channel algorithms like Poly FM)"

["EX.NOTE"]
prototype = "EX.NOTE x y"
aliases = ["EX.N"]
short = "send a note using pitch `x` and velocity `y` (voice allocated by the Disting)"

["EX.N#"]
prototype = "EX.N# x y z"
short = "send a note to channel `x` using pitch `y` and velocity `z` (voice allocated by the Disting)"

["EX.NOTE.O"]
prototype = "EX.NOTE.O x"
aliases = ["EX.NO"]
short = "send a note off using pitch `x`"

["EX.NO#"]
prototype = "EX.NO# x y"
short = "send a note off to channel `x` using pitch `y`"

["EX.ALLOFF"]
prototype = "EX.ALLOFF"
aliases = ["EX.AO"]
Expand Down
1 change: 1 addition & 0 deletions docs/whats_new.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
- **NEW**: new ops: `CV.CAL` and `CV.CAL.RESET` to calibrate CV outputs
- **FIX**: N.CS scales 7 & 8 were incorrectly swapped; make them consistent with N.S and docs
- **FIX**: libavr32 update: support CDC grid size detection (e.g. zero), increase HID message buffer
- **NEW**: new Disting EX ops: `EX.CH`, `EX.#`, `EX.N#`, `EX.NO#`
- **NEW**: apply VCV Rack compatibility patches, so branches off main can be used in both hardware and software

## v4.0.0
Expand Down
9 changes: 8 additions & 1 deletion module/help_mode.c
Original file line number Diff line number Diff line change
Expand Up @@ -1223,7 +1223,7 @@ const char* help15[HELP15_LENGTH] = { "15/17 JUST FRIENDS & W/",
"WS.LOOP X",
" SET LOOP STATE ON/OFF" };

#define HELP16_LENGTH 190
#define HELP16_LENGTH 197
const char* help16[HELP16_LENGTH] = { "16/17 DISTING EX",
"EX",
" GET CURRENT UNIT",
Expand Down Expand Up @@ -1275,12 +1275,19 @@ const char* help16[HELP16_LENGTH] = { "16/17 DISTING EX",
"EX.VOX.O X",
"EX.VO X",
" SEND NOTE OFF TO VOICE",
"EX.CH X",
"EX.# X",
" SELECT CHANNEL",
"EX.NOTE X Y",
"EX.N X Y",
" SEND NOTE",
"EX.N# X Y Z",
" SEND NOTE TO CHANNEL",
"EX.NOTE.O X",
"EX.NO X",
" SEND NOTE OFF",
"EX.NO# X Y",
" SEND NOTE OFF TO CHANNEL",
"EX.ALLOFF",
"EX.AO",
" ALL NOTES OFF",
Expand Down
4 changes: 4 additions & 0 deletions src/match_token.rl
Original file line number Diff line number Diff line change
Expand Up @@ -789,10 +789,14 @@
"EX.V" => { MATCH_OP(E_OP_EX_V); };
"EX.VOX.O" => { MATCH_OP(E_OP_EX_VOX_O); };
"EX.VO" => { MATCH_OP(E_OP_EX_VO); };
"EX.CH" => { MATCH_OP(E_OP_EX_CH); };
"EX.#" => { MATCH_OP(E_OP_EX_POUND); };
"EX.NOTE" => { MATCH_OP(E_OP_EX_NOTE); };
"EX.N" => { MATCH_OP(E_OP_EX_N); };
"EX.N#" => { MATCH_OP(E_OP_EX_N_POUND); };
"EX.NOTE.O" => { MATCH_OP(E_OP_EX_NOTE_O); };
"EX.NO" => { MATCH_OP(E_OP_EX_NO); };
"EX.NO#" => { MATCH_OP(E_OP_EX_NO_POUND); };
"EX.ALLOFF" => { MATCH_OP(E_OP_EX_ALLOFF); };
"EX.AO" => { MATCH_OP(E_OP_EX_AO); };
"EX.T" => { MATCH_OP(E_OP_EX_T); };
Expand Down
79 changes: 68 additions & 11 deletions src/ops/disting.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,18 @@ static void op_EX_VOX_get(const void *data, scene_state_t *ss, exec_state_t *es,
command_state_t *cs);
static void op_EX_VOX_O_get(const void *data, scene_state_t *ss,
exec_state_t *es, command_state_t *cs);
static void op_EX_CH_get(const void *data, scene_state_t *ss, exec_state_t *es,
command_state_t *cs);
static void op_EX_CH_set(const void *data, scene_state_t *ss, exec_state_t *es,
command_state_t *cs);
static void op_EX_NOTE_get(const void *data, scene_state_t *ss,
exec_state_t *es, command_state_t *cs);
static void op_EX_N_POUND_get(const void *data, scene_state_t *ss,
exec_state_t *es, command_state_t *cs);
static void op_EX_NOTE_O_get(const void *data, scene_state_t *ss,
exec_state_t *es, command_state_t *cs);
static void op_EX_NO_POUND_get(const void *data, scene_state_t *ss,
exec_state_t *es, command_state_t *cs);
static void op_EX_ALLOFF_get(const void *data, scene_state_t *ss,
exec_state_t *es, command_state_t *cs);
static void op_EX_T_get(const void *data, scene_state_t *ss, exec_state_t *es,
Expand Down Expand Up @@ -233,12 +241,16 @@ const tele_op_t op_EX_SB_START = MAKE_GET_OP(EX.SB.START, op_EX_SB_START_get,
const tele_op_t op_EX_SB_STOP = MAKE_GET_OP(EX.SB.STOP, op_EX_SB_STOP_get, 0, false);
const tele_op_t op_EX_SB_CONT = MAKE_GET_OP(EX.SB.CONT, op_EX_SB_CONT_get, 0, false);

const tele_op_t op_EX_VOX = MAKE_GET_OP(EX.VOX, op_EX_VOX_get, 3, false);
const tele_op_t op_EX_VOX_P = MAKE_GET_OP(EX.VOX.P, op_EX_VOX_P_get, 2, false);
const tele_op_t op_EX_VOX_O = MAKE_GET_OP(EX.VOX.O, op_EX_VOX_O_get, 1, false);
const tele_op_t op_EX_NOTE = MAKE_GET_OP(EX.NOTE, op_EX_NOTE_get, 2, false);
const tele_op_t op_EX_NOTE_O = MAKE_GET_OP(EX.NOTE.O, op_EX_NOTE_O_get, 1, false);
const tele_op_t op_EX_ALLOFF = MAKE_GET_OP(EX.ALLOFF, op_EX_ALLOFF_get, 0, false);
const tele_op_t op_EX_VOX = MAKE_GET_OP(EX.VOX, op_EX_VOX_get, 3, false);
const tele_op_t op_EX_VOX_P = MAKE_GET_OP(EX.VOX.P, op_EX_VOX_P_get, 2, false);
const tele_op_t op_EX_VOX_O = MAKE_GET_OP(EX.VOX.O, op_EX_VOX_O_get, 1, false);
const tele_op_t op_EX_CH = MAKE_GET_SET_OP(EX.CH, op_EX_CH_get, op_EX_CH_set, 0, true);
const tele_op_t op_EX_POUND = MAKE_ALIAS_OP(EX.#, op_EX_CH_get, op_EX_CH_set, 0, true);
const tele_op_t op_EX_NOTE = MAKE_GET_OP(EX.NOTE, op_EX_NOTE_get, 2, false);
const tele_op_t op_EX_N_POUND = MAKE_GET_OP(EX.N#, op_EX_N_POUND_get, 3, false);
const tele_op_t op_EX_NOTE_O = MAKE_GET_OP(EX.NOTE.O, op_EX_NOTE_O_get, 1, false);
const tele_op_t op_EX_NO_POUND = MAKE_GET_OP(EX.NO#, op_EX_NO_POUND_get, 2, false);
const tele_op_t op_EX_ALLOFF = MAKE_GET_OP(EX.ALLOFF, op_EX_ALLOFF_get, 0, false);

const tele_op_t op_EX_LP_REC = MAKE_GET_OP(EX.LP.REC, op_EX_LP_REC_get, 1, false);
const tele_op_t op_EX_LP_PLAY = MAKE_GET_OP(EX.LP.PLAY, op_EX_LP_PLAY_get, 1, false);
Expand Down Expand Up @@ -285,9 +297,10 @@ const tele_op_t op_EX_TV = MAKE_ALIAS_OP(EX.TV, op_EX_TV_get, NULL, 2, fal
// clang-format on

static u8 unit = 0;
static u8 note_channel = 1;
static u8 midi_channel = 0;
static u8 sb_channel = 0;
static u8 data[4];
static u8 data[5];

static inline void send1(u8 cmd) {
data[0] = cmd;
Expand Down Expand Up @@ -315,6 +328,15 @@ static inline void send4(u8 cmd, u8 b1, u8 b2, u8 b3) {
tele_ii_tx(DISTING_EX_1 + unit, data, 4);
}

static inline void send5(u8 cmd, u8 b1, u8 b2, u8 b3, u8 b4) {
data[0] = cmd;
data[1] = b1;
data[2] = b2;
data[3] = b3;
data[4] = b4;
tele_ii_tx(DISTING_EX_1 + unit, data, 5);
}

static void mod_EX1_func(scene_state_t *ss, exec_state_t *es,
command_state_t *cs,
const tele_command_t *post_command) {
Expand Down Expand Up @@ -695,23 +717,58 @@ static u8 calculate_note(s16 pitch) {
return (u8)note;
}

static void op_EX_CH_get(const void *NOTUSED(data), scene_state_t *ss,
exec_state_t *NOTUSED(es), command_state_t *cs) {
cs_push(cs, note_channel);
}

static void op_EX_CH_set(const void *NOTUSED(data), scene_state_t *ss,
exec_state_t *NOTUSED(es), command_state_t *cs) {
s16 ch = cs_pop(cs);
if (ch < 1 || ch > 16) return;
note_channel = ch;
}

static void op_EX_NOTE_get(const void *NOTUSED(data), scene_state_t *ss,
exec_state_t *NOTUSED(es), command_state_t *cs) {
s16 pitch = cs_pop(cs);
u16 velocity = cs_pop(cs);
u8 note = calculate_note(pitch);

send2(0x56, note);
send4(0x54, note, (u16)pitch >> 8, pitch);
send4(0x55, note, velocity >> 8, velocity);
send3(0x6A, note_channel, note);
send5(0x68, note_channel, note, (u16)pitch >> 8, pitch);
send5(0x69, note_channel, note, velocity >> 8, velocity);
}

static void op_EX_N_POUND_get(const void *NOTUSED(data), scene_state_t *ss,
exec_state_t *NOTUSED(es), command_state_t *cs) {
s16 ch = cs_pop(cs);
s16 pitch = cs_pop(cs);
u16 velocity = cs_pop(cs);
u8 note = calculate_note(pitch);
if (ch < 1 || ch > 16) return;

send3(0x6A, ch, note);
send5(0x68, ch, note, (u16)pitch >> 8, pitch);
send5(0x69, ch, note, velocity >> 8, velocity);
}

static void op_EX_NOTE_O_get(const void *NOTUSED(data), scene_state_t *ss,
exec_state_t *NOTUSED(es), command_state_t *cs) {
u16 pitch = cs_pop(cs);
u8 note = calculate_note(pitch);

send2(0x56, note);
send3(0x6A, note_channel, note);
}

static void op_EX_NO_POUND_get(const void *NOTUSED(data), scene_state_t *ss,
exec_state_t *NOTUSED(es), command_state_t *cs) {
s16 ch = cs_pop(cs);
u16 pitch = cs_pop(cs);
u8 note = calculate_note(pitch);
if (ch < 1 || ch > 16) return;

send3(0x6A, ch, note);
}

static void op_EX_ALLOFF_get(const void *NOTUSED(data), scene_state_t *ss,
Expand Down
4 changes: 4 additions & 0 deletions src/ops/disting.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,14 @@ extern const tele_op_t op_EX_VOX;
extern const tele_op_t op_EX_V;
extern const tele_op_t op_EX_VOX_O;
extern const tele_op_t op_EX_VO;
extern const tele_op_t op_EX_CH;
extern const tele_op_t op_EX_POUND;
extern const tele_op_t op_EX_NOTE;
extern const tele_op_t op_EX_N;
extern const tele_op_t op_EX_N_POUND;
extern const tele_op_t op_EX_NOTE_O;
extern const tele_op_t op_EX_NO;
extern const tele_op_t op_EX_NO_POUND;
extern const tele_op_t op_EX_ALLOFF;
extern const tele_op_t op_EX_AO;
extern const tele_op_t op_EX_T;
Expand Down
2 changes: 1 addition & 1 deletion src/ops/op.c
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ const tele_op_t *tele_ops[E_OP__LENGTH] = {
&op_EX_PV1, &op_EX_PV2, &op_EX_MIN1, &op_EX_MIN2, &op_EX_MAX1, &op_EX_MAX2,
&op_EX_PRE1, &op_EX_PRE2, &op_EX_SAVE1, &op_EX_SAVE2, &op_EX_Z1, &op_EX_Z2,
&op_EX_ZO1, &op_EX_ZO2, &op_EX_M_N_POUND, &op_EX_M_NO_POUND,
&op_EX_M_CC_POUND,
&op_EX_M_CC_POUND, &op_EX_CH, &op_EX_POUND, &op_EX_N_POUND, &op_EX_NO_POUND,

// i2c2midi
&op_I2M_CH, &op_I2M_TIME, &op_I2M_T, &op_I2M_SHIFT, &op_I2M_S, &op_I2M_NOTE,
Expand Down
4 changes: 4 additions & 0 deletions src/ops/op_enum.h
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,10 @@ typedef enum {
E_OP_EX_M_N_POUND,
E_OP_EX_M_NO_POUND,
E_OP_EX_M_CC_POUND,
E_OP_EX_CH,
E_OP_EX_POUND,
E_OP_EX_N_POUND,
E_OP_EX_NO_POUND,
E_OP_I2M_CH,
E_OP_I2M_TIME,
E_OP_I2M_T,
Expand Down

0 comments on commit d1de34e

Please sign in to comment.