prop

Files: prop.h, prop.c

Simple rhythmic notation gate generator
Creates a gate using a simple rhythmic notation system called prop. When it reaches the end of the prop string, it will loop back to the beginning.
Prop has a few basic rules:
1. A '+' denotes a on. A '-' denotes an off (rest). They each have an equal duration of a quarter note.
2. On and off values can be strung together to create equally spaced gates: +-+--
3. When notes are enclosed in parantheses '()' following a positive integer N, their duration is reduced N times: ++2(+-)
4. When notes are enclosed in brackets '[]' following a positive integer N, their duration is scaled by a factor of N: ++2[++]
5. Parenthesis and brackets can be nested: +- 2[3(+2(++)+)]2(++)

Functions

sp_prop_create(sp_prop **prop)
sp_prop_init(sp_data *sp, sp_prop *prop, const char *str)
sp_prop_compute(sp_data *sp, sp_prop *prop, SPFLOAT *dummy, SPFLOAT *out)
sp_prop_destroy(sp_prop **prop)

Mandatory Parameters

str: Prop string to be parsed.
(Recommended value: N/A)

Optional Parameters

bpm: Beats per minute of the prop string.
(Default value: 60)

Outputs

out: Gate output.

Other Functions:

sp_prop_reset(sp_data *sp, sp_prop *prop)
Resets prop back to starting position.

Example Code

#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include "soundpipe.h"

typedef struct {
    sp_prop *prop;
    sp_osc *osc;
    sp_ftbl *ft;
    sp_tenv *tenv;
} UserData;

void process(sp_data *sp, void *udata) {
    UserData *ud = udata;
    SPFLOAT osc = 0, prop = 0, tenv = 0;
    sp_osc_compute(sp, ud->osc, NULL, &osc);
    sp_prop_compute(sp, ud->prop, NULL, &prop);
    sp_tenv_compute(sp, ud->tenv, &prop, &tenv);
    sp->out[0] = osc * tenv;
}

int main() {
    UserData ud;
    sp_data *sp;
    sp_create(&sp);
    sp_srand(sp, 123345);

    sp_prop_create(&ud.prop);
    sp_osc_create(&ud.osc);
    sp_ftbl_create(sp, &ud.ft, 2048);
    sp_tenv_create(&ud.tenv);

    sp_prop_init(sp, ud.prop, "2(+{3(+++)|+}){4(+?+?)|+|-}");
    ud.prop->bpm = 80;
    sp_gen_sine(sp, ud.ft);
    sp_osc_init(sp, ud.osc, ud.ft, 0);
    sp_tenv_init(sp, ud.tenv);
    ud.tenv->atk = 0.003;
    ud.tenv->hold = 0.001;
    ud.tenv->rel =  0.2;

    ud.osc->freq = 500;

    sp->len = 44100 * 20;
    sp_process(sp, &ud, process);

    sp_prop_destroy(&ud.prop);
    sp_ftbl_destroy(&ud.ft);
    sp_osc_destroy(&ud.osc);
    sp_tenv_destroy(&ud.tenv);

    sp_destroy(&sp);
    return 0;
}