Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
New Op: MSPB (milliseconds per beat)
Loading branch information
Showing
6 changed files
with
22 additions
and
1 deletion .
+4
−0
docs/ops/maths.toml
+2
−1
src/match_token.rl
+13
−0
src/ops/maths.c
+1
−0
src/ops/maths.h
+1
−0
src/ops/op.c
+1
−0
src/ops/op_enum.h
@@ -161,6 +161,10 @@ For more info, see the post on [samdoshi.com][samdoshi_com_euclidean]
[^euclidean_rhythm_citation]: Toussaint, G. T. (2005, July). The Euclidean algorithm generates traditional musical rhythms. _In Proceedings of BRIDGES: Mathematical Connections in Art, Music and Science_ (pp. 47-56).
"""
[MSPB ]
prototype = " MSPB x"
short = " milliseconds per beat in BPM `x`"
[N ]
prototype = " N x"
short = " converts an equal temperament note number to a value usable by the CV outputs (`x` in the range `-127` to `127`)"
@@ -1,5 +1,5 @@
#include "match_token.h"
#
#include <ctype.h> // isdigit
#include <stdlib.h> // rand, strtol
@@ -133,6 +133,7 @@
"V" => { MATCH_OP(E_OP_V); };
"VV" => { MATCH_OP(E_OP_VV); };
"ER" => { MATCH_OP(E_OP_ER); };
"MSPB" => { MATCH_OP(E_OP_MSPB);; };
"XOR" => { MATCH_OP(E_OP_XOR); };
"+" => { MATCH_OP(E_OP_SYM_PLUS); };
"-" => { MATCH_OP(E_OP_SYM_DASH); };
@@ -74,6 +74,8 @@ static void op_VV_get(const void *data, scene_state_t *ss, exec_state_t *es,
command_state_t *cs);
static void op_ER_get (const void *data, scene_state_t *ss, exec_state_t *es,
command_state_t *cs);
static void op_MSPB_get (const void *data, scene_state_t *ss, exec_state_t *es,
command_state_t *cs);
// clang-format off
@@ -111,6 +113,7 @@ const tele_op_t op_N = MAKE_GET_OP(N , op_N_get , 1, true);
const tele_op_t op_V = MAKE_GET_OP(V , op_V_get , 1 , true );
const tele_op_t op_VV = MAKE_GET_OP(VV , op_VV_get , 1 , true );
const tele_op_t op_ER = MAKE_GET_OP(ER , op_ER_get , 3 , true );
const tele_op_t op_MSPB = MAKE_GET_OP(MSPB , op_MSPB_get , 1 , true );
const tele_op_t op_XOR = MAKE_ALIAS_OP(XOR, op_NE_get, NULL , 2 , true );
@@ -454,3 +457,13 @@ static void op_ER_get(const void *NOTUSED(data), scene_state_t *NOTUSED(ss),
int16_t step = cs_pop (cs);
cs_push (cs, euclidean (fill, len, step));
}
static void op_MSPB_get (const void *NOTUSED (data), scene_state_t *NOTUSED(ss),
exec_state_t *NOTUSED(es), command_state_t *cs) {
int16_t a = cs_pop (cs);
uint32_t ret;
if (a < 2 ) a = 2 ;
if (a > 1000 ) a = 1000 ;
ret = ((((uint32_t )(1 << 31 )) / ((a << 20 ) / 60 )) * 1000 ) >> 11 ;
cs_push (cs, (int16_t )ret);
}
@@ -37,6 +37,7 @@ extern const tele_op_t op_N;
extern const tele_op_t op_V;
extern const tele_op_t op_VV;
extern const tele_op_t op_ER;
extern const tele_op_t op_MSPB;
extern const tele_op_t op_XOR; // XOR alias NE
@@ -57,6 +57,7 @@ const tele_op_t *tele_ops[E_OP__LENGTH] = {
&op_MIN, &op_MAX, &op_LIM, &op_WRAP, &op_QT, &op_AVG, &op_EQ, &op_NE,
&op_LT, &op_GT, &op_LTE, &op_GTE, &op_NZ, &op_EZ, &op_RSH, &op_LSH, &op_EXP,
&op_ABS, &op_AND, &op_OR, &op_JI, &op_SCALE, &op_N, &op_V, &op_VV, &op_ER,
&op_MSPB,
&op_XOR, &op_SYM_PLUS, &op_SYM_DASH, &op_SYM_STAR, &op_SYM_FORWARD_SLASH,
&op_SYM_PERCENTAGE, &op_SYM_EQUAL_x2, &op_SYM_EXCLAMATION_EQUAL,
&op_SYM_LEFT_ANGLED, &op_SYM_RIGHT_ANGLED, &op_SYM_LEFT_ANGLED_EQUAL,
@@ -110,6 +110,7 @@ typedef enum {
E_OP_V,
E_OP_VV,
E_OP_ER,
E_OP_MSPB,
E_OP_XOR,
E_OP_SYM_PLUS,
E_OP_SYM_DASH,
Toggle all file notes