Remove old autovect-branch by moving to "dead" directory.
[official-gcc.git] / old-autovect-branch / libjava / classpath / native / jni / midi-dssi / README
blob6913414ffa6be91b78285121e035dda778ef5877
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
5 terms:
7  Copyright 2004 Chris Cannam, Steve Harris and Sean Bolton.
8  
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
16 functions.
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 */
31             return 0.0f;
32         }
34         if (lower <= 0.0f && upper >= 0.0f) {
35             /* It spans 0.0, 0.0 is often a good guess */
36             return 0.0f;
37         }
39         /* No clues, return minimum */
40         return lower;
41     }
43     /* Try all the easy ones */
44     
45     if (LADSPA_IS_HINT_DEFAULT_0(hint.HintDescriptor)) {
46         return 0.0f;
47     } else if (LADSPA_IS_HINT_DEFAULT_1(hint.HintDescriptor)) {
48         return 1.0f;
49     } else if (LADSPA_IS_HINT_DEFAULT_100(hint.HintDescriptor)) {
50         return 100.0f;
51     } else if (LADSPA_IS_HINT_DEFAULT_440(hint.HintDescriptor)) {
52         return 440.0f;
53     }
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)) {
59             return lower;
60         }
61     }
62     if (LADSPA_IS_HINT_BOUNDED_ABOVE(hint.HintDescriptor)) {
63         if (LADSPA_IS_HINT_DEFAULT_MAXIMUM(hint.HintDescriptor)) {
64             return upper;
65         }
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;
73             }
74         }
75     }
77     /* fallback */
78     return 0.0f;
82 void
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) ?
93          sample_rate : 1.0f);
95     LADSPA_Data ub = p->PortRangeHints[port].UpperBound *
96         (LADSPA_IS_HINT_SAMPLE_RATE(p->PortRangeHints[port].HintDescriptor) ?
97          sample_rate : 1.0f);
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. */
104         } else {
105             /* bounded above only. just shift the range. */
106             value = ub - 127.0f + value;
107         }
108     } else {
109         if (!LADSPA_IS_HINT_BOUNDED_ABOVE(d)) {
110             /* bounded below only. just shift the range. */
111             value = lb + value;
112         } else {
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));
119             } else {
120                 value = lb + ((ub - lb) * value / 127.0f);
121             }
122         }
123     }
125     if (verbose) {
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);
129     }
131     pluginControlIns[controlIn] = value;
132     pluginPortUpdated[controlIn] = 1;