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

dmsynth: Factor out instrument and region search.

parent 3fd64a72
...@@ -1411,6 +1411,35 @@ static int synth_preset_get_num(fluid_preset_t *fluid_preset) ...@@ -1411,6 +1411,35 @@ static int synth_preset_get_num(fluid_preset_t *fluid_preset)
return preset->patch; return preset->patch;
} }
static void find_region(struct synth *synth, int bank, int patch, int key, int vel,
struct instrument **out_instrument, struct region **out_region)
{
struct instrument *instrument;
struct region *region;
*out_instrument = NULL;
*out_region = NULL;
LIST_FOR_EACH_ENTRY(instrument, &synth->instruments, struct instrument, entry)
{
if (bank == 128 && instrument->patch == (0x80000000 | patch)) break;
else if (instrument->patch == ((bank << 8) | patch)) break;
}
if (&instrument->entry == &synth->instruments)
return;
*out_instrument = instrument;
LIST_FOR_EACH_ENTRY(region, &instrument->regions, struct region, entry)
{
if (key < region->key_range.usLow || key > region->key_range.usHigh) continue;
if (vel < region->vel_range.usLow || vel > region->vel_range.usHigh) continue;
*out_region = region;
break;
}
}
static BOOL gen_from_connection(const CONNECTION *conn, UINT *gen) static BOOL gen_from_connection(const CONNECTION *conn, UINT *gen)
{ {
switch (conn->usDestination) switch (conn->usDestination)
...@@ -1773,35 +1802,33 @@ static int synth_preset_noteon(fluid_preset_t *fluid_preset, fluid_synth_t *flui ...@@ -1773,35 +1802,33 @@ static int synth_preset_noteon(fluid_preset_t *fluid_preset, fluid_synth_t *flui
{ {
struct preset *preset = fluid_preset_get_data(fluid_preset); struct preset *preset = fluid_preset_get_data(fluid_preset);
struct synth *synth = preset->synth; struct synth *synth = preset->synth;
struct articulation *articulation;
struct instrument *instrument; struct instrument *instrument;
fluid_voice_t *fluid_voice; fluid_voice_t *fluid_voice;
struct region *region; struct region *region;
struct voice *voice;
struct wave *wave;
TRACE("(%p, %p, %u, %u, %u)\n", fluid_preset, fluid_synth, chan, key, vel); TRACE("(%p, %p, %u, %u, %u)\n", fluid_preset, fluid_synth, chan, key, vel);
EnterCriticalSection(&synth->cs); EnterCriticalSection(&synth->cs);
LIST_FOR_EACH_ENTRY(instrument, &synth->instruments, struct instrument, entry) find_region(synth, preset->bank, preset->patch, key, vel, &instrument, &region);
{
if (preset->bank == 128 && instrument->patch == (0x80000000 | preset->patch)) break;
else if (instrument->patch == ((preset->bank << 8) | preset->patch)) break;
}
if (&instrument->entry == &synth->instruments) if (!instrument)
{ {
WARN("Could not find instrument with patch %#x\n", preset->patch); WARN("Could not find instrument with patch %#x\n", preset->patch);
LeaveCriticalSection(&synth->cs); LeaveCriticalSection(&synth->cs);
return FLUID_FAILED; return FLUID_FAILED;
} }
if (!region)
LIST_FOR_EACH_ENTRY(region, &instrument->regions, struct region, entry)
{ {
struct articulation *articulation; WARN("Failed to find instrument matching note / velocity\n");
struct wave *wave = region->wave; LeaveCriticalSection(&synth->cs);
struct voice *voice; return FLUID_FAILED;
}
if (key < region->key_range.usLow || key > region->key_range.usHigh) continue; wave = region->wave;
if (vel < region->vel_range.usLow || vel > region->vel_range.usHigh) continue;
if (!(fluid_voice = fluid_synth_alloc_voice(synth->fluid_synth, wave->fluid_sample, chan, key, vel))) if (!(fluid_voice = fluid_synth_alloc_voice(synth->fluid_synth, wave->fluid_sample, chan, key, vel)))
{ {
...@@ -1858,14 +1885,10 @@ static int synth_preset_noteon(fluid_preset_t *fluid_preset, fluid_synth_t *flui ...@@ -1858,14 +1885,10 @@ static int synth_preset_noteon(fluid_preset_t *fluid_preset, fluid_synth_t *flui
LIST_FOR_EACH_ENTRY(articulation, &region->articulations, struct articulation, entry) LIST_FOR_EACH_ENTRY(articulation, &region->articulations, struct articulation, entry)
add_voice_connections(fluid_voice, &articulation->list, articulation->connections); add_voice_connections(fluid_voice, &articulation->list, articulation->connections);
fluid_synth_start_voice(synth->fluid_synth, fluid_voice); fluid_synth_start_voice(synth->fluid_synth, fluid_voice);
LeaveCriticalSection(&synth->cs);
return FLUID_OK;
}
LeaveCriticalSection(&synth->cs); LeaveCriticalSection(&synth->cs);
WARN("Failed to find instrument matching note / velocity\n"); return FLUID_OK;
return FLUID_FAILED;
} }
static void synth_preset_free(fluid_preset_t *fluid_preset) static void synth_preset_free(fluid_preset_t *fluid_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