javax.sound.midi.Sequence Java Examples
The following examples show how to use
javax.sound.midi.Sequence.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StandardMidiFileWriter.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
/** * Obtains the file types that this provider can write from the * sequence specified. * @param sequence the sequence for which midi file type support * is queried * @return array of file types. If no file types are supported, * returns an array of length 0. */ public int[] getMidiFileTypes(Sequence sequence){ int typesArray[]; Track tracks[] = sequence.getTracks(); if( tracks.length==1 ) { typesArray = new int[2]; typesArray[0] = MIDI_TYPE_0; typesArray[1] = MIDI_TYPE_1; } else { typesArray = new int[1]; typesArray[0] = MIDI_TYPE_1; } return typesArray; }
Example #2
Source File: MidiEngine.java From javagame with MIT License | 6 votes |
/** * �Đ� * * @param name * �o�^�� */ public void play(String name) { // ���ݍĐ����̃V�[�P���X�Ɠ����Ȃ牽�����Ȃ� if (currentSequenceName.equals(name)) { return; } // ���ݍĐ����̃V�[�P���X���~���� stop(); // ���O�ɑΉ�����MIDI���擾 Sequence seq = (Sequence)midiMap.get(name); // MIDI�V�[�P���X if (sequencer != null && seq != null) { try { sequencer.setSequence(seq); // �V�[�P���T�ɃZ�b�g sequencer.start(); // �Đ��J�n�I currentSequenceName = name; } catch (InvalidMidiDataException e) { e.printStackTrace(); } } }
Example #3
Source File: StandardMidiFileReader.java From Bytecoder with Apache License 2.0 | 6 votes |
@Override 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; }
Example #4
Source File: StandardMidiFileReader.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
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; }
Example #5
Source File: StandardMidiFileWriter.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
/** * Obtains the file types that this provider can write from the * sequence specified. * @param sequence the sequence for which midi file type support * is queried * @return array of file types. If no file types are supported, * returns an array of length 0. */ public int[] getMidiFileTypes(Sequence sequence){ int typesArray[]; Track tracks[] = sequence.getTracks(); if( tracks.length==1 ) { typesArray = new int[2]; typesArray[0] = MIDI_TYPE_0; typesArray[1] = MIDI_TYPE_1; } else { typesArray = new int[1]; typesArray[0] = MIDI_TYPE_1; } return typesArray; }
Example #6
Source File: StandardMidiFileReader.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
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; }
Example #7
Source File: StandardMidiFileReader.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 6 votes |
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; }
Example #8
Source File: StandardMidiFileReader.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
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; }
Example #9
Source File: StandardMidiFileReader.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
@Override 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; }
Example #10
Source File: StandardMidiFileWriter.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
public int write(Sequence in, int type, OutputStream out) throws IOException { byte [] buffer = null; int bytesRead = 0; long bytesWritten = 0; if( !isFileTypeSupported(type,in) ) { throw new IllegalArgumentException("Could not write MIDI file"); } // First get the fileStream from this sequence InputStream fileStream = getFileStream(type,in); if (fileStream == null) { throw new IllegalArgumentException("Could not write MIDI file"); } buffer = new byte[bufferSize]; while( (bytesRead = fileStream.read( buffer )) >= 0 ) { out.write( buffer, 0, (int)bytesRead ); bytesWritten += bytesRead; } // Done....return bytesWritten return (int) bytesWritten; }
Example #11
Source File: StandardMidiFileWriter.java From Bytecoder with Apache License 2.0 | 6 votes |
@Override public int write(Sequence in, int type, OutputStream out) throws IOException { Objects.requireNonNull(out); if (!isFileTypeSupported(type, in)) { throw new IllegalArgumentException("Could not write MIDI file"); } byte [] buffer = null; int bytesRead = 0; long bytesWritten = 0; // First get the fileStream from this sequence InputStream fileStream = getFileStream(type,in); if (fileStream == null) { throw new IllegalArgumentException("Could not write MIDI file"); } buffer = new byte[bufferSize]; while( (bytesRead = fileStream.read( buffer )) >= 0 ) { out.write( buffer, 0, bytesRead ); bytesWritten += bytesRead; } // Done....return bytesWritten return (int) bytesWritten; }
Example #12
Source File: StandardMidiFileWriter.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
public int write(Sequence in, int type, OutputStream out) throws IOException { byte [] buffer = null; int bytesRead = 0; long bytesWritten = 0; if( !isFileTypeSupported(type,in) ) { throw new IllegalArgumentException("Could not write MIDI file"); } // First get the fileStream from this sequence InputStream fileStream = getFileStream(type,in); if (fileStream == null) { throw new IllegalArgumentException("Could not write MIDI file"); } buffer = new byte[bufferSize]; while( (bytesRead = fileStream.read( buffer )) >= 0 ) { out.write( buffer, 0, (int)bytesRead ); bytesWritten += bytesRead; } // Done....return bytesWritten return (int) bytesWritten; }
Example #13
Source File: StandardMidiFileWriter.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 6 votes |
public int write(Sequence in, int type, OutputStream out) throws IOException { byte [] buffer = null; int bytesRead = 0; long bytesWritten = 0; if( !isFileTypeSupported(type,in) ) { throw new IllegalArgumentException("Could not write MIDI file"); } // First get the fileStream from this sequence InputStream fileStream = getFileStream(type,in); if (fileStream == null) { throw new IllegalArgumentException("Could not write MIDI file"); } buffer = new byte[bufferSize]; while( (bytesRead = fileStream.read( buffer )) >= 0 ) { out.write( buffer, 0, (int)bytesRead ); bytesWritten += bytesRead; } // Done....return bytesWritten return (int) bytesWritten; }
Example #14
Source File: StandardMidiFileWriter.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
public int write(Sequence in, int type, OutputStream out) throws IOException { byte [] buffer = null; int bytesRead = 0; long bytesWritten = 0; if( !isFileTypeSupported(type,in) ) { throw new IllegalArgumentException("Could not write MIDI file"); } // First get the fileStream from this sequence InputStream fileStream = getFileStream(type,in); if (fileStream == null) { throw new IllegalArgumentException("Could not write MIDI file"); } buffer = new byte[bufferSize]; while( (bytesRead = fileStream.read( buffer )) >= 0 ) { out.write( buffer, 0, (int)bytesRead ); bytesWritten += bytesRead; } // Done....return bytesWritten return (int) bytesWritten; }
Example #15
Source File: StandardMidiFileWriter.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
/** * Obtains the file types that this provider can write from the * sequence specified. * @param sequence the sequence for which midi file type support * is queried * @return array of file types. If no file types are supported, * returns an array of length 0. */ public int[] getMidiFileTypes(Sequence sequence){ int typesArray[]; Track tracks[] = sequence.getTracks(); if( tracks.length==1 ) { typesArray = new int[2]; typesArray[0] = MIDI_TYPE_0; typesArray[1] = MIDI_TYPE_1; } else { typesArray = new int[1]; typesArray[0] = MIDI_TYPE_1; } return typesArray; }
Example #16
Source File: StandardMidiFileReader.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
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; }
Example #17
Source File: StandardMidiFileWriter.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
/** * Obtains the file types that this provider can write from the * sequence specified. * @param sequence the sequence for which midi file type support * is queried * @return array of file types. If no file types are supported, * returns an array of length 0. */ public int[] getMidiFileTypes(Sequence sequence){ int typesArray[]; Track tracks[] = sequence.getTracks(); if( tracks.length==1 ) { typesArray = new int[2]; typesArray[0] = MIDI_TYPE_0; typesArray[1] = MIDI_TYPE_1; } else { typesArray = new int[1]; typesArray[0] = MIDI_TYPE_1; } return typesArray; }
Example #18
Source File: StandardMidiFileReader.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
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; }
Example #19
Source File: StandardMidiFileReader.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
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; }
Example #20
Source File: StandardMidiFileWriter.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
/** * Obtains the file types that this provider can write from the * sequence specified. * @param sequence the sequence for which midi file type support * is queried * @return array of file types. If no file types are supported, * returns an array of length 0. */ public int[] getMidiFileTypes(Sequence sequence){ int typesArray[]; Track tracks[] = sequence.getTracks(); if( tracks.length==1 ) { typesArray = new int[2]; typesArray[0] = MIDI_TYPE_0; typesArray[1] = MIDI_TYPE_1; } else { typesArray = new int[1]; typesArray[0] = MIDI_TYPE_1; } return typesArray; }
Example #21
Source File: StandardMidiFileWriter.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
/** * Obtains the file types that this provider can write from the * sequence specified. * @param sequence the sequence for which midi file type support * is queried * @return array of file types. If no file types are supported, * returns an array of length 0. */ public int[] getMidiFileTypes(Sequence sequence){ int typesArray[]; Track tracks[] = sequence.getTracks(); if( tracks.length==1 ) { typesArray = new int[2]; typesArray[0] = MIDI_TYPE_0; typesArray[1] = MIDI_TYPE_1; } else { typesArray = new int[1]; typesArray[0] = MIDI_TYPE_1; } return typesArray; }
Example #22
Source File: MidiSMPTE.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Exception { Sequence s = null; //File midiFile = new File("outsmpte.mid"); //InputStream is = new FileInputStream(midiFile); //is = new BufferedInputStream(is); InputStream is = new ByteArrayInputStream(smptemidifile); s = MidiSystem.getSequence(is); long duration = s.getMicrosecondLength() / 1000000; System.out.println("Duration: "+duration+" seconds "); if (duration > 14) { throw new Exception("SMPTE time reader is broken! Test FAILED"); } System.out.println("Test passed"); }
Example #23
Source File: MidiFileWriter.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
/** * Indicates whether a MIDI file of the file type specified can be written * from the sequence indicated. * * @param fileType the file type for which write capabilities are queried * @param sequence the sequence for which file writing support is queried * @return {@code true} if the file type is supported for this sequence, * otherwise {@code false} */ public boolean isFileTypeSupported(int fileType, Sequence sequence) { int types[] = getMidiFileTypes( sequence ); for(int i=0; i<types.length; i++) { if( fileType == types[i] ) { return true; } } return false; }
Example #24
Source File: SMPTESequence.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) { test(Sequence.PPQ); test(Sequence.SMPTE_24); test(Sequence.SMPTE_25); test(Sequence.SMPTE_30); test(Sequence.SMPTE_30DROP); if (failed > 0) { throw new RuntimeException("" + failed + " tests failed"); } }
Example #25
Source File: StandardMidiFileWriter.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@Override public int write(Sequence in, int type, File out) throws IOException { Objects.requireNonNull(in); FileOutputStream fos = new FileOutputStream(out); // throws IOException int bytesWritten = write( in, type, fos ); fos.close(); return bytesWritten; }
Example #26
Source File: RealTimeSequencer.java From Bytecoder with Apache License 2.0 | 5 votes |
private long millis2tick(long millis) { if (divisionType != Sequence.PPQ) { double dTick = ((((double) millis) * tempoFactor) * ((double) divisionType) * ((double) resolution)) / ((double) 1000); return (long) dTick; } return MidiUtils.microsec2ticks(millis * 1000, currTempo * inverseTempoFactor, resolution); }
Example #27
Source File: SoftMidiAudioFileReader.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
public AudioFileFormat getAudioFileFormat(Sequence seq) throws UnsupportedAudioFileException, IOException { long totallen = seq.getMicrosecondLength() / 1000000; long len = (long) (format.getFrameRate() * (totallen + 4)); return new AudioFileFormat(MIDI, format, (int) len); }
Example #28
Source File: MidiFileWriter.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
/** * Indicates whether a MIDI file of the file type specified can be written * from the sequence indicated. * * @param fileType the file type for which write capabilities are queried * @param sequence the sequence for which file writing support is queried * @return {@code true} if the file type is supported for this sequence, * otherwise {@code false} */ public boolean isFileTypeSupported(int fileType, Sequence sequence) { int types[] = getMidiFileTypes( sequence ); for(int i=0; i<types.length; i++) { if( fileType == types[i] ) { return true; } } return false; }
Example #29
Source File: MidiFileWriter.java From JDKSourceCode1.8 with MIT License | 5 votes |
/** * Indicates whether a MIDI file of the file type specified can be written * from the sequence indicated. * * @param fileType the file type for which write capabilities are queried * @param sequence the sequence for which file writing support is queried * @return {@code true} if the file type is supported for this sequence, * otherwise {@code false} */ public boolean isFileTypeSupported(int fileType, Sequence sequence) { int types[] = getMidiFileTypes( sequence ); for(int i=0; i<types.length; i++) { if( fileType == types[i] ) { return true; } } return false; }
Example #30
Source File: MidiSynth.java From jmg with GNU General Public License v2.0 | 5 votes |
protected void printSeqInfo(Sequence seq) { //System.out.println("Score Title: " + scoreTitle); //System.out.println("Score TempoEvent: " + m_currentTempo + " BPM"); //System.out.print("Sequence Division Type = "); float type = seq.getDivisionType(); /* if (Sequence.PPQ == type) System.out.println("PPQ"); else if (Sequence.SMPTE_24 == type) System.out.println("SMPTE 24 (24 fps)"); else if (Sequence.SMPTE_25 == type) System.out.println("SMPTE 25 (25 fps)"); else if (Sequence.SMPTE_30 == type) System.out.println("SMPTE 30 (30 fps)"); else if (Sequence.SMPTE_30DROP == type) System.out.println("SMPTE 30 Drop (29.97 fps)"); else System.out.println("Unknown"); System.out.println("Sequence Resolution = " + seq.getResolution()); System.out.println("Sequence TickLength = " + seq.getTickLength()); System.out.println("Sequence Microsecond Length = " + seq.getMicrosecondLength()); System.out.println("Sequencer TempoEvent (BPM) = " + m_sequencer.getTempoInBPM()); System.out.println("Sequencer TempoEvent (MPQ) = " + m_sequencer.getTempoInMPQ()); System.out.println("Sequencer TempoFactor = " + m_sequencer.getTempoFactor()); */ }