Skip to content

Commit

Permalink
Fix: playing of instrument without note.
Browse files Browse the repository at this point in the history
When an instrument is played without a note, the current playing
sample should restart its envelope, keeping its position. So it's
important not to change the current instrument.

Also, the same behavior happens even if the instrument is invalid (and
no note is specified); on the other hand, if the instrument is invalid
and a note is specified, the current note is being cut.

Co-developed with @bryc, who also prepared the tests
  • Loading branch information
rasky committed Apr 12, 2021
1 parent 0b464e8 commit 7759aec
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/play.c
Original file line number Diff line number Diff line change
Expand Up @@ -410,18 +410,17 @@ static void xm_handle_note_and_instrument(xm_context_t* ctx, xm_channel_context_
if(HAS_TONE_PORTAMENTO(ch->current) && ch->instrument != NULL && ch->sample != NULL) {
/* Tone portamento in effect, unclear stuff happens */
xm_trigger_note(ctx, ch, XM_TRIGGER_KEEP_PERIOD | XM_TRIGGER_KEEP_SAMPLE_POSITION);
} else if(s->note == 0 && ch->sample != NULL) {
/* Ghost instrument, trigger note */
/* Sample position is kept, but envelopes are reset */
xm_trigger_note(ctx, ch, XM_TRIGGER_KEEP_SAMPLE_POSITION);
} else if(s->instrument > ctx->module.num_instruments) {
/* Invalid instrument, Cut current note */
xm_cut_note(ch);
ch->instrument = NULL;
ch->sample = NULL;
} else {
ch->instrument = ctx->module.instruments + (s->instrument - 1);
if(s->note == 0 && ch->sample != NULL) {
/* Ghost instrument, trigger note */
/* Sample position is kept, but envelopes are reset */
xm_trigger_note(ctx, ch, XM_TRIGGER_KEEP_SAMPLE_POSITION);
}
}
}

Expand Down
Binary file added tests/ins-without-note1.xm
Binary file not shown.
Binary file added tests/ins-without-note2.xm
Binary file not shown.
Binary file added tests/ins-without-note3.xm
Binary file not shown.

0 comments on commit 7759aec

Please sign in to comment.