Beispiel #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;
}
Beispiel #2
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;
}