Fix example code in the API docs

order of object creation: audio driver must be last
This commit is contained in:
derselbst 2019-08-25 10:59:11 +02:00
parent f78486a50b
commit cac2c6bf84
3 changed files with 24 additions and 19 deletions

View file

@ -376,7 +376,6 @@ int main(int argc, char** argv)
settings = new_fluid_settings(); settings = new_fluid_settings();
synth = new_fluid_synth(settings); synth = new_fluid_synth(settings);
player = new_fluid_player(synth); player = new_fluid_player(synth);
adriver = new_fluid_audio_driver(settings, synth);
/* process command line arguments */ /* process command line arguments */
for (i = 1; i < argc; i++) { for (i = 1; i < argc; i++) {
if (fluid_is_soundfont(argv[i])) { if (fluid_is_soundfont(argv[i])) {
@ -386,6 +385,8 @@ int main(int argc, char** argv)
fluid_player_add(player, argv[i]); fluid_player_add(player, argv[i]);
} }
} }
/* start the synthesizer thread */
adriver = new_fluid_audio_driver(settings, synth);
/* play the midi files, if any */ /* play the midi files, if any */
fluid_player_play(player); fluid_player_play(player);
/* wait for playback termination */ /* wait for playback termination */

View file

@ -119,7 +119,11 @@ main(int argc, char *argv[])
{ {
/* create the synth, driver and sequencer instances */ /* create the synth, driver and sequencer instances */
synth = new_fluid_synth(settings); synth = new_fluid_synth(settings);
audiodriver = new_fluid_audio_driver(settings, synth); /* load a SoundFont */
n = fluid_synth_sfload(synth, argv[1], 1);
if(n != -1)
{
sequencer = new_fluid_sequencer(); sequencer = new_fluid_sequencer();
/* register the synth with the sequencer */ /* register the synth with the sequencer */
synth_destination = fluid_sequencer_register_fluidsynth(sequencer, synth_destination = fluid_sequencer_register_fluidsynth(sequencer,
@ -127,11 +131,6 @@ main(int argc, char *argv[])
/* register the client name and callback */ /* register the client name and callback */
client_destination = fluid_sequencer_register_client(sequencer, client_destination = fluid_sequencer_register_client(sequencer,
"arpeggio", sequencer_callback, NULL); "arpeggio", sequencer_callback, NULL);
/* load a SoundFont */
n = fluid_synth_sfload(synth, argv[1], 1);
if(n != -1)
{
if(argc > 2) if(argc > 2)
{ {
n = atoi(argv[2]); n = atoi(argv[2]);
@ -152,6 +151,8 @@ main(int argc, char *argv[])
} }
} }
audiodriver = new_fluid_audio_driver(settings, synth);
/* get the current time in ticks */ /* get the current time in ticks */
time_marker = fluid_sequencer_get_tick(sequencer); time_marker = fluid_sequencer_get_tick(sequencer);
/* schedule patterns */ /* schedule patterns */
@ -164,8 +165,8 @@ main(int argc, char *argv[])
} }
/* clean and exit */ /* clean and exit */
delete_fluid_sequencer(sequencer);
delete_fluid_audio_driver(audiodriver); delete_fluid_audio_driver(audiodriver);
delete_fluid_sequencer(sequencer);
delete_fluid_synth(synth); delete_fluid_synth(synth);
} }

View file

@ -105,7 +105,12 @@ main(int argc, char *argv[])
{ {
/* create the synth, driver and sequencer instances */ /* create the synth, driver and sequencer instances */
synth = new_fluid_synth(settings); synth = new_fluid_synth(settings);
audiodriver = new_fluid_audio_driver(settings, synth);
/* load a SoundFont */
n = fluid_synth_sfload(synth, argv[1], 1);
if(n != -1)
{
sequencer = new_fluid_sequencer(); sequencer = new_fluid_sequencer();
/* register the synth with the sequencer */ /* register the synth with the sequencer */
synth_destination = fluid_sequencer_register_fluidsynth(sequencer, synth_destination = fluid_sequencer_register_fluidsynth(sequencer,
@ -113,11 +118,9 @@ main(int argc, char *argv[])
/* register the client name and callback */ /* register the client name and callback */
client_destination = fluid_sequencer_register_client(sequencer, client_destination = fluid_sequencer_register_client(sequencer,
"fluidsynth_metronome", sequencer_callback, NULL); "fluidsynth_metronome", sequencer_callback, NULL);
/* load a SoundFont */
n = fluid_synth_sfload(synth, argv[1], 1);
if(n != -1) audiodriver = new_fluid_audio_driver(settings, synth);
{
if(argc > 2) if(argc > 2)
{ {
n = atoi(argv[2]); n = atoi(argv[2]);
@ -150,8 +153,8 @@ main(int argc, char *argv[])
} }
/* clean and exit */ /* clean and exit */
delete_fluid_sequencer(sequencer);
delete_fluid_audio_driver(audiodriver); delete_fluid_audio_driver(audiodriver);
delete_fluid_sequencer(sequencer);
delete_fluid_synth(synth); delete_fluid_synth(synth);
} }