Subversion Repositories svn.mios

Rev

Rev 628 | Rev 642 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 628 Rev 641
Line 31... Line 31...
31
import javax.sound.midi.MidiDevice;
31
import javax.sound.midi.MidiDevice;
32
import javax.sound.midi.MidiUnavailableException;
32
import javax.sound.midi.MidiUnavailableException;
33
import javax.sound.midi.Receiver;
33
import javax.sound.midi.Receiver;
34
import javax.sound.midi.Transmitter;
34
import javax.sound.midi.Transmitter;
35
35
36
public class MidiDeviceRouting extends Observable implements Observer {
36
public class MidiDeviceRouting extends Observable {
37
37
38
    public static int DISCONNECTED = 0;
38
    public static int DISCONNECTED = 0;
39
39
40
    public static int LOGICALLY_CONNECTED = 1;
40
    public static int LOGICALLY_CONNECTED = 1;
41
41
Line 44... Line 44...
44
    private Vector midiReadDevices;
44
    private Vector midiReadDevices;
45
45
46
    private Vector midiWriteDevices;
46
    private Vector midiWriteDevices;
47
47
48
    private Vector logicalConnections;
48
    private Vector logicalConnections;
49
-
 
50
    private MidiDeviceManager midiDeviceManager;
-
 
51
-
 
52
    private MidiRouterDeviceManager midiRouterDeviceManager;
-
 
53
-
 
54
    private MidiFilterDeviceManager midiFilterManager;
-
 
55
-
 
56
    /*
-
 
57
     * private MidiMapDeviceManager midiMapManager;
-
 
58
     */
-
 
59
49
60
    private boolean portsReleased;
50
    private boolean portsReleased;
61
51
62
    public MidiDeviceRouting() {
52
    public MidiDeviceRouting() {
63
        midiReadDevices = new Vector();
53
        midiReadDevices = new Vector();
64
        midiWriteDevices = new Vector();
54
        midiWriteDevices = new Vector();
65
55
66
        logicalConnections = new Vector();
56
        logicalConnections = new Vector();
67
-
 
68
        midiDeviceManager = new MidiDeviceManager();
-
 
69
        midiDeviceManager.addObserver(this);
-
 
70
-
 
71
        midiRouterDeviceManager = new MidiRouterDeviceManager();
-
 
72
        midiRouterDeviceManager.addObserver(this);
-
 
73
-
 
74
        midiFilterManager = new MidiFilterDeviceManager();
-
 
75
        midiFilterManager.addObserver(this);
-
 
76
-
 
77
        /*
-
 
78
         * midiMapManager = new MidiMapDeviceManager();
-
 
79
         * midiMapManager.addObserver(this);
-
 
80
         */
-
 
81
    }
57
    }
82
58
83
    public Vector getMidiReadDevices() {
59
    public Vector getMidiReadDevices() {
84
        return midiReadDevices;
60
        return midiReadDevices;
85
    }
61
    }
Line 163... Line 139...
163
        midiWriteDevices.removeAllElements();
139
        midiWriteDevices.removeAllElements();
164
        setChanged();
140
        setChanged();
165
        notifyObservers(midiWriteDevices);
141
        notifyObservers(midiWriteDevices);
166
        clearChanged();
142
        clearChanged();
167
    }
143
    }
168
-
 
169
    public MidiDeviceManager getMidiDeviceManager() {
-
 
170
        return midiDeviceManager;
-
 
171
    }
-
 
172
-
 
173
    public MidiRouterDeviceManager getMidiRouterDeviceManager() {
-
 
174
        return midiRouterDeviceManager;
-
 
175
    }
-
 
176
-
 
177
    public MidiFilterDeviceManager getMidiFilterManager() {
-
 
178
        return midiFilterManager;
-
 
179
    }
-
 
180
-
 
181
    /*
-
 
182
     * public MidiMapDeviceManager getMidiMapManager() { return midiMapManager;
-
 
183
     * }
-
 
184
     */
-
 
185
144
186
    public void connectDevices(MidiDevice transmittingDevice,
145
    public void connectDevices(MidiDevice transmittingDevice,
187
            MidiDevice receivingDevice) {
146
            MidiDevice receivingDevice) {
188
147
189
        if (devicesConnected(transmittingDevice, receivingDevice) == PHYSICALLY_CONNECTED) {
148
        if (devicesConnected(transmittingDevice, receivingDevice) == PHYSICALLY_CONNECTED) {
Line 440... Line 399...
440
        }
399
        }
441
400
442
        return DISCONNECTED;
401
        return DISCONNECTED;
443
    }
402
    }
444
403
445
    public void reorder() {
-
 
446
        midiReadDevices.removeAll(midiDeviceManager
-
 
447
                .getSelectedMidiReadDevices());
-
 
448
        midiWriteDevices.removeAll(midiDeviceManager
-
 
449
                .getSelectedMidiWriteDevices());
-
 
450
        midiReadDevices.removeAll(midiRouterDeviceManager
-
 
451
                .getMidiRouterDevices());
-
 
452
        midiWriteDevices.removeAll(midiRouterDeviceManager
-
 
453
                .getMidiRouterDevices());
-
 
454
        midiReadDevices.removeAll(midiFilterManager.getMidiFilterDevices());
-
 
455
        midiWriteDevices.removeAll(midiFilterManager.getMidiFilterDevices());
-
 
456
-
 
457
        /*
-
 
458
         * midiReadDevices.removeAll(midiMapManager.getMidiMapDevices());
-
 
459
         * midiWriteDevices.removeAll(midiMapManager.getMidiMapDevices());
-
 
460
         */
-
 
461
-
 
462
        Iterator it = midiDeviceManager.getMidiReadDevices().iterator();
-
 
463
        while (it.hasNext()) {
-
 
464
-
 
465
            Object object = it.next();
-
 
466
-
 
467
            if (midiDeviceManager.getSelectedMidiReadDevices().contains(object)) {
-
 
468
                midiReadDevices.add(object);
-
 
469
            }
-
 
470
        }
-
 
471
-
 
472
        it = midiDeviceManager.getMidiWriteDevices().iterator();
-
 
473
        while (it.hasNext()) {
-
 
474
-
 
475
            Object object = it.next();
-
 
476
-
 
477
            if (midiDeviceManager.getSelectedMidiWriteDevices()
-
 
478
                    .contains(object)) {
-
 
479
                midiWriteDevices.add(object);
-
 
480
            }
-
 
481
        }
-
 
482
-
 
483
        midiReadDevices.addAll(midiRouterDeviceManager.getMidiRouterDevices());
-
 
484
        midiWriteDevices.addAll(midiRouterDeviceManager.getMidiRouterDevices());
-
 
485
        midiReadDevices.addAll(midiFilterManager.getMidiFilterDevices());
-
 
486
        midiWriteDevices.addAll(midiFilterManager.getMidiFilterDevices());
-
 
487
-
 
488
        /*
-
 
489
         * midiReadDevices.addAll(midiMapManager.getMidiMapDevices());
-
 
490
         * midiWriteDevices.addAll(midiMapManager.getMidiMapDevices());
-
 
491
         */
-
 
492
-
 
493
        setChanged();
-
 
494
        notifyObservers(midiReadDevices);
-
 
495
        clearChanged();
-
 
496
-
 
497
        setChanged();
-
 
498
        notifyObservers(midiWriteDevices);
-
 
499
        clearChanged();
-
 
500
    }
-
 
501
-
 
502
    public void update(Observable observable, Object object) {
-
 
503
        if (observable == midiDeviceManager
-
 
504
                || observable == midiRouterDeviceManager
-
 
505
                || observable == midiFilterManager
-
 
506
        /* || observable == midiMapManager */) {
-
 
507
-
 
508
            MidiDevice midiDevice = (MidiDevice) object;
-
 
509
-
 
510
            if (midiReadDevices.contains(midiDevice)
-
 
511
                    || midiWriteDevices.contains(midiDevice)) {
-
 
512
                disconnectDevice(midiDevice);
-
 
513
                removeMidiReadDevice(midiDevice);
-
 
514
                removeMidiWriteDevice(midiDevice);
-
 
515
            } else {
-
 
516
                reorder();
-
 
517
            }
-
 
518
        }
-
 
519
    }
-
 
520
404
521
    public static class LogicalConnection {
405
    public static class LogicalConnection {
522
406
523
        private MidiDevice sourceDevice;
407
        private MidiDevice sourceDevice;
524
408