Subversion Repositories svn.mios

Rev

Rev 505 | 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
package org.midibox.sidedit;
21
 
22
import javax.sound.midi.MidiMessage;
628 adamjking 23
 
213 tk 24
import org.midibox.midi.MidiUtils;
25
import org.midibox.sidlibr.Patch;
26
 
27
public class SIDSysexParameterControl extends SIDSysexParameter {
28
 
29
    public final static Object RECEIVE = new Object();
30
 
31
    public final static Object SEND = new Object();
32
 
33
    protected boolean receive;
34
 
35
    protected boolean send;
628 adamjking 36
 
213 tk 37
    protected int type;
628 adamjking 38
 
213 tk 39
    protected String[] valAlias;
40
    protected String[] spValAlias;
628 adamjking 41
 
42
    public int[] snapvals = { 0 };
43
    public boolean useAlias = true; // Only for rate knob
213 tk 44
    public boolean snap = false;
628 adamjking 45
 
213 tk 46
    protected String tooltip;
628 adamjking 47
 
213 tk 48
    protected Object tooltipListener;
628 adamjking 49
 
50
    public SIDSysexParameterControl(int type, String[] valAlias, Patch patch,
51
            int addres, int start_bit, int reso, String name, String tooltip) {
213 tk 52
        super(patch, addres, start_bit, reso, name);
53
        setReceive(true);
54
        setSend(true);
55
        this.tooltip = tooltip;
56
        this.type = type;
57
        this.valAlias = valAlias;
58
        this.spValAlias = sparseValAlias(valAlias);
59
    }
628 adamjking 60
 
61
    public SIDSysexParameterControl(int type, String[] valAlias, Patch patch,
62
            int addres, int start_bit, int reso, String name) {
213 tk 63
        super(patch, addres, start_bit, reso, name);
64
        setReceive(true);
65
        setSend(true);
66
        this.tooltip = name;
67
        this.type = type;
628 adamjking 68
        this.valAlias = valAlias;
213 tk 69
        this.spValAlias = sparseValAlias(valAlias);
70
    }
628 adamjking 71
 
213 tk 72
    public boolean isReceive() {
73
        return receive;
74
    }
75
 
76
    public void setTooltipListener(Object object) {
77
        tooltipListener = object;
78
    }
628 adamjking 79
 
213 tk 80
    public Object getTooltipListener() {
81
        return tooltipListener;
82
    }
628 adamjking 83
 
213 tk 84
    public String getTooltip() {
85
        return tooltip;
86
    }
628 adamjking 87
 
213 tk 88
    public void setReceive(boolean respond) {
89
        this.receive = respond;
90
 
91
        setChanged();
92
        notifyObservers(RECEIVE);
93
        clearChanged();
94
    }
95
 
96
    public boolean isSend() {
97
        return send;
98
    }
99
 
100
    public void setSend(boolean send) {
101
        this.send = send;
628 adamjking 102
 
213 tk 103
        setChanged();
104
        notifyObservers(SEND);
105
        clearChanged();
106
    }
107
 
108
    public void setMidiValue(int value, boolean forward) {
109
        super.setMidiValue(value, forward);
110
    }
111
 
112
    public int getType() {
113
        return type;
114
    }
628 adamjking 115
 
213 tk 116
    public String[] getValAlias() {
117
        return valAlias;
118
    }
628 adamjking 119
 
213 tk 120
    public String[] getSparseValAlias() {
121
        return spValAlias;
122
    }
628 adamjking 123
 
213 tk 124
    public int lookUpValue(int i) {
125
        String s = valAlias[i];
126
        int val = 0;
628 adamjking 127
        for (int j = 0; j < spValAlias.length; j++) {
246 rutgerv 128
            if (spValAlias[j].equals(s)) {
213 tk 129
                val = j;
130
                break;
628 adamjking 131
            }
213 tk 132
        }
133
        return val;
628 adamjking 134
    }
135
 
213 tk 136
    public int lookUpAlias(String s) {
137
        int val = 0;
628 adamjking 138
        for (int j = 0; j < valAlias.length; j++) {
505 rutgerv 139
            System.out.println(s);
140
            System.out.println(valAlias[j]);
246 rutgerv 141
            if (valAlias[j].equals(s)) {
213 tk 142
                val = j;
143
                break;
628 adamjking 144
            }
213 tk 145
        }
146
        return val;
147
    }
628 adamjking 148
 
213 tk 149
    public String[] sparseValAlias(String[] in) {
628 adamjking 150
        if (valAlias != null) {
213 tk 151
            int temp = 0;
628 adamjking 152
            for (int i = 0; i < in.length; i++) {
153
                if (in[i] != "") {
154
                    temp = temp + 1;
213 tk 155
                }
628 adamjking 156
            }
157
 
158
            String[] out = new String[temp];
213 tk 159
            temp = 0;
628 adamjking 160
            for (int i = 0; i < in.length; i++) {
161
                if (in[i] != "") {
213 tk 162
                    out[temp] = in[i];
163
                    temp = temp + 1;
164
                }
165
            }
628 adamjking 166
            return out;
213 tk 167
        } else {
628 adamjking 168
            String[] out = { "" };
213 tk 169
            return out;
170
        }
171
    }
172
 
173
    public void send(MidiMessage message, long lTimeStamp) {
628 adamjking 174
        String m = MidiUtils.getHexString(message.getMessage())
175
                .replace(" ", "");
176
        if (m.indexOf(SIDSysexInfo.acknowledgedSysex.replace("<device>", "00")) == 0) {
177
            // System.out.println("MBSID: Acknowdledged!");
178
        } else if (m.equals(SIDSysexInfo.error1Sysex.replace("<device>", "00"))) {
213 tk 179
            System.out.println("MBSID: Received less bytes then expected");
628 adamjking 180
        } else if (m.equals(SIDSysexInfo.error2Sysex.replace("<device>", "00"))) {
213 tk 181
            System.out.println("MBSID: Wrong checksum");
628 adamjking 182
        } else if (m.equals(SIDSysexInfo.error3Sysex.replace("<device>", "00"))) {
183
            System.out
184
                    .println("MBSID: Bankstick or patch/drumset/ensemble not available");
185
        } else if (m.equals(SIDSysexInfo.error4Sysex.replace("<device>", "00"))) {
213 tk 186
            System.out.println("MBSID: Parameter not available");
628 adamjking 187
        } else if (m.equals(SIDSysexInfo.error5Sysex.replace("<device>", "00"))) {
213 tk 188
            System.out.println("MBSID: RAM access not supported");
628 adamjking 189
        } else if (m.equals(SIDSysexInfo.error6Sysex.replace("<device>", "00"))) {
213 tk 190
            System.out.println("MBSID: BankStick too small");
628 adamjking 191
        } else {
192
            System.out.println("MBSID: Unknown Sysex string: " + m);
213 tk 193
        }
628 adamjking 194
 
213 tk 195
        if (receive) {
196
            super.send(message, lTimeStamp);
197
        }
198
    }
628 adamjking 199
 
213 tk 200
}