iiwusynth-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[iiwusynth-devel] Improved SoundFont API


From: Peter Hanappe
Subject: [iiwusynth-devel] Improved SoundFont API
Date: Fri, 20 Dec 2002 11:41:43 +0100
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.0.0) Gecko/20020623 Debian/1.0.0-0.woody.1


Hi all,

I'd like to propose some changes to the soundfont API. This concerns
mainly Josh and Antoine. The current API is, to be honest, ugly.
I'd like to simplify things a bit.

First, the iiwu_sfloader_t, iiwu_sfont_t, and iiwu_preset_t types are
made completely opaque, so soundfont developers can cast any structure
to it.

Second, the soundfont loader registers the interface functions to the
the synthesizer only once. There's no longer a need to allocate a
iiwu_preset_t structure for every preset as is currently the
case. This registration is like registering three classes and a loader
instance. Details below.

Does this seems like a worthy improvement?

Cheers,
Peter

----------------

/* SoundFont API */


typedef struct _iiwu_sfloader_t iiwu_sfloader_t;
typedef struct _iiwu_sfont_t iiwu_sfont_t;
typedef struct _iiwu_preset_t iiwu_preset_t;

typedef struct _iiwu_sfloader_interface_t iiwu_sfloader_interface_t;
typedef struct _iiwu_sfont_interface_t iiwu_sfont_interface_t;
typedef struct _iiwu_preset_interface_t iiwu_preset_interface_t;

/** Register a new SoundFont loader.

    \param synth The synthesizer object
    \param name The name of the loader
    \param loader Pointer the to instance of the loader
    \param loader_if Pointer to the interface of the loader
    \param sfont_if Pointer to the interface of the SoundFonts
    \param preset_if Pointer to the interface of the presets
    \returns 0 if the loader was register, non zero if error.
 */
int iiwu_synth_register_sfloader(iiwu_synth_t* synth,
                                  char* name,
                                  iiwu_sfloader_t* loader,
                                  iiwu_sfloader_interface_t* loader_if,
                                  iiwu_sfont_interface_t* sfont_if,
                                  iiwu_preset_interface_t* preset_if);

/** Unregister a SoundFont loader */
void iiwu_synth_unregister_sfloader(iiwu_synth_t* synth, iiwu_sfloader_t* loader);


struct _iiwu_sfloader_interface_t {
  /** Free al ressources allocated by the SoundFont loader. */
  int (*free)(iiwu_sfloader_t* loader);

  /** Load a SoundFont. The function should return NULL if it wasn't
      able to load the file. */
  iiwu_sfont_t* (*load)(iiwu_sfloader_t* loader, const char* filename);
};


struct _iiwu_sfont_interface_t {

  /** Free al ressources allocated by the SoundFont. The 'free'
      callback function should return 0 when it was able to free all
      resources. It should return a non-zero value if some of the
      samples could not be freed because they are still in use. */
  int (*free)(iiwu_sfont_t* sfont);

  /** Return the name of the soundfont */
  char* (*get_name)(iiwu_sfont_t* sfont);

  /** Get a preset of the soundfont */
iiwu_preset_t* (*get_preset)(iiwu_sfont_t* sfont, unsigned int bank, unsigned int prenum);

  /** Start the iteration of the presets */
  void (*iteration_start)(iiwu_sfont_t* sfont);

  /* return 0 when no more presets are available, 1 otherwise */
  int (*iteration_next)(iiwu_sfont_t* sfont, iiwu_preset_t* preset);
};


struct _iiwu_preset_interface_t {
  /** Return the name of the preset */
  char* (*get_name)(iiwu_preset_t* preset);

  /** Return the bank number of the preset */
  int (*get_banknum)(iiwu_preset_t* preset);

  /** Return the preset number of the preset */
  int (*get_presetnum)(iiwu_preset_t* preset);

  /** Handle a noteon event. */
int (*noteon)(iiwu_preset_t* preset, iiwu_synth_t* synth, int chan, int key, int vel);

  /** Handle notification events. */
  void (*notify)(iiwu_preset_t* preset, int reason);
};





reply via email to

[Prev in Thread] Current Thread [Next in Thread]