Subversion Repositories svn.mios

Rev

Rev 723 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 723 Rev 808
Line 43... Line 43...
43
43
44
    protected LinkedList transmitters;
44
    protected LinkedList transmitters;
45
45
46
    protected LinkedList receivers;
46
    protected LinkedList receivers;
47
47
-
 
48
    protected Receiver midiInReceiver;
-
 
49
48
    protected MidiOutPort midiOutPort;
50
    protected Receiver midiOutReceiver;
49
51
50
    protected long timeStart = System.currentTimeMillis();
52
    protected long timeStart = System.currentTimeMillis();
51
53
52
    public VirtualMidiDevice(String name, int maxNoTransmitters,
54
    public VirtualMidiDevice(String name, int maxNoTransmitters,
53
            int maxNoReceivers) {
55
            int maxNoReceivers) {
Line 56... Line 58...
56
58
57
        this.maxNoTransmitters = maxNoTransmitters;
59
        this.maxNoTransmitters = maxNoTransmitters;
58
        this.maxNoReceivers = maxNoReceivers;
60
        this.maxNoReceivers = maxNoReceivers;
59
        this.transmitters = new LinkedList();
61
        this.transmitters = new LinkedList();
60
        this.receivers = new LinkedList();
62
        this.receivers = new LinkedList();
61
        this.midiOutPort = new MidiOutPort();
63
        this.midiOutReceiver = new MidiOutReceiver();
62
    }
64
    }
63
65
64
    public void setName(String name) {
66
    public void setName(String name) {
-
 
67
65
        this.info = new VirtualMidiDevice.MyInfo(name, "midibox.org",
68
        this.info = new VirtualMidiDevice.MyInfo(name, "midibox.org",
66
                "Virtual MIDI Device", "v1.0");
69
                "Virtual MIDI Device", "v1.0");
67
70
68
        setChanged();
71
        setChanged();
69
72
Line 108... Line 111...
108
111
109
    public List getReceivers() {
112
    public List getReceivers() {
110
        return (LinkedList) receivers.clone();
113
        return (LinkedList) receivers.clone();
111
    }
114
    }
112
115
113
    public MidiOutPort getMidiOutPort() {
116
    public Receiver getMidiOutReceiver() {
114
        return midiOutPort;
117
        return midiOutReceiver;
-
 
118
    }
-
 
119
-
 
120
    public Receiver getMidiInReceiver() {
-
 
121
        return midiInReceiver;
-
 
122
    }
-
 
123
-
 
124
    public void setMidiInReceiver(Receiver midiInReceiver) {
-
 
125
        this.midiInReceiver = midiInReceiver;
115
    }
126
    }
116
127
117
    public Transmitter getTransmitter() {
128
    public Transmitter getTransmitter() {
118
        MyTransmitter transmitter = new MyTransmitter();
129
        MyTransmitter transmitter = new MyTransmitter();
119
        transmitters.add(transmitter);
130
        transmitters.add(transmitter);
120
        return transmitter;
131
        return transmitter;
121
    }
132
    }
122
133
123
    public MidiDevice.Info getDeviceInfo() {
134
    public MidiDevice.Info getDeviceInfo() {
124
        return info;
135
        return info;
125
    }
-
 
126
-
 
127
    protected void receiveFromReceivers(MidiMessage message, long timestamp) {
-
 
128
-
 
129
    }
-
 
130
-
 
131
    protected void sendToTransmitters(MidiMessage message, long timeStamp) {
-
 
132
        synchronized (transmitters) {
-
 
133
            Iterator it = transmitters.iterator();
-
 
134
            while (it.hasNext()) {
-
 
135
                Transmitter transmitter = (Transmitter) it.next();
-
 
136
                if (transmitter != null) {
-
 
137
                    Receiver receiver = transmitter.getReceiver();
-
 
138
                    if (receiver != null) {
-
 
139
                        receiver.send(message, timeStamp);
-
 
140
                    }
-
 
141
                }
-
 
142
            }
-
 
143
        }
-
 
144
    }
136
    }
145
137
146
    public class MyReceiver implements Receiver {
138
    public class MyReceiver implements Receiver {
147
139
148
        public void close() {
140
        public void close() {
Line 150... Line 142...
150
                receivers.remove(this);
142
                receivers.remove(this);
151
            }
143
            }
152
        }
144
        }
153
145
154
        public void send(MidiMessage message, long timeStamp) {
146
        public void send(MidiMessage message, long timeStamp) {
-
 
147
-
 
148
            if (midiInReceiver != null) {
-
 
149
155
            receiveFromReceivers(message, timeStamp);
150
                midiInReceiver.send(message, timeStamp);
-
 
151
            }
156
        }
152
        }
157
    }
153
    }
158
154
159
    public class MyTransmitter implements Transmitter {
155
    public class MyTransmitter implements Transmitter {
160
156
Line 181... Line 177...
181
                String version) {
177
                String version) {
182
            super(name, vendor, description, version);
178
            super(name, vendor, description, version);
183
        }
179
        }
184
    }
180
    }
185
181
186
    public class MidiOutPort implements Receiver {
182
    public class MidiOutReceiver implements Receiver {
-
 
183
187
        public void close() {
184
        public void close() {
188
185
189
        }
186
        }
190
187
191
        public void send(MidiMessage message, long timestamp) {
188
        public void send(MidiMessage message, long timeStamp) {
-
 
189
            synchronized (transmitters) {
-
 
190
                Iterator it = transmitters.iterator();
-
 
191
                while (it.hasNext()) {
-
 
192
                    Transmitter transmitter = (Transmitter) it.next();
-
 
193
                    if (transmitter != null) {
-
 
194
                        Receiver receiver = transmitter.getReceiver();
-
 
195
                        if (receiver != null) {
192
            sendToTransmitters(message, timestamp);
196
                            receiver.send(message, timeStamp);
-
 
197
                        }
-
 
198
                    }
-
 
199
                }
-
 
200
            }
193
        }
201
        }
194
    }
202
    }
195
}
203
}