1:
37:
38:
39: package ;
40:
41: import ;
42: import ;
43: import ;
44:
45: import ;
46: import ;
47: import ;
48: import ;
49: import ;
50: import ;
51: import ;
52: import ;
53: import ;
54: import ;
55: import ;
56: import ;
57:
58:
66: public class DSSISynthesizer implements Synthesizer
67: {
68:
74: class DSSIInstrument extends Instrument
75: {
76: DSSIInstrument (Soundbank soundbank, Patch patch, String name)
77: {
78: super (soundbank, patch, name, null);
79: }
80:
81:
83: public Object getData()
84: {
85: return null;
86: }
87:
88: }
89:
90:
96: class DSSISoundbank implements Soundbank
97: {
98: private String name;
99: private String description;
100: private List instruments = new ArrayList();
101: private List resources = new ArrayList();
102: private String vendor;
103: private String version;
104:
105: public DSSISoundbank(String name, String description, String vendor, String version)
106: {
107: this.name = name;
108: this.description = description;
109: this.vendor = vendor;
110: this.version = version;
111: }
112:
113: void add(Instrument instrument)
114: {
115: instruments.add(instrument);
116: }
117:
118:
120: public String getName()
121: {
122: return name;
123: }
124:
125:
127: public String getVersion()
128: {
129: return version;
130: }
131:
132:
134: public String getVendor()
135: {
136: return vendor;
137: }
138:
139:
141: public String getDescription()
142: {
143: return description;
144: }
145:
146:
148: public SoundbankResource[] getResources()
149: {
150: return (SoundbankResource[])
151: resources.toArray(new SoundbankResource[resources.size()]);
152: }
153:
154:
156: public Instrument[] getInstruments()
157: {
158: return (Instrument[])
159: instruments.toArray(new Instrument[instruments.size()]);
160: }
161:
162:
164: public Instrument getInstrument(Patch patch)
165: {
166: Iterator itr = instruments.iterator();
167:
168: while (itr.hasNext())
169: {
170: Instrument i = (Instrument) itr.next();
171: if (i.getPatch().equals(patch))
172: return i;
173: }
174:
175: return null;
176: }
177: }
178:
179:
186: class DSSIReceiver implements Receiver
187: {
188:
191: public void send(MidiMessage message, long timeStamp)
192: throws IllegalStateException
193: {
194: if (message instanceof ShortMessage)
195: {
196: ShortMessage smessage = (ShortMessage) message;
197:
198: switch (message.getStatus())
199: {
200: case ShortMessage.NOTE_ON:
201: int velocity = smessage.getData2();
202: if (velocity > 0)
203: channels[smessage.getChannel()].noteOn(smessage.getData1(),
204: smessage.getData2());
205: else
206: channels[smessage.getChannel()].noteOff(smessage.getData1());
207: break;
208: case ShortMessage.CONTROL_CHANGE:
209: channels[smessage.getChannel()].controlChange(smessage.getData1(),
210: smessage.getData2());
211: break;
212: default:
213: System.out.println ("Unhandled message: " + message.getStatus());
214: break;
215: }
216: }
217: }
218:
219:
222: public void close()
223: {
224:
225: }
226:
227: }
228:
229: static native void noteOn_(long handle, int channel, int noteNumber, int velocity);
230: static native void noteOff_(long handle, int channel, int noteNumber, int velocity);
231: static native void setPolyPressure_(long handle, int channel, int noteNumber, int pressure);
232: static native int getPolyPressure_(long handle, int channel, int noteNumber);
233: static native void controlChange_(long handle, int channel, int control, int value);
234: static native void open_(long handle);
235: static native void close_(long handle);
236: static native String getProgramName_(long handle, int index);
237: static native int getProgramBank_(long handle, int index);
238: static native int getProgramProgram_(long handle, int index);
239: static native void selectProgram_(long handle, int bank, int program);
240:
241:
245: public class DSSIMidiChannel implements MidiChannel
246: {
247: int channel = 0;
248:
249:
252: public DSSIMidiChannel(int channel)
253: {
254: super();
255: this.channel = channel;
256: }
257:
258:
261: public void noteOn(int noteNumber, int velocity)
262: {
263: noteOn_(sohandle, channel, noteNumber, velocity);
264: }
265:
266:
269: public void noteOff(int noteNumber, int velocity)
270: {
271: noteOff_(sohandle, channel, noteNumber, velocity);
272: }
273:
274:
277: public void noteOff(int noteNumber)
278: {
279: noteOff_(sohandle, channel, noteNumber, -1);
280: }
281:
282:
285: public void setPolyPressure(int noteNumber, int pressure)
286: {
287: setPolyPressure_(sohandle, channel, noteNumber, pressure);
288: }
289:
290:
293: public int getPolyPressure(int noteNumber)
294: {
295: return getPolyPressure_(sohandle, channel, noteNumber);
296: }
297:
298:
301: public void setChannelPressure(int pressure)
302: {
303:
304:
305: }
306:
307:
310: public int getChannelPressure()
311: {
312:
313: return 0;
314: }
315:
316:
317: public void controlChange(int controller, int value)
318: {
319: controlChange_(sohandle, channel, controller, value);
320: }
321:
322:
325: public int getController(int controller)
326: {
327:
328: return 0;
329: }
330:
331:
334: public void programChange(int program)
335: {
336:
337:
338: }
339:
340:
343: public void programChange(int bank, int program)
344: {
345:
346:
347: }
348:
349:
352: public int getProgram()
353: {
354:
355: return 0;
356: }
357:
358:
361: public void setPitchBend(int bend)
362: {
363:
364:
365: }
366:
367:
370: public int getPitchBend()
371: {
372:
373: return 0;
374: }
375:
376:
379: public void resetAllControllers()
380: {
381:
382:
383: }
384:
385:
388: public void allNotesOff()
389: {
390:
391:
392: }
393:
394:
397: public void allSoundOff()
398: {
399:
400:
401: }
402:
403:
406: public boolean localControl(boolean on)
407: {
408:
409: return false;
410: }
411:
412:
415: public void setMono(boolean on)
416: {
417:
418:
419: }
420:
421:
424: public boolean getMono()
425: {
426:
427: return false;
428: }
429:
430:
433: public void setOmni(boolean on)
434: {
435:
436:
437: }
438:
439:
442: public boolean getOmni()
443: {
444:
445: return false;
446: }
447:
448:
451: public void setMute(boolean mute)
452: {
453:
454:
455: }
456:
457:
460: public boolean getMute()
461: {
462:
463: return false;
464: }
465:
466:
469: public void setSolo(boolean solo)
470: {
471:
472:
473: }
474:
475:
478: public boolean getSolo()
479: {
480:
481: return false;
482: }
483:
484: }
485:
486: long sohandle;
487: long handle;
488: private Info info;
489:
490: MidiChannel channels[] = new MidiChannel[16];
491:
492:
493: List soundbanks = new ArrayList();
494: DSSISoundbank defaultSoundbank;
495:
496:
503: public DSSISynthesizer(Info info, String soname, long index)
504: {
505: super();
506: this.info = info;
507: sohandle = DSSIMidiDeviceProvider.dlopen_(soname);
508: handle = DSSIMidiDeviceProvider.getDSSIHandle_(sohandle, index);
509: channels[0] = new DSSIMidiChannel(0);
510: defaultSoundbank = new DSSISoundbank("name", "description",
511: "vendor", "version");
512: soundbanks.add(defaultSoundbank);
513:
514: int i = 0;
515: String name;
516: do
517: {
518: name = getProgramName_(sohandle, i);
519: if (name != null)
520: {
521: defaultSoundbank.
522: add(new DSSIInstrument(defaultSoundbank,
523: new Patch(getProgramBank_(sohandle, i),
524: getProgramProgram_(sohandle, i)),
525: name));
526: i++;
527: }
528: } while (name != null);
529: }
530:
531:
534: public int getMaxPolyphony()
535: {
536:
537: return 0;
538: }
539:
540:
543: public long getLatency()
544: {
545:
546:
547: return 0;
548: }
549:
550:
553: public MidiChannel[] getChannels()
554: {
555: return channels;
556: }
557:
558:
561: public VoiceStatus[] getVoiceStatus()
562: {
563:
564: return null;
565: }
566:
567:
570: public boolean isSoundbankSupported(Soundbank soundbank)
571: {
572:
573: return false;
574: }
575:
576:
578: public boolean loadInstrument(Instrument instrument)
579: {
580:
581:
582: if (instrument.getSoundbank() != defaultSoundbank)
583: throw new IllegalArgumentException ("Synthesizer doesn't support this instrument's soundbank");
584:
585: Patch patch = instrument.getPatch();
586: selectProgram_(sohandle, patch.getBank(), patch.getProgram());
587: return true;
588: }
589:
590:
593: public void unloadInstrument(Instrument instrument)
594: {
595:
596:
597: }
598:
599:
602: public boolean remapInstrument(Instrument from, Instrument to)
603: {
604:
605: return false;
606: }
607:
608:
610: public Soundbank getDefaultSoundbank()
611: {
612: return defaultSoundbank;
613: }
614:
615:
617: public Instrument[] getAvailableInstruments()
618: {
619: List instruments = new ArrayList();
620: Iterator itr = soundbanks.iterator();
621: while (itr.hasNext())
622: {
623: Soundbank sb = (Soundbank) itr.next();
624: Instrument ins[] = sb.getInstruments();
625: for (int i = 0; i < ins.length; i++)
626: instruments.add(ins[i]);
627: }
628: return (Instrument[])
629: instruments.toArray(new Instrument[instruments.size()]);
630: }
631:
632:
635: public Instrument[] getLoadedInstruments()
636: {
637:
638: return null;
639: }
640:
641:
644: public boolean loadAllInstruments(Soundbank soundbank)
645: {
646:
647: return false;
648: }
649:
650:
653: public void unloadAllInstruments(Soundbank soundbank)
654: {
655:
656: }
657:
658:
661: public boolean loadInstruments(Soundbank soundbank, Patch[] patchList)
662: {
663:
664: return false;
665: }
666:
667:
670: public void unloadInstruments(Soundbank soundbank, Patch[] patchList)
671: {
672:
673:
674: }
675:
676:
678: public Info getDeviceInfo()
679: {
680: return info;
681: }
682:
683:
685: public void open() throws MidiUnavailableException
686: {
687: open_(sohandle);
688: }
689:
690:
692: public void close()
693: {
694: close_(sohandle);
695: }
696:
697:
700: public boolean isOpen()
701: {
702:
703: return false;
704: }
705:
706:
709: public long getMicrosecondPosition()
710: {
711:
712: return 0;
713: }
714:
715:
717: public int getMaxReceivers()
718: {
719: return 1;
720: }
721:
722:
724: public int getMaxTransmitters()
725: {
726: return 0;
727: }
728:
729:
731: public Receiver getReceiver() throws MidiUnavailableException
732: {
733: return new DSSIReceiver();
734: }
735:
736:
738: public Transmitter getTransmitter() throws MidiUnavailableException
739: {
740: return null;
741: }
742: }