5. Core Commands

Some core commands for programming gestures.

5.1. Begin

Begin: begins a phrase. Takes in duration (in beats) as an argument.

<<funcdefs>>=
void gest_begin(gest_d *g, int beats, int div);

The begin command creates and initializes a new phrase, which then gets appended to the last phrase.

The first phrase to get created becomes the beginning phrase in gest.

<<funcs>>=
void gest_begin(gest_d *g, int beats, int div)
{
    gest_phrase *phrase;

    phrase = gest_alloc(g, sizeof(gest_phrase));
    phrase_init(g, phrase, beats, div);

    if (g->phrase_top == NULL) {
        g->phrase_top = phrase;
    }

<<append_metaphrase>>

    if (g->phrase_selected != NULL) {
        g->phrase_selected->next = phrase;
    }

    g->phrase_selected = phrase;

    /* TODO make this a targetondeck flag */
    set_curnode(g, g->phrase_selected->top);
}

5.2. End

End: closes out the phrase. If the phrase isn't fully completed a non-zero value is returned.

<<funcdefs>>=
int gest_end(gest_d *g);

Error checking is done by examining the top-level polyramp in the currently selected phrase. A completed phrase will have every child node capped with a target.

<<funcs>>=
int gest_end(gest_d *g)
{
    int count;
    gest_node *top;

    top = g->phrase_selected->top;

    count = node_count(top, NULL);

    if (count != top->modifier) return 1;

<<metaphrase_next_position>>
    return 0;
}

5.3. Polyramp

Polyramp: Takes the current ramp, and divides it up into N beats.

<<funcdefs>>=
int gest_polyramp(gest_d *g, int div);

When a new polyramp node is made, it's node becomes the actively selected node to be populated. If something goes wrong, an non-zero error value is returned/

<<funcs>>=
int gest_polyramp(gest_d *g, int div)
{
    gest_node *n;

    n = mkpolyramp(g, g->curnode, div);

    if (n == NULL) {
        return 1;
    }

    set_curnode(g, n);

    return 0;
}

5.4. Monoramp

Monoramp: Produces a monoramp that takes up N beats.

<<funcdefs>>=
int gest_monoramp(gest_d *g, int nbeats);
<<funcs>>=
int gest_monoramp(gest_d *g, int nbeats)
{
    gest_node *n;

    n = mkmonoramp(g, g->curnode, nbeats);

    if (n == NULL) {
        return 1;
    }

    set_curnode(g, n);

    return 0;
}

5.5. Addtarget

Target: Caps the current ramp with a scalar target, as a floating point value. uses linear behavior by default.

<<funcdefs>>=
int gest_addtarget(gest_d *g, SKFLT val);
<<funcs>>=
int gest_addtarget(gest_d *g, SKFLT val)
{
    gest_target *t;

    t = mktarget(g);

    if (t == NULL) {
        return 1;
    }

    if (g->toptarget == NULL) {
        g->toptarget = t;
    }

    if (g->curtarget != NULL) {
        g->curtarget->next = t;
    }

    g->curtarget = t;
    t->value = val;
    gest_behavior_linear(g);

    return 0;
}

5.6. Finish

The finish command gest_finish completes population and initializes gest to start at the top.

<<funcdefs>>=
void gest_finish(gest_d *g);
<<funcs>>=
void gest_finish(gest_d *g)
{
    gest_node *top;
    gest_target *target;

    g->den = 1;
    g->num = 1;

    g->phrase_selected = g->phrase_top;

    top = dive_to_target(g, g->phrase_top->top);

    set_curnode(g, top);
    target = node_target(g, top);
    target->curbehavior = target_behavior(g, target);
    set_curtarget(g, target, 0);

    init_state(&g->nxtstate);
    find_next_node(g, g->curnode, &g->nxtstate);
    g->nxttarget = g->nxtstate.target;

    if (g->nxttarget != NULL) {
        g->nxtval = g->nxttarget->value;
    } else {
        g->nxtval = g->curval;
    }
}

5.7. Loopit

The command gest_loopit will loop the current phrase back to the beginning phrase.

<<funcdefs>>=
void gest_loopit(gest_d *g);
<<funcs>>=
void gest_loopit(gest_d *g)
{
    g->curtarget->next = g->toptarget;
    g->phrase_selected->next = g->phrase_top;
<<metaphrase_loopit>>
}



prev | home | next