Save This Page
Home » openjdk-7 » javax.sound » midi » spi » [javadoc | source]
    1   /*
    2    * Copyright 1999-2002 Sun Microsystems, Inc.  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.  Sun designates this
    8    * particular file as subject to the "Classpath" exception as provided
    9    * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
   22    * CA 95054 USA or visit www.sun.com if you need additional information or
   23    * have any questions.
   24    */
   25   
   26   package javax.sound.midi.spi;
   27   
   28   import java.io.File;
   29   import java.io.IOException;
   30   import java.io.OutputStream;
   31   
   32   import javax.sound.midi.Sequence;
   33   import javax.sound.midi.MidiFileFormat;
   34   
   35   /**
   36    * A <code>MidiFileWriter</code> supplies MIDI file-writing services.  Classes
   37    * that implement this interface can write one or more types of MIDI file from
   38    * a <code>{@link Sequence}</code> object.
   39    *
   40    * @author Kara Kytle
   41    * @since 1.3
   42    */
   43   public abstract class MidiFileWriter {
   44   
   45   
   46       /**
   47        * Obtains the set of MIDI file types for which file writing support is
   48        * provided by this file writer.
   49        * @return array of file types.  If no file types are supported,
   50        * an array of length 0 is returned.
   51        */
   52       public abstract int[] getMidiFileTypes();
   53   
   54   
   55       /**
   56        * Obtains the file types that this file writer can write from the
   57        * sequence specified.
   58        * @param sequence the sequence for which MIDI file type support
   59        * is queried
   60        * @return array of file types.  If no file types are supported,
   61        * returns an array of length 0.
   62        */
   63       public abstract int[] getMidiFileTypes(Sequence sequence);
   64   
   65   
   66       /**
   67        * Indicates whether file writing support for the specified MIDI file type
   68        * is provided by this file writer.
   69        * @param fileType the file type for which write capabilities are queried
   70        * @return <code>true</code> if the file type is supported,
   71        * otherwise <code>false</code>
   72        */
   73       public boolean isFileTypeSupported(int fileType) {
   74   
   75           int types[] = getMidiFileTypes();
   76           for(int i=0; i<types.length; i++) {
   77               if( fileType == types[i] ) {
   78                   return true;
   79               }
   80           }
   81           return false;
   82       }
   83   
   84   
   85       /**
   86        * Indicates whether a MIDI file of the file type specified can be written
   87        * from the sequence indicated.
   88        * @param fileType the file type for which write capabilities are queried
   89        * @param sequence  the sequence for which file writing support is queried
   90        * @return <code>true</code> if the file type is supported for this sequence,
   91        * otherwise <code>false</code>
   92        */
   93       public boolean isFileTypeSupported(int fileType, Sequence sequence) {
   94   
   95           int types[] = getMidiFileTypes( sequence );
   96           for(int i=0; i<types.length; i++) {
   97               if( fileType == types[i] ) {
   98                   return true;
   99               }
  100           }
  101           return false;
  102       }
  103   
  104   
  105       /**
  106        * Writes a stream of bytes representing a MIDI file of the file type
  107        * indicated to the output stream provided.
  108        * @param in sequence containing MIDI data to be written to the file
  109        * @param fileType type of the file to be written to the output stream
  110        * @param out stream to which the file data should be written
  111        * @return the number of bytes written to the output stream
  112        * @throws IOException if an I/O exception occurs
  113        * @throws IllegalArgumentException if the file type is not supported by
  114        * this file writer
  115        * @see #isFileTypeSupported(int, Sequence)
  116        * @see     #getMidiFileTypes(Sequence)
  117        */
  118       public abstract int write(Sequence in, int fileType, OutputStream out) throws IOException;
  119   
  120   
  121       /**
  122        * Writes a stream of bytes representing a MIDI file of the file type
  123        * indicated to the external file provided.
  124        * @param in sequence containing MIDI data to be written to the external file
  125        * @param fileType type of the file to be written to the external file
  126        * @param out external file to which the file data should be written
  127        * @return the number of bytes written to the file
  128        * @throws IOException if an I/O exception occurs
  129        * @throws IllegalArgumentException if the file type is not supported by
  130        * this file writer
  131        * @see #isFileTypeSupported(int, Sequence)
  132        * @see     #getMidiFileTypes(Sequence)
  133        */
  134       public abstract int write(Sequence in, int fileType, File out) throws IOException;
  135   }

Save This Page
Home » openjdk-7 » javax.sound » midi » spi » [javadoc | source]