| The file native/jni/midi-dssi/gnu_javax_sound_midi_dssi_DSSISynthesizer.c |
| contains two functions (get_port_default and set_control) derived from |
| example code in the DSSI distribution (http://dssi.sourceforge.net). |
| The original DSSI example code is distributed under the following |
| terms: |
| |
| Copyright 2004 Chris Cannam, Steve Harris and Sean Bolton. |
| |
| Permission to use, copy, modify, distribute, and sell this software |
| for any purpose is hereby granted without fee, provided that the |
| above copyright notice and this permission notice are included in |
| all copies or substantial portions of the software. |
| |
| |
| The rest of this file contain the original versions of these |
| functions. |
| |
| |
| LADSPA_Data get_port_default(const LADSPA_Descriptor *plugin, int port) |
| { |
| LADSPA_PortRangeHint hint = plugin->PortRangeHints[port]; |
| float lower = hint.LowerBound * |
| (LADSPA_IS_HINT_SAMPLE_RATE(hint.HintDescriptor) ? sample_rate : 1.0f); |
| float upper = hint.UpperBound * |
| (LADSPA_IS_HINT_SAMPLE_RATE(hint.HintDescriptor) ? sample_rate : 1.0f); |
| |
| if (!LADSPA_IS_HINT_HAS_DEFAULT(hint.HintDescriptor)) { |
| if (!LADSPA_IS_HINT_BOUNDED_BELOW(hint.HintDescriptor) || |
| !LADSPA_IS_HINT_BOUNDED_ABOVE(hint.HintDescriptor)) { |
| /* No hint, its not bounded, wild guess */ |
| return 0.0f; |
| } |
| |
| if (lower <= 0.0f && upper >= 0.0f) { |
| /* It spans 0.0, 0.0 is often a good guess */ |
| return 0.0f; |
| } |
| |
| /* No clues, return minimum */ |
| return lower; |
| } |
| |
| /* Try all the easy ones */ |
| |
| if (LADSPA_IS_HINT_DEFAULT_0(hint.HintDescriptor)) { |
| return 0.0f; |
| } else if (LADSPA_IS_HINT_DEFAULT_1(hint.HintDescriptor)) { |
| return 1.0f; |
| } else if (LADSPA_IS_HINT_DEFAULT_100(hint.HintDescriptor)) { |
| return 100.0f; |
| } else if (LADSPA_IS_HINT_DEFAULT_440(hint.HintDescriptor)) { |
| return 440.0f; |
| } |
| |
| /* All the others require some bounds */ |
| |
| if (LADSPA_IS_HINT_BOUNDED_BELOW(hint.HintDescriptor)) { |
| if (LADSPA_IS_HINT_DEFAULT_MINIMUM(hint.HintDescriptor)) { |
| return lower; |
| } |
| } |
| if (LADSPA_IS_HINT_BOUNDED_ABOVE(hint.HintDescriptor)) { |
| if (LADSPA_IS_HINT_DEFAULT_MAXIMUM(hint.HintDescriptor)) { |
| return upper; |
| } |
| if (LADSPA_IS_HINT_BOUNDED_BELOW(hint.HintDescriptor)) { |
| if (LADSPA_IS_HINT_DEFAULT_LOW(hint.HintDescriptor)) { |
| return lower * 0.75f + upper * 0.25f; |
| } else if (LADSPA_IS_HINT_DEFAULT_MIDDLE(hint.HintDescriptor)) { |
| return lower * 0.5f + upper * 0.5f; |
| } else if (LADSPA_IS_HINT_DEFAULT_HIGH(hint.HintDescriptor)) { |
| return lower * 0.25f + upper * 0.75f; |
| } |
| } |
| } |
| |
| /* fallback */ |
| return 0.0f; |
| } |
| |
| |
| void |
| setControl(d3h_instance_t *instance, long controlIn, snd_seq_event_t *event) |
| { |
| long port = pluginControlInPortNumbers[controlIn]; |
| |
| const LADSPA_Descriptor *p = instance->plugin->descriptor->LADSPA_Plugin; |
| |
| LADSPA_PortRangeHintDescriptor d = p->PortRangeHints[port].HintDescriptor; |
| |
| LADSPA_Data lb = p->PortRangeHints[port].LowerBound * |
| (LADSPA_IS_HINT_SAMPLE_RATE(p->PortRangeHints[port].HintDescriptor) ? |
| sample_rate : 1.0f); |
| |
| LADSPA_Data ub = p->PortRangeHints[port].UpperBound * |
| (LADSPA_IS_HINT_SAMPLE_RATE(p->PortRangeHints[port].HintDescriptor) ? |
| sample_rate : 1.0f); |
| |
| float value = (float)event->data.control.value; |
| |
| if (!LADSPA_IS_HINT_BOUNDED_BELOW(d)) { |
| if (!LADSPA_IS_HINT_BOUNDED_ABOVE(d)) { |
| /* unbounded: might as well leave the value alone. */ |
| } else { |
| /* bounded above only. just shift the range. */ |
| value = ub - 127.0f + value; |
| } |
| } else { |
| if (!LADSPA_IS_HINT_BOUNDED_ABOVE(d)) { |
| /* bounded below only. just shift the range. */ |
| value = lb + value; |
| } else { |
| /* bounded both ends. more interesting. */ |
| if (LADSPA_IS_HINT_LOGARITHMIC(d)) { |
| const float llb = logf(lb); |
| const float lub = logf(ub); |
| |
| value = expf(llb + ((lub - llb) * value / 127.0f)); |
| } else { |
| value = lb + ((ub - lb) * value / 127.0f); |
| } |
| } |
| } |
| |
| if (verbose) { |
| printf("%s: %s MIDI controller %d=%d -> control in %ld=%f\n", myName, |
| instance->friendly_name, event->data.control.param, |
| event->data.control.value, controlIn, value); |
| } |
| |
| pluginControlIns[controlIn] = value; |
| pluginPortUpdated[controlIn] = 1; |
| } |
| |