Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix, left-factoring of mapping rules. #17

Merged
merged 2 commits into from
Jun 30, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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