fluidsynth.c
changeset 542 3de4970b36d4
parent 532 b8e8ae4852b2
child 545 32e5ed415a34
equal deleted inserted replaced
541:323b314739ef 542:3de4970b36d4
    64 	freq = mixer->freq;
    64 	freq = mixer->freq;
    65 
    65 
    66 	return 0;
    66 	return 0;
    67 }
    67 }
    68 
    68 
    69 FluidSynthMidiSong *fluidsynth_loadsong_common(int (*function)(FluidSynthMidiSong*, void*), void *data)
    69 static FluidSynthMidiSong *fluidsynth_loadsong_common(int (*function)(FluidSynthMidiSong*, void*), void *data)
    70 {
    70 {
    71 	FluidSynthMidiSong *song;
    71 	FluidSynthMidiSong *song;
    72 	fluid_settings_t *settings = NULL;
    72 	fluid_settings_t *settings = NULL;
    73 
    73 
    74 	if ((song = malloc(sizeof(FluidSynthMidiSong)))) {
    74 	if ((song = malloc(sizeof(FluidSynthMidiSong)))) {
   103 		Mix_SetError("Insufficient memory for song");
   103 		Mix_SetError("Insufficient memory for song");
   104 	}
   104 	}
   105 	return NULL;
   105 	return NULL;
   106 }
   106 }
   107 
   107 
   108 int fluidsynth_loadsong_internal(FluidSynthMidiSong *song, void *data)
   108 static int fluidsynth_loadsong_RW_internal(FluidSynthMidiSong *song, void *data)
   109 {
       
   110 	const char* path = (const char*) data;
       
   111 
       
   112 	if (fluidsynth.fluid_player_add(song->player, path) == FLUID_OK) {
       
   113 		return 1;
       
   114 	} else {
       
   115 		Mix_SetError("FluidSynth failed to load %s", path);
       
   116 		return 0;
       
   117 	}
       
   118 }
       
   119 
       
   120 int fluidsynth_loadsong_RW_internal(FluidSynthMidiSong *song, void *data)
       
   121 {
   109 {
   122 	off_t offset;
   110 	off_t offset;
   123 	size_t size;
   111 	size_t size;
   124 	char *buffer;
   112 	char *buffer;
   125 	SDL_RWops *rw = (SDL_RWops*) data;
   113 	SDL_RWops *rw = (SDL_RWops*) data;
   144 		Mix_SetError("Insufficient memory for song");
   132 		Mix_SetError("Insufficient memory for song");
   145 	}
   133 	}
   146 	return 0;
   134 	return 0;
   147 }
   135 }
   148 
   136 
   149 FluidSynthMidiSong *fluidsynth_loadsong(const char *midifile)
       
   150 {
       
   151 	return fluidsynth_loadsong_common(fluidsynth_loadsong_internal, (void*) midifile);
       
   152 }
       
   153 
       
   154 FluidSynthMidiSong *fluidsynth_loadsong_RW(SDL_RWops *rw, int freerw)
   137 FluidSynthMidiSong *fluidsynth_loadsong_RW(SDL_RWops *rw, int freerw)
   155 {
   138 {
   156 	FluidSynthMidiSong *song;
   139 	FluidSynthMidiSong *song;
   157 
   140 
   158 	song = fluidsynth_loadsong_common(fluidsynth_loadsong_RW_internal, (void*) rw);
   141 	song = fluidsynth_loadsong_common(fluidsynth_loadsong_RW_internal, (void*) rw);