classpath-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[cp-patches] Patch: javax.sound.midi missing methods


From: Anthony Green
Subject: [cp-patches] Patch: javax.sound.midi missing methods
Date: Tue, 27 Sep 2005 20:43:25 -0700

japi pointed out some missing methods and typos.  I'm checking in this
fix.

Thanks, 

AG



2005-09-27  Anthony Green  <address@hidden>

        * javax/sound/midi/MidiSystem.java (getSequence): Add
        missing methods.
        * javax/sound/midi/Sequencer.java (stopRecording): Ditto.
        * javax/sound/midi/ShortMessage.java (ShortMessage): Ditto.
        (setMessage): Fix visibility.  Add missing implementations.
        * javax/sound/midi/ShoundbankResouce.java: Rename "soundBank" to
        "soundbank", and "getSoundBank" to "getSoundbank".
        

Index: javax/sound/midi/MidiSystem.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/sound/midi/MidiSystem.java,v
retrieving revision 1.2
diff -u -r1.2 MidiSystem.java
--- javax/sound/midi/MidiSystem.java    26 Sep 2005 17:24:00 -0000      1.2
+++ javax/sound/midi/MidiSystem.java    28 Sep 2005 03:36:31 -0000
@@ -331,9 +331,75 @@
         return sb;
     }
     throw new InvalidMidiDataException("Can't read MidiFileFormat from file " 
-                                      + file);
+                                       + file);
   } 
   
+  /**
+   * Read a Sequence object from the given stream.
+   * 
+   * @param stream the stream from which to read the Sequence
+   * @return the Sequence object
+   * @throws InvalidMidiDataException if we were unable to read the Sequence
+   * @throws IOException if an I/O error happened while reading
+   */
+  public static Sequence getSequence(InputStream stream)
+    throws InvalidMidiDataException, IOException
+  {
+    Iterator readers = ServiceFactory.lookupProviders(MidiFileReader.class);
+    while (readers.hasNext())
+    {
+      MidiFileReader sr = (MidiFileReader) readers.next();
+      Sequence sq = sr.getSequence(stream);
+      if (sq != null)
+        return sq;
+    }
+    throw new InvalidMidiDataException("Can't read Sequence from stream");
+  }
+
+  /**
+   * Read a Sequence object from the given url.
+   * 
+   * @param url the url from which to read the Sequence
+   * @return the Sequence object
+   * @throws InvalidMidiDataException if we were unable to read the Sequence
+   * @throws IOException if an I/O error happened while reading
+   */
+  public static Sequence getSequence(URL url)
+    throws InvalidMidiDataException, IOException
+  {
+    Iterator readers = ServiceFactory.lookupProviders(MidiFileReader.class);
+    while (readers.hasNext())
+    {
+      MidiFileReader sr = (MidiFileReader) readers.next();
+      Sequence sq = sr.getSequence(url);
+      if (sq != null)
+        return sq;
+    }
+    throw new InvalidMidiDataException("Cannot read from url " + url);
+  }
+
+  /**
+   * Read a Sequence object from the given file.
+   * 
+   * @param file the file from which to read the Sequence
+   * @return the Sequence object
+   * @throws InvalidMidiDataException if we were unable to read the Sequence
+   * @throws IOException if an I/O error happened while reading
+   */
+  public static Sequence getSequence(File file)
+    throws InvalidMidiDataException, IOException
+  {
+    Iterator readers = ServiceFactory.lookupProviders(MidiFileReader.class);
+    while (readers.hasNext())
+    {
+      MidiFileReader sr = (MidiFileReader) readers.next();
+      Sequence sq = sr.getSequence(file);
+      if (sq != null)
+        return sq;
+    }
+    throw new InvalidMidiDataException("Can't read Sequence from file " 
+                                       + file);
+  } 
   
   /**
    * Return an array of supported MIDI file types on this system.
Index: javax/sound/midi/Sequencer.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/sound/midi/Sequencer.java,v
retrieving revision 1.2
diff -u -r1.2 Sequencer.java
--- javax/sound/midi/Sequencer.java     26 Sep 2005 17:24:00 -0000      1.2
+++ javax/sound/midi/Sequencer.java     28 Sep 2005 03:36:31 -0000
@@ -103,6 +103,11 @@
   public void startRecording();
   
   /**
+   * Stop recording, although continue playing.
+   */
+  public void stopRecording();
+  
+  /**
    * Returns true if sequence is recording.
    * 
    * @return true if the sequence is recording and false otherwise
Index: javax/sound/midi/ShortMessage.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/sound/midi/ShortMessage.java,v
retrieving revision 1.2
diff -u -r1.2 ShortMessage.java
--- javax/sound/midi/ShortMessage.java  26 Sep 2005 17:24:00 -0000      1.2
+++ javax/sound/midi/ShortMessage.java  28 Sep 2005 03:36:31 -0000
@@ -142,6 +142,26 @@
    */
   public static final int PITCH_BEND = 0xE0; 
 
+  // Create and initialize a default, arbitrary message.
+  private static byte[] defaultMessage;
+  static
+  {
+    defaultMessage = new byte[1];
+    defaultMessage[0] = (byte) STOP;
+  }
+  
+  /**
+   * Create a short MIDI message.
+   * 
+   * The spec requires that this represent a valid MIDI message, but doesn't
+   * specify what it should be.  We've chosen the STOP message for our
+   * implementation.
+   */
+  public ShortMessage()
+  {
+    this(defaultMessage);   
+  }
+  
   /**
    * Create a short MIDI message.
    * 
@@ -163,7 +183,7 @@
    * @param data2 the second data byte for this message
    * @throws InvalidMidiDataException if status is bad, or data is out of range
    */
-  private void setMessage(int status, int data1, int data2)
+  public void setMessage(int status, int data1, int data2)
     throws InvalidMidiDataException
   {
     length = getDataLength(status);
@@ -185,6 +205,14 @@
         data[2] = (byte) data2;
       }
     }
+  }
+  
+  public void setMessage(int command, int channel, int data1, int data2)
+    throws InvalidMidiDataException
+  {
+    // TODO: This could probably stand some error checking.
+    // It currently assumes command and channel are valid values.
+    setMessage(command + channel, data1, data2);
   }
   
   /**
Index: javax/sound/midi/SoundbankResource.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/sound/midi/SoundbankResource.java,v
retrieving revision 1.1
diff -u -r1.1 SoundbankResource.java
--- javax/sound/midi/SoundbankResource.java     26 Sep 2005 16:35:00 -0000      
1.1
+++ javax/sound/midi/SoundbankResource.java     28 Sep 2005 03:36:31 -0000
@@ -47,20 +47,20 @@
  */
 public abstract class SoundbankResource
 {
-  private final Soundbank soundBank;
+  private final Soundbank soundbank;
   private final String name;
   private final Class dataClass;
   
   /**
    * Create a SoundbankResource object.
    * 
-   * @param soundBank the soundbank object containing this resource
+   * @param soundbank the soundbank object containing this resource
    * @param name the name of the resource
    * @param dataClass the class used to represent the audio data
    */
-  protected SoundbankResource(Soundbank soundBank, String name, Class 
dataClass)
+  protected SoundbankResource(Soundbank soundbank, String name, Class 
dataClass)
   {
-    this.soundBank = soundBank;   
+    this.soundbank = soundbank;   
     this.name = name;
     this.dataClass = dataClass;
   }
@@ -70,9 +70,9 @@
    * 
    * @return the sound bank in which this resource resides
    */
-  public Soundbank getSoundBank()
+  public Soundbank getSoundbank()
   {
-    return soundBank;
+    return soundbank;
   }
   
   /**








reply via email to

[Prev in Thread] Current Thread [Next in Thread]