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

Per-channel ALL_SOUND_OFF when seeking/stopping player #980

Merged
merged 22 commits into from
Sep 28, 2021
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
4c5bb51
send notes_off when seeking player
albedozero Sep 15, 2021
3ce2405
add notesoff_channels to _fluid_player_t
albedozero Sep 15, 2021
4308795
add per-channel sending of notes_off in player
albedozero Sep 15, 2021
545f1e9
add fluid_player_set_notesoff_channels to API
albedozero Sep 15, 2021
9c7bb50
fix typo in fluid_player_callback
albedozero Sep 15, 2021
cedfb64
add fluid_synth_all_notes_release to API
albedozero Sep 15, 2021
03c07c4
add fluid_synth_all_notes_release
albedozero Sep 15, 2021
0395e91
release all notes when seeking/stopping player
albedozero Sep 15, 2021
e07b902
Revert "release all notes when seeking/stopping player"
albedozero Sep 16, 2021
56811d0
Revert "add fluid_synth_all_notes_release"
albedozero Sep 16, 2021
470c19c
Revert "add fluid_synth_all_notes_release to API"
albedozero Sep 16, 2021
f4046b1
Revert "add fluid_player_set_notesoff_channels to API"
albedozero Sep 16, 2021
260f54e
per-channel all_sounds_off in player
albedozero Sep 16, 2021
98928ce
tabs->spaces
albedozero Sep 16, 2021
cd613db
use midi events to stop player
albedozero Sep 20, 2021
b37fbde
moar tabs grr
albedozero Sep 21, 2021
49ea38a
dynamically track channels_playing
albedozero Sep 21, 2021
df4d7f8
trying to fix dynamic channels_playing list
albedozero Sep 22, 2021
4cf7826
Revert "trying to fix dynamic channels_playing list"
albedozero Sep 22, 2021
fb0388c
Revert "dynamically track channels_playing"
albedozero Sep 22, 2021
aa21ae1
max channels 16 for fluid_event_t structure
albedozero Sep 28, 2021
eb986f6
reinitialize channel_isplaying when resetting player
albedozero Sep 28, 2021
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
32 changes: 30 additions & 2 deletions src/midi/fluid_midi.c
Original file line number Diff line number Diff line change
Expand Up @@ -1604,6 +1604,10 @@ fluid_track_send_events(fluid_track_t *track,
if(player->playback_callback)
{
player->playback_callback(player->playback_userdata, event);
if(event->type == NOTE_ON && !player->channel_isplaying[event->channel])
derselbst marked this conversation as resolved.
Show resolved Hide resolved
{
player->channel_isplaying[event->channel] = 1;
}
}
}

Expand Down Expand Up @@ -1660,6 +1664,11 @@ new_fluid_player(fluid_synth_t *synth)
player->track[i] = NULL;
}

for(i = 0; i < synth->midi_channels; i++)
{
player->channel_isplaying[i] = 0;
derselbst marked this conversation as resolved.
Show resolved Hide resolved
}

player->synth = synth;
player->system_timer = NULL;
player->sample_timer = NULL;
Expand Down Expand Up @@ -2080,18 +2089,30 @@ fluid_player_callback(void *data, unsigned int msec)
int i;
int loadnextfile;
int status = FLUID_PLAYER_DONE;
fluid_midi_event_t mute_event;
fluid_player_t *player;
fluid_synth_t *synth;
player = (fluid_player_t *) data;
synth = player->synth;

loadnextfile = player->currentfile == NULL ? 1 : 0;

fluid_midi_event_set_type(&mute_event, CONTROL_CHANGE);
mute_event.param1 = ALL_SOUND_OFF;
mute_event.param2 = 1;

if(fluid_player_get_status(player) != FLUID_PLAYER_PLAYING)
{
if(fluid_atomic_int_get(&player->stopping))
{
fluid_synth_all_notes_off(synth, -1);
for(i = 0; i < synth->midi_channels; i++)
albedozero marked this conversation as resolved.
Show resolved Hide resolved
{
if(player->channel_isplaying[i])
{
fluid_midi_event_set_channel(&mute_event, i);
player->playback_callback(player->playback_userdata, &mute_event);
}
}
fluid_atomic_int_set(&player->stopping, 0);
}
return 1;
Expand Down Expand Up @@ -2121,7 +2142,14 @@ fluid_player_callback(void *data, unsigned int msec)
seek_ticks = fluid_atomic_int_get(&player->seek_ticks);
if(seek_ticks >= 0)
{
fluid_synth_all_sounds_off(synth, -1); /* avoid hanging notes */
for(i = 0; i < synth->midi_channels; i++)
{
if(player->channel_isplaying[i])
{
fluid_midi_event_set_channel(&mute_event, i);
player->playback_callback(player->playback_userdata, &mute_event);
}
}
}

for(i = 0; i < player->ntracks; i++)
Expand Down
3 changes: 3 additions & 0 deletions src/midi/fluid_midi.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ fluid_midi_event_t *fluid_midi_parser_parse(fluid_midi_parser_t *parser, unsigne


#define MAX_NUMBER_OF_TRACKS 128
#define MAX_NUMBER_OF_CHANNELS 256
derselbst marked this conversation as resolved.
Show resolved Hide resolved

enum fluid_midi_event_type
{
Expand Down Expand Up @@ -325,6 +326,8 @@ struct _fluid_player_t
void *playback_userdata; /* pointer to user-defined data passed to playback_callback function */
handle_midi_tick_func_t tick_callback; /* function fired on each tick change */
void *tick_userdata; /* pointer to user-defined data passed to tick_callback function */

int channel_isplaying[MAX_NUMBER_OF_CHANNELS]; /* flags indicating channels on which notes have played */
};

void fluid_player_settings(fluid_settings_t *settings);
Expand Down