Skip to content

Commit

Permalink
Added support for relative volume (v+ and v-)
Browse files Browse the repository at this point in the history
  • Loading branch information
sik committed Nov 26, 2016
1 parent 5974de5 commit b6fb377
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
6 changes: 6 additions & 0 deletions mml2esf/doc/echomml.txt
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,12 @@ put spaces *in the middle* of a command.

Decrease or increase the volume by 1, respectively.

v+ v-

Followed by a number, increase or decrease the volume by that amount,
respectively. Like doing multiple ( or ) in a row, except only one
event is generated (which is better).

p

Followed by a number between 0 and 3, changes the panning of the
Expand Down
27 changes: 26 additions & 1 deletion mml2esf/tool/mml.c
Original file line number Diff line number Diff line change
Expand Up @@ -822,12 +822,32 @@ static int parse_commands(const char *data, unsigned channel, unsigned line)
if (channel == 0x10) goto noctrl;
data++;

// Check if it's relative
int sign = 0;
if (*data == '+') {
sign = 1;
data++;
} else if (*data == '-') {
sign = -1;
data++;
}

// Get volume
int volume = parse_number(&data);
if (volume == -1) {
fprintf(stderr, "Error[%u]: missing new volume\n", line);
return -1;
}
switch (sign) {
case 0:
break;
case 1:
volume = chanstat[channel].volume + volume;
break;
case -1:
volume = chanstat[channel].volume - volume;
break;
}
if (volume < 0 || volume > 15) {
fprintf(stderr, "Error[%u]: invalid volume value\n", line);
return -1;
Expand Down Expand Up @@ -907,10 +927,15 @@ static int parse_commands(const char *data, unsigned channel, unsigned line)
}

// Whitespace? (skip it)
else if (*data == ' ' || (*data >= 0x08 && *data <= 0x0D)) {
else if (is_whitespace(*data)) {
data++;
}

// Comment?
else if (*data == ';') {
break;
}

// Unknown or unimplemented command
else {
fprintf(stderr, "Error[%u]: invalid command \"%c\"\n", line, *data);
Expand Down

0 comments on commit b6fb377

Please sign in to comment.