1 The file native/jni/midi-dssi/gnu_javax_sound_midi_dssi_DSSISynthesizer.c
2 contains two functions (get_port_default and set_control) derived from
3 example code in the DSSI distribution (http://dssi.sourceforge.net).
4 The original DSSI example code is distributed under the following
7 Copyright 2004 Chris Cannam, Steve Harris and Sean Bolton.
9 Permission to use, copy, modify, distribute, and sell this software
10 for any purpose is hereby granted without fee, provided that the
11 above copyright notice and this permission notice are included in
12 all copies or substantial portions of the software.
15 The rest of this file contain the original versions of these
19 LADSPA_Data get_port_default(const LADSPA_Descriptor *plugin, int port)
21 LADSPA_PortRangeHint hint = plugin->PortRangeHints[port];
22 float lower = hint.LowerBound *
23 (LADSPA_IS_HINT_SAMPLE_RATE(hint.HintDescriptor) ? sample_rate : 1.0f);
24 float upper = hint.UpperBound *
25 (LADSPA_IS_HINT_SAMPLE_RATE(hint.HintDescriptor) ? sample_rate : 1.0f);
27 if (!LADSPA_IS_HINT_HAS_DEFAULT(hint.HintDescriptor)) {
28 if (!LADSPA_IS_HINT_BOUNDED_BELOW(hint.HintDescriptor) ||
29 !LADSPA_IS_HINT_BOUNDED_ABOVE(hint.HintDescriptor)) {
30 /* No hint, its not bounded, wild guess */
34 if (lower <= 0.0f && upper >= 0.0f) {
35 /* It spans 0.0, 0.0 is often a good guess */
39 /* No clues, return minimum */
43 /* Try all the easy ones */
45 if (LADSPA_IS_HINT_DEFAULT_0(hint.HintDescriptor)) {
47 } else if (LADSPA_IS_HINT_DEFAULT_1(hint.HintDescriptor)) {
49 } else if (LADSPA_IS_HINT_DEFAULT_100(hint.HintDescriptor)) {
51 } else if (LADSPA_IS_HINT_DEFAULT_440(hint.HintDescriptor)) {
55 /* All the others require some bounds */
57 if (LADSPA_IS_HINT_BOUNDED_BELOW(hint.HintDescriptor)) {
58 if (LADSPA_IS_HINT_DEFAULT_MINIMUM(hint.HintDescriptor)) {
62 if (LADSPA_IS_HINT_BOUNDED_ABOVE(hint.HintDescriptor)) {
63 if (LADSPA_IS_HINT_DEFAULT_MAXIMUM(hint.HintDescriptor)) {
66 if (LADSPA_IS_HINT_BOUNDED_BELOW(hint.HintDescriptor)) {
67 if (LADSPA_IS_HINT_DEFAULT_LOW(hint.HintDescriptor)) {
68 return lower * 0.75f + upper * 0.25f;
69 } else if (LADSPA_IS_HINT_DEFAULT_MIDDLE(hint.HintDescriptor)) {
70 return lower * 0.5f + upper * 0.5f;
71 } else if (LADSPA_IS_HINT_DEFAULT_HIGH(hint.HintDescriptor)) {
72 return lower * 0.25f + upper * 0.75f;
83 setControl(d3h_instance_t *instance, long controlIn, snd_seq_event_t *event)
85 long port = pluginControlInPortNumbers[controlIn];
87 const LADSPA_Descriptor *p = instance->plugin->descriptor->LADSPA_Plugin;
89 LADSPA_PortRangeHintDescriptor d = p->PortRangeHints[port].HintDescriptor;
91 LADSPA_Data lb = p->PortRangeHints[port].LowerBound *
92 (LADSPA_IS_HINT_SAMPLE_RATE(p->PortRangeHints[port].HintDescriptor) ?
95 LADSPA_Data ub = p->PortRangeHints[port].UpperBound *
96 (LADSPA_IS_HINT_SAMPLE_RATE(p->PortRangeHints[port].HintDescriptor) ?
99 float value = (float)event->data.control.value;
101 if (!LADSPA_IS_HINT_BOUNDED_BELOW(d)) {
102 if (!LADSPA_IS_HINT_BOUNDED_ABOVE(d)) {
103 /* unbounded: might as well leave the value alone. */
105 /* bounded above only. just shift the range. */
106 value = ub - 127.0f + value;
109 if (!LADSPA_IS_HINT_BOUNDED_ABOVE(d)) {
110 /* bounded below only. just shift the range. */
113 /* bounded both ends. more interesting. */
114 if (LADSPA_IS_HINT_LOGARITHMIC(d)) {
115 const float llb = logf(lb);
116 const float lub = logf(ub);
118 value = expf(llb + ((lub - llb) * value / 127.0f));
120 value = lb + ((ub - lb) * value / 127.0f);
126 printf("%s: %s MIDI controller %d=%d -> control in %ld=%f\n", myName,
127 instance->friendly_name, event->data.control.param,
128 event->data.control.value, controlIn, value);
131 pluginControlIns[controlIn] = value;
132 pluginPortUpdated[controlIn] = 1;