Commit a303bb39 authored by Anton Baskanov's avatar Anton Baskanov Committed by Alexandre Julliard

dmsynth: Keep track of voice/wave mapping.

parent ad6e87c6
...@@ -320,6 +320,13 @@ struct event ...@@ -320,6 +320,13 @@ struct event
BYTE midi[3]; BYTE midi[3];
}; };
struct voice
{
struct list entry;
fluid_voice_t *fluid_voice;
struct wave *wave;
};
struct synth struct synth
{ {
IDirectMusicSynth8 IDirectMusicSynth8_iface; IDirectMusicSynth8 IDirectMusicSynth8_iface;
...@@ -336,6 +343,7 @@ struct synth ...@@ -336,6 +343,7 @@ struct synth
struct list instruments; struct list instruments;
struct list waves; struct list waves;
struct list events; struct list events;
struct list voices;
fluid_settings_t *fluid_settings; fluid_settings_t *fluid_settings;
fluid_sfont_t *fluid_sfont; fluid_sfont_t *fluid_sfont;
...@@ -584,6 +592,8 @@ static HRESULT WINAPI synth_Open(IDirectMusicSynth8 *iface, DMUS_PORTPARAMS *par ...@@ -584,6 +592,8 @@ static HRESULT WINAPI synth_Open(IDirectMusicSynth8 *iface, DMUS_PORTPARAMS *par
static HRESULT WINAPI synth_Close(IDirectMusicSynth8 *iface) static HRESULT WINAPI synth_Close(IDirectMusicSynth8 *iface)
{ {
struct synth *This = impl_from_IDirectMusicSynth8(iface); struct synth *This = impl_from_IDirectMusicSynth8(iface);
struct voice *voice;
void *next;
TRACE("(%p)\n", This); TRACE("(%p)\n", This);
...@@ -597,6 +607,14 @@ static HRESULT WINAPI synth_Close(IDirectMusicSynth8 *iface) ...@@ -597,6 +607,14 @@ static HRESULT WINAPI synth_Close(IDirectMusicSynth8 *iface)
fluid_synth_remove_sfont(This->fluid_synth, This->fluid_sfont); fluid_synth_remove_sfont(This->fluid_synth, This->fluid_sfont);
delete_fluid_synth(This->fluid_synth); delete_fluid_synth(This->fluid_synth);
This->fluid_synth = NULL; This->fluid_synth = NULL;
LIST_FOR_EACH_ENTRY_SAFE(voice, next, &This->voices, struct voice, entry)
{
list_remove(&voice->entry);
wave_release(voice->wave);
free(voice);
}
This->open = FALSE; This->open = FALSE;
LeaveCriticalSection(&This->cs); LeaveCriticalSection(&This->cs);
...@@ -1742,6 +1760,7 @@ static int synth_preset_noteon(fluid_preset_t *fluid_preset, fluid_synth_t *flui ...@@ -1742,6 +1760,7 @@ static int synth_preset_noteon(fluid_preset_t *fluid_preset, fluid_synth_t *flui
{ {
struct articulation *articulation; struct articulation *articulation;
struct wave *wave = region->wave; struct wave *wave = region->wave;
struct voice *voice;
if (key < region->key_range.usLow || key > region->key_range.usHigh) continue; if (key < region->key_range.usLow || key > region->key_range.usHigh) continue;
if (vel < region->vel_range.usLow || vel > region->vel_range.usHigh) continue; if (vel < region->vel_range.usLow || vel > region->vel_range.usHigh) continue;
...@@ -1763,6 +1782,29 @@ static int synth_preset_noteon(fluid_preset_t *fluid_preset, fluid_synth_t *flui ...@@ -1763,6 +1782,29 @@ static int synth_preset_noteon(fluid_preset_t *fluid_preset, fluid_synth_t *flui
return FLUID_FAILED; return FLUID_FAILED;
} }
LIST_FOR_EACH_ENTRY(voice, &synth->voices, struct voice, entry)
{
if (voice->fluid_voice == fluid_voice)
{
wave_release(voice->wave);
break;
}
}
if (&voice->entry == &synth->voices)
{
if (!(voice = calloc(1, sizeof(struct voice))))
{
delete_fluid_sample(fluid_sample);
return FLUID_FAILED;
}
voice->fluid_voice = fluid_voice;
list_add_tail(&synth->voices, &voice->entry);
}
voice->wave = wave;
wave_addref(voice->wave);
set_default_voice_connections(fluid_voice); set_default_voice_connections(fluid_voice);
if (region->wave_sample.cSampleLoops) if (region->wave_sample.cSampleLoops)
{ {
...@@ -1885,6 +1927,7 @@ HRESULT synth_create(IUnknown **ret_iface) ...@@ -1885,6 +1927,7 @@ HRESULT synth_create(IUnknown **ret_iface)
list_init(&obj->instruments); list_init(&obj->instruments);
list_init(&obj->waves); list_init(&obj->waves);
list_init(&obj->events); list_init(&obj->events);
list_init(&obj->voices);
if (!(obj->fluid_settings = new_fluid_settings())) goto failed; if (!(obj->fluid_settings = new_fluid_settings())) goto failed;
if (!(obj->fluid_sfont = new_fluid_sfont(synth_sfont_get_name, synth_sfont_get_preset, if (!(obj->fluid_sfont = new_fluid_sfont(synth_sfont_get_name, synth_sfont_get_preset,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment