On Sunday 03 August 2014 18:26:25 Element Green wrote:
> some of the functions are in public headers, but not all of them.  For
> example fluid_sfont_iteration_next() is defined in the private header at
> src/sfloader/fluid_sfont.h.  Its a simple macro though, which could
> theoretically be done from ones own code, although this seems pretty
> hackish to me.  But it would work.  Not sure why these weren't put in
> public headers to begin with, since they seem downright useful.

Hi,

The public header is <fluidsynth/sfont.h>

Public API documentation is here:
http://fluidsynth.sourceforge.net/api/struct__fluid__sfont__t.html
http://fluidsynth.sourceforge.net/api/sfont_8h.html

A simple example in C is attached.

Regards,
Pedro
/* FluidSynth Instruments - An example of using fluidsynth
 *
 * This code is in the public domain.
 *
 * To compile:
 *   gcc -o fluidsynth_instr fluidsynth_instr.c -lfluidsynth
 *
 * To run
 *   fluidsynth_instr soundfont
 *
 * [Pedro López-Cabanillas]
 *
 */

#include <stdio.h>
#include <fluidsynth.h>

int main(int argc, char** argv) 
{
	fluid_settings_t* settings = NULL;
	fluid_synth_t* synth = NULL;
	fluid_sfont_t* sfont = NULL;
	int err = 0, sfid = -1;

	if (argc != 2) {
		fprintf(stderr, "Usage: fluidsynth_instr [soundfont]\n");
		return 1;
	}

	/* Create the settings object. This example uses the default
	 * values for the settings. */
	settings = new_fluid_settings();
	if (settings == NULL) {
		fprintf(stderr, "Failed to create the settings\n");
		err = 2;
		goto cleanup;
	}
  
	/* Create the synthesizer */
	synth = new_fluid_synth(settings);
	if (synth == NULL) {
		fprintf(stderr, "Failed to create the synthesizer\n");
		err = 3;
		goto cleanup;
	}

	/* Load the soundfont */
	sfid = fluid_synth_sfload(synth, argv[1], 1);
	if (sfid == -1) {
		fprintf(stderr, "Failed to load the SoundFont\n");
		err = 4;
		goto cleanup;
	}

	/* Iterate soundfont's presets */
	sfont = fluid_synth_get_sfont_by_id(synth, sfid);
	if (sfont) {
		fluid_preset_t preset;
		sfont->iteration_start(sfont);
		while (sfont->iteration_next(sfont, &preset)) {
			int bank = preset.get_banknum(&preset);
			int prog = preset.get_num(&preset);
			char* name = preset.get_name(&preset);
			printf("bank: %d prog: %d name: %s\n", bank, prog, name);
		}
	}

	printf("done\n");

 cleanup:
	if (synth) {
		delete_fluid_synth(synth);
	}
	if (settings) {
		delete_fluid_settings(settings);
	}
	
	return err;
}
_______________________________________________
fluid-dev mailing list
fluid-dev@nongnu.org
https://lists.nongnu.org/mailman/listinfo/fluid-dev

Reply via email to