Rev 739 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
684 | adamjking | 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.apps.sidv2editor; |
||
22 | |||
23 | import javax.sound.midi.MidiDevice; |
||
24 | |||
25 | import org.midibox.midi.MidiDeviceManager; |
||
26 | import org.midibox.midi.MidiDeviceRouting; |
||
808 | adamjking | 27 | import org.midibox.midi.VirtualMidiDevice; |
684 | adamjking | 28 | import org.midibox.sidlibr.SIDLibController; |
808 | adamjking | 29 | import org.midibox.sidlibr.SysExController; |
684 | adamjking | 30 | |
31 | public class SIDV2Editor { |
||
32 | |||
33 | private MidiDeviceRouting midiDeviceRouting; |
||
808 | adamjking | 34 | private SysExController sysexController; |
35 | private VirtualMidiDevice sysexControllerDevice; |
||
684 | adamjking | 36 | private SIDLibController sidLibController; |
37 | |||
38 | private MidiDevice localMidiDevice; |
||
39 | private MidiDevice inputMidiDevice; |
||
40 | private MidiDevice outputMidiDevice; |
||
41 | |||
42 | private MidiDeviceManager midiDeviceManager; |
||
43 | |||
44 | public SIDV2Editor() { |
||
45 | |||
46 | this(new MidiDeviceManager(), new MidiDeviceRouting()); |
||
47 | } |
||
48 | |||
49 | public SIDV2Editor(MidiDeviceManager midiDeviceManager, |
||
50 | MidiDeviceRouting midiDeviceRouting) { |
||
51 | |||
52 | this.midiDeviceManager = midiDeviceManager; |
||
53 | |||
54 | this.midiDeviceRouting = midiDeviceRouting; |
||
55 | |||
808 | adamjking | 56 | sysexControllerDevice = new VirtualMidiDevice("MidiBox SID V2 Editor", |
57 | -1, -1); |
||
58 | sysexController = new SysExController(sysexControllerDevice |
||
59 | .getMidiOutReceiver()); |
||
60 | sysexControllerDevice.setMidiInReceiver(sysexController); |
||
684 | adamjking | 61 | |
62 | this.localMidiDevice = sysexControllerDevice; |
||
63 | |||
808 | adamjking | 64 | sidLibController = new SIDLibController(sysexController); |
684 | adamjking | 65 | |
66 | if (midiDeviceRouting != null) { |
||
67 | midiDeviceManager.rescanDevices(); |
||
68 | midiDeviceRouting.addMidiReadDevices(midiDeviceManager |
||
739 | adamjking | 69 | .getSelectedMidiReadDevices().values()); |
684 | adamjking | 70 | midiDeviceRouting.addMidiWriteDevices(midiDeviceManager |
739 | adamjking | 71 | .getSelectedMidiWriteDevices().values()); |
684 | adamjking | 72 | } |
73 | } |
||
74 | |||
75 | public MidiDeviceManager getMidiDeviceManager() { |
||
76 | return midiDeviceManager; |
||
77 | } |
||
78 | |||
79 | public MidiDeviceRouting getMidiDeviceRouting() { |
||
80 | return midiDeviceRouting; |
||
81 | } |
||
82 | |||
808 | adamjking | 83 | public SysExController getSysExController() { |
84 | return sysexController; |
||
85 | } |
||
86 | |||
87 | public VirtualMidiDevice getSysexControllerDevice() { |
||
684 | adamjking | 88 | return sysexControllerDevice; |
89 | } |
||
90 | |||
91 | public SIDLibController getSIDLibController() { |
||
92 | return sidLibController; |
||
93 | } |
||
94 | |||
95 | public int getInputDeviceIndex() { |
||
96 | return midiDeviceRouting.getMidiReadDevices().indexOf(inputMidiDevice); |
||
97 | } |
||
98 | |||
99 | public int getOutputDeviceIndex() { |
||
100 | return midiDeviceRouting.getMidiWriteDevices() |
||
101 | .indexOf(outputMidiDevice); |
||
102 | } |
||
103 | |||
104 | public MidiDevice getLocalMidiDevice() { |
||
105 | return localMidiDevice; |
||
106 | } |
||
107 | |||
108 | public MidiDevice getInputMidiDevice() { |
||
109 | return inputMidiDevice; |
||
110 | } |
||
111 | |||
112 | public MidiDevice getOutputMidiDevice() { |
||
113 | return outputMidiDevice; |
||
114 | } |
||
115 | |||
116 | public void reconnectAllDevices() { // This function is a workaround for the |
||
117 | // SysEx (string length doesn't reset) |
||
118 | // bug in the javax.sound.midi class |
||
119 | if (midiDeviceRouting != null) { |
||
738 | adamjking | 120 | midiDeviceRouting.disconnectDevices(inputMidiDevice, |
121 | localMidiDevice); |
||
122 | midiDeviceRouting.disconnectDevices(localMidiDevice, |
||
123 | outputMidiDevice); |
||
684 | adamjking | 124 | midiDeviceRouting.connectDevices(inputMidiDevice, localMidiDevice); |
125 | midiDeviceRouting.connectDevices(localMidiDevice, outputMidiDevice); |
||
126 | } |
||
127 | |||
128 | } |
||
129 | |||
130 | public int findInputDeviceHash(int hash) { |
||
131 | int temp = -1; |
||
132 | for (int i = 0; i < midiDeviceRouting.getMidiReadDevices().size(); i++) { |
||
133 | if (((MidiDevice) midiDeviceRouting.getMidiReadDevices().elementAt( |
||
134 | i)).getDeviceInfo().toString().hashCode() == hash) { |
||
135 | temp = i; |
||
136 | break; |
||
137 | } |
||
138 | } |
||
139 | return temp; |
||
140 | } |
||
141 | |||
142 | public int findOuputDeviceHash(int hash) { |
||
143 | int temp = -1; |
||
144 | for (int i = 0; i < midiDeviceRouting.getMidiWriteDevices().size(); i++) { |
||
145 | if (((MidiDevice) midiDeviceRouting.getMidiWriteDevices() |
||
146 | .elementAt(i)).getDeviceInfo().toString().hashCode() == hash) { |
||
147 | temp = i; |
||
148 | break; |
||
149 | } |
||
150 | } |
||
151 | return temp; |
||
152 | } |
||
153 | |||
154 | public int getInputDeviceHash() { |
||
155 | return inputMidiDevice.getDeviceInfo().toString().hashCode(); |
||
156 | } |
||
157 | |||
158 | public int getOutputDeviceHash() { |
||
159 | return outputMidiDevice.getDeviceInfo().toString().hashCode(); |
||
160 | } |
||
161 | |||
162 | public void closeMidi() { |
||
163 | midiDeviceRouting.disconnectDevices(inputMidiDevice, localMidiDevice); |
||
164 | midiDeviceRouting.disconnectDevices(localMidiDevice, outputMidiDevice); |
||
165 | } |
||
166 | |||
167 | public void setInputDeviceIndex(int index) { |
||
168 | if (index != getInputDeviceIndex()) { |
||
169 | midiDeviceRouting.disconnectDevices(inputMidiDevice, |
||
170 | localMidiDevice); |
||
171 | inputMidiDevice = (MidiDevice) midiDeviceRouting |
||
172 | .getMidiReadDevices().elementAt(index); |
||
173 | midiDeviceRouting.connectDevices(inputMidiDevice, localMidiDevice); |
||
174 | } |
||
175 | } |
||
176 | |||
177 | public void setOutputDeviceIndex(int index) { |
||
178 | if (index != getOutputDeviceIndex()) { |
||
179 | midiDeviceRouting.disconnectDevices(localMidiDevice, |
||
180 | outputMidiDevice); |
||
181 | outputMidiDevice = (MidiDevice) midiDeviceRouting |
||
182 | .getMidiWriteDevices().elementAt(index); |
||
183 | midiDeviceRouting.connectDevices(localMidiDevice, outputMidiDevice); |
||
184 | } |
||
185 | } |
||
186 | } |