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:
59: import ;
60:
61:
69: public class DSSISynthesizer implements Synthesizer
70: {
71:
77: class DSSIInstrument extends Instrument
78: {
79: DSSIInstrument (Soundbank soundbank, Patch patch, String name)
80: {
81: super (soundbank, patch, name, null);
82: }
83:
84:
86: public Object getData()
87: {
88: return null;
89: }
90:
91: }
92:
93:
99: class DSSISoundbank implements Soundbank
100: {
101: private String name;
102: private String description;
103: private List instruments = new ArrayList();
104: private List resources = new ArrayList();
105: private String vendor;
106: private String version;
107:
108: public DSSISoundbank(String name, String description, String vendor, String version)
109: {
110: this.name = name;
111: this.description = description;
112: this.vendor = vendor;
113: this.version = version;
114: }
115:
116: void add(Instrument instrument)
117: {
118: instruments.add(instrument);
119: }
120:
121:
123: public String getName()
124: {
125: return name;
126: }
127:
128:
130: public String getVersion()
131: {
132: return version;
133: }
134:
135:
137: public String getVendor()
138: {
139: return vendor;
140: }
141:
142:
144: public String getDescription()
145: {
146: return description;
147: }
148:
149:
151: public SoundbankResource[] getResources()
152: {
153: return (SoundbankResource[])
154: resources.toArray(new SoundbankResource[resources.size()]);
155: }
156:
157:
159: public Instrument[] getInstruments()
160: {
161: return (Instrument[])
162: instruments.toArray(new Instrument[instruments.size()]);
163: }
164:
165:
167: public Instrument getInstrument(Patch patch)
168: {
169: Iterator itr = instruments.iterator();
170:
171: while (itr.hasNext())
172: {
173: Instrument i = (Instrument) itr.next();
174: if (i.getPatch().equals(patch))
175: return i;
176: }
177:
178: return null;
179: }
180: }
181:
182:
189: class DSSIReceiver implements Receiver
190: {
191:
194: public void send(MidiMessage message, long timeStamp)
195: throws IllegalStateException
196: {
197: if (message instanceof ShortMessage)
198: {
199: ShortMessage smessage = (ShortMessage) message;
200:
201: switch (message.getStatus())
202: {
203: case ShortMessage.NOTE_ON:
204: int velocity = smessage.getData2();
205: if (velocity > 0)
206: channels[smessage.getChannel()].noteOn(smessage.getData1(),
207: smessage.getData2());
208: else
209: channels[smessage.getChannel()].noteOff(smessage.getData1());
210: break;
211: case ShortMessage.CONTROL_CHANGE:
212: channels[smessage.getChannel()].controlChange(smessage.getData1(),
213: smessage.getData2());
214: break;
215: default:
216: System.out.println ("Unhandled message: " + message.getStatus());
217: break;
218: }
219: }
220: }
221:
222:
225: public void close()
226: {
227:
228: }
229:
230: }
231:
232: static native void noteOn_(long handle, int channel, int noteNumber, int velocity);
233: static native void noteOff_(long handle, int channel, int noteNumber, int velocity);
234: static native void setPolyPressure_(long handle, int channel, int noteNumber, int pressure);
235: static native int getPolyPressure_(long handle, int channel, int noteNumber);
236: static native void controlChange_(long handle, int channel, int control, int value);
237: static native void open_(long handle);
238: static native void close_(long handle);
239: static native String getProgramName_(long handle, int index);
240: static native int getProgramBank_(long handle, int index);
241: static native int getProgramProgram_(long handle, int index);
242: static native void selectProgram_(long handle, int bank, int program);
243:
244:
248: public class DSSIMidiChannel implements MidiChannel
249: {
250: int channel = 0;
251:
252:
255: public DSSIMidiChannel(int channel)
256: {
257: super();
258: this.channel = channel;
259: }
260:
261:
264: public void noteOn(int noteNumber, int velocity)
265: {
266: noteOn_(sohandle, channel, noteNumber, velocity);
267: }
268:
269:
272: public void noteOff(int noteNumber, int velocity)
273: {
274: noteOff_(sohandle, channel, noteNumber, velocity);
275: }
276:
277:
280: public void noteOff(int noteNumber)
281: {
282: noteOff_(sohandle, channel, noteNumber, -1);
283: }
284:
285:
288: public void setPolyPressure(int noteNumber, int pressure)
289: {
290: setPolyPressure_(sohandle, channel, noteNumber, pressure);
291: }
292:
293:
296: public int getPolyPressure(int noteNumber)
297: {
298: return getPolyPressure_(sohandle, channel, noteNumber);
299: }
300:
301:
304: public void setChannelPressure(int pressure)
305: {
306:
307:
308: }
309:
310:
313: public int getChannelPressure()
314: {
315:
316: return 0;
317: }
318:
319:
320: public void controlChange(int controller, int value)
321: {
322: controlChange_(sohandle, channel, controller, value);
323: }
324:
325:
328: public int getController(int controller)
329: {
330:
331: return 0;
332: }
333:
334:
337: public void programChange(int program)
338: {
339:
340:
341: }
342:
343:
346: public void programChange(int bank, int program)
347: {
348:
349:
350: }
351:
352:
355: public int getProgram()
356: {
357:
358: return 0;
359: }
360:
361:
364: public void setPitchBend(int bend)
365: {
366:
367:
368: }
369:
370:
373: public int getPitchBend()
374: {
375:
376: return 0;
377: }
378:
379:
382: public void resetAllControllers()
383: {
384:
385:
386: }
387:
388:
391: public void allNotesOff()
392: {
393:
394:
395: }
396:
397:
400: public void allSoundOff()
401: {
402:
403:
404: }
405:
406:
409: public boolean localControl(boolean on)
410: {
411:
412: return false;
413: }
414:
415:
418: public void setMono(boolean on)
419: {
420:
421:
422: }
423:
424:
427: public boolean getMono()
428: {
429:
430: return false;
431: }
432:
433:
436: public void setOmni(boolean on)
437: {
438:
439:
440: }
441:
442:
445: public boolean getOmni()
446: {
447:
448: return false;
449: }
450:
451:
454: public void setMute(boolean mute)
455: {
456:
457:
458: }
459:
460:
463: public boolean getMute()
464: {
465:
466: return false;
467: }
468:
469:
472: public void setSolo(boolean solo)
473: {
474:
475:
476: }
477:
478:
481: public boolean getSolo()
482: {
483:
484: return false;
485: }
486:
487: }
488:
489: long sohandle;
490: long handle;
491: private Info info;
492:
493: MidiChannel channels[] = new MidiChannel[16];
494:
495:
496: List soundbanks = new ArrayList();
497: DSSISoundbank defaultSoundbank;
498:
499:
506: public DSSISynthesizer(Info info, String soname, long index)
507: {
508: super();
509: this.info = info;
510: sohandle = DSSIMidiDeviceProvider.dlopen_(soname);
511: handle = DSSIMidiDeviceProvider.getDSSIHandle_(sohandle, index);
512: channels[0] = new DSSIMidiChannel(0);
513: defaultSoundbank = new DSSISoundbank("name", "description",
514: "vendor", "version");
515: soundbanks.add(defaultSoundbank);
516:
517: int i = 0;
518: String name;
519: do
520: {
521: name = getProgramName_(sohandle, i);
522: if (name != null)
523: {
524: defaultSoundbank.
525: add(new DSSIInstrument(defaultSoundbank,
526: new Patch(getProgramBank_(sohandle, i),
527: getProgramProgram_(sohandle, i)),
528: name));
529: i++;
530: }
531: } while (name != null);
532: }
533:
534:
537: public int getMaxPolyphony()
538: {
539:
540: return 0;
541: }
542:
543:
546: public long getLatency()
547: {
548:
549:
550: return 0;
551: }
552:
553:
556: public MidiChannel[] getChannels()
557: {
558: return channels;
559: }
560:
561:
564: public VoiceStatus[] getVoiceStatus()
565: {
566:
567: return null;
568: }
569:
570:
573: public boolean isSoundbankSupported(Soundbank soundbank)
574: {
575:
576: return false;
577: }
578:
579:
581: public boolean loadInstrument(Instrument instrument)
582: {
583:
584:
585: if (instrument.getSoundbank() != defaultSoundbank)
586: throw new IllegalArgumentException ("Synthesizer doesn't support this instrument's soundbank");
587:
588: Patch patch = instrument.getPatch();
589: selectProgram_(sohandle, patch.getBank(), patch.getProgram());
590: return true;
591: }
592:
593:
596: public void unloadInstrument(Instrument instrument)
597: {
598:
599:
600: }
601:
602:
605: public boolean remapInstrument(Instrument from, Instrument to)
606: {
607:
608: return false;
609: }
610:
611:
613: public Soundbank getDefaultSoundbank()
614: {
615: return defaultSoundbank;
616: }
617:
618:
620: public Instrument[] getAvailableInstruments()
621: {
622: List instruments = new ArrayList();
623: Iterator itr = soundbanks.iterator();
624: while (itr.hasNext())
625: {
626: Soundbank sb = (Soundbank) itr.next();
627: Instrument ins[] = sb.getInstruments();
628: for (int i = 0; i < ins.length; i++)
629: instruments.add(ins[i]);
630: }
631: return (Instrument[])
632: instruments.toArray(new Instrument[instruments.size()]);
633: }
634:
635:
638: public Instrument[] getLoadedInstruments()
639: {
640:
641: return null;
642: }
643:
644:
647: public boolean loadAllInstruments(Soundbank soundbank)
648: {
649:
650: return false;
651: }
652:
653:
656: public void unloadAllInstruments(Soundbank soundbank)
657: {
658:
659: }
660:
661:
664: public boolean loadInstruments(Soundbank soundbank, Patch[] patchList)
665: {
666:
667: return false;
668: }
669:
670:
673: public void unloadInstruments(Soundbank soundbank, Patch[] patchList)
674: {
675:
676:
677: }
678:
679:
681: public Info getDeviceInfo()
682: {
683: return info;
684: }
685:
686:
688: public void open() throws MidiUnavailableException
689: {
690: open_(sohandle);
691: }
692:
693:
695: public void close()
696: {
697: close_(sohandle);
698: }
699:
700:
703: public boolean isOpen()
704: {
705:
706: return false;
707: }
708:
709:
712: public long getMicrosecondPosition()
713: {
714:
715: return 0;
716: }
717:
718:
720: public int getMaxReceivers()
721: {
722: return 1;
723: }
724:
725:
727: public int getMaxTransmitters()
728: {
729: return 0;
730: }
731:
732:
734: public Receiver getReceiver() throws MidiUnavailableException
735: {
736: return new DSSIReceiver();
737: }
738:
739:
741: public Transmitter getTransmitter() throws MidiUnavailableException
742: {
743: return null;
744: }
745: }