Skip to content

Commit

Permalink
FADER.SCALE, FADER.CAL.MIN/MAX, FADER.CAL.RESET (#198)
Browse files Browse the repository at this point in the history
* add faderbank scaling

* use ss_update_fader_scale_all

* docs

* changelog

* remove commented line of code

* clean up help_mode.c
  • Loading branch information
discohead authored Apr 18, 2020
1 parent 3db3954 commit 93eaa26
Show file tree
Hide file tree
Showing 15 changed files with 265 additions and 15 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- **NEW**: new kria remote op: `KR.DUR`
- **NEW**: new op: `NR` (binary math pattern generator)
- **NEW**: new ops: `N.S, N.C, N.CS` (use western scales and chords to get values from `N` table)
- **NEW**: new ops: `FADER.SCALE, FADER.CAL.MIN, FADER.CAL.MAX, FADER.CAL.RESET` for scaling 16n Faderbank values (aliases `FB.S, FB.C.MIN, FB.C.MAX, FB.C.R`)
- **NEW**: new Tracker mode keybinding `alt-[ ]` semitone up, down
- **NEW**: new Tracker mode keybinding `ctrl-[ ]` fifth up, down
- **NEW**: new Tracker mode keybinding `shift-[ ]` octave up, down
Expand Down
32 changes: 31 additions & 1 deletion docs/ops/fader.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,34 @@
["FADER"]
prototype = "FADER x"
aliases = ["FB"]
short = "reads the value of the `FADER` slider `x`; default return range is from 0 to 16383"
short = "reads the value of the `FADER` slider `x`; default return range is from 0 to 16383"

["FADER.SCALE"]
prototype = "FADER.SCALE x y z"
aliases = ["FB.S"]
short = "Set static scaling of the `FADER x` to between `min` and `max`."

["FADER.CAL.MIN"]
prototype = "FADER.CAL.MIN x"
aliases = ["FB.C.MIN"]
short = "Reads `FADER x` minimum position and assigns a zero value"
description = """
1. Slide FADER x all the way down to the bottom
2. Execute `FADER.CAL.MIN x` from the live terminal
3. Call `FADER x` and confirm the 0 result
"""

["FADER.CAL.MAX"]
prototype = "FADER.CAL.MAX x"
aliases = ["FB.C.MAX"]
short = "Reads `FADER x` maximum position and assigns the maximum point"
description = """
1. Slide FADER x all the way up to the top
2. Execute `FADER.CAL.MAX x` from the live terminal
3. Call `FADER x` and verify that the result is 16383
"""

["FADER.CAL.RESET"]
prototype = "FADER.CAL.RESET x"
aliases = ["FB.C.R"]
short = "Resets the calibration for FADER x"
34 changes: 32 additions & 2 deletions module/help_mode.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ const char* help2[HELP2_LENGTH] = { "2/13 VARIABLES",
"Q.AVG|AVERAGE OF ALL Q",
"J, K|UNIQUE PER SCRIPT" };

#define HELP3_LENGTH 30
#define HELP3_LENGTH 60
const char* help3[HELP3_LENGTH] = { "3/13 PARAMETERS",
" ",
"TR A-D|SET TR VALUE (0,1)",
Expand All @@ -117,9 +117,22 @@ const char* help3[HELP3_LENGTH] = { "3/13 PARAMETERS",
"IN|GET IN JACK VAL",
"IN.SCALE X Y",
" SCALE IN RANGE",
"IN.CAL.MIN",
" CALIBRATE IN MIN",
"IN.CAL.MAX",
" CALIBRATE IN MAX",
"IN.CAL.RESET",
" RESET IN CALIBRATION",
" ",
"PARAM|GET KNOB VAL",
"PARAM.SCALE X Y",
" SCALE KNOB RANGE",
"PARAM.CAL.MIN",
" CALIBRATE KNOB MIN",
"PARAM.CAL.MAX",
" CALIBRATE KNOB MAX",
"PARAM.CAL.RESET",
" RESET KNOB CALIBRATION",
" ",
"M|METRO TIME (MS)",
"M.ACT|ENABLE METRO (0/1)",
Expand All @@ -134,7 +147,24 @@ const char* help3[HELP3_LENGTH] = { "3/13 PARAMETERS",
" 1 RISING, 2 FALLING, 3 BOTH",
"SCENE|GET/SET SCENE #",
"SCENE.G|SET SCENE, EXCL GRID",
"LAST N|GET SCRIPT LAST RUN" };
"LAST N|GET SCRIPT LAST RUN",
" ",
"// 16n FADERBANK OPS",
"FADER X",
"FB X",
" GET FADER X VAL",
"FADER.SCALE X Y Z",
"FB.S X Y Z",
" SCALE FADER X RANGE",
"FADER.CAL.MIN X",
"FB.C.MIN X",
" CALIBRATE FADER X MIN"
"FADER.CAL.MAX X",
"FB.C.MAX X",
" CALIBRATE FADER X MAX",
"FADER.CAL.RESET X",
"FB.C.R X",
" RESET FADER X CALIBRATION"};

#define HELP4_LENGTH 73
const char* help4[HELP4_LENGTH] = { "4/13 DATA AND TABLES",
Expand Down
1 change: 1 addition & 0 deletions module/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1023,6 +1023,7 @@ int main(void) {
flash_get_cal(&scene_state.cal);
ss_update_param_scale(&scene_state);
ss_update_in_scale(&scene_state);
ss_update_fader_scale_all(&scene_state);

// load preset from flash
preset_select = flash_last_saved_scene();
Expand Down
8 changes: 8 additions & 0 deletions src/match_token.rl
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,15 @@

# fader
"FADER" => { MATCH_OP(E_OP_FADER); };
"FADER.SCALE" => { MATCH_OP(E_OP_FADER_SCALE); };
"FADER.CAL.MIN" => { MATCH_OP(E_OP_FADER_CAL_MIN); };
"FADER.CAL.MAX" => { MATCH_OP(E_OP_FADER_CAL_MAX); };
"FADER.CAL.RESET" => { MATCH_OP(E_OP_FADER_CAL_RESET); };
"FB" => { MATCH_OP(E_OP_FB); };
"FB.S" => { MATCH_OP(E_OP_FB_S); };
"FB.C.MIN" => { MATCH_OP(E_OP_FB_C_MIN); };
"FB.C.MAX" => { MATCH_OP(E_OP_FB_C_MAX); };
"FB.C.R" => { MATCH_OP(E_OP_FB_C_R); };

# ER301
"SC.TR" => { MATCH_OP(E_OP_SC_TR); };
Expand Down
93 changes: 87 additions & 6 deletions src/ops/fader.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,38 @@
static void op_FADER_get(const void *data, scene_state_t *ss, exec_state_t *es,
command_state_t *cs);

static void op_FADER_SCALE_set(const void *data, scene_state_t *ss, exec_state_t *es,
command_state_t *cs);

static void op_FADER_CAL_MIN_set(const void *data, scene_state_t *ss, exec_state_t *es,
command_state_t *cs);

static void op_FADER_CAL_MAX_set(const void *data, scene_state_t *ss, exec_state_t *es,
command_state_t *cs);

static void op_FADER_CAL_RESET_set(const void *data, scene_state_t *ss, exec_state_t *es,
command_state_t *cs);

const tele_op_t op_FADER = MAKE_GET_OP(FADER, op_FADER_get, 1, true);
const tele_op_t op_FADER_SCALE = MAKE_GET_OP(FADER.SCALE, op_FADER_SCALE_set, 3, false);
const tele_op_t op_FADER_CAL_MIN = MAKE_GET_OP (FADER.CAL.MIN, op_FADER_CAL_MIN_set, 1, true);
const tele_op_t op_FADER_CAL_MAX = MAKE_GET_OP (FADER.CAL.MAX, op_FADER_CAL_MAX_set, 1, true);
const tele_op_t op_FADER_CAL_RESET = MAKE_GET_OP (FADER.CAL.RESET, op_FADER_CAL_RESET_set, 1, false);

const tele_op_t op_FB = MAKE_ALIAS_OP(FB, op_FADER_get, NULL, 1, true);
const tele_op_t op_FB_S = MAKE_ALIAS_OP(FB.S, op_FADER_SCALE_set, NULL, 3, false);
const tele_op_t op_FB_C_MIN = MAKE_ALIAS_OP(FB.C.MIN, op_FADER_CAL_MIN_set, NULL, 1, true);
const tele_op_t op_FB_C_MAX = MAKE_ALIAS_OP(FB.C.MAX, op_FADER_CAL_MAX_set, NULL, 1, true);
const tele_op_t op_FB_C_R = MAKE_ALIAS_OP(FB.C.R, op_FADER_CAL_RESET_set, NULL, 1, false);

static int16_t receive_fader(int16_t input) {
// convert the input to the device and the port
uint8_t port = input % 16;
uint8_t device = input / 16;
uint8_t address = FADER + device;
int16_t value = ReceiveValue(address, port);
return value;
}

static void op_FADER_get(const void *NOTUSED(data), scene_state_t *ss,
exec_state_t *NOTUSED(es), command_state_t *cs) {
Expand All @@ -26,9 +53,63 @@ static void op_FADER_get(const void *NOTUSED(data), scene_state_t *ss,
cs_push(cs, 0);
return;
}
// convert the input to the device and the port
uint8_t port = input % 16;
uint8_t device = input / 16;
uint8_t address = FADER + device;
ReceiveIt(address, port, cs);
}
int16_t value = receive_fader(input);
cs_push(cs, scale_get(ss->variables.fader_scales[input], value));
}

static void op_FADER_SCALE_set(const void *NOTUSED(data), scene_state_t *ss,
exec_state_t *NOTUSED(es), command_state_t *cs) {
int16_t fader = cs_pop(cs);
int16_t min = cs_pop(cs);
int16_t max = cs_pop(cs);
fader -= 1;
if (fader < 0 || fader > 15) {
return;
}
ss_set_fader_scale(ss, fader, min, max);
}

static void op_FADER_CAL_MIN_set(const void *NOTUSED(data), scene_state_t *ss,
exec_state_t *NOTUSED(es),
command_state_t *cs) {
uint16_t input = cs_pop(cs);
// zero-index the input
input -= 1;
// return if out of range
if (input < 0 || input > 15) {
cs_push(cs, 0);
return;
}
int16_t value = receive_fader(input);
ss_set_fader_min(ss, input, value);
cs_push(cs, value);
}

static void op_FADER_CAL_MAX_set(const void *NOTUSED(data), scene_state_t *ss,
exec_state_t *NOTUSED(es),
command_state_t *cs) {
uint16_t input = cs_pop(cs);
// zero-index the input
input -= 1;
// return if out of range
if (input < 0 || input > 15) {
cs_push(cs, 0);
return;
}
int16_t value = receive_fader(input);
ss_set_fader_max(ss, input, value);
cs_push(cs, value);
}

static void op_FADER_CAL_RESET_set(const void *NOTUSED(data), scene_state_t *ss,
exec_state_t *NOTUSED(es),
command_state_t *cs) {
uint16_t fader = cs_pop(cs);
// zero-index the input
fader -= 1;
// return if out of range
if (fader < 0 || fader > 15) {
return;
}
ss_reset_fader_cal(ss, fader);
}
10 changes: 9 additions & 1 deletion src/ops/fader.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@
#include "ops/op.h"

extern const tele_op_t op_FADER;
extern const tele_op_t op_FADER_SCALE;
extern const tele_op_t op_FADER_CAL_MIN;
extern const tele_op_t op_FADER_CAL_MAX;
extern const tele_op_t op_FADER_CAL_RESET;
extern const tele_op_t op_FB;
extern const tele_op_t op_FB_S;
extern const tele_op_t op_FB_C_MIN;
extern const tele_op_t op_FB_C_MAX;
extern const tele_op_t op_FB_C_R;

#endif
#endif
2 changes: 2 additions & 0 deletions src/ops/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ static void op_INIT_get(const void *NOTUSED(data), scene_state_t *ss,
// Once calibration data is loaded, the scales need to be reset
ss_update_param_scale(ss);
ss_update_in_scale(ss);
ss_update_fader_scale_all(ss);

tele_vars_updated();
tele_metro_updated();
Expand All @@ -81,6 +82,7 @@ static void op_INIT_SCENE_get(const void *NOTUSED(data), scene_state_t *ss,
ss->cal = caldata;
ss_update_param_scale(ss);
ss_update_in_scale(ss);
ss_update_fader_scale_all(ss);
tele_vars_updated();
tele_metro_updated();
}
Expand Down
3 changes: 2 additions & 1 deletion src/ops/op.c
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@ const tele_op_t *tele_ops[E_OP__LENGTH] = {
&op_TI_PRM_INIT,

// fader
&op_FADER, &op_FB,
&op_FADER, &op_FADER_SCALE, &op_FADER_CAL_MIN, &op_FADER_CAL_MAX,
&op_FADER_CAL_RESET, &op_FB, &op_FB_S, &op_FB_C_MIN, &op_FB_C_MAX, &op_FB_C_R,

// ER301
&op_SC_TR, &op_SC_TR_TOG, &op_SC_TR_PULSE, &op_SC_TR_TIME, &op_SC_TR_POL,
Expand Down
8 changes: 8 additions & 0 deletions src/ops/op_enum.h
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,15 @@ typedef enum {
E_OP_TI_PRM_MAP,
E_OP_TI_PRM_INIT,
E_OP_FADER,
E_OP_FADER_SCALE,
E_OP_FADER_CAL_MIN,
E_OP_FADER_CAL_MAX,
E_OP_FADER_CAL_RESET,
E_OP_FB,
E_OP_FB_S,
E_OP_FB_C_MIN,
E_OP_FB_C_MAX,
E_OP_FB_C_R,
E_OP_SC_TR,
E_OP_SC_TR_TOG,
E_OP_SC_TR_PULSE,
Expand Down
6 changes: 5 additions & 1 deletion src/ops/telex.c
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,10 @@ void TXDeviceSet(uint8_t model, uint8_t command, command_state_t *cs) {
TXSend(model, command, output, value, true);
}
void ReceiveIt(uint8_t address, uint8_t port, command_state_t *cs) {
int16_t value = ReceiveValue(address, port);
cs_push(cs, value);
}
int16_t ReceiveValue(uint8_t address, uint8_t port) {
// tell the device what value you are going to query
uint8_t buffer[2];
buffer[0] = port;
Expand All @@ -405,7 +409,7 @@ void ReceiveIt(uint8_t address, uint8_t port, command_state_t *cs) {
buffer[1] = 0;
tele_ii_rx(address, buffer, 2);
int16_t value = (buffer[0] << 8) + buffer[1];
cs_push(cs, value);
return value;
}
void TXReceive(uint8_t model, command_state_t *cs, uint8_t mode, bool shift) {
// zero-index the output
Expand Down
3 changes: 2 additions & 1 deletion src/ops/telex.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ void TXSend(uint8_t model, uint8_t command, uint8_t output, int16_t value,
void TXCmd(uint8_t model, uint8_t command, uint8_t output);
void TXSet(uint8_t model, uint8_t command, command_state_t *cs);
void ReceiveIt(uint8_t address, uint8_t port, command_state_t *cs);
int16_t ReceiveValue(uint8_t address, uint8_t port);
void TXDeviceSet(uint8_t model, uint8_t command, command_state_t *cs);
void TXReceive(uint8_t model, command_state_t *cs, uint8_t mode, bool shift);
uint8_t DeviceToOutput(int16_t device);
Expand Down Expand Up @@ -298,4 +299,4 @@ void PRMInit(uint8_t input);
#define TI_STORE 0x22
#define TI_RESET 0x23

#endif
#endif
2 changes: 2 additions & 0 deletions src/scale.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ typedef struct {
SCALE_T p_max;
SCALE_T i_min;
SCALE_T i_max;
SCALE_T f_min[16];
SCALE_T f_max[16];
} cal_data_t;

typedef struct {
Expand Down
Loading

0 comments on commit 93eaa26

Please sign in to comment.