OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libjava/] [classpath/] [native/] [jni/] [midi-dssi/] [README] - Blame information for rev 774

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 774 jeremybenn
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:
6
 
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.
13
 
14
 
15
The rest of this file contain the original versions of these
16
functions.
17
 
18
 
19
LADSPA_Data get_port_default(const LADSPA_Descriptor *plugin, int port)
20
{
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);
26
 
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
        }
33
 
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
        }
38
 
39
        /* No clues, return minimum */
40
        return lower;
41
    }
42
 
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
    }
54
 
55
    /* All the others require some bounds */
56
 
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
    }
76
 
77
    /* fallback */
78
    return 0.0f;
79
}
80
 
81
 
82
void
83
setControl(d3h_instance_t *instance, long controlIn, snd_seq_event_t *event)
84
{
85
    long port = pluginControlInPortNumbers[controlIn];
86
 
87
    const LADSPA_Descriptor *p = instance->plugin->descriptor->LADSPA_Plugin;
88
 
89
    LADSPA_PortRangeHintDescriptor d = p->PortRangeHints[port].HintDescriptor;
90
 
91
    LADSPA_Data lb = p->PortRangeHints[port].LowerBound *
92
        (LADSPA_IS_HINT_SAMPLE_RATE(p->PortRangeHints[port].HintDescriptor) ?
93
         sample_rate : 1.0f);
94
 
95
    LADSPA_Data ub = p->PortRangeHints[port].UpperBound *
96
        (LADSPA_IS_HINT_SAMPLE_RATE(p->PortRangeHints[port].HintDescriptor) ?
97
         sample_rate : 1.0f);
98
 
99
    float value = (float)event->data.control.value;
100
 
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);
117
 
118
                value = expf(llb + ((lub - llb) * value / 127.0f));
119
            } else {
120
                value = lb + ((ub - lb) * value / 127.0f);
121
            }
122
        }
123
    }
124
 
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
    }
130
 
131
    pluginControlIns[controlIn] = value;
132
    pluginPortUpdated[controlIn] = 1;
133
}
134
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.