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<Instrument> instruments = new ArrayList<Instrument>();
101: private List<SoundbankResource> resources = new ArrayList<SoundbankResource>();
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 resources.toArray(new SoundbankResource[resources.size()]);
151: }
152:
153:
155: public Instrument[] getInstruments()
156: {
157: return instruments.toArray(new Instrument[instruments.size()]);
158: }
159:
160:
162: public Instrument getInstrument(Patch patch)
163: {
164: Iterator<Instrument> itr = instruments.iterator();
165:
166: while (itr.hasNext())
167: {
168: Instrument i = itr.next();
169: if (i.getPatch().equals(patch))
170: return i;
171: }
172:
173: return null;
174: }
175: }
176:
177:
184: class DSSIReceiver implements Receiver
185: {
186:
189: public void send(MidiMessage message, long timeStamp)
190: throws IllegalStateException
191: {
192: if (message instanceof ShortMessage)
193: {
194: ShortMessage smessage = (ShortMessage) message;
195:
196: switch (message.getStatus())
197: {
198: case ShortMessage.NOTE_ON:
199: int velocity = smessage.getData2();
200: if (velocity > 0)
201: channels[smessage.getChannel()].noteOn(smessage.getData1(),
202: smessage.getData2());
203: else
204: channels[smessage.getChannel()].noteOff(smessage.getData1());
205: break;
206: case ShortMessage.CONTROL_CHANGE:
207: channels[smessage.getChannel()].controlChange(smessage.getData1(),
208: smessage.getData2());
209: break;
210: default:
211: System.out.println ("Unhandled message: " + message.getStatus());
212: break;
213: }
214: }
215: }
216:
217:
220: public void close()
221: {
222:
223: }
224:
225: }
226:
227: static native void noteOn_(long handle, int channel, int noteNumber, int velocity);
228: static native void noteOff_(long handle, int channel, int noteNumber, int velocity);
229: static native void setPolyPressure_(long handle, int channel, int noteNumber, int pressure);
230: static native int getPolyPressure_(long handle, int channel, int noteNumber);
231: static native void controlChange_(long handle, int channel, int control, int value);
232: static native void open_(long handle);
233: static native void close_(long handle);
234: static native String getProgramName_(long handle, int index);
235: static native int getProgramBank_(long handle, int index);
236: static native int getProgramProgram_(long handle, int index);
237: static native void selectProgram_(long handle, int bank, int program);
238:
239:
243: public class DSSIMidiChannel implements MidiChannel
244: {
245: int channel = 0;
246:
247:
250: public DSSIMidiChannel(int channel)
251: {
252: super();
253: this.channel = channel;
254: }
255:
256:
259: public void noteOn(int noteNumber, int velocity)
260: {
261: noteOn_(sohandle, channel, noteNumber, velocity);
262: }
263:
264:
267: public void noteOff(int noteNumber, int velocity)
268: {
269: noteOff_(sohandle, channel, noteNumber, velocity);
270: }
271:
272:
275: public void noteOff(int noteNumber)
276: {
277: noteOff_(sohandle, channel, noteNumber, -1);
278: }
279:
280:
283: public void setPolyPressure(int noteNumber, int pressure)
284: {
285: setPolyPressure_(sohandle, channel, noteNumber, pressure);
286: }
287:
288:
291: public int getPolyPressure(int noteNumber)
292: {
293: return getPolyPressure_(sohandle, channel, noteNumber);
294: }
295:
296:
299: public void setChannelPressure(int pressure)
300: {
301:
302:
303: }
304:
305:
308: public int getChannelPressure()
309: {
310:
311: return 0;
312: }
313:
314:
315: public void controlChange(int controller, int value)
316: {
317: controlChange_(sohandle, channel, controller, value);
318: }
319:
320:
323: public int getController(int controller)
324: {
325:
326: return 0;
327: }
328:
329:
332: public void programChange(int program)
333: {
334:
335:
336: }
337:
338:
341: public void programChange(int bank, int program)
342: {
343:
344:
345: }
346:
347:
350: public int getProgram()
351: {
352:
353: return 0;
354: }
355:
356:
359: public void setPitchBend(int bend)
360: {
361:
362:
363: }
364:
365:
368: public int getPitchBend()
369: {
370:
371: return 0;
372: }
373:
374:
377: public void resetAllControllers()
378: {
379:
380:
381: }
382:
383:
386: public void allNotesOff()
387: {
388:
389:
390: }
391:
392:
395: public void allSoundOff()
396: {
397:
398:
399: }
400:
401:
404: public boolean localControl(boolean on)
405: {
406:
407: return false;
408: }
409:
410:
413: public void setMono(boolean on)
414: {
415:
416:
417: }
418:
419:
422: public boolean getMono()
423: {
424:
425: return false;
426: }
427:
428:
431: public void setOmni(boolean on)
432: {
433:
434:
435: }
436:
437:
440: public boolean getOmni()
441: {
442:
443: return false;
444: }
445:
446:
449: public void setMute(boolean mute)
450: {
451:
452:
453: }
454:
455:
458: public boolean getMute()
459: {
460:
461: return false;
462: }
463:
464:
467: public void setSolo(boolean solo)
468: {
469:
470:
471: }
472:
473:
476: public boolean getSolo()
477: {
478:
479: return false;
480: }
481:
482: }
483:
484: long sohandle;
485: long handle;
486: private Info info;
487:
488: MidiChannel channels[] = new MidiChannel[16];
489:
490:
491: List<Soundbank> soundbanks = new ArrayList<Soundbank>();
492: DSSISoundbank defaultSoundbank;
493:
494:
501: public DSSISynthesizer(Info info, String soname, long index)
502: {
503: super();
504: this.info = info;
505: sohandle = DSSIMidiDeviceProvider.dlopen_(soname);
506: handle = DSSIMidiDeviceProvider.getDSSIHandle_(sohandle, index);
507: channels[0] = new DSSIMidiChannel(0);
508: defaultSoundbank = new DSSISoundbank("name", "description",
509: "vendor", "version");
510: soundbanks.add(defaultSoundbank);
511:
512: int i = 0;
513: String name;
514: do
515: {
516: name = getProgramName_(sohandle, i);
517: if (name != null)
518: {
519: defaultSoundbank.
520: add(new DSSIInstrument(defaultSoundbank,
521: new Patch(getProgramBank_(sohandle, i),
522: getProgramProgram_(sohandle, i)),
523: name));
524: i++;
525: }
526: } while (name != null);
527: }
528:
529:
532: public int getMaxPolyphony()
533: {
534:
535: return 0;
536: }
537:
538:
541: public long getLatency()
542: {
543:
544:
545: return 0;
546: }
547:
548:
551: public MidiChannel[] getChannels()
552: {
553: return channels;
554: }
555:
556:
559: public VoiceStatus[] getVoiceStatus()
560: {
561:
562: return null;
563: }
564:
565:
568: public boolean isSoundbankSupported(Soundbank soundbank)
569: {
570:
571: return false;
572: }
573:
574:
576: public boolean loadInstrument(Instrument instrument)
577: {
578:
579:
580: if (instrument.getSoundbank() != defaultSoundbank)
581: throw new IllegalArgumentException ("Synthesizer doesn't support this instrument's soundbank");
582:
583: Patch patch = instrument.getPatch();
584: selectProgram_(sohandle, patch.getBank(), patch.getProgram());
585: return true;
586: }
587:
588:
591: public void unloadInstrument(Instrument instrument)
592: {
593:
594:
595: }
596:
597:
600: public boolean remapInstrument(Instrument from, Instrument to)
601: {
602:
603: return false;
604: }
605:
606:
608: public Soundbank getDefaultSoundbank()
609: {
610: return defaultSoundbank;
611: }
612:
613:
615: public Instrument[] getAvailableInstruments()
616: {
617: List<Instrument> instruments = new ArrayList<Instrument>();
618: Iterator<Soundbank> itr = soundbanks.iterator();
619: while (itr.hasNext())
620: {
621: Soundbank sb = itr.next();
622: Instrument ins[] = sb.getInstruments();
623: for (int i = 0; i < ins.length; i++)
624: instruments.add(ins[i]);
625: }
626: return instruments.toArray(new Instrument[instruments.size()]);
627: }
628:
629:
632: public Instrument[] getLoadedInstruments()
633: {
634:
635: return null;
636: }
637:
638:
641: public boolean loadAllInstruments(Soundbank soundbank)
642: {
643:
644: return false;
645: }
646:
647:
650: public void unloadAllInstruments(Soundbank soundbank)
651: {
652:
653: }
654:
655:
658: public boolean loadInstruments(Soundbank soundbank, Patch[] patchList)
659: {
660:
661: return false;
662: }
663:
664:
667: public void unloadInstruments(Soundbank soundbank, Patch[] patchList)
668: {
669:
670:
671: }
672:
673:
675: public Info getDeviceInfo()
676: {
677: return info;
678: }
679:
680:
682: public void open() throws MidiUnavailableException
683: {
684: open_(sohandle);
685: }
686:
687:
689: public void close()
690: {
691: close_(sohandle);
692: }
693:
694:
697: public boolean isOpen()
698: {
699:
700: return false;
701: }
702:
703:
706: public long getMicrosecondPosition()
707: {
708:
709: return 0;
710: }
711:
712:
714: public int getMaxReceivers()
715: {
716: return 1;
717: }
718:
719:
721: public int getMaxTransmitters()
722: {
723: return 0;
724: }
725:
726:
728: public Receiver getReceiver() throws MidiUnavailableException
729: {
730: return new DSSIReceiver();
731: }
732:
733:
735: public Transmitter getTransmitter() throws MidiUnavailableException
736: {
737: return null;
738: }
739: }