Save This Page
Home » openjdk-7 » com.sun.media » sound » [javadoc | source]
    1   /*
    2    * Copyright (c) 1999, 2007, 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    * MIDI output device provider.
   34    *
   35    * @author Kara Kytle
   36    * @author Florian Bomers
   37    */
   38   public class MidiOutDeviceProvider extends AbstractMidiDeviceProvider {
   39   
   40       /** Cache of info objects for all MIDI output devices on the system. */
   41       static Info[] infos = null;
   42   
   43       /** Cache of open MIDI output devices on the system. */
   44       static MidiDevice[] devices = null;
   45   
   46       private static boolean enabled;
   47   
   48       // STATIC
   49   
   50       static {
   51           // initialize
   52           Platform.initialize();
   53           enabled = Platform.isMidiIOEnabled();
   54       }
   55   
   56       // CONSTRUCTOR
   57   
   58       /**
   59        * Required public no-arg constructor.
   60        */
   61       public MidiOutDeviceProvider() {
   62           if (Printer.trace) Printer.trace("MidiOutDeviceProvider: constructor");
   63       }
   64   
   65       // implementation of abstract methods in AbstractMidiDeviceProvider
   66   
   67       AbstractMidiDeviceProvider.Info createInfo(int index) {
   68           if (!enabled) {
   69               return null;
   70           }
   71           return new MidiOutDeviceInfo(index, MidiOutDeviceProvider.class);
   72       }
   73   
   74       MidiDevice createDevice(AbstractMidiDeviceProvider.Info info) {
   75           if (enabled && (info instanceof MidiOutDeviceInfo)) {
   76               return new MidiOutDevice(info);
   77           }
   78           return null;
   79       }
   80   
   81       int getNumDevices() {
   82           if (!enabled) {
   83               if (Printer.debug)Printer.debug("MidiOutDevice not enabled, returning 0 devices");
   84               return 0;
   85           }
   86           return nGetNumDevices();
   87       }
   88   
   89       MidiDevice[] getDeviceCache() { return devices; }
   90       void setDeviceCache(MidiDevice[] devices) { this.devices = devices; }
   91       Info[] getInfoCache() { return infos; }
   92       void setInfoCache(Info[] infos) { this.infos = infos; }
   93   
   94   
   95       // INNER CLASSES
   96   
   97       /**
   98        * Info class for MidiOutDevices.  Adds the
   99        * provider's Class to keep the provider class from being
  100        * unloaded.  Otherwise, at least on JDK1.1.7 and 1.1.8,
  101        * the provider class can be unloaded.  Then, then the provider
  102        * is next invoked, the static block is executed again and a new
  103        * instance of the device object is created.  Even though the
  104        * previous instance may still exist and be open / in use / etc.,
  105        * the new instance will not reflect that state...
  106        */
  107       static class MidiOutDeviceInfo extends AbstractMidiDeviceProvider.Info {
  108           private Class providerClass;
  109   
  110           private MidiOutDeviceInfo(int index, Class providerClass) {
  111               super(nGetName(index), nGetVendor(index), nGetDescription(index), nGetVersion(index), index);
  112               this.providerClass = providerClass;
  113           }
  114   
  115       } // class MidiOutDeviceInfo
  116   
  117   
  118       // NATIVE METHODS
  119   
  120       private static native int nGetNumDevices();
  121       private static native String nGetName(int index);
  122       private static native String nGetVendor(int index);
  123       private static native String nGetDescription(int index);
  124       private static native String nGetVersion(int index);
  125   }

Save This Page
Home » openjdk-7 » com.sun.media » sound » [javadoc | source]