Subversion Repositories svn.mios

Rev

Rev 555 | Rev 666 | 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.sidlibr;
22
 
23
import javax.sound.midi.MidiMessage;
24
import javax.sound.midi.Receiver;
25
import javax.sound.midi.SysexMessage;
628 adamjking 26
 
213 tk 27
import org.midibox.sidedit.SIDSysexInfo;
28
 
29
public class Patch implements Receiver {
30
    public static Object LEAD = new Object();
31
    public static Object BASSLINE = new Object();
32
    public static Object DRUM = new Object();
505 rutgerv 33
    public static Object MULTI = new Object();
628 adamjking 34
    private static int delay = 10; // Delay in ms between Sysex Strings
213 tk 35
    protected int[] patch = new int[512];
628 adamjking 36
    private int WOPT = 0;
213 tk 37
    protected Receiver receiver;
396 tk 38
 
628 adamjking 39
    // TK: for quick & dirty initialisation
40
    // presets are based on
41
    // $MIOS_PATH/apps/synthesizers/midibox_sid_v2/src/sid_preset_*.inc
42
    final int[] defaultLeadPatch = new int[] { 0x4C, 0x65, 0x61, 0x64, 0x20,
43
            0x50, 0x61, 0x74, 0x63, 0x68, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
44
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
45
            0x00, 0xff, 0x00, 0x00, 0x80, 0x00, 0xff, 0x00, 0x00, 0x80, 0x00,
46
            0xff, 0x00, 0x00, 0x80, 0x00, 0xff, 0x00, 0x00, 0x80, 0x00, 0xff,
47
            0x00, 0x00, 0x80, 0x00, 0xff, 0x50, 0x00, 0x80, 0x00, 0xff, 0x00,
48
            0x00, 0x80, 0x00, 0xff, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00,
49
            0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x00,
50
            0x7f, 0x00, 0x10, 0x00, 0x02, 0x00, 0x00, 0x00, 0x10, 0x00, 0x02,
51
            0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0xf0, 0x00, 0x08, 0x00, 0x00,
52
            0x40, 0x80, 0x02, 0x00, 0x00, 0x1f, 0x05, 0x00, 0x00, 0x14, 0x00,
53
            0xf0, 0x00, 0x08, 0x00, 0x00, 0x40, 0x80, 0x02, 0x00, 0x00, 0x1f,
54
            0x05, 0x00, 0x00, 0x14, 0x00, 0xf0, 0x00, 0x08, 0x00, 0x00, 0x40,
55
            0x80, 0x02, 0x00, 0x00, 0x1f, 0x05, 0x00, 0x00, 0x04, 0x00, 0xf0,
56
            0x00, 0x08, 0x00, 0x00, 0x40, 0x80, 0x02, 0x00, 0x00, 0x1f, 0x05,
57
            0x00, 0x00, 0x14, 0x00, 0xf0, 0x00, 0x08, 0x00, 0x00, 0x40, 0x80,
58
            0x02, 0x00, 0x00, 0x1f, 0x05, 0x00, 0x00, 0x14, 0x00, 0xf0, 0x00,
59
            0x08, 0x00, 0x00, 0x40, 0x80, 0x02, 0x00, 0x00, 0x1f, 0x05, 0x00,
60
            0x01, 0x80, 0x00, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x00, 0x01,
61
            0x80, 0x00, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x00, 0x01, 0x80,
62
            0x00, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x00, 0, 0, 0x00, 0xc0,
63
            0x00, 0x30, 0xff, 0x00, 0x00, 0xff, 0x30, 0x40, 0x20, 0x00, 0x00,
64
            0x80, 0x80, 0x80, 0x00, 0x40, 0x00, 0x50, 0xff, 0x00, 0x00, 0xff,
65
            0x50, 0x10, 0x30, 0x00, 0x00, 0x80, 0x80, 0x80, 0x01, 0x00, 0x03,
66
            0xc0, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x03, 0xc0, 0x00, 0x00,
67
            0x00, 0x00, 0x03, 0x00, 0x03, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x04,
68
            0x00, 0x03, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x03, 0xc0,
69
            0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x03, 0xc0, 0x00, 0x00, 0x00,
70
            0x00, 0x07, 0x00, 0x03, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00,
71
            0x03, 0xc0, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x0f, 0x3f, 0x03,
72
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
73
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
74
            0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00,
75
            0x00, 0x00, 0x00, 0x00, 0, 0, 0xcb, 0x00, 0x00, 0x1f, 0x80, 0xcb,
76
            0x00, 0x20, 0x3f, 0xa0, 0xcb, 0x00, 0x40, 0x5f, 0xc0, 0xcb, 0x00,
77
            0x60, 0x7f, 0xe0, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
78
            0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
79
            0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
80
            0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
81
            0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
82
            0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
83
            0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
84
            0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
85
            0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
86
            0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
87
            0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
88
            0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, };
396 tk 89
 
628 adamjking 90
    final int[] defaultBasslinePatch = new int[] { 0x42, 0x61, 0x73, 0x73,
91
            0x6C, 0x69, 0x6E, 0x65, 0x20, 0x50, 0x61, 0x74, 0x63, 0x68, 0x20,
92
            0x20, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x61, 0x00,
93
            0x08, 0x00, 0xff, 0x65, 0x00, 0xff, 0x00, 0xff, 0x69, 0x00, 0x60,
94
            0x00, 0xff, 0x6d, 0x00, 0x30, 0x00, 0xff, 0x71, 0x00, 0x20, 0x00,
95
            0xff, 0x00, 0x00, 0x80, 0x00, 0xff, 0x51, 0x00, 0x80, 0x00, 0xff,
96
            0x00, 0x00, 0x80, 0x00, 0xff, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80,
97
            0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00,
98
            0x00, 0x7f, 0x00, 0x17, 0x08, 0x00, 0xf0, 0x00, 0x00, 0x17, 0x08,
99
            0x00, 0xf0, 0x00, 0x00, 0x01, 0x04, 0x00, 0xc0, 0x00, 0x09, 0x10,
100
            0x00, 0x28, 0x80, 0x02, 0x28, 0x00, 0x1f, 0x05, 0x00, 0x07, 0x00,
101
            0x00, 0x00, 0x03, 0x80, 0x06, 0x00, 0x00, 0x80, 0x80, 0x03, 0x80,
102
            0x16, 0x00, 0x00, 0x80, 0x80, 0x00, 0x80, 0x80, 0xa0, 0x04, 0x38,
103
            0x20, 0x10, 0x80, 0x03, 0x00, 0x0f, 0x00, 0x00, 0x28, 0x00, 0x00,
104
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
105
            0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
106
            0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x00, 0xc0,
107
            0x00, 0x09, 0x10, 0x00, 0x28, 0x80, 0x02, 0x28, 0x00, 0x1f, 0x05,
108
            0x00, 0x07, 0x00, 0x00, 0x00, 0x03, 0x80, 0x06, 0x00, 0x00, 0x80,
109
            0x80, 0x03, 0x80, 0x16, 0x00, 0x00, 0x80, 0x80, 0x00, 0x80, 0x80,
110
            0xa0, 0x04, 0x38, 0x20, 0x10, 0x80, 0x03, 0x08, 0x0f, 0x00, 0x00,
111
            0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
112
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
113
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
114
            0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
115
            0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
116
            0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
117
            0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
118
            0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
119
            0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
120
            0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
121
            0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
122
            0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
123
            0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
124
            0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
125
            0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x40, 0x40, 0x40, 0x40, 0x40,
126
            0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
127
            0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
128
            0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
129
            0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
130
            0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
131
            0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
132
            0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
133
            0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
134
            0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
135
            0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
136
            0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
137
            0x40, 0x40, };
396 tk 138
 
628 adamjking 139
    final int[] defaultDrumPatch = new int[] { 0x44, 0x72, 0x75, 0x6D, 0x20,
140
            0x4B, 0x69, 0x74, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
141
            0x02, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
142
            0x00, 0xff, 0x00, 0x00, 0x80, 0x00, 0xff, 0x00, 0x00, 0x80, 0x00,
143
            0xff, 0x00, 0x00, 0x80, 0x00, 0xff, 0x00, 0x00, 0x80, 0x00, 0xff,
144
            0x00, 0x00, 0x80, 0x00, 0xff, 0x00, 0x00, 0x80, 0x00, 0xff, 0x00,
145
            0x00, 0x80, 0x00, 0xff, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00,
146
            0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x03, 0x08,
147
            0x7f, 0x0f, 0x10, 0x00, 0x02, 0x00, 0x00, 0x00, 0x10, 0x00, 0x02,
148
            0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0xc9, 0x80, 0x80, 0x80, 0x80,
149
            0x00, 0x00, 0x00, 0x01, 0x09, 0xc9, 0x80, 0x80, 0x80, 0x80, 0x00,
150
            0x00, 0x00, 0x02, 0x09, 0xc9, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00,
151
            0x00, 0x03, 0x09, 0xc9, 0xff, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00,
152
            0x04, 0x09, 0xc9, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x05,
153
            0x09, 0xc9, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x06, 0x09,
154
            0xc9, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x07, 0x09, 0xc9,
155
            0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x08, 0x09, 0xc9, 0x80,
156
            0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x09, 0x09, 0xc9, 0x80, 0x80,
157
            0x80, 0x80, 0x00, 0x00, 0x00, 0x0a, 0x09, 0xc9, 0x80, 0x80, 0x80,
158
            0x80, 0x00, 0x00, 0x00, 0x0b, 0x09, 0xc9, 0x80, 0x80, 0x80, 0x80,
159
            0x00, 0x00, 0x00, 0x0c, 0x09, 0xc9, 0x80, 0x80, 0x80, 0x80, 0x00,
160
            0x00, 0x00, 0x0d, 0x09, 0xc9, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00,
161
            0x00, 0x0e, 0x09, 0xc9, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00,
162
            0x0f, 0x09, 0xc9, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x11, 0x00,
163
            0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
164
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
165
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x00, 0x11,
166
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
167
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
168
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x00, 0x11, 0x00,
169
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
170
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
171
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x00, 0x11, 0x00, 0x00,
172
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
173
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
174
            0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x00, 0x11, 0x00, 0x00, 0x00,
175
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
176
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
177
            0x00, 0x00, 0x00, 0x00, 0x11, 0x00, 0x11, 0x00, 0x00, 0x00, 0x00,
178
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
179
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
180
            0x00, 0x00, 0x00, 0x11, 0x00, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00,
181
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
182
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
183
            0x00, 0x00, 0x11, 0x00, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
184
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
185
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
186
            0x00, };
396 tk 187
 
628 adamjking 188
    final int[] defaultMultiPatch = new int[] { 0x4D, 0x75, 0x6C, 0x74, 0x69,
189
            0x20, 0x50, 0x61, 0x74, 0x63, 0x68, 0x20, 0x20, 0x20, 0x20, 0x20,
190
            0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
191
            0x00, 0xff, 0x00, 0x00, 0x80, 0x00, 0xff, 0x00, 0x00, 0x80, 0x00,
192
            0xff, 0x00, 0x00, 0x80, 0x00, 0xff, 0x00, 0x00, 0x80, 0x00, 0xff,
193
            0x00, 0x00, 0x80, 0x00, 0xff, 0x00, 0x00, 0x80, 0x00, 0xff, 0x00,
194
            0x00, 0x80, 0x00, 0xff, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00,
195
            0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x00,
196
            0x7f, 0x00, 0x10, 0x00, 0x02, 0x00, 0x00, 0x00, 0x10, 0x00, 0x02,
197
            0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0xfa, 0x00, 0x08, 0x00, 0x00,
198
            0x40, 0x80, 0x02, 0x00, 0x00, 0x1f, 0x05, 0x00, 0x08, 0x00, 0x00,
199
            0x79, 0x01, 0x80, 0x06, 0x00, 0x00, 0xc0, 0x80, 0x01, 0x80, 0x16,
200
            0x00, 0x00, 0x90, 0x80, 0x00, 0x80, 0x80, 0x80, 0x30, 0x30, 0x40,
201
            0x20, 0x80, 0xc7, 0x00, 0x00, 0x0f, 0xd0, 0x00, 0x04, 0x00, 0xfa,
202
            0x00, 0x08, 0x00, 0x00, 0x40, 0x80, 0x02, 0x00, 0x00, 0x1f, 0x05,
203
            0x00, 0x08, 0x00, 0x00, 0x79, 0x01, 0x80, 0x06, 0x00, 0x00, 0xc0,
204
            0x80, 0x01, 0x80, 0x16, 0x00, 0x00, 0x90, 0x80, 0x00, 0x80, 0x80,
205
            0x80, 0x30, 0x30, 0x40, 0x20, 0x80, 0xc7, 0x00, 0x10, 0x1f, 0xd0,
206
            0x00, 0x04, 0x00, 0xfa, 0x00, 0x08, 0x00, 0x00, 0x40, 0x80, 0x02,
207
            0x00, 0x00, 0x1f, 0x05, 0x00, 0x08, 0x00, 0x00, 0x79, 0x01, 0x80,
208
            0x06, 0x00, 0x00, 0xc0, 0x80, 0x01, 0x80, 0x16, 0x00, 0x00, 0x90,
209
            0x80, 0x00, 0x80, 0x80, 0x80, 0x30, 0x30, 0x40, 0x20, 0x80, 0xc7,
210
            0x00, 0x20, 0x2f, 0xd0, 0x00, 0x04, 0x00, 0xfa, 0x00, 0x08, 0x00,
211
            0x00, 0x40, 0x80, 0x02, 0x00, 0x00, 0x1f, 0x05, 0x00, 0x08, 0x00,
212
            0x00, 0x79, 0x01, 0x80, 0x06, 0x00, 0x00, 0xc0, 0x80, 0x01, 0x80,
213
            0x16, 0x00, 0x00, 0x90, 0x80, 0x00, 0x80, 0x80, 0x80, 0x30, 0x30,
214
            0x40, 0x20, 0x80, 0xc7, 0x00, 0x30, 0x3f, 0xd0, 0x00, 0x04, 0x00,
215
            0xfa, 0x00, 0x08, 0x00, 0x00, 0x40, 0x80, 0x02, 0x00, 0x00, 0x1f,
216
            0x05, 0x00, 0x08, 0x00, 0x00, 0x79, 0x01, 0x80, 0x06, 0x00, 0x00,
217
            0xc0, 0x80, 0x01, 0x80, 0x16, 0x00, 0x00, 0x90, 0x80, 0x00, 0x80,
218
            0x80, 0x80, 0x30, 0x30, 0x40, 0x20, 0x80, 0xc7, 0x00, 0x40, 0x4f,
219
            0xd0, 0x00, 0x04, 0x00, 0xfa, 0x00, 0x08, 0x00, 0x00, 0x40, 0x80,
220
            0x02, 0x00, 0x00, 0x1f, 0x05, 0x00, 0x08, 0x00, 0x00, 0x79, 0x01,
221
            0x80, 0x06, 0x00, 0x00, 0xc0, 0x80, 0x01, 0x80, 0x16, 0x00, 0x00,
222
            0x90, 0x80, 0x00, 0x80, 0x80, 0x80, 0x30, 0x30, 0x40, 0x20, 0x80,
223
            0xc7, 0x00, 0x50, 0x5f, 0xd0, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
224
            0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
225
            0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
226
            0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
227
            0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
228
            0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
229
            0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
230
            0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
231
            0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
232
            0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
233
            0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
234
            0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40,
235
            0x40, };
396 tk 236
 
213 tk 237
    public Patch(Receiver receiver) {
628 adamjking 238
        this.receiver = receiver;
213 tk 239
        initPatch();
240
    }
628 adamjking 241
 
213 tk 242
    private void initPatch() {
628 adamjking 243
        // TK: initialize patch depending on engine
244
        int e = getParameter(16, 0, 2);
245
        int i;
396 tk 246
 
628 adamjking 247
        // (quick & dirty initialisation - presets are based on
248
        // $MIOS_PATH/apps/synthesizers/midibox_sid_v2/src/sid_preset_*.inc)
249
        // Btw.: I've no idea, why the two nibbles of defaultLeadPatch[] bytes
250
        // are swapped - please enlight me ;)
251
        switch (e) {
252
        case 0:
253
            for (i = 0; i < 512; ++i) {
254
                patch[i] = ((defaultLeadPatch[i] & 0x0f) << 4)
255
                        | ((defaultLeadPatch[i] & 0xf0) >> 4);
256
            }
257
            setPatchName("Lead Patch      ");
258
            break;
259
        case 1:
260
            for (i = 0; i < 512; ++i) {
261
                patch[i] = ((defaultBasslinePatch[i] & 0x0f) << 4)
262
                        | ((defaultBasslinePatch[i] & 0xf0) >> 4);
263
            }
264
            setPatchName("Bassline Patch  ");
265
            break;
266
        case 2:
267
            for (i = 0; i < 512; ++i) {
268
                patch[i] = ((defaultDrumPatch[i] & 0x0f) << 4)
269
                        | ((defaultDrumPatch[i] & 0xf0) >> 4);
270
            }
271
            setPatchName("Drum Kit        ");
272
            break;
273
        case 3:
274
            for (i = 0; i < 512; ++i) {
275
                patch[i] = ((defaultMultiPatch[i] & 0x0f) << 4)
276
                        | ((defaultMultiPatch[i] & 0xf0) >> 4);
277
            }
278
            setPatchName("Multi Patch     ");
279
            break;
280
        }
213 tk 281
    }
628 adamjking 282
 
283
    public void setPatchName(String s) {
284
        for (int i = 0; i < 16; i++) {
285
            int value = ((int) s.charAt(i)) & 0xFF;
213 tk 286
            patch[i] = nibbleSwap(value);
287
        }
288
    }
628 adamjking 289
 
290
    public String getPatchName() {
213 tk 291
        String s = new String("");
628 adamjking 292
        for (int i = 0; i < 16; i++) {
293
            s = s + (char) nibbleSwap(patch[i]);
213 tk 294
        }
628 adamjking 295
        return s;
213 tk 296
    }
628 adamjking 297
 
213 tk 298
    public Object getEngine() {
299
        int e = getParameter(16, 0, 2);
300
        Object engine = new Object();
301
        switch (e) {
628 adamjking 302
        case 0:
303
            engine = LEAD;
304
            break;
305
        case 1:
306
            engine = BASSLINE;
307
            break;
308
        case 2:
309
            engine = DRUM;
310
            break;
311
        case 3:
312
            engine = MULTI;
313
            break;
314
        default:
315
            System.out.println("Unknown engine!");
316
            break;
317
        }
318
        return engine;
213 tk 319
    }
628 adamjking 320
 
213 tk 321
    public String getEngineStr() {
322
        int e = getParameter(16, 0, 2);
323
        String engine = "";
324
        switch (e) {
628 adamjking 325
        case 0:
326
            engine = "LEAD";
327
            break;
328
        case 1:
329
            engine = "BASSLINE";
330
            break;
331
        case 2:
332
            engine = "DRUM";
333
            break;
334
        case 3:
335
            engine = "MULTI";
336
            break;
337
        default:
338
            System.out.println("Unknown engine!");
339
            break;
340
        }
341
        return engine;
213 tk 342
    }
628 adamjking 343
 
213 tk 344
    public String getSysexString() {
345
        String s = "";
346
        int sum = 0;
628 adamjking 347
        for (int i = 0; i < patch.length; i++) {
348
            String newStr = calcValue(nibbleSwap(patch[i]), 1);
349
            sum = sum + Integer.parseInt(newStr.substring(1, 2), 16);
350
            sum = sum + Integer.parseInt(newStr.substring(3, 4), 16);
213 tk 351
            s = s + newStr;
352
        }
353
        String checksum = Integer.toHexString(-sum & 0x7F);
628 adamjking 354
        if (checksum.length() == 1) {
213 tk 355
            checksum = "0" + checksum;
356
        }
628 adamjking 357
        return (s + checksum);
213 tk 358
    }
628 adamjking 359
 
213 tk 360
    public String parsePatch(String d) {
628 adamjking 361
        String status;
362
        int dsi = 20; // Index where real patch data starts
213 tk 363
        int checksum = 0;
628 adamjking 364
        for (int i = 0; i < 512; i++) {
365
            String s1 = d.substring((4 * i) + dsi + 1, (4 * i) + dsi + 2);
366
            String s2 = d.substring((4 * i) + dsi + 3, (4 * i) + dsi + 4);
367
            checksum = checksum + Integer.parseInt(s1, 16);
368
            checksum = checksum + Integer.parseInt(s2, 16);
369
            int temp = Integer.parseInt(s1 + s2, 16);
213 tk 370
            patch[i] = temp;
371
        }
628 adamjking 372
        int chk = Integer.parseInt(d.substring((4 * 512) + dsi, (4 * 512) + dsi
373
                + 2), 16);
213 tk 374
        if (chk != (-checksum & 0x7F)) {
375
            status = "checksum error";
628 adamjking 376
        } else {
377
            status = "succesful";
213 tk 378
        }
628 adamjking 379
        return status;
213 tk 380
    }
628 adamjking 381
 
213 tk 382
    public void setPatch(int[] p) {
383
        patch = p;
384
    }
628 adamjking 385
 
213 tk 386
    public int[] getPatch() {
387
        return patch;
388
    }
628 adamjking 389
 
213 tk 390
    public void setEngine(Object object) {
628 adamjking 391
        if (object == LEAD) {
504 rutgerv 392
            setParameter(16, 0, 0, 2, true);
628 adamjking 393
        } else if (object == BASSLINE) {
504 rutgerv 394
            setParameter(16, 1, 0, 2, true);
628 adamjking 395
        } else if (object == DRUM) {
504 rutgerv 396
            setParameter(16, 2, 0, 2, true);
628 adamjking 397
        } else if (object == MULTI) {
504 rutgerv 398
            setParameter(16, 3, 0, 2, true);
213 tk 399
        }
396 tk 400
 
401
        // TK: patch has to be re-initialized after engine change
402
        initPatch();
628 adamjking 403
    }
404
 
213 tk 405
    public int getParameter(int address, int start_bit, int resolution) {
406
        int value = 0;
407
        int absres = Math.abs(resolution);
628 adamjking 408
 
409
        // resolution < 8 bit: gets value of bit length 'resolution' starting on
410
        // the start_bit
213 tk 411
        if (absres < 8) {
412
            int bitmask = 0;
628 adamjking 413
            for (int j = 0; j < absres; j++) { // Iterate over all bits
414
                bitmask = bitmask | (int) Math.pow(2, (start_bit + j));
415
            }
416
            value = (bitmask & nibbleSwap(patch[address])) >> start_bit;
213 tk 417
        }
628 adamjking 418
 
213 tk 419
        // 8 bit values
420
        if (absres == 8) {
628 adamjking 421
            value = nibbleSwap(patch[address]);
213 tk 422
        }
628 adamjking 423
 
213 tk 424
        // 12 bit values
425
        if (absres == 12) {
426
            int temp1 = nibbleSwap(patch[address]);
628 adamjking 427
            int temp2 = nibbleSwap(patch[address + 1] & 0xF0);
213 tk 428
            value = (temp2 << 8) + temp1;
429
        }
628 adamjking 430
 
213 tk 431
        // 16 bit values
432
        if (absres == 16) {
433
            int temp1 = nibbleSwap(patch[address]);
628 adamjking 434
            int temp2 = nibbleSwap(patch[address + 1]);
213 tk 435
            value = (temp2 << 8) + temp1;
436
        }
628 adamjking 437
 
213 tk 438
        // Shift positive integers down to make them bipolar (if required)
439
        if (resolution < 0) {
628 adamjking 440
            int midimin = -((int) Math.ceil((Math.pow(2, absres) - 1) / 2));
441
            value = value + midimin;
213 tk 442
        }
628 adamjking 443
 
213 tk 444
        return value;
445
    }
628 adamjking 446
 
447
    public void setParameter(int address, int value, int start_bit,
448
            int resolution, boolean forward) {
213 tk 449
        int absres = Math.abs(resolution);
628 adamjking 450
 
213 tk 451
        // Shift all bipolar values up to make them fit into a positive integer
452
        if (resolution < 0) {
628 adamjking 453
            int midimin = -((int) Math.ceil((Math.pow(2, absres) - 1) / 2));
454
            value = value - midimin;
213 tk 455
        }
628 adamjking 456
 
457
        // resolution < 8 bit: sets value of bit length 'resolution' starting on
458
        // the start_bit
459
        if (absres < 8) {
460
            int temp = nibbleSwap(patch[address]); // Retrieve data
461
 
462
            for (int j = 0; j < absres; j++) { // Iterate over all bits
213 tk 463
                int this_bit = start_bit + j;
628 adamjking 464
                int bitmask0 = (int) Math.pow(2, j); // Bitmask for checking if
465
                // current bit needs to
466
                // change
467
                int bitmask1 = (int) Math.pow(2, (this_bit)); // Bitmask for
468
                // turning bits
469
                // on
470
                int bitmask2 = (~bitmask1) & 0xFF; // Bitmask for turning bits
471
                // off
472
                if ((value & bitmask0) == 0) {
473
                    temp = (temp & bitmask2) & 0xFF; // Turn bit off
213 tk 474
                }
628 adamjking 475
                if ((value & bitmask0) != 0) {
476
                    temp = (temp | bitmask1) & 0xFF; // Turn bit on
477
                }
478
            }
479
            patch[address] = nibbleSwap(temp); // Put back new data
504 rutgerv 480
            if (forward) {
481
                sysexSend(address, temp, 1);
482
            }
213 tk 483
        }
628 adamjking 484
 
213 tk 485
        // 8 bit values
486
        if (absres == 8) {
487
            patch[address] = nibbleSwap(value & 0xFF);
504 rutgerv 488
            if (forward) {
489
                sysexSend(address, (value & 0xFF), 1);
490
            }
213 tk 491
        }
628 adamjking 492
 
213 tk 493
        // 12 bit values
494
        if (absres == 12) {
628 adamjking 495
            int temp = nibbleSwap(patch[address + 1]); // Retrieve data
213 tk 496
            temp = (temp & 0xFF00);
497
            patch[address] = nibbleSwap(value & 0xFF);
628 adamjking 498
            patch[address + 1] = nibbleSwap(temp + ((value & 0xF00) >> 8));
504 rutgerv 499
            if (forward) {
628 adamjking 500
                sysexSend(address, ((temp << 4) + (value & 0xFFF)), 2);
504 rutgerv 501
            }
213 tk 502
        }
628 adamjking 503
 
213 tk 504
        // 16 bit values
505
        if (absres == 16) {
506
            patch[address] = nibbleSwap(value & 0xFF);
628 adamjking 507
            patch[address + 1] = nibbleSwap((value & 0xFF00) >> 8);
504 rutgerv 508
            if (forward) {
509
                sysexSend(address, (value & 0xFFFF), 2);
510
            }
213 tk 511
        }
512
    }
628 adamjking 513
 
514
    private static int nibbleSwap(int inInt) {
213 tk 515
        int nibble0 = (((byte) inInt) << 4) & 0xf0;
516
        int nibble1 = (((byte) inInt) >>> 4) & 0x0f;
517
        return (nibble0 | nibble1);
518
    }
628 adamjking 519
 
272 rutgerv 520
    public void setStereoLink(boolean b) {
521
        if (b) {
522
            WOPT = WOPT | 0x01;
523
        } else {
524
            WOPT = WOPT & 0x02;
525
        }
526
    }
628 adamjking 527
 
272 rutgerv 528
    public void setOscillatorLink(boolean b) {
529
        if (b) {
530
            WOPT = WOPT | 0x02;
531
        } else {
532
            WOPT = WOPT & 0x01;
533
        }
534
    }
628 adamjking 535
 
536
    public void sysexSend(int addr, int value, int bytes) {
537
        SysexMessage sysexMessage = new SysexMessage();
293 rutgerv 538
        try {
539
            String strMessage = SIDSysexInfo.editPatchParameterSysex;
540
            strMessage = strMessage.replace("<device>", "00");
628 adamjking 541
            strMessage = strMessage.replace("<wopt>", "0"
542
                    + Integer.toHexString(WOPT));
293 rutgerv 543
            strMessage = strMessage.replace("<address>", calcAddr(addr));
628 adamjking 544
            strMessage = strMessage.replace("<value>", calcValue(value, bytes));
545
 
546
            int nLengthInBytes = strMessage.length() / 2;
547
            byte[] abMessage = new byte[nLengthInBytes];
548
            for (int i = 0; i < nLengthInBytes; i++) {
549
                abMessage[i] = (byte) Integer.parseInt(strMessage.substring(
550
                        i * 2, i * 2 + 2), 16);
293 rutgerv 551
            }
628 adamjking 552
 
293 rutgerv 553
            System.out.println(strMessage);
628 adamjking 554
            sysexMessage.setMessage(abMessage, abMessage.length);
555
        } catch (Exception e) {
293 rutgerv 556
            System.out.println("exception!");
557
            System.out.println(e);
213 tk 558
        }
505 rutgerv 559
        receiver.send(sysexMessage, -1);
628 adamjking 560
 
505 rutgerv 561
        try {
562
            Thread.currentThread().sleep(delay);
563
        } catch (InterruptedException e) {
564
            e.printStackTrace();
565
        }
628 adamjking 566
 
213 tk 567
    }
628 adamjking 568
 
213 tk 569
    protected String calcAddr(int addr) {
570
        String str0 = Integer.toHexString(addr & 0x00F);
571
        String str1 = Integer.toHexString((addr & 0x070) >> 4);
572
        String str2 = Integer.toHexString((addr & 0x180) >> 7);
573
        return ("0" + str2 + str1 + str0);
574
    }
628 adamjking 575
 
213 tk 576
    protected String calcValue(int val, int byt) {
577
        String s = "";
628 adamjking 578
        if (byt == 1) {
213 tk 579
            String s0 = "0";
628 adamjking 580
            String s1 = Integer.toHexString(val & 0x0F);
581
            String s2 = Integer.toHexString((val & 0xF0) >> 4);
582
            s = (s0 + s1 + s0 + s2);
583
        } else if (byt == 2) {
213 tk 584
            String s0 = "0";
628 adamjking 585
            String s1 = Integer.toHexString(val & 0x000F);
586
            String s2 = Integer.toHexString((val & 0x00F0) >> 4);
587
            String s3 = Integer.toHexString((val & 0x0F00) >> 8);
588
            String s4 = Integer.toHexString((val & 0xF000) >> 12);
589
            s = (s0 + s1 + s0 + s2 + s0 + s3 + s0 + s4);
213 tk 590
        }
591
        return s;
592
    }
628 adamjking 593
 
213 tk 594
    public void close() {
595
    }
628 adamjking 596
 
213 tk 597
    public Receiver getReceiver() {
598
        return receiver;
599
    }
600
 
601
    public void send(MidiMessage message, long lTimeStamp) {
602
 
603
    }
628 adamjking 604
 
213 tk 605
    public Patch clone() {
606
        Patch p = new Patch(receiver);
607
        p.setPatch(patch.clone());
628 adamjking 608
        return p;
609
    }
213 tk 610
}