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)
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)
{
switch (conn->usDestination)
......@@ -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 synth *synth = preset->synth;
struct articulation *articulation;
struct instrument *instrument;
fluid_voice_t *fluid_voice;
struct region *region;
struct voice *voice;
struct wave *wave;
TRACE("(%p, %p, %u, %u, %u)\n", fluid_preset, fluid_synth, chan, key, vel);
EnterCriticalSection(&synth->cs);
LIST_FOR_EACH_ENTRY(instrument, &synth->instruments, struct instrument, entry)
{
if (preset->bank == 128 && instrument->patch == (0x80000000 | preset->patch)) break;
else if (instrument->patch == ((preset->bank << 8) | preset->patch)) break;
}
find_region(synth, preset->bank, preset->patch, key, vel, &instrument, &region);
if (&instrument->entry == &synth->instruments)
if (!instrument)
{
WARN("Could not find instrument with patch %#x\n", preset->patch);
LeaveCriticalSection(&synth->cs);
return FLUID_FAILED;
}
LIST_FOR_EACH_ENTRY(region, &instrument->regions, struct region, entry)
if (!region)
{
struct articulation *articulation;
struct wave *wave = region->wave;
struct voice *voice;
WARN("Failed to find instrument matching note / velocity\n");
LeaveCriticalSection(&synth->cs);
return FLUID_FAILED;
}
if (key < region->key_range.usLow || key > region->key_range.usHigh) continue;
if (vel < region->vel_range.usLow || vel > region->vel_range.usHigh) continue;
wave = region->wave;
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
LIST_FOR_EACH_ENTRY(articulation, &region->articulations, struct articulation, entry)
add_voice_connections(fluid_voice, &articulation->list, articulation->connections);
fluid_synth_start_voice(synth->fluid_synth, fluid_voice);
LeaveCriticalSection(&synth->cs);
return FLUID_OK;
}
LeaveCriticalSection(&synth->cs);
WARN("Failed to find instrument matching note / velocity\n");
return FLUID_FAILED;
return FLUID_OK;
}
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