jdk/src/share/classes/javax/sound/midi/MidiSystem.java
changeset 25131 49006bd0e69d
parent 22959 2d9d076cee41
child 25777 bb88947b6766
equal deleted inserted replaced
25130:adfaa02ea516 25131:49006bd0e69d
   185      * @return an array of <code>MidiDevice.Info</code> objects, one
   185      * @return an array of <code>MidiDevice.Info</code> objects, one
   186      * for each installed MIDI device.  If no such devices are installed,
   186      * for each installed MIDI device.  If no such devices are installed,
   187      * an array of length 0 is returned.
   187      * an array of length 0 is returned.
   188      */
   188      */
   189     public static MidiDevice.Info[] getMidiDeviceInfo() {
   189     public static MidiDevice.Info[] getMidiDeviceInfo() {
   190         List allInfos = new ArrayList();
   190         List<MidiDevice.Info> allInfos = new ArrayList<>();
   191         List providers = getMidiDeviceProviders();
   191         List<MidiDeviceProvider> providers = getMidiDeviceProviders();
   192 
   192 
   193         for(int i = 0; i < providers.size(); i++) {
   193         for(int i = 0; i < providers.size(); i++) {
   194             MidiDeviceProvider provider = (MidiDeviceProvider) providers.get(i);
   194             MidiDeviceProvider provider = providers.get(i);
   195             MidiDevice.Info[] tmpinfo = provider.getDeviceInfo();
   195             MidiDevice.Info[] tmpinfo = provider.getDeviceInfo();
   196             for (int j = 0; j < tmpinfo.length; j++) {
   196             for (int j = 0; j < tmpinfo.length; j++) {
   197                 allInfos.add( tmpinfo[j] );
   197                 allInfos.add( tmpinfo[j] );
   198             }
   198             }
   199         }
   199         }
   200         MidiDevice.Info[] infosArray = (MidiDevice.Info[]) allInfos.toArray(new MidiDevice.Info[0]);
   200         MidiDevice.Info[] infosArray = allInfos.toArray(new MidiDevice.Info[0]);
   201         return infosArray;
   201         return infosArray;
   202     }
   202     }
   203 
   203 
   204 
   204 
   205     /**
   205     /**
   212      * @throws IllegalArgumentException if the info object does not represent
   212      * @throws IllegalArgumentException if the info object does not represent
   213      * a MIDI device installed on the system
   213      * a MIDI device installed on the system
   214      * @see #getMidiDeviceInfo
   214      * @see #getMidiDeviceInfo
   215      */
   215      */
   216     public static MidiDevice getMidiDevice(MidiDevice.Info info) throws MidiUnavailableException {
   216     public static MidiDevice getMidiDevice(MidiDevice.Info info) throws MidiUnavailableException {
   217         List providers = getMidiDeviceProviders();
   217         List<MidiDeviceProvider> providers = getMidiDeviceProviders();
   218 
   218 
   219         for(int i = 0; i < providers.size(); i++) {
   219         for(int i = 0; i < providers.size(); i++) {
   220             MidiDeviceProvider provider = (MidiDeviceProvider) providers.get(i);
   220             MidiDeviceProvider provider = providers.get(i);
   221             if (provider.isDeviceSupported(info)) {
   221             if (provider.isDeviceSupported(info)) {
   222                 MidiDevice device = provider.getDevice(info);
   222                 MidiDevice device = provider.getDevice(info);
   223                 return device;
   223                 return device;
   224             }
   224             }
   225         }
   225         }
   526         throws InvalidMidiDataException, IOException {
   526         throws InvalidMidiDataException, IOException {
   527 
   527 
   528         SoundbankReader sp = null;
   528         SoundbankReader sp = null;
   529         Soundbank s = null;
   529         Soundbank s = null;
   530 
   530 
   531         List providers = getSoundbankReaders();
   531         List<SoundbankReader> providers = getSoundbankReaders();
   532 
   532 
   533         for(int i = 0; i < providers.size(); i++) {
   533         for(int i = 0; i < providers.size(); i++) {
   534             sp = (SoundbankReader)providers.get(i);
   534             sp = providers.get(i);
   535             s = sp.getSoundbank(stream);
   535             s = sp.getSoundbank(stream);
   536 
   536 
   537             if( s!= null) {
   537             if( s!= null) {
   538                 return s;
   538                 return s;
   539             }
   539             }
   557         throws InvalidMidiDataException, IOException {
   557         throws InvalidMidiDataException, IOException {
   558 
   558 
   559         SoundbankReader sp = null;
   559         SoundbankReader sp = null;
   560         Soundbank s = null;
   560         Soundbank s = null;
   561 
   561 
   562         List providers = getSoundbankReaders();
   562         List<SoundbankReader> providers = getSoundbankReaders();
   563 
   563 
   564         for(int i = 0; i < providers.size(); i++) {
   564         for(int i = 0; i < providers.size(); i++) {
   565             sp = (SoundbankReader)providers.get(i);
   565             sp = providers.get(i);
   566             s = sp.getSoundbank(url);
   566             s = sp.getSoundbank(url);
   567 
   567 
   568             if( s!= null) {
   568             if( s!= null) {
   569                 return s;
   569                 return s;
   570             }
   570             }
   589         throws InvalidMidiDataException, IOException {
   589         throws InvalidMidiDataException, IOException {
   590 
   590 
   591         SoundbankReader sp = null;
   591         SoundbankReader sp = null;
   592         Soundbank s = null;
   592         Soundbank s = null;
   593 
   593 
   594         List providers = getSoundbankReaders();
   594         List<SoundbankReader> providers = getSoundbankReaders();
   595 
   595 
   596         for(int i = 0; i < providers.size(); i++) {
   596         for(int i = 0; i < providers.size(); i++) {
   597             sp = (SoundbankReader)providers.get(i);
   597             sp = providers.get(i);
   598             s = sp.getSoundbank(file);
   598             s = sp.getSoundbank(file);
   599 
   599 
   600             if( s!= null) {
   600             if( s!= null) {
   601                 return s;
   601                 return s;
   602             }
   602             }
   639      * @see InputStream#mark
   639      * @see InputStream#mark
   640      */
   640      */
   641     public static MidiFileFormat getMidiFileFormat(InputStream stream)
   641     public static MidiFileFormat getMidiFileFormat(InputStream stream)
   642         throws InvalidMidiDataException, IOException {
   642         throws InvalidMidiDataException, IOException {
   643 
   643 
   644         List providers = getMidiFileReaders();
   644         List<MidiFileReader> providers = getMidiFileReaders();
   645         MidiFileFormat format = null;
   645         MidiFileFormat format = null;
   646 
   646 
   647         for(int i = 0; i < providers.size(); i++) {
   647         for(int i = 0; i < providers.size(); i++) {
   648             MidiFileReader reader = (MidiFileReader) providers.get(i);
   648             MidiFileReader reader =  providers.get(i);
   649             try {
   649             try {
   650                 format = reader.getMidiFileFormat( stream ); // throws IOException
   650                 format = reader.getMidiFileFormat( stream ); // throws IOException
   651                 break;
   651                 break;
   652             } catch (InvalidMidiDataException e) {
   652             } catch (InvalidMidiDataException e) {
   653                 continue;
   653                 continue;
   685      * @see #getMidiFileFormat(File)
   685      * @see #getMidiFileFormat(File)
   686      */
   686      */
   687     public static MidiFileFormat getMidiFileFormat(URL url)
   687     public static MidiFileFormat getMidiFileFormat(URL url)
   688         throws InvalidMidiDataException, IOException {
   688         throws InvalidMidiDataException, IOException {
   689 
   689 
   690         List providers = getMidiFileReaders();
   690         List<MidiFileReader> providers = getMidiFileReaders();
   691         MidiFileFormat format = null;
   691         MidiFileFormat format = null;
   692 
   692 
   693         for(int i = 0; i < providers.size(); i++) {
   693         for(int i = 0; i < providers.size(); i++) {
   694             MidiFileReader reader = (MidiFileReader) providers.get(i);
   694             MidiFileReader reader = providers.get(i);
   695             try {
   695             try {
   696                 format = reader.getMidiFileFormat( url ); // throws IOException
   696                 format = reader.getMidiFileFormat( url ); // throws IOException
   697                 break;
   697                 break;
   698             } catch (InvalidMidiDataException e) {
   698             } catch (InvalidMidiDataException e) {
   699                 continue;
   699                 continue;
   731      * @see #getMidiFileFormat(URL)
   731      * @see #getMidiFileFormat(URL)
   732      */
   732      */
   733     public static MidiFileFormat getMidiFileFormat(File file)
   733     public static MidiFileFormat getMidiFileFormat(File file)
   734         throws InvalidMidiDataException, IOException {
   734         throws InvalidMidiDataException, IOException {
   735 
   735 
   736         List providers = getMidiFileReaders();
   736         List<MidiFileReader> providers = getMidiFileReaders();
   737         MidiFileFormat format = null;
   737         MidiFileFormat format = null;
   738 
   738 
   739         for(int i = 0; i < providers.size(); i++) {
   739         for(int i = 0; i < providers.size(); i++) {
   740             MidiFileReader reader = (MidiFileReader) providers.get(i);
   740             MidiFileReader reader = providers.get(i);
   741             try {
   741             try {
   742                 format = reader.getMidiFileFormat( file ); // throws IOException
   742                 format = reader.getMidiFileFormat( file ); // throws IOException
   743                 break;
   743                 break;
   744             } catch (InvalidMidiDataException e) {
   744             } catch (InvalidMidiDataException e) {
   745                 continue;
   745                 continue;
   786      * @see InputStream#mark
   786      * @see InputStream#mark
   787      */
   787      */
   788     public static Sequence getSequence(InputStream stream)
   788     public static Sequence getSequence(InputStream stream)
   789         throws InvalidMidiDataException, IOException {
   789         throws InvalidMidiDataException, IOException {
   790 
   790 
   791         List providers = getMidiFileReaders();
   791         List<MidiFileReader> providers = getMidiFileReaders();
   792         Sequence sequence = null;
   792         Sequence sequence = null;
   793 
   793 
   794         for(int i = 0; i < providers.size(); i++) {
   794         for(int i = 0; i < providers.size(); i++) {
   795             MidiFileReader reader = (MidiFileReader) providers.get(i);
   795             MidiFileReader reader = providers.get(i);
   796             try {
   796             try {
   797                 sequence = reader.getSequence( stream ); // throws IOException
   797                 sequence = reader.getSequence( stream ); // throws IOException
   798                 break;
   798                 break;
   799             } catch (InvalidMidiDataException e) {
   799             } catch (InvalidMidiDataException e) {
   800                 continue;
   800                 continue;
   830      * @throws IOException if an I/O exception occurs while accessing the URL
   830      * @throws IOException if an I/O exception occurs while accessing the URL
   831      */
   831      */
   832     public static Sequence getSequence(URL url)
   832     public static Sequence getSequence(URL url)
   833         throws InvalidMidiDataException, IOException {
   833         throws InvalidMidiDataException, IOException {
   834 
   834 
   835         List providers = getMidiFileReaders();
   835         List<MidiFileReader> providers = getMidiFileReaders();
   836         Sequence sequence = null;
   836         Sequence sequence = null;
   837 
   837 
   838         for(int i = 0; i < providers.size(); i++) {
   838         for(int i = 0; i < providers.size(); i++) {
   839             MidiFileReader reader = (MidiFileReader) providers.get(i);
   839             MidiFileReader reader = providers.get(i);
   840             try {
   840             try {
   841                 sequence = reader.getSequence( url ); // throws IOException
   841                 sequence = reader.getSequence( url ); // throws IOException
   842                 break;
   842                 break;
   843             } catch (InvalidMidiDataException e) {
   843             } catch (InvalidMidiDataException e) {
   844                 continue;
   844                 continue;
   874      * @throws IOException if an I/O exception occurs
   874      * @throws IOException if an I/O exception occurs
   875      */
   875      */
   876     public static Sequence getSequence(File file)
   876     public static Sequence getSequence(File file)
   877         throws InvalidMidiDataException, IOException {
   877         throws InvalidMidiDataException, IOException {
   878 
   878 
   879         List providers = getMidiFileReaders();
   879         List<MidiFileReader> providers = getMidiFileReaders();
   880         Sequence sequence = null;
   880         Sequence sequence = null;
   881 
   881 
   882         for(int i = 0; i < providers.size(); i++) {
   882         for(int i = 0; i < providers.size(); i++) {
   883             MidiFileReader reader = (MidiFileReader) providers.get(i);
   883             MidiFileReader reader = providers.get(i);
   884             try {
   884             try {
   885                 sequence = reader.getSequence( file ); // throws IOException
   885                 sequence = reader.getSequence( file ); // throws IOException
   886                 break;
   886                 break;
   887             } catch (InvalidMidiDataException e) {
   887             } catch (InvalidMidiDataException e) {
   888                 continue;
   888                 continue;
   903      * @return array of unique file types.  If no file types are supported,
   903      * @return array of unique file types.  If no file types are supported,
   904      * an array of length 0 is returned.
   904      * an array of length 0 is returned.
   905      */
   905      */
   906     public static int[] getMidiFileTypes() {
   906     public static int[] getMidiFileTypes() {
   907 
   907 
   908         List providers = getMidiFileWriters();
   908         List<MidiFileWriter> providers = getMidiFileWriters();
   909         Set allTypes = new HashSet();
   909         Set<Integer> allTypes = new HashSet<>();
   910 
   910 
   911         // gather from all the providers
   911         // gather from all the providers
   912 
   912 
   913         for (int i = 0; i < providers.size(); i++ ) {
   913         for (int i = 0; i < providers.size(); i++ ) {
   914             MidiFileWriter writer = (MidiFileWriter) providers.get(i);
   914             MidiFileWriter writer = providers.get(i);
   915             int[] types = writer.getMidiFileTypes();
   915             int[] types = writer.getMidiFileTypes();
   916             for (int j = 0; j < types.length; j++ ) {
   916             for (int j = 0; j < types.length; j++ ) {
   917                 allTypes.add(new Integer(types[j]));
   917                 allTypes.add(new Integer(types[j]));
   918             }
   918             }
   919         }
   919         }
   920         int resultTypes[] = new int[allTypes.size()];
   920         int resultTypes[] = new int[allTypes.size()];
   921         int index = 0;
   921         int index = 0;
   922         Iterator iterator = allTypes.iterator();
   922         Iterator<Integer> iterator = allTypes.iterator();
   923         while (iterator.hasNext()) {
   923         while (iterator.hasNext()) {
   924             Integer integer = (Integer) iterator.next();
   924             Integer integer = iterator.next();
   925             resultTypes[index++] = integer.intValue();
   925             resultTypes[index++] = integer.intValue();
   926         }
   926         }
   927         return resultTypes;
   927         return resultTypes;
   928     }
   928     }
   929 
   929 
   935      * @return <code>true</code> if the file type is supported,
   935      * @return <code>true</code> if the file type is supported,
   936      * otherwise <code>false</code>
   936      * otherwise <code>false</code>
   937      */
   937      */
   938     public static boolean isFileTypeSupported(int fileType) {
   938     public static boolean isFileTypeSupported(int fileType) {
   939 
   939 
   940         List providers = getMidiFileWriters();
   940         List<MidiFileWriter> providers = getMidiFileWriters();
   941 
   941 
   942         for (int i = 0; i < providers.size(); i++ ) {
   942         for (int i = 0; i < providers.size(); i++ ) {
   943             MidiFileWriter writer = (MidiFileWriter) providers.get(i);
   943             MidiFileWriter writer = providers.get(i);
   944             if( writer.isFileTypeSupported(fileType)) {
   944             if( writer.isFileTypeSupported(fileType)) {
   945                 return true;
   945                 return true;
   946             }
   946             }
   947         }
   947         }
   948         return false;
   948         return false;
   957      * @return the set of unique supported file types.  If no file types are supported,
   957      * @return the set of unique supported file types.  If no file types are supported,
   958      * returns an array of length 0.
   958      * returns an array of length 0.
   959      */
   959      */
   960     public static int[] getMidiFileTypes(Sequence sequence) {
   960     public static int[] getMidiFileTypes(Sequence sequence) {
   961 
   961 
   962         List providers = getMidiFileWriters();
   962         List<MidiFileWriter> providers = getMidiFileWriters();
   963         Set allTypes = new HashSet();
   963         Set<Integer> allTypes = new HashSet<>();
   964 
   964 
   965         // gather from all the providers
   965         // gather from all the providers
   966 
   966 
   967         for (int i = 0; i < providers.size(); i++ ) {
   967         for (int i = 0; i < providers.size(); i++ ) {
   968             MidiFileWriter writer = (MidiFileWriter) providers.get(i);
   968             MidiFileWriter writer = providers.get(i);
   969             int[] types = writer.getMidiFileTypes(sequence);
   969             int[] types = writer.getMidiFileTypes(sequence);
   970             for (int j = 0; j < types.length; j++ ) {
   970             for (int j = 0; j < types.length; j++ ) {
   971                 allTypes.add(new Integer(types[j]));
   971                 allTypes.add(new Integer(types[j]));
   972             }
   972             }
   973         }
   973         }
   974         int resultTypes[] = new int[allTypes.size()];
   974         int resultTypes[] = new int[allTypes.size()];
   975         int index = 0;
   975         int index = 0;
   976         Iterator iterator = allTypes.iterator();
   976         Iterator<Integer> iterator = allTypes.iterator();
   977         while (iterator.hasNext()) {
   977         while (iterator.hasNext()) {
   978             Integer integer = (Integer) iterator.next();
   978             Integer integer = iterator.next();
   979             resultTypes[index++] = integer.intValue();
   979             resultTypes[index++] = integer.intValue();
   980         }
   980         }
   981         return resultTypes;
   981         return resultTypes;
   982     }
   982     }
   983 
   983 
   991      * @return <code>true</code> if the file type is supported for this
   991      * @return <code>true</code> if the file type is supported for this
   992      * sequence, otherwise <code>false</code>
   992      * sequence, otherwise <code>false</code>
   993      */
   993      */
   994     public static boolean isFileTypeSupported(int fileType, Sequence sequence) {
   994     public static boolean isFileTypeSupported(int fileType, Sequence sequence) {
   995 
   995 
   996         List providers = getMidiFileWriters();
   996         List<MidiFileWriter> providers = getMidiFileWriters();
   997 
   997 
   998         for (int i = 0; i < providers.size(); i++ ) {
   998         for (int i = 0; i < providers.size(); i++ ) {
   999             MidiFileWriter writer = (MidiFileWriter) providers.get(i);
   999             MidiFileWriter writer = providers.get(i);
  1000             if( writer.isFileTypeSupported(fileType,sequence)) {
  1000             if( writer.isFileTypeSupported(fileType,sequence)) {
  1001                 return true;
  1001                 return true;
  1002             }
  1002             }
  1003         }
  1003         }
  1004         return false;
  1004         return false;
  1018      * @see #isFileTypeSupported(int, Sequence)
  1018      * @see #isFileTypeSupported(int, Sequence)
  1019      * @see     #getMidiFileTypes(Sequence)
  1019      * @see     #getMidiFileTypes(Sequence)
  1020      */
  1020      */
  1021     public static int write(Sequence in, int fileType, OutputStream out) throws IOException {
  1021     public static int write(Sequence in, int fileType, OutputStream out) throws IOException {
  1022 
  1022 
  1023         List providers = getMidiFileWriters();
  1023         List<MidiFileWriter> providers = getMidiFileWriters();
  1024         //$$fb 2002-04-17: Fix for 4635287: Standard MidiFileWriter cannot write empty Sequences
  1024         //$$fb 2002-04-17: Fix for 4635287: Standard MidiFileWriter cannot write empty Sequences
  1025         int bytesWritten = -2;
  1025         int bytesWritten = -2;
  1026 
  1026 
  1027         for (int i = 0; i < providers.size(); i++ ) {
  1027         for (int i = 0; i < providers.size(); i++ ) {
  1028             MidiFileWriter writer = (MidiFileWriter) providers.get(i);
  1028             MidiFileWriter writer = providers.get(i);
  1029             if( writer.isFileTypeSupported( fileType, in ) ) {
  1029             if( writer.isFileTypeSupported( fileType, in ) ) {
  1030 
  1030 
  1031                 bytesWritten = writer.write(in, fileType, out);
  1031                 bytesWritten = writer.write(in, fileType, out);
  1032                 break;
  1032                 break;
  1033             }
  1033             }
  1052      * @see #isFileTypeSupported(int, Sequence)
  1052      * @see #isFileTypeSupported(int, Sequence)
  1053      * @see     #getMidiFileTypes(Sequence)
  1053      * @see     #getMidiFileTypes(Sequence)
  1054      */
  1054      */
  1055     public static int write(Sequence in, int type, File out) throws IOException {
  1055     public static int write(Sequence in, int type, File out) throws IOException {
  1056 
  1056 
  1057         List providers = getMidiFileWriters();
  1057         List<MidiFileWriter> providers = getMidiFileWriters();
  1058         //$$fb 2002-04-17: Fix for 4635287: Standard MidiFileWriter cannot write empty Sequences
  1058         //$$fb 2002-04-17: Fix for 4635287: Standard MidiFileWriter cannot write empty Sequences
  1059         int bytesWritten = -2;
  1059         int bytesWritten = -2;
  1060 
  1060 
  1061         for (int i = 0; i < providers.size(); i++ ) {
  1061         for (int i = 0; i < providers.size(); i++ ) {
  1062             MidiFileWriter writer = (MidiFileWriter) providers.get(i);
  1062             MidiFileWriter writer = providers.get(i);
  1063             if( writer.isFileTypeSupported( type, in ) ) {
  1063             if( writer.isFileTypeSupported( type, in ) ) {
  1064 
  1064 
  1065                 bytesWritten = writer.write(in, type, out);
  1065                 bytesWritten = writer.write(in, type, out);
  1066                 break;
  1066                 break;
  1067             }
  1067             }
  1073     }
  1073     }
  1074 
  1074 
  1075 
  1075 
  1076 
  1076 
  1077     // HELPER METHODS
  1077     // HELPER METHODS
  1078 
  1078     @SuppressWarnings("unchecked")
  1079     private static List getMidiDeviceProviders() {
  1079     private static List<MidiDeviceProvider> getMidiDeviceProviders() {
  1080         return getProviders(MidiDeviceProvider.class);
  1080         return (List<MidiDeviceProvider>) getProviders(MidiDeviceProvider.class);
  1081     }
  1081     }
  1082 
  1082 
  1083 
  1083     @SuppressWarnings("unchecked")
  1084     private static List getSoundbankReaders() {
  1084     private static List<SoundbankReader> getSoundbankReaders() {
  1085         return getProviders(SoundbankReader.class);
  1085         return (List<SoundbankReader>) getProviders(SoundbankReader.class);
  1086     }
  1086     }
  1087 
  1087 
  1088 
  1088     @SuppressWarnings("unchecked")
  1089     private static List getMidiFileWriters() {
  1089     private static List<MidiFileWriter> getMidiFileWriters() {
  1090         return getProviders(MidiFileWriter.class);
  1090         return (List<MidiFileWriter>) getProviders(MidiFileWriter.class);
  1091     }
  1091     }
  1092 
  1092 
  1093 
  1093     @SuppressWarnings("unchecked")
  1094     private static List getMidiFileReaders() {
  1094     private static List<MidiFileReader> getMidiFileReaders() {
  1095         return getProviders(MidiFileReader.class);
  1095         return (List<MidiFileReader>) getProviders(MidiFileReader.class);
  1096     }
  1096     }
  1097 
  1097 
  1098 
  1098 
  1099     /** Attempts to locate and return a default MidiDevice of the specified
  1099     /** Attempts to locate and return a default MidiDevice of the specified
  1100      * type.
  1100      * type.
  1107      *
  1107      *
  1108      * @param deviceClass The requested device type, one of Synthesizer.class,
  1108      * @param deviceClass The requested device type, one of Synthesizer.class,
  1109      * Sequencer.class, Receiver.class or Transmitter.class.
  1109      * Sequencer.class, Receiver.class or Transmitter.class.
  1110      * @throws  MidiUnavalableException on failure.
  1110      * @throws  MidiUnavalableException on failure.
  1111      */
  1111      */
  1112     private static MidiDevice getDefaultDeviceWrapper(Class deviceClass)
  1112     private static MidiDevice getDefaultDeviceWrapper(Class<?> deviceClass)
  1113         throws MidiUnavailableException{
  1113         throws MidiUnavailableException{
  1114         try {
  1114         try {
  1115             return getDefaultDevice(deviceClass);
  1115             return getDefaultDevice(deviceClass);
  1116         } catch (IllegalArgumentException iae) {
  1116         } catch (IllegalArgumentException iae) {
  1117             MidiUnavailableException mae = new MidiUnavailableException();
  1117             MidiUnavailableException mae = new MidiUnavailableException();
  1126      *
  1126      *
  1127      * @param deviceClass The requested device type, one of Synthesizer.class,
  1127      * @param deviceClass The requested device type, one of Synthesizer.class,
  1128      * Sequencer.class, Receiver.class or Transmitter.class.
  1128      * Sequencer.class, Receiver.class or Transmitter.class.
  1129      * @throws  IllegalArgumentException on failure.
  1129      * @throws  IllegalArgumentException on failure.
  1130      */
  1130      */
  1131     private static MidiDevice getDefaultDevice(Class deviceClass) {
  1131     private static MidiDevice getDefaultDevice(Class<?> deviceClass) {
  1132         List providers = getMidiDeviceProviders();
  1132         List<MidiDeviceProvider> providers = getMidiDeviceProviders();
  1133         String providerClassName = JDK13Services.getDefaultProviderClassName(deviceClass);
  1133         String providerClassName = JDK13Services.getDefaultProviderClassName(deviceClass);
  1134         String instanceName = JDK13Services.getDefaultInstanceName(deviceClass);
  1134         String instanceName = JDK13Services.getDefaultInstanceName(deviceClass);
  1135         MidiDevice device;
  1135         MidiDevice device;
  1136 
  1136 
  1137         if (providerClassName != null) {
  1137         if (providerClassName != null) {
  1177         @param providerClassName The class name of the provider to be returned.
  1177         @param providerClassName The class name of the provider to be returned.
  1178         @param provider The list of MidiDeviceProviders that is searched.
  1178         @param provider The list of MidiDeviceProviders that is searched.
  1179         @return A MidiDeviceProvider of the requested class, or null if none
  1179         @return A MidiDeviceProvider of the requested class, or null if none
  1180         is found.
  1180         is found.
  1181     */
  1181     */
  1182     private static MidiDeviceProvider getNamedProvider(String providerClassName, List providers) {
  1182     private static MidiDeviceProvider getNamedProvider(String providerClassName,
       
  1183                                                        List<MidiDeviceProvider> providers) {
  1183         for(int i = 0; i < providers.size(); i++) {
  1184         for(int i = 0; i < providers.size(); i++) {
  1184             MidiDeviceProvider provider = (MidiDeviceProvider) providers.get(i);
  1185             MidiDeviceProvider provider = providers.get(i);
  1185             if (provider.getClass().getName().equals(providerClassName)) {
  1186             if (provider.getClass().getName().equals(providerClassName)) {
  1186                 return provider;
  1187                 return provider;
  1187             }
  1188             }
  1188         }
  1189         }
  1189         return null;
  1190         return null;
  1198 
  1199 
  1199         @return A MidiDevice matching the requirements, or null if none is found.
  1200         @return A MidiDevice matching the requirements, or null if none is found.
  1200     */
  1201     */
  1201     private static MidiDevice getNamedDevice(String deviceName,
  1202     private static MidiDevice getNamedDevice(String deviceName,
  1202                                              MidiDeviceProvider provider,
  1203                                              MidiDeviceProvider provider,
  1203                                              Class deviceClass) {
  1204                                              Class<?> deviceClass) {
  1204         MidiDevice device;
  1205         MidiDevice device;
  1205         // try to get MIDI port
  1206         // try to get MIDI port
  1206         device = getNamedDevice(deviceName, provider, deviceClass,
  1207         device = getNamedDevice(deviceName, provider, deviceClass,
  1207                                  false, false);
  1208                                  false, false);
  1208         if (device != null) {
  1209         if (device != null) {
  1230 
  1231 
  1231       @return A MidiDevice matching the requirements, or null if none is found.
  1232       @return A MidiDevice matching the requirements, or null if none is found.
  1232      */
  1233      */
  1233     private static MidiDevice getNamedDevice(String deviceName,
  1234     private static MidiDevice getNamedDevice(String deviceName,
  1234                                              MidiDeviceProvider provider,
  1235                                              MidiDeviceProvider provider,
  1235                                              Class deviceClass,
  1236                                              Class<?> deviceClass,
  1236                                              boolean allowSynthesizer,
  1237                                              boolean allowSynthesizer,
  1237                                              boolean allowSequencer) {
  1238                                              boolean allowSequencer) {
  1238         MidiDevice.Info[] infos = provider.getDeviceInfo();
  1239         MidiDevice.Info[] infos = provider.getDeviceInfo();
  1239         for (int i = 0; i < infos.length; i++) {
  1240         for (int i = 0; i < infos.length; i++) {
  1240             if (infos[i].getName().equals(deviceName)) {
  1241             if (infos[i].getName().equals(deviceName)) {
  1257         @param deviceClass The requested device type, one of Synthesizer.class,
  1258         @param deviceClass The requested device type, one of Synthesizer.class,
  1258         Sequencer.class, Receiver.class or Transmitter.class.
  1259         Sequencer.class, Receiver.class or Transmitter.class.
  1259         @return A Mixer matching the requirements, or null if none is found.
  1260         @return A Mixer matching the requirements, or null if none is found.
  1260     */
  1261     */
  1261     private static MidiDevice getNamedDevice(String deviceName,
  1262     private static MidiDevice getNamedDevice(String deviceName,
  1262                                              List providers,
  1263                                              List<MidiDeviceProvider> providers,
  1263                                              Class deviceClass) {
  1264                                              Class<?> deviceClass) {
  1264         MidiDevice device;
  1265         MidiDevice device;
  1265         // try to get MIDI port
  1266         // try to get MIDI port
  1266         device = getNamedDevice(deviceName, providers, deviceClass,
  1267         device = getNamedDevice(deviceName, providers, deviceClass,
  1267                                  false, false);
  1268                                  false, false);
  1268         if (device != null) {
  1269         if (device != null) {
  1290         @param deviceClass The requested device type, one of Synthesizer.class,
  1291         @param deviceClass The requested device type, one of Synthesizer.class,
  1291         Sequencer.class, Receiver.class or Transmitter.class.
  1292         Sequencer.class, Receiver.class or Transmitter.class.
  1292         @return A Mixer matching the requirements, or null if none is found.
  1293         @return A Mixer matching the requirements, or null if none is found.
  1293      */
  1294      */
  1294     private static MidiDevice getNamedDevice(String deviceName,
  1295     private static MidiDevice getNamedDevice(String deviceName,
  1295                                              List providers,
  1296                                              List<MidiDeviceProvider> providers,
  1296                                              Class deviceClass,
  1297                                              Class<?> deviceClass,
  1297                                              boolean allowSynthesizer,
  1298                                              boolean allowSynthesizer,
  1298                                              boolean allowSequencer) {
  1299                                              boolean allowSequencer) {
  1299         for(int i = 0; i < providers.size(); i++) {
  1300         for(int i = 0; i < providers.size(); i++) {
  1300             MidiDeviceProvider provider = (MidiDeviceProvider) providers.get(i);
  1301             MidiDeviceProvider provider = providers.get(i);
  1301             MidiDevice device = getNamedDevice(deviceName, provider,
  1302             MidiDevice device = getNamedDevice(deviceName, provider,
  1302                                                deviceClass,
  1303                                                deviceClass,
  1303                                                allowSynthesizer,
  1304                                                allowSynthesizer,
  1304                                                allowSequencer);
  1305                                                allowSequencer);
  1305             if (device != null) {
  1306             if (device != null) {
  1316         Sequencer.class, Receiver.class or Transmitter.class.
  1317         Sequencer.class, Receiver.class or Transmitter.class.
  1317         @return A MidiDevice is considered appropriate, or null if no
  1318         @return A MidiDevice is considered appropriate, or null if no
  1318         appropriate device is found.
  1319         appropriate device is found.
  1319     */
  1320     */
  1320     private static MidiDevice getFirstDevice(MidiDeviceProvider provider,
  1321     private static MidiDevice getFirstDevice(MidiDeviceProvider provider,
  1321                                              Class deviceClass) {
  1322                                              Class<?> deviceClass) {
  1322         MidiDevice device;
  1323         MidiDevice device;
  1323         // try to get MIDI port
  1324         // try to get MIDI port
  1324         device = getFirstDevice(provider, deviceClass,
  1325         device = getFirstDevice(provider, deviceClass,
  1325                                 false, false);
  1326                                 false, false);
  1326         if (device != null) {
  1327         if (device != null) {
  1346         Sequencer.class, Receiver.class or Transmitter.class.
  1347         Sequencer.class, Receiver.class or Transmitter.class.
  1347         @return A MidiDevice is considered appropriate, or null if no
  1348         @return A MidiDevice is considered appropriate, or null if no
  1348         appropriate device is found.
  1349         appropriate device is found.
  1349      */
  1350      */
  1350     private static MidiDevice getFirstDevice(MidiDeviceProvider provider,
  1351     private static MidiDevice getFirstDevice(MidiDeviceProvider provider,
  1351                                              Class deviceClass,
  1352                                              Class<?> deviceClass,
  1352                                              boolean allowSynthesizer,
  1353                                              boolean allowSynthesizer,
  1353                                              boolean allowSequencer) {
  1354                                              boolean allowSequencer) {
  1354         MidiDevice.Info[] infos = provider.getDeviceInfo();
  1355         MidiDevice.Info[] infos = provider.getDeviceInfo();
  1355         for (int j = 0; j < infos.length; j++) {
  1356         for (int j = 0; j < infos.length; j++) {
  1356             MidiDevice device = provider.getDevice(infos[j]);
  1357             MidiDevice device = provider.getDevice(infos[j]);
  1369         @param deviceClass The requested device type, one of Synthesizer.class,
  1370         @param deviceClass The requested device type, one of Synthesizer.class,
  1370         Sequencer.class, Receiver.class or Transmitter.class.
  1371         Sequencer.class, Receiver.class or Transmitter.class.
  1371         @return A MidiDevice that is considered appropriate, or null
  1372         @return A MidiDevice that is considered appropriate, or null
  1372         if none is found.
  1373         if none is found.
  1373     */
  1374     */
  1374     private static MidiDevice getFirstDevice(List providers,
  1375     private static MidiDevice getFirstDevice(List<MidiDeviceProvider> providers,
  1375                                              Class deviceClass) {
  1376                                              Class<?> deviceClass) {
  1376         MidiDevice device;
  1377         MidiDevice device;
  1377         // try to get MIDI port
  1378         // try to get MIDI port
  1378         device = getFirstDevice(providers, deviceClass,
  1379         device = getFirstDevice(providers, deviceClass,
  1379                                 false, false);
  1380                                 false, false);
  1380         if (device != null) {
  1381         if (device != null) {
  1400         @param deviceClass The requested device type, one of Synthesizer.class,
  1401         @param deviceClass The requested device type, one of Synthesizer.class,
  1401         Sequencer.class, Receiver.class or Transmitter.class.
  1402         Sequencer.class, Receiver.class or Transmitter.class.
  1402         @return A MidiDevice that is considered appropriate, or null
  1403         @return A MidiDevice that is considered appropriate, or null
  1403         if none is found.
  1404         if none is found.
  1404      */
  1405      */
  1405     private static MidiDevice getFirstDevice(List providers,
  1406     private static MidiDevice getFirstDevice(List<MidiDeviceProvider> providers,
  1406                                              Class deviceClass,
  1407                                              Class<?> deviceClass,
  1407                                              boolean allowSynthesizer,
  1408                                              boolean allowSynthesizer,
  1408                                              boolean allowSequencer) {
  1409                                              boolean allowSequencer) {
  1409         for(int i = 0; i < providers.size(); i++) {
  1410         for(int i = 0; i < providers.size(); i++) {
  1410             MidiDeviceProvider provider = (MidiDeviceProvider) providers.get(i);
  1411             MidiDeviceProvider provider = providers.get(i);
  1411             MidiDevice device = getFirstDevice(provider, deviceClass,
  1412             MidiDevice device = getFirstDevice(provider, deviceClass,
  1412                                                allowSynthesizer,
  1413                                                allowSynthesizer,
  1413                                                allowSequencer);
  1414                                                allowSequencer);
  1414             if (device != null) {
  1415             if (device != null) {
  1415                 return device;
  1416                 return device;
  1439         classes (Sequencer and Synthesizer), this flag has no effect.
  1440         classes (Sequencer and Synthesizer), this flag has no effect.
  1440         @return true if the device is considered appropriate according to the
  1441         @return true if the device is considered appropriate according to the
  1441         rules given above, false otherwise.
  1442         rules given above, false otherwise.
  1442     */
  1443     */
  1443     private static boolean isAppropriateDevice(MidiDevice device,
  1444     private static boolean isAppropriateDevice(MidiDevice device,
  1444                                                Class deviceClass,
  1445                                                Class<?> deviceClass,
  1445                                                boolean allowSynthesizer,
  1446                                                boolean allowSynthesizer,
  1446                                                boolean allowSequencer) {
  1447                                                boolean allowSequencer) {
  1447         if (deviceClass.isInstance(device)) {
  1448         if (deviceClass.isInstance(device)) {
  1448             // This clause is for deviceClass being either Synthesizer
  1449            // This clause is for deviceClass being either Synthesizer
  1449             // or Sequencer.
  1450             // or Sequencer.
  1450             return true;
  1451             return true;
  1451         } else {
  1452         } else {
  1452             // Now the case that deviceClass is Transmitter or
  1453             // Now the case that deviceClass is Transmitter or
  1453             // Receiver. If neither allowSynthesizer nor allowSequencer is
  1454             // Receiver. If neither allowSynthesizer nor allowSequencer is
  1477      * Obtains the set of services currently installed on the system
  1478      * Obtains the set of services currently installed on the system
  1478      * using the SPI mechanism in 1.3.
  1479      * using the SPI mechanism in 1.3.
  1479      * @return a List of instances of providers for the requested service.
  1480      * @return a List of instances of providers for the requested service.
  1480      * If no providers are available, a List of length 0 will be returned.
  1481      * If no providers are available, a List of length 0 will be returned.
  1481      */
  1482      */
  1482     private static List getProviders(Class providerClass) {
  1483      private static List<?> getProviders(Class<?> providerClass) {
  1483         return JDK13Services.getProviders(providerClass);
  1484          return JDK13Services.getProviders(providerClass);
  1484     }
  1485     }
  1485 }
  1486 }