summaryrefslogtreecommitdiff
path: root/javax/sound
diff options
context:
space:
mode:
authorAnthony Green <green@redhat.com>2005-09-28 03:44:04 +0000
committerAnthony Green <green@redhat.com>2005-09-28 03:44:04 +0000
commit9c801d4df8b39b97d73bdc2393300a9666fae96f (patch)
tree92cc63be7a9dd7f0db9f9a86999497e7d581a82d /javax/sound
parent73bfcbc28c7712a3e56ece12f518774ee8a02526 (diff)
downloadclasspath-9c801d4df8b39b97d73bdc2393300a9666fae96f.tar.gz
2005-09-27 Anthony Green <green@redhat.com>
* 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".
Diffstat (limited to 'javax/sound')
-rw-r--r--javax/sound/midi/MidiSystem.java68
-rw-r--r--javax/sound/midi/Sequencer.java5
-rw-r--r--javax/sound/midi/ShortMessage.java30
-rw-r--r--javax/sound/midi/SoundbankResource.java12
4 files changed, 107 insertions, 8 deletions
diff --git a/javax/sound/midi/MidiSystem.java b/javax/sound/midi/MidiSystem.java
index c73b47018..8ea12eb70 100644
--- a/javax/sound/midi/MidiSystem.java
+++ b/javax/sound/midi/MidiSystem.java
@@ -331,9 +331,75 @@ public class MidiSystem
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.
diff --git a/javax/sound/midi/Sequencer.java b/javax/sound/midi/Sequencer.java
index d8841583a..894d876e9 100644
--- a/javax/sound/midi/Sequencer.java
+++ b/javax/sound/midi/Sequencer.java
@@ -103,6 +103,11 @@ public interface Sequencer extends MidiDevice
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
diff --git a/javax/sound/midi/ShortMessage.java b/javax/sound/midi/ShortMessage.java
index 12a283706..43c0e25fe 100644
--- a/javax/sound/midi/ShortMessage.java
+++ b/javax/sound/midi/ShortMessage.java
@@ -142,6 +142,26 @@ public class ShortMessage extends MidiMessage
*/
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 @@ public class ShortMessage extends MidiMessage
* @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);
@@ -187,6 +207,14 @@ public class ShortMessage extends MidiMessage
}
}
+ 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);
+ }
+
/**
* Set the MIDI message to one that requires no data bytes.
*
diff --git a/javax/sound/midi/SoundbankResource.java b/javax/sound/midi/SoundbankResource.java
index 03a751993..435017e4c 100644
--- a/javax/sound/midi/SoundbankResource.java
+++ b/javax/sound/midi/SoundbankResource.java
@@ -47,20 +47,20 @@ package javax.sound.midi;
*/
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 @@ public abstract class SoundbankResource
*
* @return the sound bank in which this resource resides
*/
- public Soundbank getSoundBank()
+ public Soundbank getSoundbank()
{
- return soundBank;
+ return soundbank;
}
/**