Esempio n. 1
0
/*
 * fluid_player_load
 */
int fluid_player_load(fluid_player_t* player, char *filename)
{
	fluid_midi_file* midifile;

	midifile = new_fluid_midi_file(filename);
	if (midifile == NULL) {
		return FLUID_FAILED;
	}
	player->division = fluid_midi_file_get_division(midifile);
	fluid_player_set_midi_tempo(player, player->miditempo); // Update deltatime
	/*FLUID_LOG(FLUID_DBG, "quarter note division=%d\n", player->division); */

	if (fluid_midi_file_load_tracks(midifile, player) != FLUID_OK){
		return FLUID_FAILED;
	}
	delete_fluid_midi_file(midifile);
	return FLUID_OK;
}
Esempio n. 2
0
/*
 * fluid_track_send_events
 */
int
fluid_track_send_events(fluid_track_t *track,
			fluid_synth_t *synth,
			fluid_player_t *player,
			unsigned int ticks)
{
    int status = FLUID_OK;
    fluid_midi_event_t *event;

    while (1) {

        event = track->cur;
        if (event == NULL) {
            return status;
        }

        /* 		printf("track=%02d\tticks=%05u\ttrack=%05u\tdtime=%05u\tnext=%05u\n", */
        /* 		       track->num, */
        /* 		       ticks, */
        /* 		       track->ticks, */
        /* 		       event->dtime, */
        /* 		       track->ticks + event->dtime); */

        if (track->ticks + event->dtime > ticks) {
            return status;
        }

        track->ticks += event->dtime;

        if (!player || event->type == MIDI_EOT) {
        }
        else if (event->type == MIDI_SET_TEMPO) {
            fluid_player_set_midi_tempo(player, event->param1);
        }
        else {
            if (player->playback_callback)
                player->playback_callback(player->playback_userdata, event);
        }

        fluid_track_next_event(track);

    }
    return status;
}
Esempio n. 3
0
/**
 * Set the tempo of a MIDI player in beats per minute.
 * @param player MIDI player instance
 * @param bpm Tempo in beats per minute
 * @return Always returns #FLUID_OK
 */
int
fluid_player_set_bpm(fluid_player_t *player, int bpm)
{
    return fluid_player_set_midi_tempo(player, (int) ((double) 60 * 1e6 / bpm));
}
Esempio n. 4
0
/*
 * fluid_player_load
 */
int
fluid_player_load(fluid_player_t *player, fluid_playlist_item *item)
{
    fluid_midi_file *midifile;
    char* buffer;
    size_t buffer_length;
    int buffer_owned;

    if (item->filename != NULL)
    {
        fluid_file fp;
        /* This file is specified by filename; load the file from disk */
        FLUID_LOG(FLUID_DBG, "%s: %d: Loading midifile %s", __FILE__, __LINE__,
                item->filename);
        /* Read the entire contents of the file into the buffer */
        fp = FLUID_FOPEN(item->filename, "rb");
        if (fp == NULL) {
            FLUID_LOG(FLUID_ERR, "Couldn't open the MIDI file");
            return FLUID_FAILED;
        }
        buffer = fluid_file_read_full(fp, &buffer_length);
        if (buffer == NULL)
        {
            FLUID_FCLOSE(fp);
            return FLUID_FAILED;
        }
        buffer_owned = 1;
        FLUID_FCLOSE(fp);
    }
    else
    {
        /* This file is specified by a pre-loaded buffer; load from memory */
        FLUID_LOG(FLUID_DBG, "%s: %d: Loading midifile from memory (%p)",
                __FILE__, __LINE__, item->buffer);
        buffer = (char *) item->buffer;
        buffer_length = item->buffer_len;
        /* Do not free the buffer (it is owned by the playlist) */
        buffer_owned = 0;
    }

    midifile = new_fluid_midi_file(buffer, buffer_length);
    if (midifile == NULL) {
        if (buffer_owned) {
            FLUID_FREE(buffer);
        }
        return FLUID_FAILED;
    }
    player->division = fluid_midi_file_get_division(midifile);
    fluid_player_set_midi_tempo(player, player->miditempo); // Update deltatime
    /*FLUID_LOG(FLUID_DBG, "quarter note division=%d\n", player->division); */

    if (fluid_midi_file_load_tracks(midifile, player) != FLUID_OK) {
        if (buffer_owned) {
            FLUID_FREE(buffer);
        }
        delete_fluid_midi_file(midifile);
        return FLUID_FAILED;
    }
    delete_fluid_midi_file(midifile);
    if (buffer_owned) {
        FLUID_FREE(buffer);
    }
    return FLUID_OK;
}