void
sequencer_callback (unsigned int time, fluid_event_t *event,
                    fluid_sequencer_t *seq, void *data)
{
    schedule_timer_event ();
    schedule_pattern ();
}
예제 #2
0
static int timer_add(char *id, unsigned int delay, char *cb_name,
                     delay_cb_t cb, char *argt, void **argv)
{
#define MAX_ARG      64
#define MAX_LENGTH   64
#define FLDLIST_DIM  MAX_ARG + 10

    fsif_field_t  fldlist[FLDLIST_DIM];
    unsigned int  srcid;
    int           success;
    char         *state;

    if (!id || !cb_name || !cb || !argt || strlen(argt) > MAX_ARG)
        success = FALSE;
    else {
        srcid   =  schedule_timer_event(id, delay);
        success = srcid;
        state   = srcid ? "active" : "failed";

        if (!build_fldlist(fldlist,id,state,delay,srcid,cb_name,cb,argt,argv)||
            !fsif_add_factstore_entry(FACTSTORE_TIMER, fldlist)               )
        {
            cancel_timer_event_by_srcid(srcid);
            success = FALSE;            
        }
    }

    return success;

#undef FLDLIST_DIM
#undef MAX_LENGTH
#undef MAX_ARG
}
int
main (int argc, char *argv[])
{
    int n;
    fluid_settings_t *settings;
    settings = new_fluid_settings ();
    if (argc < 2) {
        usage (argv[0]);
    } else {
        /* create the synth, driver and sequencer instances */
        synth = new_fluid_synth (settings);
        audiodriver = new_fluid_audio_driver (settings, synth);
        sequencer = new_fluid_sequencer ();
        /* register the synth with the sequencer */
        synth_destination = fluid_sequencer_register_fluidsynth (sequencer,
                synth);
        /* register the client name and callback */
        client_destination = fluid_sequencer_register_client (sequencer,
                "fluidsynth_metronome", sequencer_callback, NULL);
        /* load a SoundFont */
        n = fluid_synth_sfload (synth, argv[1], 1);
        if (n != -1) {
            if (argc > 2) {
                n = atoi (argv[2]);
                if (n > 0) pattern_size = n;
            }
            if (argc > 3) {
                n = atoi (argv[3]);
                if (n > 0) note_duration = 60000 / n;
            }
            /* get the current time in ticks */
            time_marker = fluid_sequencer_get_tick (sequencer);
            /* schedule patterns */
            schedule_pattern ();
            schedule_timer_event ();
            schedule_pattern ();
            /* wait for user input */
            printf ("press <Enter> to stop\n");
            n = getchar ();
        }
        /* clean and exit */
        delete_fluid_sequencer (sequencer);
        delete_fluid_audio_driver (audiodriver);
        delete_fluid_synth (synth);
    }
    delete_fluid_settings (settings);
    return 0;
}