Subversion Repositories svn.mios

Rev

Rev 628 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 628 Rev 641
1
/*
1
/*
2
 * @(#)SIDV2librarian.java  beta1   2008/01/21
2
 * @(#)SIDV2librarian.java  beta1   2008/01/21
3
 *
3
 *
4
 * Copyright (C) 2008    Rutger Vlek (rutgervlek@hotmail.com)
4
 * Copyright (C) 2008    Rutger Vlek (rutgervlek@hotmail.com)
5
 *                     
5
 *                     
6
 * This application is free software; you can redistribute it and/or modify
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
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
8
 * the Free Software Foundation; either version 2 of the License, or
9
 * (at your option) any later version.
9
 * (at your option) any later version.
10
 *
10
 *
11
 * This application is distributed in the hope that it will be useful,
11
 * This application is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
14
 * GNU General Public License for more details.
15
 *
15
 *
16
 * You should have received a copy of the GNU General Public License
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
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
18
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19
 */
19
 */
20
20
21
package org.midibox.apps.SIDV2librarian;
21
package org.midibox.apps.SIDV2librarian;
22
22
23
import javax.sound.midi.MidiDevice;
23
import javax.sound.midi.MidiDevice;
24
24
-
 
25
import org.midibox.midi.MidiDeviceManager;
25
import org.midibox.midi.MidiDeviceRouting;
26
import org.midibox.midi.MidiDeviceRouting;
26
import org.midibox.sidlibr.SIDLibController;
27
import org.midibox.sidlibr.SIDLibController;
27
import org.midibox.sidlibr.SysExControllerDevice;
28
import org.midibox.sidlibr.SysExControllerDevice;
28
29
29
public class SIDV2librarian {
30
public class SIDV2librarian {
30
31
31
    private MidiDeviceRouting midiDeviceRouting;
32
    private MidiDeviceRouting midiDeviceRouting;
32
    private SysExControllerDevice sysexControllerDevice;
33
    private SysExControllerDevice sysexControllerDevice;
33
    private SIDLibController sidLibController;
34
    private SIDLibController sidLibController;
34
35
35
    private MidiDevice localMidiDevice;
36
    private MidiDevice localMidiDevice;
36
    private MidiDevice inputMidiDevice;
37
    private MidiDevice inputMidiDevice;
37
    private MidiDevice outputMidiDevice;
38
    private MidiDevice outputMidiDevice;
-
 
39
   
-
 
40
    private MidiDeviceManager midiDeviceManager;
38
41
39
    public SIDV2librarian() {
42
    public SIDV2librarian() {
40
43
41
        this(new MidiDeviceRouting());
44
        this(new MidiDeviceManager(), new MidiDeviceRouting());
42
    }
45
    }
43
46
44
    public SIDV2librarian(MidiDeviceRouting midiDeviceRouting) {
47
    public SIDV2librarian(MidiDeviceManager midiDeviceManager, MidiDeviceRouting midiDeviceRouting) {
-
 
48
-
 
49
        this.midiDeviceManager = midiDeviceManager;
45
50
       
46
        this.midiDeviceRouting = midiDeviceRouting;
51
        this.midiDeviceRouting = midiDeviceRouting;
47
52
48
        sysexControllerDevice = new SysExControllerDevice(
53
        sysexControllerDevice = new SysExControllerDevice(
49
                "MidiBox SID V2 Editor");
54
                "MidiBox SID V2 Editor");
50
55
51
        this.localMidiDevice = sysexControllerDevice;
56
        this.localMidiDevice = sysexControllerDevice;
52
57
53
        sidLibController = new SIDLibController(sysexControllerDevice
58
        sidLibController = new SIDLibController(sysexControllerDevice
54
                .getSysExController());
59
                .getSysExController());
55
60
56
        if (midiDeviceRouting != null) {
61
        if (midiDeviceRouting != null) {
57
            midiDeviceRouting.getMidiDeviceManager().rescanDevices();
62
            midiDeviceManager.rescanDevices();
58
-
 
59
            midiDeviceRouting.reorder();
63
            midiDeviceRouting.addMidiReadDevices(midiDeviceManager.getSelectedMidiReadDevices());
-
 
64
            midiDeviceRouting.addMidiWriteDevices(midiDeviceManager.getSelectedMidiWriteDevices());
60
        }
65
        }
-
 
66
    }
-
 
67
-
 
68
    public MidiDeviceManager getMidiDeviceManager() {
-
 
69
        return midiDeviceManager;
61
    }
70
    }
62
71
63
    public MidiDeviceRouting getMidiDeviceRouting() {
72
    public MidiDeviceRouting getMidiDeviceRouting() {
64
        return midiDeviceRouting;
73
        return midiDeviceRouting;
65
    }
74
    }
66
75
67
    public SysExControllerDevice getSysExControllerDevice() {
76
    public SysExControllerDevice getSysExControllerDevice() {
68
        return sysexControllerDevice;
77
        return sysexControllerDevice;
69
    }
78
    }
70
79
71
    public SIDLibController getSIDLibController() {
80
    public SIDLibController getSIDLibController() {
72
        return sidLibController;
81
        return sidLibController;
73
    }
82
    }
74
83
75
    public int getInputDeviceIndex() {
84
    public int getInputDeviceIndex() {
76
        return midiDeviceRouting.getMidiReadDevices().indexOf(inputMidiDevice);
85
        return midiDeviceRouting.getMidiReadDevices().indexOf(inputMidiDevice);
77
    }
86
    }
78
87
79
    public int getOutputDeviceIndex() {
88
    public int getOutputDeviceIndex() {
80
        return midiDeviceRouting.getMidiWriteDevices()
89
        return midiDeviceRouting.getMidiWriteDevices()
81
                .indexOf(outputMidiDevice);
90
                .indexOf(outputMidiDevice);
82
    }
91
    }
83
92
84
    public MidiDevice getLocalMidiDevice() {
93
    public MidiDevice getLocalMidiDevice() {
85
        return localMidiDevice;
94
        return localMidiDevice;
86
    }
95
    }
87
96
88
    public MidiDevice getInputMidiDevice() {
97
    public MidiDevice getInputMidiDevice() {
89
        return inputMidiDevice;
98
        return inputMidiDevice;
90
    }
99
    }
91
100
92
    public MidiDevice getOutputMidiDevice() {
101
    public MidiDevice getOutputMidiDevice() {
93
        return outputMidiDevice;
102
        return outputMidiDevice;
94
    }
103
    }
95
104
96
    public void reconnectAllDevices() { // This function is a workaround for the
105
    public void reconnectAllDevices() { // This function is a workaround for the
97
        // SysEx (string length doesn't reset)
106
        // SysEx (string length doesn't reset)
98
        // bug in the javax.sound.midi class
107
        // bug in the javax.sound.midi class
99
108
100
        if (midiDeviceRouting != null) {
109
        if (midiDeviceRouting != null) {
101
110
102
            System.out.println("Now reconnecting!");
111
            System.out.println("Now reconnecting!");
103
            midiDeviceRouting.disconnectDevices(inputMidiDevice,
112
            midiDeviceRouting.disconnectDevices(inputMidiDevice,
104
                    localMidiDevice);
113
                    localMidiDevice);
105
            System.out.println("Disconnection of "
114
            System.out.println("Disconnection of "
106
                    + inputMidiDevice.getDeviceInfo() + " succesfull");
115
                    + inputMidiDevice.getDeviceInfo() + " succesfull");
107
            midiDeviceRouting.disconnectDevices(localMidiDevice,
116
            midiDeviceRouting.disconnectDevices(localMidiDevice,
108
                    outputMidiDevice);
117
                    outputMidiDevice);
109
            System.out.println("Disconnection of "
118
            System.out.println("Disconnection of "
110
                    + outputMidiDevice.getDeviceInfo() + " succesfull");
119
                    + outputMidiDevice.getDeviceInfo() + " succesfull");
111
120
112
            midiDeviceRouting.connectDevices(inputMidiDevice, localMidiDevice);
121
            midiDeviceRouting.connectDevices(inputMidiDevice, localMidiDevice);
113
            System.out.println("Reconnection of "
122
            System.out.println("Reconnection of "
114
                    + inputMidiDevice.getDeviceInfo() + " succesfull");
123
                    + inputMidiDevice.getDeviceInfo() + " succesfull");
115
            midiDeviceRouting.connectDevices(localMidiDevice, outputMidiDevice);
124
            midiDeviceRouting.connectDevices(localMidiDevice, outputMidiDevice);
116
            System.out.println("Reconnection of "
125
            System.out.println("Reconnection of "
117
                    + outputMidiDevice.getDeviceInfo() + " succesfull");
126
                    + outputMidiDevice.getDeviceInfo() + " succesfull");
118
        }
127
        }
119
128
120
    }
129
    }
121
130
122
    public int findInputDeviceHash(int hash) {
131
    public int findInputDeviceHash(int hash) {
123
        int temp = -1;
132
        int temp = -1;
124
        for (int i = 0; i < midiDeviceRouting.getMidiReadDevices().size(); i++) {
133
        for (int i = 0; i < midiDeviceRouting.getMidiReadDevices().size(); i++) {
125
            if (((MidiDevice) midiDeviceRouting.getMidiReadDevices().elementAt(
134
            if (((MidiDevice) midiDeviceRouting.getMidiReadDevices().elementAt(
126
                    i)).getDeviceInfo().toString().hashCode() == hash) {
135
                    i)).getDeviceInfo().toString().hashCode() == hash) {
127
                temp = i;
136
                temp = i;
128
                break;
137
                break;
129
            }
138
            }
130
        }
139
        }
131
        return temp;
140
        return temp;
132
    }
141
    }
133
142
134
    public int findOuputDeviceHash(int hash) {
143
    public int findOuputDeviceHash(int hash) {
135
        int temp = -1;
144
        int temp = -1;
136
        for (int i = 0; i < midiDeviceRouting.getMidiWriteDevices().size(); i++) {
145
        for (int i = 0; i < midiDeviceRouting.getMidiWriteDevices().size(); i++) {
137
            if (((MidiDevice) midiDeviceRouting.getMidiWriteDevices()
146
            if (((MidiDevice) midiDeviceRouting.getMidiWriteDevices()
138
                    .elementAt(i)).getDeviceInfo().toString().hashCode() == hash) {
147
                    .elementAt(i)).getDeviceInfo().toString().hashCode() == hash) {
139
                temp = i;
148
                temp = i;
140
                break;
149
                break;
141
            }
150
            }
142
        }
151
        }
143
        return temp;
152
        return temp;
144
    }
153
    }
145
154
146
    public int getInputDeviceHash() {
155
    public int getInputDeviceHash() {
147
        return inputMidiDevice.getDeviceInfo().toString().hashCode();
156
        return inputMidiDevice.getDeviceInfo().toString().hashCode();
148
    }
157
    }
149
158
150
    public int getOutputDeviceHash() {
159
    public int getOutputDeviceHash() {
151
        return outputMidiDevice.getDeviceInfo().toString().hashCode();
160
        return outputMidiDevice.getDeviceInfo().toString().hashCode();
152
    }
161
    }
153
162
154
    public void closeMidi() {
163
    public void closeMidi() {
155
        midiDeviceRouting.disconnectDevices(inputMidiDevice, localMidiDevice);
164
        midiDeviceRouting.disconnectDevices(inputMidiDevice, localMidiDevice);
156
        midiDeviceRouting.disconnectDevices(localMidiDevice, outputMidiDevice);
165
        midiDeviceRouting.disconnectDevices(localMidiDevice, outputMidiDevice);
157
    }
166
    }
158
167
159
    public void setInputDeviceIndex(int index) {
168
    public void setInputDeviceIndex(int index) {
160
        if (index != getInputDeviceIndex()) {
169
        if (index != getInputDeviceIndex()) {
161
            midiDeviceRouting.disconnectDevices(inputMidiDevice,
170
            midiDeviceRouting.disconnectDevices(inputMidiDevice,
162
                    localMidiDevice);
171
                    localMidiDevice);
163
            inputMidiDevice = (MidiDevice) midiDeviceRouting
172
            inputMidiDevice = (MidiDevice) midiDeviceRouting
164
                    .getMidiReadDevices().elementAt(index);
173
                    .getMidiReadDevices().elementAt(index);
165
            midiDeviceRouting.connectDevices(inputMidiDevice, localMidiDevice);
174
            midiDeviceRouting.connectDevices(inputMidiDevice, localMidiDevice);
166
            System.out.println("Connection of "
175
            System.out.println("Connection of "
167
                    + inputMidiDevice.getDeviceInfo() + " succesfull");
176
                    + inputMidiDevice.getDeviceInfo() + " succesfull");
168
        }
177
        }
169
    }
178
    }
170
179
171
    public void setOutputDeviceIndex(int index) {
180
    public void setOutputDeviceIndex(int index) {
172
        if (index != getOutputDeviceIndex()) {
181
        if (index != getOutputDeviceIndex()) {
173
            midiDeviceRouting.disconnectDevices(localMidiDevice,
182
            midiDeviceRouting.disconnectDevices(localMidiDevice,
174
                    outputMidiDevice);
183
                    outputMidiDevice);
175
            outputMidiDevice = (MidiDevice) midiDeviceRouting
184
            outputMidiDevice = (MidiDevice) midiDeviceRouting
176
                    .getMidiWriteDevices().elementAt(index);
185
                    .getMidiWriteDevices().elementAt(index);
177
            midiDeviceRouting.connectDevices(localMidiDevice, outputMidiDevice);
186
            midiDeviceRouting.connectDevices(localMidiDevice, outputMidiDevice);
178
            System.out.println("Connection of "
187
            System.out.println("Connection of "
179
                    + outputMidiDevice.getDeviceInfo() + " succesfull");
188
                    + outputMidiDevice.getDeviceInfo() + " succesfull");
180
        }
189
        }
181
    }
190
    }
182
}
191
}
183
 
192