Subversion Repositories svn.mios

Rev

Rev 504 | Rev 696 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
213 tk 1
/*
2
 * @(#)SIDV2librarian.java  beta1   2008/01/21
3
 *
4
 * Copyright (C) 2008    Rutger Vlek (rutgervlek@hotmail.com)
5
 *
6
 * This application is free software; you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation; either version 2 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * This application is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this application; if not, write to the Free Software
18
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19
 */
20
 
21
package org.midibox.sidedit;
22
 
23
import java.util.Observable;
628 adamjking 24
 
213 tk 25
import javax.sound.midi.MidiMessage;
26
import javax.sound.midi.Receiver;
27
 
28
import org.midibox.sidlibr.Patch;
29
 
30
public class SIDSysexParameter extends Observable implements Receiver {
31
 
32
    public final static Object VALUE = new Object();
33
 
34
    protected Receiver receiver;
35
 
36
    protected int value;
37
 
38
    protected int address;
628 adamjking 39
 
213 tk 40
    protected int start_bit;
41
 
42
    protected int midimax, midimin;
43
 
44
    protected int resolution;
628 adamjking 45
 
213 tk 46
    protected String name;
628 adamjking 47
 
213 tk 48
    protected Patch patch;
628 adamjking 49
 
50
    public SIDSysexParameter(Patch p, int address, int start_b, int reso,
51
            String name) {
213 tk 52
        setReceiver(p.getReceiver());
53
        setMidiMaxMinValues(reso);
54
        this.address = address;
55
        this.start_bit = start_b;
56
        this.patch = p;
57
        this.name = name;
504 rutgerv 58
        setMidiValue(p.getParameter(address, start_b, reso), false);
213 tk 59
    }
628 adamjking 60
 
213 tk 61
    public Receiver getReceiver() {
62
        return receiver;
63
    }
628 adamjking 64
 
213 tk 65
    protected void setReceiver(Receiver receiver) {
66
        this.receiver = receiver;
67
    }
68
 
69
    public int getMidiValue() {
70
        return limitMidiValue(value);
71
    }
72
 
73
    public void setMidiValue(int value, boolean forward) {
74
        this.value = limitMidiValue(value);
75
 
504 rutgerv 76
        patch.setParameter(address, this.value, start_bit, resolution, forward);
628 adamjking 77
 
213 tk 78
        setChanged();
79
        notifyObservers(VALUE);
80
        clearChanged();
81
    }
628 adamjking 82
 
213 tk 83
    public void setMidiMaxMinValues(int reso) {
84
        if (reso < 0) {
628 adamjking 85
            midimax = (int) Math.floor((Math.pow(2, Math.abs(reso)) - 1) / 2);
86
            midimin = -((int) Math.ceil((Math.pow(2, Math.abs(reso)) - 1) / 2));
87
        } else {
88
            midimax = (int) Math.pow(2, reso) - 1;
213 tk 89
            midimin = 0;
90
        }
91
        resolution = reso;
92
    }
93
 
628 adamjking 94
    public int getMidiMaxValue() {
213 tk 95
        return midimax;
96
    }
628 adamjking 97
 
98
    public int getMidiMinValue() {
213 tk 99
        return midimin;
100
    }
628 adamjking 101
 
213 tk 102
    public String getMidiName() {
103
        return name;
104
    }
105
 
106
    public void send(MidiMessage message, long lTimeStamp) {
628 adamjking 107
 
213 tk 108
    }
109
 
110
    public void close() {
111
    }
628 adamjking 112
 
213 tk 113
    protected int limitMidiValue(int i) {
628 adamjking 114
        if (i > midimax) {
115
            i = midimax;
116
        }
117
        if (i < midimin) {
118
            i = midimin;
119
        }
213 tk 120
        return i;
121
    }
122
}