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

2005-09-27 Thread Anthony Green
japi pointed out some missing methods and typos.  I'm checking in this
fix.

Thanks, 

AG



2005-09-27  Anthony Green  <[EMAIL PROTECTED]>

* 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.java26 Sep 2005 17:24:00 -  1.2
+++ javax/sound/midi/MidiSystem.java28 Sep 2005 03:36:31 -
@@ -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 -  1.2
+++ javax/sound/midi/Sequencer.java 28 Sep 2005 03:36:31 -
@@ -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 -  1.2
+++ javax/sound/midi/ShortMessage.java  28 Sep 2005 03:36:31 -
@@ -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 th

Re: [cp-patches] Patch: javax.sound.midi

2005-09-26 Thread Anthony Green
On Mon, 2005-09-26 at 09:48 -0600, Tom Tromey wrote:
> There are one or two places where the code goes past column 79.
> (I'm not super concerned about this.  I think we need a reformatting
> flag day anyway.)

I've cleaned most of these up in the attached patch.  This patch also
removes the declaration of some unchecked IllegalArgumentException
throws, as per the hacking guide.  I'm checking it in.

AG

2005-09-26  Anthony Green  <[EMAIL PROTECTED]>

* javax/sound/midi/Synthesizer.java (loadInstrument,
unloadInstrument, remapInstrument, loadAllInstruments,
unloadAllInstruments, unloadInstrument, loadInstrument): Don't
declare the unchecked IllegalArgumentException.
* javax/sound/midi/MidiSystem.java (getMidiDevice, write): Ditto.

* javax/sound/midi/ShortMessage.java: Fix 80-column formatting
problem.
* javax/sound/midi/Sequence.java: Ditto.
* javax/sound/midi/MidiMessage.java: Ditto.
* javax/sound/midi/MidiSystem.java: Ditto.
* javax/sound/midi/MidiFileFormat.java: Ditto.

Index: javax/sound//midi/MidiFileFormat.java
===
RCS file: /cvsroot/classpath/classpath/javax/sound/midi/MidiFileFormat.java,v
retrieving revision 1.1
diff -u -r1.1 MidiFileFormat.java
--- javax/sound//midi/MidiFileFormat.java   26 Sep 2005 16:35:00 -  
1.1
+++ javax/sound//midi/MidiFileFormat.java   26 Sep 2005 17:20:29 -
@@ -95,7 +95,8 @@
* @param bytes the MIDI file size in bytes
* @param microseconds the MIDI file length in microseconds
*/
-  public MidiFileFormat(int type, float divisionType, int resolution, int 
bytes, long microseconds)
+  public MidiFileFormat(int type, float divisionType, 
+   int resolution, int bytes, long microseconds)
   {
 this.type = type;
 this.divisionType = divisionType;
Index: javax/sound//midi/MidiMessage.java
===
RCS file: /cvsroot/classpath/classpath/javax/sound/midi/MidiMessage.java,v
retrieving revision 1.1
diff -u -r1.1 MidiMessage.java
--- javax/sound//midi/MidiMessage.java  26 Sep 2005 16:35:00 -  1.1
+++ javax/sound//midi/MidiMessage.java  26 Sep 2005 17:20:29 -
@@ -75,7 +75,8 @@
* @param length The length of the MIDI message.
* @throws InvalidMidiDataException Thrown when the MIDI message is invalid.
*/
-  protected void setMessage(byte[] data, int length) throws 
InvalidMidiDataException
+  protected void setMessage(byte[] data, int length) 
+throws InvalidMidiDataException
   {
 this.data = new byte[length];
 System.arraycopy(data, 0, this.data, 0, length);
Index: javax/sound//midi/MidiSystem.java
===
RCS file: /cvsroot/classpath/classpath/javax/sound/midi/MidiSystem.java,v
retrieving revision 1.1
diff -u -r1.1 MidiSystem.java
--- javax/sound//midi/MidiSystem.java   26 Sep 2005 16:35:00 -  1.1
+++ javax/sound//midi/MidiSystem.java   26 Sep 2005 17:20:29 -
@@ -71,7 +71,8 @@
*/
   public static MidiDevice.Info[] getMidiDeviceInfo()
   {
-Iterator deviceProviders = 
ServiceFactory.lookupProviders(MidiDeviceProvider.class);
+Iterator deviceProviders = 
+   ServiceFactory.lookupProviders(MidiDeviceProvider.class);
 List infoList = new ArrayList();
 
 while (deviceProviders.hasNext())
@@ -82,7 +83,8 @@
 infoList.add(infos[--i]);
 }
 
-return (MidiDevice.Info[]) infoList.toArray(new 
MidiDevice.Info[infoList.size()]);
+return (MidiDevice.Info[]) 
+   infoList.toArray(new MidiDevice.Info[infoList.size()]);
   }
   
   /**
@@ -94,9 +96,10 @@
* @throws IllegalArgumentException if the device described by info is not 
found
*/
   public static MidiDevice getMidiDevice(MidiDevice.Info info) 
-throws MidiUnavailableException, IllegalArgumentException
+throws MidiUnavailableException
   {
-Iterator deviceProviders = 
ServiceFactory.lookupProviders(MidiDeviceProvider.class);
+Iterator deviceProviders = 
+   ServiceFactory.lookupProviders(MidiDeviceProvider.class);
 
 if (! deviceProviders.hasNext())
   throw new MidiUnavailableException("No MIDI device providers 
available.");
@@ -109,7 +112,8 @@
 return provider.getDevice(info);
 } while (deviceProviders.hasNext());
 
-throw new IllegalArgumentException("MIDI device " + info + " not 
available.");
+throw new IllegalArgumentException("MIDI device " 
+  + info + " not available.");
   }
   
   /**
@@ -259,7 +263,8 @@
   if (sb != null)
 return sb;
 }
-throw new InvalidMidiDataException("Cannot read soundbank from file " + 
file);
+throw new InvalidMidiDataException("Cannot read soundbank from file " 
+  + file);
   } 
 
   /**
@@ -281,7 +286,7 @@
   i

Re: [cp-patches] Patch: javax.sound.midi

2005-09-26 Thread Tom Tromey
Anthony> This doesn't quite work because ShortMessage's parent
Anthony> declares an abstract clone(), so you can't super.clone() it.
Anthony> Perhaps they did this to force the implementation method I
Anthony> chose.

Ok, thanks.  How amazingly lame.

Tom


___
Classpath-patches mailing list
Classpath-patches@gnu.org
http://lists.gnu.org/mailman/listinfo/classpath-patches


Re: [cp-patches] Patch: javax.sound.midi

2005-09-26 Thread Anthony Green
On Mon, 2005-09-26 at 09:48 -0600, Tom Tromey wrote:
> I think this is looking great.  I think it is OK to go in.

Thanks.  I'll do that.

> I think @author should have your full name, like:
> 
> @author Anthony Green ([EMAIL PROTECTED])
> 
> Each class' javadoc should say '@since 1.3'.

Ok, I've fixed these.

> At least ShortMessage.clone() uses 'new ShortMessage(...)'.
> This doesn't work if the class is extended.  You must write:
> 
>   try
> {
>   ShortMessage dup = (ShortMessage) super.clone();
>   .. set fields
> }
>   catch (CloneNotSupportedException _)
> {
>   .. I forget what we decided here
>   .. look for other examples
> }
> 
> I didn't look to see if this occurs elsewhere.

This doesn't quite work because ShortMessage's parent declares an
abstract clone(), so you can't super.clone() it.  Perhaps they did this
to force the implementation method I chose.

> There are one or two places where the code goes past column 79.
> (I'm not super concerned about this.  I think we need a reformatting
> flag day anyway.)

I'll clean these up in a subsequent commit.

Thanks,

AG




___
Classpath-patches mailing list
Classpath-patches@gnu.org
http://lists.gnu.org/mailman/listinfo/classpath-patches


Re: [cp-patches] Patch: javax.sound.midi

2005-09-26 Thread Tom Tromey
> "Anthony" == Anthony Green <[EMAIL PROTECTED]> writes:

Anthony> Here's a virtually complete javax.sound.midi implementation.
Anthony> No providers yet.
Anthony> Ok?

I took a quick look through this.

I think this is looking great.  I think it is OK to go in.

First though, some minor nits, one real bug:


I think @author should have your full name, like:

@author Anthony Green ([EMAIL PROTECTED])

Each class' javadoc should say '@since 1.3'.

At least ShortMessage.clone() uses 'new ShortMessage(...)'.
This doesn't work if the class is extended.  You must write:

  try
{
  ShortMessage dup = (ShortMessage) super.clone();
  .. set fields
}
  catch (CloneNotSupportedException _)
{
  .. I forget what we decided here
  .. look for other examples
}

I didn't look to see if this occurs elsewhere.

There are one or two places where the code goes past column 79.
(I'm not super concerned about this.  I think we need a reformatting
flag day anyway.)

Tom


___
Classpath-patches mailing list
Classpath-patches@gnu.org
http://lists.gnu.org/mailman/listinfo/classpath-patches


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

2005-09-25 Thread Anthony Green
Here's a virtually complete javax.sound.midi implementation.  No
providers yet. 

Ok?

AG


2005-09-25  Anthony Green  <[EMAIL PROTECTED]>

* javax/sound/midi/InvalidMidiDataException.java
javax/sound/midi/MidiFileFormat.java
javax/sound/midi/ControllerEventListener.java
javax/sound/midi/Patch.java javax/sound/midi/Sequence.java
javax/sound/midi/SysexMessage.java javax/sound/midi/Sequencer.java
javax/sound/midi/spi/MidiFileReader.java
javax/sound/midi/spi/MidiFileWriter.java
javax/sound/midi/spi/SoundbankReader.java
javax/sound/midi/spi/MidiDeviceProvider.java
javax/sound/midi/Track.java javax/sound/midi/MidiChannel.java
javax/sound/midi/MetaMessage.java javax/sound/midi/Instrument.java
javax/sound/midi/MidiMessage.java
javax/sound/midi/MidiUnavailableException.java
javax/sound/midi/Transmitter.java javax/sound/midi/MidiEvent.java
javax/sound/midi/VoiceStatus.java javax/sound/midi/MidiDevice.java
javax/sound/midi/SoundbankResource.java
javax/sound/midi/Soundbank.java javax/sound/midi/Receiver.java
javax/sound/midi/MetaEventListener.java
javax/sound/midi/ShortMessage.java
javax/sound/midi/Synthesizer.java
javax/sound/midi/MidiSystem.java: New files.





javax-sound-midi-20050925.tar.gz
Description: application/compressed-tar
___
Classpath-patches mailing list
Classpath-patches@gnu.org
http://lists.gnu.org/mailman/listinfo/classpath-patches