Subversion Repositories svn.mios

Rev

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

Rev 639 Rev 641
Line 22... Line 22...
22
22
23
import java.util.Iterator;
23
import java.util.Iterator;
24
import java.util.Observable;
24
import java.util.Observable;
25
import java.util.Observer;
25
import java.util.Observer;
26
26
-
 
27
import javax.sound.midi.MidiDevice;
-
 
28
-
 
29
import org.midibox.midi.MidiDeviceManager;
27
import org.midibox.midi.MidiDeviceRouting;
30
import org.midibox.midi.MidiDeviceRouting;
28
import org.midibox.midi.MidiFilterDevice;
31
import org.midibox.midi.MidiFilterDevice;
-
 
32
import org.midibox.midi.MidiFilterDeviceManager;
29
import org.midibox.midi.MidiKeyboardControllerDevice;
33
import org.midibox.midi.MidiKeyboardControllerDevice;
30
import org.midibox.midi.MidiMonitorFiltered;
34
import org.midibox.midi.MidiMonitorFiltered;
31
import org.midibox.midi.MidiMonitorFilteredDevice;
35
import org.midibox.midi.MidiMonitorFilteredDevice;
32
import org.midibox.midi.MidiRouterDevice;
36
import org.midibox.midi.MidiRouterDevice;
33
import org.midibox.mios.DebugFunctionDevice;
37
import org.midibox.mios.DebugFunctionDevice;
Line 39... Line 43...
39
public class MIOSStudio implements Observer {
43
public class MIOSStudio implements Observer {
40
44
41
    protected MidiDeviceRouting midiDeviceRouting;
45
    protected MidiDeviceRouting midiDeviceRouting;
42
46
43
    protected MidiRouterDevice miosStudioInPort;
47
    protected MidiRouterDevice miosStudioInPort;
44
   
-
 
45
    protected MidiRouterDevice miosStudioThruPort;
-
 
46
48
47
    protected MidiFilterDevice midiThruFilterDevice;
49
    protected MidiFilterDevice midiThruFilterDevice;
48
50
49
    // TODO: implement a map for MIDI thru
51
    // TODO: implement a map for MIDI thru
50
52
51
    /*
53
    /*
52
     * private MidiMapDevice midiThruMapDevice;
54
     * private MidiMapDevice midiThruMapDevice;
53
     */
55
     */
-
 
56
-
 
57
    protected MidiRouterDevice miosStudioThruPort;
54
58
55
    protected MidiRouterDevice miosStudioOutPort;
59
    protected MidiRouterDevice miosStudioOutPort;
-
 
60
-
 
61
    private MidiDeviceManager midiDeviceManager;
-
 
62
-
 
63
    private MidiFilterDeviceManager midiFilterManager;
-
 
64
-
 
65
    /*
-
 
66
     * private MidiMapDeviceManager midiMapManager;
-
 
67
     */
56
68
57
    private MidiMonitorFilteredDevice midiInPortMonitorDevice;
69
    private MidiMonitorFilteredDevice midiInPortMonitorDevice;
58
70
59
    private MidiMonitorFilteredDevice midiOutPortMonitorDevice;
71
    private MidiMonitorFilteredDevice midiOutPortMonitorDevice;
60
72
Line 105... Line 117...
105
117
106
        midiDeviceRouting = new MidiDeviceRouting();
118
        midiDeviceRouting = new MidiDeviceRouting();
107
119
108
        miosStudioInPort = new MidiRouterDevice("MIOS Studio In Port");
120
        miosStudioInPort = new MidiRouterDevice("MIOS Studio In Port");
109
121
110
        miosStudioOutPort = new MidiRouterDevice("MIOS Studio Out Port");
122
        midiThruFilterDevice = new MidiFilterDevice("MIOS Studio Thru Filter");
-
 
123
-
 
124
        /*
-
 
125
         * midiThruMapDevice = new MidiMapDevice("MIOS Studio Thru Map");
-
 
126
         */
111
127
112
        miosStudioThruPort = new MidiRouterDevice("MIOS Studio Thru Port");
128
        miosStudioThruPort = new MidiRouterDevice("MIOS Studio Thru Port");
113
129
114
        midiThruFilterDevice = new MidiFilterDevice("MIOS Studio Thru Filter");
130
        miosStudioOutPort = new MidiRouterDevice("MIOS Studio Out Port");
-
 
131
-
 
132
        midiDeviceManager = new MidiDeviceManager();
-
 
133
        midiDeviceManager.addObserver(this);
-
 
134
-
 
135
        midiFilterManager = new MidiFilterDeviceManager();
-
 
136
        midiFilterManager.addObserver(this);
115
137
116
        /*
138
        /*
117
         * midiThruMapDevice = new MidiMapDevice("MIOS Studio Thru Map");
139
         * midiMapManager = new MidiMapDeviceManager();
-
 
140
         * midiMapManager.addObserver(this);
118
         */
141
         */
119
142
120
        midiInPortMonitorDevice = new MidiMonitorFilteredDevice(
143
        midiInPortMonitorDevice = new MidiMonitorFilteredDevice(
121
                "MIDI Monitor: IN");
144
                "MIDI Monitor: IN");
122
145
Line 179... Line 202...
179
        miosTerminalFiltered.getMidiFilter().stop = false;
202
        miosTerminalFiltered.getMidiFilter().stop = false;
180
        miosTerminalFiltered.getMidiFilter().systemReset = false;
203
        miosTerminalFiltered.getMidiFilter().systemReset = false;
181
        miosTerminalFiltered.getMidiFilter().timingClock = false;
204
        miosTerminalFiltered.getMidiFilter().timingClock = false;
182
        miosTerminalFiltered.getMidiFilter().tuneRequest = false;
205
        miosTerminalFiltered.getMidiFilter().tuneRequest = false;
183
    }
206
    }
-
 
207
-
 
208
    public MidiDeviceManager getMidiDeviceManager() {
-
 
209
        return midiDeviceManager;
-
 
210
    }
-
 
211
-
 
212
    public MidiFilterDeviceManager getMidiFilterManager() {
-
 
213
        return midiFilterManager;
-
 
214
    }
-
 
215
-
 
216
    /*
-
 
217
     * public MidiMapDeviceManager getMidiMapManager() { return midiMapManager;
-
 
218
     * }
-
 
219
     */
184
220
185
    public MidiDeviceRouting getMidiDeviceRouting() {
221
    public MidiDeviceRouting getMidiDeviceRouting() {
186
        return midiDeviceRouting;
222
        return midiDeviceRouting;
187
    }
223
    }
188
224
Line 229... Line 265...
229
    }
265
    }
230
266
231
    public void setMidiThruOutPort(boolean midiThru) {
267
    public void setMidiThruOutPort(boolean midiThru) {
232
        this.midiThruOutPort = midiThru;
268
        this.midiThruOutPort = midiThru;
233
269
234
        midiDeviceRouting.connectDevices(miosStudioInPort,
270
        midiDeviceRouting
235
                midiThruFilterDevice);
271
                .connectDevices(miosStudioInPort, midiThruFilterDevice);
236
       
272
237
        if (midiThru) {
273
        if (midiThru) {
238
274
239
            /*
275
            /*
240
             * midiDeviceRouting.connectDevices(midiThruFilterDevice,
276
             * midiDeviceRouting.connectDevices(midiThruFilterDevice,
Line 304... Line 340...
304
            if (!midiThruOutPort) {
340
            if (!midiThruOutPort) {
305
                midiDeviceRouting.addMidiReadDevice(miosStudioThruPort);
341
                midiDeviceRouting.addMidiReadDevice(miosStudioThruPort);
306
            }
342
            }
307
        }
343
        }
308
344
-
 
345
        reorder();
-
 
346
    }
-
 
347
-
 
348
    public void reorder() {
-
 
349
-
 
350
        midiDeviceRouting.getMidiReadDevices().removeAll(
-
 
351
                midiFilterManager.getMidiFilterDevices());
-
 
352
        midiDeviceRouting.getMidiWriteDevices().removeAll(
-
 
353
                midiFilterManager.getMidiFilterDevices());
-
 
354
-
 
355
        midiDeviceRouting.getMidiReadDevices().removeAll(
-
 
356
                midiDeviceManager.getSelectedMidiReadDevices());
-
 
357
        midiDeviceRouting.getMidiWriteDevices().removeAll(
-
 
358
                midiDeviceManager.getSelectedMidiWriteDevices());
-
 
359
-
 
360
        /*
-
 
361
         * midiReadDevices.removeAll(midiMapManager.getMidiMapDevices());
-
 
362
         * midiWriteDevices.removeAll(midiMapManager.getMidiMapDevices());
-
 
363
         */
-
 
364
309
        // get midiDeviceRouting to add physical, virtual, filters and maps
365
        midiDeviceRouting.addMidiReadDevices(midiFilterManager
-
 
366
                .getMidiFilterDevices());
-
 
367
        midiDeviceRouting.addMidiWriteDevices(midiFilterManager
310
        midiDeviceRouting.reorder();
368
                .getMidiFilterDevices());
-
 
369
-
 
370
        Iterator it = midiDeviceManager.getMidiReadDevices().iterator();
-
 
371
-
 
372
        while (it.hasNext()) {
-
 
373
-
 
374
            Object object = it.next();
-
 
375
-
 
376
            if (midiDeviceManager.getSelectedMidiReadDevices().contains(object)) {
-
 
377
                midiDeviceRouting.addMidiReadDevice((MidiDevice) object);
-
 
378
            }
-
 
379
        }
-
 
380
-
 
381
        it = midiDeviceManager.getMidiWriteDevices().iterator();
-
 
382
        while (it.hasNext()) {
-
 
383
-
 
384
            Object object = it.next();
-
 
385
-
 
386
            if (midiDeviceManager.getSelectedMidiWriteDevices()
-
 
387
                    .contains(object)) {
-
 
388
                midiDeviceRouting.addMidiWriteDevice((MidiDevice) object);
-
 
389
            }
-
 
390
        }
-
 
391
-
 
392
        /*
-
 
393
         * midiReadDevices.addAll(midiMapManager.getMidiMapDevices());
-
 
394
         * midiWriteDevices.addAll(midiMapManager.getMidiMapDevices());
-
 
395
         */
311
    }
396
    }
312
397
313
    protected void routeIndividualDevices() {
398
    protected void routeIndividualDevices() {
314
399
315
        midiDeviceRouting.addMidiWriteDevice(miosStudioInPort);
400
        midiDeviceRouting.addMidiWriteDevice(miosStudioInPort);
Line 416... Line 501...
416
501
417
        midiDeviceRouting.connectDevices(miosStudioInPort, miosTerminalDevice);
502
        midiDeviceRouting.connectDevices(miosStudioInPort, miosTerminalDevice);
418
    }
503
    }
419
504
420
    public void update(Observable observable, Object object) {
505
    public void update(Observable observable, Object object) {
421
        /*
-
 
422
         * if (observable == sysexSendReceiveDeviceManager) {
-
 
423
         *
-
 
424
         * SysexSendReceiveDevice ssrt = (SysexSendReceiveDevice) object;
-
 
425
         *
-
 
426
         * if (sysexSendReceiveDeviceManager.getSysexSendReceiveDevices()
-
 
427
         * .contains(ssrt)) {
-
 
428
         *
-
 
429
         * midiDeviceRouting.connectDevices(miosStudioInPort, ssrt);
-
 
430
         * midiDeviceRouting.connectDevices(ssrt, miosStudioOutPort);
-
 
431
         *
-
 
432
         * if (routeIndividualDevices) {
-
 
433
         * midiDeviceRouting.addMidiReadDevice(ssrt);
-
 
434
         * midiDeviceRouting.addMidiWriteDevice(ssrt);
-
 
435
         * setRouteIndividualDevices(true); } } else {
-
 
436
         * midiDeviceRouting.disconnectDevice(ssrt);
-
 
437
         *
-
 
438
         * if (routeIndividualDevices) {
-
 
439
         * midiDeviceRouting.removeMidiReadDevice(ssrt);
-
 
440
         * midiDeviceRouting.removeMidiWriteDevice(ssrt); } } }
-
 
441
         */
-
 
442
506
443
        if (observable == hexFileUploadDeviceManager) {
507
        if (observable == hexFileUploadDeviceManager) {
444
508
445
            HexFileUploadDevice hutd = (HexFileUploadDevice) object;
509
            HexFileUploadDevice hutd = (HexFileUploadDevice) object;
446
510
447
            if (hexFileUploadDeviceManager.getHexFileUploadDevices().contains(
511
            if (hexFileUploadDeviceManager.getHexFileUploadDevices().contains(
448
                    hutd)) {
512
                    hutd)) {
449
513
450
                midiDeviceRouting.connectDevices(miosStudioInPort, hutd);
514
                midiDeviceRouting.connectDevices(miosStudioInPort, hutd);
451
                midiDeviceRouting.connectDevices(hutd, miosStudioOutPort);
515
                midiDeviceRouting.connectDevices(hutd, miosStudioOutPort);
452
-
 
453
                if (routeIndividualDevices) {
-
 
454
                    midiDeviceRouting.addMidiReadDevice(hutd);
-
 
455
                    midiDeviceRouting.addMidiWriteDevice(hutd);
-
 
456
                    setRouteIndividualDevices(true);
-
 
457
                }
-
 
458
516
459
            } else {
517
            } else {
460
                midiDeviceRouting.disconnectDevice(hutd);
518
                midiDeviceRouting.disconnectDevice(hutd);
-
 
519
            }
461
520
462
                if (routeIndividualDevices) {
521
            setRouteIndividualDevices(routeIndividualDevices);
463
                    midiDeviceRouting.removeMidiReadDevice(hutd);
-
 
464
                    midiDeviceRouting.removeMidiWriteDevice(hutd);
-
 
465
                }
522
        }
-
 
523
-
 
524
        if (observable == midiDeviceManager) {
-
 
525
-
 
526
            MidiDevice midiDevice = (MidiDevice) object;
-
 
527
-
 
528
            if (!midiDeviceManager.getSelectedMidiReadDevices().contains(midiDevice)
-
 
529
                    && !midiDeviceManager.getSelectedMidiWriteDevices().contains(
-
 
530
                            midiDevice)) {
-
 
531
                midiDeviceRouting.disconnectDevice(midiDevice);
466
            }
532
            }
-
 
533
-
 
534
            setRouteIndividualDevices(routeIndividualDevices);
467
        }
535
        }
468
536
469
        if (object == "Edit") {
537
        if (observable == midiFilterManager) {
470
538
471
            boolean portsReleased = midiDeviceRouting.getPortsReleased();
539
            MidiDevice midiFilter = (MidiDevice) object;
472
540
473
            if (!portsReleased) {
-
 
474
                midiDeviceRouting.setPortsReleased(true);
541
            if (!midiFilterManager.getMidiFilterDevices().contains(midiFilter)) {
475
                midiDeviceRouting.setPortsReleased(false);
542
                midiDeviceRouting.disconnectDevice(midiFilter);
476
            }
543
            }
-
 
544
-
 
545
            setRouteIndividualDevices(routeIndividualDevices);
477
        }
546
        }
478
    }
547
    }
479
}
548
}