use of javax.sound.midi.Sequence in project yyl_example by Relucent.
the class PlayMidi method play.
public static void play(URL url) {
try {
Sequence seq = MidiSystem.getSequence(url);
midi = MidiSystem.getSequencer();
midi.open();
midi.setSequence(seq);
if (!midi.isRunning())
midi.start();
} catch (Exception ex) {
ex.printStackTrace();
}
}
use of javax.sound.midi.Sequence in project jdk8u_jdk by JetBrains.
the class SoftMidiAudioFileReader method getAudioInputStream.
public AudioInputStream getAudioInputStream(InputStream inputstream) throws UnsupportedAudioFileException, IOException {
inputstream.mark(200);
Sequence seq;
try {
seq = MidiSystem.getSequence(inputstream);
} catch (InvalidMidiDataException e) {
inputstream.reset();
throw new UnsupportedAudioFileException();
} catch (IOException e) {
inputstream.reset();
throw new UnsupportedAudioFileException();
}
return getAudioInputStream(seq);
}
use of javax.sound.midi.Sequence in project jdk8u_jdk by JetBrains.
the class SMFParser method getSequence.
public Sequence getSequence(InputStream stream) throws InvalidMidiDataException, IOException {
SMFParser smfParser = new SMFParser();
MidiFileFormat format = getMidiFileFormatFromStream(stream, MidiFileFormat.UNKNOWN_LENGTH, smfParser);
// must be MIDI Type 0 or Type 1
if ((format.getType() != 0) && (format.getType() != 1)) {
throw new InvalidMidiDataException("Invalid or unsupported file type: " + format.getType());
}
// construct the sequence object
Sequence sequence = new Sequence(format.getDivisionType(), format.getResolution());
// for each track, go to the beginning and read the track events
for (int i = 0; i < smfParser.tracks; i++) {
if (smfParser.nextTrack()) {
smfParser.readTrack(sequence.createTrack());
} else {
break;
}
}
return sequence;
}
use of javax.sound.midi.Sequence in project tika by apache.
the class MidiParser method parse.
public void parse(InputStream stream, ContentHandler handler, Metadata metadata, ParseContext context) throws IOException, SAXException, TikaException {
metadata.set(Metadata.CONTENT_TYPE, "audio/midi");
XHTMLContentHandler xhtml = new XHTMLContentHandler(handler, metadata);
xhtml.startDocument();
// MidiSystem expects the stream to support the mark feature
if (!stream.markSupported()) {
stream = new BufferedInputStream(stream);
}
try {
Sequence sequence = MidiSystem.getSequence(stream);
Track[] tracks = sequence.getTracks();
metadata.set("tracks", String.valueOf(tracks.length));
// TODO: Use XMPDM.TRACKS?
Patch[] patches = sequence.getPatchList();
metadata.set("patches", String.valueOf(patches.length));
float type = sequence.getDivisionType();
if (type == Sequence.PPQ) {
metadata.set("divisionType", "PPQ");
} else if (type == Sequence.SMPTE_24) {
metadata.set("divisionType", "SMPTE_24");
} else if (type == Sequence.SMPTE_25) {
metadata.set("divisionType", "SMPTE_25");
} else if (type == Sequence.SMPTE_30) {
metadata.set("divisionType", "SMPTE_30");
} else if (type == Sequence.SMPTE_30DROP) {
metadata.set("divisionType", "SMPTE_30DROP");
} else if (type == Sequence.SMPTE_24) {
metadata.set("divisionType", String.valueOf(type));
}
for (Track track : tracks) {
xhtml.startElement("p");
for (int i = 0; i < track.size(); i++) {
MidiMessage message = track.get(i).getMessage();
if (message instanceof MetaMessage) {
MetaMessage meta = (MetaMessage) message;
// Types 1-15 are reserved for text events
if (meta.getType() >= 1 && meta.getType() <= 15) {
// FIXME: What's the encoding?
xhtml.characters(new String(meta.getData(), ISO_8859_1));
}
}
}
xhtml.endElement("p");
}
} catch (InvalidMidiDataException ignore) {
// There is no way to know whether this exception was
// caused by the document being corrupted or by the format
// just being unsupported. So we do nothing.
}
xhtml.endDocument();
}
use of javax.sound.midi.Sequence in project jdk8u_jdk by JetBrains.
the class SMFParser method getSequence.
public Sequence getSequence(File file) throws InvalidMidiDataException, IOException {
// throws IOException
InputStream is = new FileInputStream(file);
is = new BufferedInputStream(is, bisBufferSize);
Sequence seq = null;
try {
seq = getSequence(is);
} finally {
is.close();
}
return seq;
}
Aggregations