Skip to content

Commit

Permalink
allow sharing the left-hand side of rules
Browse files Browse the repository at this point in the history
This allows to abbreviate a collection of rules where the same OSC message is
mapped to different MIDI messages. E.g.,

    /multi/{i} ff, touch,x,y : controlchange( channel, touch, x*127);
    /multi/{i} ff, touch,x,y : controlchange( channel, touch+10, y*127);

may now be written as:

    /multi/{i} ff, touch,x,y : controlchange( channel, touch, x*127);
    : controlchange( channel, touch+10, y*127);

Note that the latter simply gets expanded to the former. There's no change in
semantics (except that an OSC message path can't start with a colon any
longer, but that's rather unlikely anyway).
  • Loading branch information
agraef committed Jun 30, 2015
1 parent 308b45b commit ee3ec6b
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void init_regs(float ***regs, int n)
int load_map(CONVERTER* conv, char* file)
{
int i;
char path[200],line[400],*home;
char path[200],line[400],prefix[400],*home;
FILE* map = NULL;
FILE* tmp = NULL;
PAIRHANDLE *p;
Expand Down Expand Up @@ -156,12 +156,39 @@ int load_map(CONVERTER* conv, char* file)
int nkeys = 0;
rewind(map);
i=0;
*prefix = 0;
while(!feof(map))
{
char rule[800];
if (!fgets(line,400,map)) break;
if(!is_empty(line))
{
p[i] = alloc_pair(line, conv->tab, conv->registers, &nkeys);
// This provides a quick and dirty way to left-factor rules, where
// the same osc message is mapped to different midi messages. -ag
char *s = line;
while (*s && isspace(*s)) ++s;
if (*s == ':')
{
// Line starts with ':' delimiter, use prefix from previous
// rule.
strcat(strcpy(rule, prefix), s);
}
else
{
// Skip over the OSC path.
while (*s && !isspace(*s)) ++s;
// Skip over the rest of the lhs of the rule.
while (*s && *s != ':') ++s;
if (*s == ':')
{
// Complete rule, store prefix for subsequent rules.
int n = s-line;
strncpy(prefix, line, n);
prefix[n] = 0;
}
strcpy(rule, line);
}
p[i] = alloc_pair(rule, conv->tab, conv->registers, &nkeys);
if(p[i++])
{
if(conv->verbose)
Expand Down

0 comments on commit ee3ec6b

Please sign in to comment.