< prev index next >

src/java.desktop/share/classes/com/sun/media/sound/AbstractMidiDeviceProvider.java

Print this page


   1 /*
   2  * Copyright (c) 2002, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.media.sound;
  27 


  28 import javax.sound.midi.MidiDevice;
  29 import javax.sound.midi.spi.MidiDeviceProvider;
  30 
  31 
  32 /**
  33  * Super class for MIDI input or output device provider.
  34  *
  35  * @author Florian Bomers
  36  */
  37 public abstract class AbstractMidiDeviceProvider extends MidiDeviceProvider {
  38 
  39     private static final boolean enabled;
  40 
  41     /**
  42      * Create objects representing all MIDI output devices on the system.
  43      */
  44     static {
  45         if (Printer.trace) Printer.trace("AbstractMidiDeviceProvider: static");
  46         Platform.initialize();
  47         enabled = Platform.isMidiIOEnabled();
  48         if (Printer.trace) Printer.trace("AbstractMidiDeviceProvider: enabled: " + enabled);
  49 
  50         // $$fb number of MIDI devices may change with time
  51         // also for memory's sake, do not initialize the arrays here


 110                     // what to do with the MidiDevice instances that are left
 111                     // in the devices array ?? Close them ?
 112                 }
 113             }
 114             // commit new list of infos.
 115             setInfoCache(newInfos);
 116             setDeviceCache(newDevices);
 117         }
 118     }
 119 
 120     @Override
 121     public final MidiDevice.Info[] getDeviceInfo() {
 122         readDeviceInfos();
 123         Info[] infos = getInfoCache();
 124         MidiDevice.Info[] localArray = new MidiDevice.Info[infos.length];
 125         System.arraycopy(infos, 0, localArray, 0, infos.length);
 126         return localArray;
 127     }
 128 
 129     @Override
 130     public final MidiDevice getDevice(MidiDevice.Info info) {

 131         if (info instanceof Info) {
 132             readDeviceInfos();
 133             MidiDevice[] devices = getDeviceCache();
 134             Info[] infos = getInfoCache();
 135             Info thisInfo = (Info) info;
 136             int index = thisInfo.getIndex();
 137             if (index >= 0 && index < devices.length && infos[index] == info) {
 138                 if (devices[index] == null) {
 139                     devices[index] = createDevice(thisInfo);
 140                 }
 141                 if (devices[index] != null) {
 142                     return devices[index];
 143                 }
 144             }
 145         }
 146         throw MidiUtils.unsupportedDevice(info);
 147     }
 148 
 149 
 150     // INNER CLASSES


   1 /*
   2  * Copyright (c) 2002, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.media.sound;
  27 
  28 import java.util.Objects;
  29 
  30 import javax.sound.midi.MidiDevice;
  31 import javax.sound.midi.spi.MidiDeviceProvider;
  32 

  33 /**
  34  * Super class for MIDI input or output device provider.
  35  *
  36  * @author Florian Bomers
  37  */
  38 public abstract class AbstractMidiDeviceProvider extends MidiDeviceProvider {
  39 
  40     private static final boolean enabled;
  41 
  42     /**
  43      * Create objects representing all MIDI output devices on the system.
  44      */
  45     static {
  46         if (Printer.trace) Printer.trace("AbstractMidiDeviceProvider: static");
  47         Platform.initialize();
  48         enabled = Platform.isMidiIOEnabled();
  49         if (Printer.trace) Printer.trace("AbstractMidiDeviceProvider: enabled: " + enabled);
  50 
  51         // $$fb number of MIDI devices may change with time
  52         // also for memory's sake, do not initialize the arrays here


 111                     // what to do with the MidiDevice instances that are left
 112                     // in the devices array ?? Close them ?
 113                 }
 114             }
 115             // commit new list of infos.
 116             setInfoCache(newInfos);
 117             setDeviceCache(newDevices);
 118         }
 119     }
 120 
 121     @Override
 122     public final MidiDevice.Info[] getDeviceInfo() {
 123         readDeviceInfos();
 124         Info[] infos = getInfoCache();
 125         MidiDevice.Info[] localArray = new MidiDevice.Info[infos.length];
 126         System.arraycopy(infos, 0, localArray, 0, infos.length);
 127         return localArray;
 128     }
 129 
 130     @Override
 131     public final MidiDevice getDevice(final MidiDevice.Info info) {
 132         Objects.requireNonNull(info);
 133         if (info instanceof Info) {
 134             readDeviceInfos();
 135             MidiDevice[] devices = getDeviceCache();
 136             Info[] infos = getInfoCache();
 137             Info thisInfo = (Info) info;
 138             int index = thisInfo.getIndex();
 139             if (index >= 0 && index < devices.length && infos[index] == info) {
 140                 if (devices[index] == null) {
 141                     devices[index] = createDevice(thisInfo);
 142                 }
 143                 if (devices[index] != null) {
 144                     return devices[index];
 145                 }
 146             }
 147         }
 148         throw MidiUtils.unsupportedDevice(info);
 149     }
 150 
 151 
 152     // INNER CLASSES


< prev index next >