Subversion Repositories svn.mios

Rev

Rev 639 | Rev 642 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
628 adamjking 1
/*
2
 * @(#)MIOSStudio.java  beta8   2006/04/23
3
 *
4
 * Copyright (C) 2008    Adam King (adamjking@optusnet.com.au)
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.miosstudio;
22
 
23
import java.util.Iterator;
24
import java.util.Observable;
25
import java.util.Observer;
26
 
641 adamjking 27
import javax.sound.midi.MidiDevice;
28
 
29
import org.midibox.midi.MidiDeviceManager;
628 adamjking 30
import org.midibox.midi.MidiDeviceRouting;
31
import org.midibox.midi.MidiFilterDevice;
641 adamjking 32
import org.midibox.midi.MidiFilterDeviceManager;
628 adamjking 33
import org.midibox.midi.MidiKeyboardControllerDevice;
34
import org.midibox.midi.MidiMonitorFiltered;
35
import org.midibox.midi.MidiMonitorFilteredDevice;
36
import org.midibox.midi.MidiRouterDevice;
37
import org.midibox.mios.DebugFunctionDevice;
38
import org.midibox.mios.HexFileUploadDevice;
39
import org.midibox.mios.HexFileUploadDeviceManager;
40
import org.midibox.mios.LCDMessageDevice;
41
import org.midibox.mios.MIOSTerminal;
42
 
43
public class MIOSStudio implements Observer {
44
 
45
    protected MidiDeviceRouting midiDeviceRouting;
46
 
47
    protected MidiRouterDevice miosStudioInPort;
48
 
49
    protected MidiFilterDevice midiThruFilterDevice;
50
 
51
    // TODO: implement a map for MIDI thru
52
 
53
    /*
54
     * private MidiMapDevice midiThruMapDevice;
55
     */
56
 
641 adamjking 57
    protected MidiRouterDevice miosStudioThruPort;
58
 
628 adamjking 59
    protected MidiRouterDevice miosStudioOutPort;
60
 
641 adamjking 61
    private MidiDeviceManager midiDeviceManager;
62
 
63
    private MidiFilterDeviceManager midiFilterManager;
64
 
65
    /*
66
     * private MidiMapDeviceManager midiMapManager;
67
     */
68
 
628 adamjking 69
    private MidiMonitorFilteredDevice midiInPortMonitorDevice;
70
 
71
    private MidiMonitorFilteredDevice midiOutPortMonitorDevice;
72
 
73
    // Debuging for command line
74
 
75
    /*
76
     * private DumpReceiverDevice inDumpReceiverDevice;
77
     *
78
     * private DumpReceiverDevice outDumpReceiverDevice;
79
     */
80
 
81
    private MidiKeyboardControllerDevice midiKeyboardControllerDevice;
82
 
83
    // TODO: implement a manager for sysex sending and receing tasks
84
 
85
    /*
86
     * private SysexSendReceiveDeviceManager sysexSendReceiveDeviceManager;
87
     */
88
 
89
    private HexFileUploadDeviceManager hexFileUploadDeviceManager;
90
 
91
    // TODO: implement a device for reading and writing to MIOS
92
 
93
    /*
94
     * private MemoryReadWriteDevice memoryReadWriteDevice;
95
     */
96
 
97
    private LCDMessageDevice lcdMessageDevice;
98
 
99
    private DebugFunctionDevice debugFunctionDevice;
100
 
101
    private MidiMonitorFilteredDevice miosTerminalDevice;
102
 
103
    private boolean routeIndividualDevices;
104
 
639 adamjking 105
    private boolean midiThruOutPort = false;
628 adamjking 106
 
107
    public MIOSStudio() {
108
 
109
        createDevices();
110
 
111
        setRouteIndividualDevices(false);
112
 
113
        connectDevices();
114
    }
115
 
116
    protected void createDevices() {
117
 
118
        midiDeviceRouting = new MidiDeviceRouting();
119
 
120
        miosStudioInPort = new MidiRouterDevice("MIOS Studio In Port");
121
 
641 adamjking 122
        midiThruFilterDevice = new MidiFilterDevice("MIOS Studio Thru Filter");
628 adamjking 123
 
641 adamjking 124
        /*
125
         * midiThruMapDevice = new MidiMapDevice("MIOS Studio Thru Map");
126
         */
127
 
639 adamjking 128
        miosStudioThruPort = new MidiRouterDevice("MIOS Studio Thru Port");
129
 
641 adamjking 130
        miosStudioOutPort = new MidiRouterDevice("MIOS Studio Out Port");
628 adamjking 131
 
641 adamjking 132
        midiDeviceManager = new MidiDeviceManager();
133
        midiDeviceManager.addObserver(this);
134
 
135
        midiFilterManager = new MidiFilterDeviceManager();
136
        midiFilterManager.addObserver(this);
137
 
628 adamjking 138
        /*
641 adamjking 139
         * midiMapManager = new MidiMapDeviceManager();
140
         * midiMapManager.addObserver(this);
628 adamjking 141
         */
142
 
143
        midiInPortMonitorDevice = new MidiMonitorFilteredDevice(
144
                "MIDI Monitor: IN");
145
 
146
        midiOutPortMonitorDevice = new MidiMonitorFilteredDevice(
147
                "MIDI Monitor: OUT");
148
 
149
        /*
150
         * inDumpReceiverDevice = new DumpReceiverDevice("Dump Receiver: IN");
151
         *
152
         * outDumpReceiverDevice = new DumpReceiverDevice("Dump Receiver: OUT");
153
         */
154
 
155
        midiKeyboardControllerDevice = new MidiKeyboardControllerDevice(
156
                "MIDI Keyboard Controller", 0);
157
 
158
        /*
159
         * sysexSendReceiveDeviceManager = new SysexSendReceiveDeviceManager();
160
         * sysexSendReceiveDeviceManager.newSysexSendReceive();
161
         * sysexSendReceiveDeviceManager.addObserver(this);
162
         */
163
 
164
        hexFileUploadDeviceManager = new HexFileUploadDeviceManager();
165
        hexFileUploadDeviceManager.newHexFileUploadDevice();
166
        hexFileUploadDeviceManager.addObserver(this);
167
 
168
        /*
169
         * memoryReadWriteDevice = new MemoryReadWriteDevice( "MIOS Memory
170
         * Read/Write");
171
         */
172
 
173
        lcdMessageDevice = new LCDMessageDevice("MIOS LCD Message");
174
 
175
        debugFunctionDevice = new DebugFunctionDevice("MIOS Debug Function");
176
 
177
        MidiMonitorFiltered miosTerminalFiltered = new MidiMonitorFiltered(
178
                new MIOSTerminal());
179
 
180
        miosTerminalDevice = new MidiMonitorFilteredDevice("MIOS Terminal",
181
                miosTerminalFiltered);
182
 
183
        // special for MIOS Terminal:
184
        // disable all messages by default, only allow pass SysEx
185
        // user can enable other MIDI events again if required
186
        miosTerminalFiltered.getMidiFilter().sysexMessage = true;
187
 
188
        miosTerminalFiltered.getMidiFilter().metaMessage = false;
189
        miosTerminalFiltered.getMidiFilter().activeSensing = false;
190
        miosTerminalFiltered.getMidiFilter().channelPressure = false;
191
        miosTerminalFiltered.getMidiFilter().continueMessage = false;
192
        miosTerminalFiltered.getMidiFilter().controlChange = false;
193
        miosTerminalFiltered.getMidiFilter().midiTimeCode = false;
194
        miosTerminalFiltered.getMidiFilter().noteOff = false;
195
        miosTerminalFiltered.getMidiFilter().noteOn = false;
196
        miosTerminalFiltered.getMidiFilter().pitchBend = false;
197
        miosTerminalFiltered.getMidiFilter().pollyPressure = false;
198
        miosTerminalFiltered.getMidiFilter().programChange = false;
199
        miosTerminalFiltered.getMidiFilter().songPositionPointer = false;
200
        miosTerminalFiltered.getMidiFilter().songSelect = false;
201
        miosTerminalFiltered.getMidiFilter().start = false;
202
        miosTerminalFiltered.getMidiFilter().stop = false;
203
        miosTerminalFiltered.getMidiFilter().systemReset = false;
204
        miosTerminalFiltered.getMidiFilter().timingClock = false;
205
        miosTerminalFiltered.getMidiFilter().tuneRequest = false;
206
    }
207
 
641 adamjking 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
     */
220
 
628 adamjking 221
    public MidiDeviceRouting getMidiDeviceRouting() {
222
        return midiDeviceRouting;
223
    }
224
 
225
    public MidiMonitorFilteredDevice getMidiOutPortMonitorDevice() {
226
        return midiOutPortMonitorDevice;
227
    }
228
 
229
    public MidiMonitorFilteredDevice getMidiInPortMonitorDevice() {
230
        return midiInPortMonitorDevice;
231
    }
232
 
233
    public MidiKeyboardControllerDevice getMidiKeyboardControllerDevice() {
234
        return midiKeyboardControllerDevice;
235
    }
236
 
237
    /*
238
     * public SysexSendReceiveDeviceManager getSysexSendReceiveDeviceManager() {
239
     * return sysexSendReceiveDeviceManager; }
240
     */
241
 
242
    public HexFileUploadDeviceManager getHexFileUploadDeviceManager() {
243
        return hexFileUploadDeviceManager;
244
    }
245
 
246
    public DebugFunctionDevice getDebugFunctionDevice() {
247
        return debugFunctionDevice;
248
    }
249
 
250
    /*
251
     * public MemoryReadWriteDevice getMemoryReadWriteDevice() { return
252
     * memoryReadWriteDevice; }
253
     */
254
 
255
    public LCDMessageDevice getLcdMessageDevice() {
256
        return lcdMessageDevice;
257
    }
258
 
259
    public MidiMonitorFilteredDevice getMIOSTerminalDevice() {
260
        return miosTerminalDevice;
261
    }
262
 
639 adamjking 263
    public boolean isMidiThruOutPort() {
264
        return midiThruOutPort;
628 adamjking 265
    }
266
 
639 adamjking 267
    public void setMidiThruOutPort(boolean midiThru) {
268
        this.midiThruOutPort = midiThru;
628 adamjking 269
 
641 adamjking 270
        midiDeviceRouting
271
                .connectDevices(miosStudioInPort, midiThruFilterDevice);
272
 
628 adamjking 273
        if (midiThru) {
639 adamjking 274
 
628 adamjking 275
            /*
276
             * midiDeviceRouting.connectDevices(midiThruFilterDevice,
277
             * midiThruMapDevice);
278
             */
279
 
639 adamjking 280
            midiDeviceRouting.disconnectDevice(miosStudioThruPort);
641 adamjking 281
 
639 adamjking 282
            midiDeviceRouting.disconnectDevices(midiThruFilterDevice,
641 adamjking 283
                    miosStudioThruPort);
639 adamjking 284
 
628 adamjking 285
            midiDeviceRouting.connectDevices(midiThruFilterDevice,
286
                    miosStudioOutPort);
287
        } else {
641 adamjking 288
 
628 adamjking 289
            /*
290
             * midiDeviceRouting.disconnectDevices(midiThruFilterDevice,
291
             * midiThruMapDevice);
292
             */
641 adamjking 293
 
628 adamjking 294
            midiDeviceRouting.disconnectDevices(midiThruFilterDevice,
641 adamjking 295
                    miosStudioOutPort);
296
 
639 adamjking 297
            midiDeviceRouting.connectDevices(midiThruFilterDevice,
298
                    miosStudioThruPort);
628 adamjking 299
        }
641 adamjking 300
 
639 adamjking 301
        setRouteIndividualDevices(routeIndividualDevices);
628 adamjking 302
    }
303
 
304
    public MidiRouterDevice getMiosStudioInPort() {
305
        return miosStudioInPort;
306
    }
307
 
308
    public MidiRouterDevice getMiosStudioOutPort() {
309
        return miosStudioOutPort;
310
    }
311
 
312
    public MidiFilterDevice getMidiThruFilterDevice() {
313
        return midiThruFilterDevice;
314
    }
315
 
316
    /*
317
     * public MidiMapDevice getMidiThruMapDevice() { return midiThruMapDevice; }
318
     */
319
 
320
    public boolean isRouteIndividualDevices() {
321
        return routeIndividualDevices;
322
    }
323
 
324
    public void setRouteIndividualDevices(boolean routeIndividualDevices) {
325
        this.routeIndividualDevices = routeIndividualDevices;
326
 
327
        // remove all devices
328
        midiDeviceRouting.removeAllMidiReadDevices();
329
        midiDeviceRouting.removeAllMidiWriteDevices();
330
 
331
        // add internal MIOSStudio devices if selected
332
        if (routeIndividualDevices) {
333
 
334
            routeIndividualDevices();
335
 
336
        } else {
337
            midiDeviceRouting.addMidiWriteDevice(miosStudioInPort);
338
            midiDeviceRouting.addMidiReadDevice(miosStudioOutPort);
641 adamjking 339
 
639 adamjking 340
            if (!midiThruOutPort) {
341
                midiDeviceRouting.addMidiReadDevice(miosStudioThruPort);
342
            }
628 adamjking 343
        }
344
 
641 adamjking 345
        reorder();
628 adamjking 346
    }
347
 
641 adamjking 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
 
365
        midiDeviceRouting.addMidiReadDevices(midiFilterManager
366
                .getMidiFilterDevices());
367
        midiDeviceRouting.addMidiWriteDevices(midiFilterManager
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
         */
396
    }
397
 
628 adamjking 398
    protected void routeIndividualDevices() {
399
 
400
        midiDeviceRouting.addMidiWriteDevice(miosStudioInPort);
401
        midiDeviceRouting.addMidiReadDevice(miosStudioInPort);
402
 
403
        midiDeviceRouting.addMidiWriteDevice(midiThruFilterDevice);
404
        midiDeviceRouting.addMidiReadDevice(midiThruFilterDevice);
405
 
406
        /*
407
         * midiDeviceRouting.addMidiWriteDevice(midiThruMapDevice);
408
         * midiDeviceRouting.addMidiReadDevice(midiThruMapDevice);
409
         */
641 adamjking 410
 
639 adamjking 411
        if (!midiThruOutPort) {
641 adamjking 412
 
639 adamjking 413
            midiDeviceRouting.addMidiWriteDevice(miosStudioThruPort);
414
            midiDeviceRouting.addMidiReadDevice(miosStudioThruPort);
415
        }
628 adamjking 416
        midiDeviceRouting.addMidiWriteDevice(miosStudioOutPort);
417
        midiDeviceRouting.addMidiReadDevice(miosStudioOutPort);
418
 
419
        midiDeviceRouting.addMidiWriteDevice(midiOutPortMonitorDevice);
420
 
421
        midiDeviceRouting.addMidiWriteDevice(midiInPortMonitorDevice);
422
 
423
        /*
424
         * midiDeviceRouting.addMidiWriteDevice(inDumpReceiverDevice);
425
         *
426
         * midiDeviceRouting.addMidiWriteDevice(outDumpReceiverDevice);
427
         */
428
 
429
        midiDeviceRouting.addMidiWriteDevice(midiKeyboardControllerDevice);
430
        midiDeviceRouting.addMidiReadDevice(midiKeyboardControllerDevice);
431
 
432
        /*
433
         * midiDeviceRouting.addMidiReadDevices(sysexSendReceiveDeviceManager
434
         * .getSysexSendReceiveDevices()); midiDeviceRouting.addMidiWriteDevices
435
         * (sysexSendReceiveDeviceManager .getSysexSendReceiveDevices());
436
         */
437
 
438
        midiDeviceRouting.addMidiReadDevices(hexFileUploadDeviceManager
439
                .getHexFileUploadDevices());
440
        midiDeviceRouting.addMidiWriteDevices(hexFileUploadDeviceManager
441
                .getHexFileUploadDevices());
442
        /*
443
         * midiDeviceRouting.addMidiWriteDevice(memoryReadWriteDevice);
444
         * midiDeviceRouting.addMidiReadDevice(memoryReadWriteDevice);
445
         */
446
 
447
        midiDeviceRouting.addMidiReadDevice(lcdMessageDevice);
448
 
449
        midiDeviceRouting.addMidiWriteDevice(debugFunctionDevice);
450
        midiDeviceRouting.addMidiReadDevice(debugFunctionDevice);
451
 
452
        midiDeviceRouting.addMidiWriteDevice(miosTerminalDevice);
453
    }
454
 
455
    public void connectDevices() {
456
 
639 adamjking 457
        setMidiThruOutPort(midiThruOutPort);
641 adamjking 458
 
628 adamjking 459
        midiDeviceRouting.connectDevices(miosStudioInPort,
460
                midiInPortMonitorDevice);
461
 
462
        midiDeviceRouting.connectDevices(miosStudioOutPort,
463
                midiOutPortMonitorDevice);
464
 
465
        /*
466
         * midiDeviceRouting.connectDevices(inVirtualMidiPortDevice,
467
         * inDumpReceiverDevice);
468
         * midiDeviceRouting.connectDevices(outVirtualMidiPortDevice,
469
         * outDumpReceiverDevice);
470
         */
641 adamjking 471
 
628 adamjking 472
        midiDeviceRouting.connectDevices(miosStudioInPort,
473
                midiKeyboardControllerDevice);
474
        midiDeviceRouting.connectDevices(midiKeyboardControllerDevice,
475
                miosStudioOutPort);
476
        /*
477
         * Iterator it = sysexSendReceiveDeviceManager
478
         * .getSysexSendReceiveDevices().iterator(); while (it.hasNext()) {
479
         * SysexSendReceiveDevice ssrt = (SysexSendReceiveDevice) it.next();
480
         * midiDeviceRouting.connectDevices(miosStudioInPort, ssrt);
481
         * midiDeviceRouting.connectDevices(ssrt, miosStudioOutPort); }
482
         */
483
        Iterator it = hexFileUploadDeviceManager.getHexFileUploadDevices()
484
                .iterator();
485
        while (it.hasNext()) {
486
            HexFileUploadDevice hutd = (HexFileUploadDevice) it.next();
487
            midiDeviceRouting.connectDevices(miosStudioInPort, hutd);
488
            midiDeviceRouting.connectDevices(hutd, miosStudioOutPort);
489
        }
490
        /*
491
         * midiDeviceRouting.connectDevices(miosStudioInPort,
492
         * memoryReadWriteDevice);
493
         * midiDeviceRouting.connectDevices(memoryReadWriteDevice,
494
         * miosStudioOutPort);
495
         */
496
 
497
        midiDeviceRouting.connectDevices(lcdMessageDevice, miosStudioOutPort);
498
        midiDeviceRouting.connectDevices(miosStudioInPort, debugFunctionDevice);
499
        midiDeviceRouting
500
                .connectDevices(debugFunctionDevice, miosStudioOutPort);
501
 
502
        midiDeviceRouting.connectDevices(miosStudioInPort, miosTerminalDevice);
503
    }
504
 
505
    public void update(Observable observable, Object object) {
506
 
507
        if (observable == hexFileUploadDeviceManager) {
508
 
509
            HexFileUploadDevice hutd = (HexFileUploadDevice) object;
510
 
511
            if (hexFileUploadDeviceManager.getHexFileUploadDevices().contains(
512
                    hutd)) {
513
 
514
                midiDeviceRouting.connectDevices(miosStudioInPort, hutd);
515
                midiDeviceRouting.connectDevices(hutd, miosStudioOutPort);
516
 
517
            } else {
518
                midiDeviceRouting.disconnectDevice(hutd);
641 adamjking 519
            }
628 adamjking 520
 
641 adamjking 521
            setRouteIndividualDevices(routeIndividualDevices);
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);
628 adamjking 532
            }
641 adamjking 533
 
534
            setRouteIndividualDevices(routeIndividualDevices);
628 adamjking 535
        }
536
 
641 adamjking 537
        if (observable == midiFilterManager) {
628 adamjking 538
 
641 adamjking 539
            MidiDevice midiFilter = (MidiDevice) object;
628 adamjking 540
 
641 adamjking 541
            if (!midiFilterManager.getMidiFilterDevices().contains(midiFilter)) {
542
                midiDeviceRouting.disconnectDevice(midiFilter);
628 adamjking 543
            }
641 adamjking 544
 
545
            setRouteIndividualDevices(routeIndividualDevices);
628 adamjking 546
        }
547
    }
548
}