Example of an arpeggio generated using the MIDI sequencer API
#include <stdlib.h>
#include <stdio.h>
#include <fluidsynth.h>
short synth_destination, client_destination;
unsigned int time_marker;
unsigned int duration = 1440;
unsigned int notes[] = { 60, 64, 67, 72, 76, 79, 84, 79, 76, 72, 67, 64 };
unsigned int pattern_size;
void
void
schedule_noteon(int chan, short key, unsigned int ticks)
{
}
void
schedule_noteoff(int chan, short key, unsigned int ticks)
{
}
void
schedule_timer_event(void)
{
}
void
schedule_pattern(void)
{
int i, note_time, note_duration;
note_time = time_marker;
note_duration = duration / pattern_size;
for(i = 0; i < pattern_size; ++i)
{
schedule_noteon(0, notes[i], note_time);
note_time += note_duration;
schedule_noteoff(0, notes[i], note_time);
}
time_marker += duration;
}
void
{
schedule_timer_event();
schedule_pattern();
}
void
usage(char *prog_name)
{
printf("Usage: %s soundfont.sf2 [steps [duration]]\n", prog_name);
printf("\t(optional) steps: number of pattern notes, from 2 to %d\n",
pattern_size);
printf("\t(optional) duration: of the pattern in ticks, default %d\n",
duration);
}
int
main(int argc, char *argv[])
{
int n;
pattern_size = sizeof(notes) / sizeof(int);
if(argc < 2)
{
usage(argv[0]);
}
else
{
if(n != -1)
{
synth);
"arpeggio", sequencer_callback, NULL);
if(argc > 2)
{
n = atoi(argv[2]);
if((n > 1) && (n <= pattern_size))
{
pattern_size = n;
}
}
if(argc > 3)
{
n = atoi(argv[3]);
if(n > 0)
{
duration = n;
}
}
schedule_pattern();
schedule_timer_event();
schedule_pattern();
printf("press <Enter> to stop\n");
n = getchar();
}
}
return 0;
}
FLUIDSYNTH_API fluid_sequencer_t * new_fluid_sequencer2(int use_system_timer)
Create a new sequencer object.
Definition: fluid_seq.c:109
FLUIDSYNTH_API void delete_fluid_synth(fluid_synth_t *synth)
Delete a FluidSynth instance.
Definition: fluid_synth.c:984
FLUIDSYNTH_API void delete_fluid_audio_driver(fluid_audio_driver_t *driver)
Deletes an audio driver instance.
Definition: fluid_adriver.c:385
struct _fluid_audio_driver_t fluid_audio_driver_t
Audio driver instance.
Definition: types.h:44
struct _fluid_sequencer_t fluid_sequencer_t
Sequencer instance.
Definition: types.h:55
FLUIDSYNTH_API fluid_event_t * new_fluid_event(void)
Create a new sequencer event structure.
Definition: fluid_event.c:57
FLUIDSYNTH_API void fluid_event_noteoff(fluid_event_t *evt, int channel, short key)
Set a sequencer event to be a note off event.
Definition: fluid_event.c:155
FLUIDSYNTH_API void delete_fluid_sequencer(fluid_sequencer_t *seq)
Free a sequencer object.
Definition: fluid_seq.c:150
FLUIDSYNTH_API fluid_seq_id_t fluid_sequencer_register_client(fluid_sequencer_t *seq, const char *name, fluid_event_callback_t callback, void *data)
Register a sequencer client.
Definition: fluid_seq.c:198
FLUIDSYNTH_API fluid_settings_t * new_fluid_settings(void)
Create a new settings object.
Definition: fluid_settings.c:261
struct _fluid_synth_t fluid_synth_t
Synthesizer instance.
Definition: types.h:37
FLUIDSYNTH_API void fluid_event_set_source(fluid_event_t *evt, fluid_seq_id_t src)
Set source of a sequencer event.
Definition: fluid_event.c:104
struct _fluid_event_t fluid_event_t
Sequencer event.
Definition: types.h:54
FLUIDSYNTH_API int fluid_sequencer_send_at(fluid_sequencer_t *seq, fluid_event_t *evt, unsigned int time, int absolute)
Schedule an event for sending at a later time.
Definition: fluid_seq.c:444
FLUIDSYNTH_API int fluid_synth_sfload(fluid_synth_t *synth, const char *filename, int reset_presets)
Load a SoundFont file (filename is interpreted by SoundFont loaders).
Definition: fluid_synth.c:4598
FLUIDSYNTH_API fluid_audio_driver_t * new_fluid_audio_driver(fluid_settings_t *settings, fluid_synth_t *synth)
Create a new audio driver.
Definition: fluid_adriver.c:308
FLUIDSYNTH_API void delete_fluid_event(fluid_event_t *evt)
Delete a sequencer event structure.
Definition: fluid_event.c:79
struct _fluid_hashtable_t fluid_settings_t
Configuration settings instance.
Definition: types.h:36
FLUIDSYNTH_API void fluid_event_set_dest(fluid_event_t *evt, fluid_seq_id_t dest)
Set destination of this sequencer event, i.e.
Definition: fluid_event.c:115
FLUIDSYNTH_API unsigned int fluid_sequencer_get_tick(fluid_sequencer_t *seq)
Get the current tick of a sequencer.
Definition: fluid_seq.c:492
FLUIDSYNTH_API fluid_seq_id_t fluid_sequencer_register_fluidsynth(fluid_sequencer_t *seq, fluid_synth_t *synth)
Registers a synthesizer as a destination client of the given sequencer.
Definition: fluid_seqbind.c:103
FLUIDSYNTH_API void fluid_event_noteon(fluid_event_t *evt, int channel, short key, short vel)
Set a sequencer event to be a note on event.
Definition: fluid_event.c:140
FLUIDSYNTH_API void delete_fluid_settings(fluid_settings_t *settings)
Delete the provided settings object.
Definition: fluid_settings.c:284
FLUIDSYNTH_API fluid_synth_t * new_fluid_synth(fluid_settings_t *settings)
Create new FluidSynth instance.
Definition: fluid_synth.c:603
FLUIDSYNTH_API void fluid_event_timer(fluid_event_t *evt, void *data)
Set a sequencer event to be a timer event.
Definition: fluid_event.c:126
Generated for libfluidsynth by
1.8.18