Java Code Examples for javax.sound.midi.Sequence#getTracks()
The following examples show how to use
javax.sound.midi.Sequence#getTracks() .
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 TencentKona-8 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: StandardMidiFileWriter.java From jdk8u-dev-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 3
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 4
Source File: MidiSequencerImpl.java From tuxguitar with GNU Lesser General Public License v2.1 | 6 votes |
public void resetTracks(){ try { Sequence sequence = this.getSequencer().getSequence(); if(sequence != null){ Track[] tracks = sequence.getTracks(); if( tracks != null ){ int count = tracks.length; for( int i = 0 ; i < count; i++ ){ this.setSolo( i , false ); this.setMute( i , false ); } } } } catch (Throwable throwable) { throwable.printStackTrace(); } }
Example 5
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 6
Source File: StandardMidiFileWriter.java From openjdk-8 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 7
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 8
Source File: StandardMidiFileWriter.java From hottub 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 9
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 10
Source File: StandardMidiFileWriter.java From openjdk-jdk9 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. */ @Override 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 11
Source File: StandardMidiFileWriter.java From Bytecoder with Apache License 2.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. */ @Override 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 12
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 13
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 14
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 15
Source File: StandardMidiFileWriter.java From dragonwell8_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 16
Source File: RealTimeSequencer.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
synchronized void setSequence(Sequence seq) { if (seq == null) { init(); return; } tracks = seq.getTracks(); muteSoloChanged(); resolution = seq.getResolution(); divisionType = seq.getDivisionType(); trackReadPos = new int[tracks.length]; // trigger re-initialization checkPointMillis = 0; needReindex = true; }
Example 17
Source File: RealTimeSequencer.java From Bytecoder with Apache License 2.0 | 5 votes |
synchronized void setSequence(Sequence seq) { if (seq == null) { init(); return; } tracks = seq.getTracks(); muteSoloChanged(); resolution = seq.getResolution(); divisionType = seq.getDivisionType(); trackReadPos = new int[tracks.length]; // trigger re-initialization checkPointMillis = 0; needReindex = true; }
Example 18
Source File: SeqRecordDoesNotCopy.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
public static void main(String argv[]) { Sequencer s = null; try { s = MidiSystem.getSequencer(); s.open(); } catch (final MidiUnavailableException ignored) { // the test is not applicable return; } try { Sequence seq = new Sequence(Sequence.PPQ, 384, 2); s.setSequence(seq); Track t = seq.getTracks()[0]; ShortMessage msg = new ShortMessage(); msg.setMessage(0x90, 0x40, 0x7F); t.add(new MidiEvent(msg, 11000)); msg.setMessage(0x90, 0x40, 0x00); t.add(new MidiEvent(msg, 12000)); t = seq.getTracks()[1]; s.recordEnable(t, -1); System.out.println("Started recording..."); s.startRecording(); Receiver r = s.getReceiver(); Thread.sleep(100); // send a normal message System.out.println("Recording a normal NOTE ON message..."); msg.setMessage(0x90, 0x40, 0x6F); r.send(msg, -1); Thread.sleep(100); // send a normal message System.out.println("Recording a normal NOTE OFF message..."); msg.setMessage(0x90, 0x40, 0x00); r.send(msg, -1); Thread.sleep(100); s.stop(); // now see if the messages were recorded System.out.println("Recorded messages:"); int sameMessage = 0; for (int i = 0; i < t.size(); i++) { System.out.print(" "+(i+1)+". "); printEvent(t.get(i)); if (t.get(i).getMessage() == msg) { System.out.println("## Failed: Same Message reference!"); sameMessage++; } } if (sameMessage > 0) { System.out.println("## Failed: The same instance was recorded!"); throw new Exception("Test FAILED!"); } System.out.println("Did not detect any duplicate messages."); System.out.println("Test passed."); } catch (Exception e) { System.out.println("Unexpected Exception: "+e); //e.printStackTrace(); throw new RuntimeException("Test FAILED!"); } finally { s.close(); } }
Example 19
Source File: SlicerTest.java From mpcmaid with GNU Lesser General Public License v2.1 | 4 votes |
public void testMarkers() { assertEquals("Slicer: 3.8424037s (169450 samples), 9 markers", slicer.toString()); System.out.println(markers); assertEquals(9, markers.size()); assertFalse(markers.isUnset()); Marker marker = markers.getSelectedMarker(); assertEquals(0, marker.getLocation()); System.out.println(marker); markers.selectMarker(4); assertEquals(4, markers.getSelectedMarkerIndex()); assertEquals(79872, markers.getSelectedMarkerLocation()); assertEquals(79872, markers.getSelectedMarker().getLocation()); assertEquals(0, markers.getRangeFrom(0).getFrom()); final LocationRange range3 = markers.getRangeFrom(3); System.out.println(range3); final LocationRange range4 = markers.getRangeFrom(4); System.out.println(range4); assertEquals(3.8424037, markers.getDuration(), 0.000001); assertEquals(124.92, markers.getTempo(), 0.01); // remove markers.deleteSelectedMarker(); assertEquals(8, markers.size()); assertEquals(3, markers.getSelectedMarkerIndex()); final LocationRange range3bis = markers.getRangeFrom(3); assertEquals(range3.getFrom(), range3bis.getFrom()); assertEquals(range4.getTo(), range3bis.getTo()); // last range extends up to the Frame Length final LocationRange range7 = markers.getRangeFrom(7); assertEquals(169450, range7.getTo()); System.out.println(range7); final int[] midiTicks = { 0, 32, 97, 129, 190, 222, 288, 320, 381, 413, 478, 510, 575, 607, 673, 705, 705 }; try { final Sequence midiSequence = markers.exportMidiSequence(null, MIDI_PPQ); final Track track = midiSequence.getTracks()[0]; assertEquals(17, track.size()); for (int i = 0; i < track.size(); i++) { // System.out.println(track.get(i).getTick()); assertEquals(midiTicks[i], track.get(i).getTick()); } } catch (IOException e) { e.printStackTrace(); } assertEquals(3, markers.getSelectedMarkerIndex()); markers.insertMarker(); assertEquals(4, markers.getSelectedMarkerIndex()); assertEquals(73727, markers.getLocation(4)); }
Example 20
Source File: Midi2WavRenderer.java From computoser with GNU Affero General Public License v3.0 | 4 votes |
public static double send(Sequence seq, Receiver recv) { float divtype = seq.getDivisionType(); assert (seq.getDivisionType() == Sequence.PPQ); Track[] tracks = seq.getTracks(); int[] trackspos = new int[tracks.length]; int mpq = 500000; int seqres = seq.getResolution(); long lasttick = 0; long curtime = 0; while (true) { MidiEvent selevent = null; int seltrack = -1; for (int i = 0; i < tracks.length; i++) { int trackpos = trackspos[i]; Track track = tracks[i]; if (trackpos < track.size()) { MidiEvent event = track.get(trackpos); if (selevent == null || event.getTick() < selevent.getTick()) { selevent = event; seltrack = i; } } } if (seltrack == -1) break; trackspos[seltrack]++; long tick = selevent.getTick(); if (divtype == Sequence.PPQ) curtime += ((tick - lasttick) * mpq) / seqres; else curtime = (long) ((tick * 1000000.0 * divtype) / seqres); lasttick = tick; MidiMessage msg = selevent.getMessage(); if (msg instanceof MetaMessage) { if (divtype == Sequence.PPQ) if (((MetaMessage) msg).getType() == 0x51) { byte[] data = ((MetaMessage) msg).getData(); mpq = ((data[0] & 0xff) << 16) | ((data[1] & 0xff) << 8) | (data[2] & 0xff); } } else { if (recv != null) recv.send(msg, curtime); } } return curtime / 1000000.0; }