Skip to content

Commit

Permalink
Merge pull request #17 from agraef/master
Browse files Browse the repository at this point in the history
Bugfix, left-factoring of mapping rules.
  • Loading branch information
ssj71 committed Jun 30, 2015
2 parents 58ac3dd + ee3ec6b commit d95a240
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 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
3 changes: 1 addition & 2 deletions src/pair.c
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,6 @@ int get_pair_argtypes(char* config, char* path, PAIR* p, table tab, float** regs
case 'F'://false
case 'N'://nil
case 'I'://infinity
p->osc_map[j] = -1;//initialize mapping to be not used
p->types[j++] = argtypes[i];
p->argc++;
case ' ':
Expand All @@ -553,7 +552,7 @@ int get_pair_argtypes(char* config, char* path, PAIR* p, table tab, float** regs
}
p->types[j] = 0;//null terminate. It's good practice
for(i=0; i<len+p->argc_in_path; i++)
p->osc_map[j] = -1;//initialize mapping for in-path args
p->osc_map[i] = -1;//initialize mapping for all args
return 0;
}

Expand Down

0 comments on commit d95a240

Please sign in to comment.