本文整理匯總了Java中javax.sound.midi.Track類的典型用法代碼示例。如果您正苦於以下問題:Java Track類的具體用法?Java Track怎麽用?Java Track使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Track類屬於javax.sound.midi包,在下文中一共展示了Track類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getMidiFileTypes
import javax.sound.midi.Track; //導入依賴的package包/類
/**
* 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;
}
示例2: recordEnable
import javax.sound.midi.Track; //導入依賴的package包/類
@Override
public void recordEnable(Track track, int channel) {
if (!findTrack(track)) {
throw new IllegalArgumentException("Track does not exist in the current sequence");
}
synchronized(recordingTracks) {
RecordingTrack rc = RecordingTrack.get(recordingTracks, track);
if (rc != null) {
rc.channel = channel;
} else {
recordingTracks.add(new RecordingTrack(track, channel));
}
}
}
示例3: getMidiFileTypes
import javax.sound.midi.Track; //導入依賴的package包/類
/**
* 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;
}
示例4: partName
import javax.sound.midi.Track; //導入依賴的package包/類
/**
* scan the part attribute name for a known string to create a gm program change and instrument name event
* @param part
* @param track the track that shall correspond to the part
* @param generateProgramChanges if true, program change events are generated (useful for MIR and as a cheap kind of piano reduction)
*/
private void partName(Element part, Track track, boolean generateProgramChanges) {
short chan = Short.parseShort(part.getAttributeValue("midi.channel"));
if ((part.getAttribute("name") == null) || part.getAttributeValue("name").isEmpty()) { // if there is no name
if (generateProgramChanges)
track.add(EventMaker.createProgramChange(chan, 0, (short)0)); // add program change event for Acoustic Grand Piano
track.add(EventMaker.createInstrumentName(0, "")); // add an empty instrument name event to the track
return;
}
String name = part.getAttributeValue("name");
if (generateProgramChanges)
track.add(EventMaker.createProgramChange(chan, 0, name)); // add program change event
track.add(EventMaker.createInstrumentName(0, name)); // add an instrument name event to the track
}
示例5: parseScore
import javax.sound.midi.Track; //導入依賴的package包/類
/**
* parse the elements in the score map of part (part.dated.score) to midi events and add them to track
*
* @param part the msm source
* @param track the midi track
*/
private void parseScore(Element part, Track track) {
if ((part.getFirstChildElement("dated") == null)
|| (part.getFirstChildElement("dated").getFirstChildElement("score") == null)
|| (part.getAttribute("midi.channel") == null)) // if no sufficient information
return; // cancel
int chan = Integer.parseInt(part.getAttributeValue("midi.channel")); // get the midi channel number
for (Element n = part.getFirstChildElement("dated").getFirstChildElement("score").getFirstChildElement("note"); n != null; n = Helper.getNextSiblingElement("note", n)) { // go through all note elements in score
// switch (n.getLocalName()) {
// case "rest": // rests are not represented in midi
// break;
// case "note": // for note elements create note_on and note_off events
int pitch = Math.round(Float.parseFloat(n.getAttributeValue("midi.pitch"))); // Math.round(float) returns int; so far pitches are well captured by number type float
long date = Math.round(Double.parseDouble(n.getAttributeValue("midi.date"))); // Math.round(double) returns long
long dur = Math.round(Double.parseDouble(n.getAttributeValue("midi.duration")));
track.add(EventMaker.createNoteOn(chan, date, pitch, 100));
track.add(EventMaker.createNoteOff(chan, date + dur, pitch, 100));
// break;
// }
// TODO: process text (not implemented in mei-to-msm-export, yet, but planned to be added in the future)
}
}
示例6: parseMarkerMap
import javax.sound.midi.Track; //導入依賴的package包/類
/**
* parse the markerMap and create marker events from it
* @param part
* @param track
*/
private void parseMarkerMap(Element part, Track track) {
if ((part.getFirstChildElement("dated") == null)
|| (part.getFirstChildElement("dated").getFirstChildElement("markerMap") == null)) // if no sufficient information
return; // cancel
String message; // the marker message
for (Element e = part.getFirstChildElement("dated").getFirstChildElement("markerMap").getFirstChildElement("marker"); e != null; e = Helper.getNextSiblingElement("marker", e)) {
try {
message = e.getAttributeValue("message");
} catch (NullPointerException | NumberFormatException error) {
message = "marker";
}
track.add(EventMaker.createMarker(Math.round(Double.parseDouble(e.getAttributeValue("midi.date"))), message));
}
}
示例7: resetTracks
import javax.sound.midi.Track; //導入依賴的package包/類
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();
}
}
示例8: computeTrackLength
import javax.sound.midi.Track; //導入依賴的package包/類
/**
* Compute the length of a track as it will be written to the
* output stream.
*
* @param track the track to measure
* @param dos a MidiDataOutputStream used for helper method
* @return the length of the track
*/
private int computeTrackLength(Track track, MidiDataOutputStream dos)
{
int count = 0, length = 0, i = 0, eventCount = track.size();
long ptick = 0;
while (i < eventCount)
{
MidiEvent me = track.get(i);
long tick = me.getTick();
length += dos.variableLengthIntLength((int) (tick - ptick));
ptick = tick;
length += me.getMessage().getLength();
i++;
}
return length;
}
示例9: computeTrackLength
import javax.sound.midi.Track; //導入依賴的package包/類
/**
* Compute the length of a track as it will be written to the
* output stream.
*
* @param track the track to measure
* @param dos a MidiDataOutputStream used for helper method
* @return the length of the track
*/
private int computeTrackLength(Track track, MidiDataOutputStream dos)
{
int count = 0, length = 0, i = 0, eventCount = track.size();
long ptick = 0;
while (i < eventCount)
{
MidiEvent me = track.get(i);
long tick = me.getTick();
length += dos.variableLengthIntLength((int) (tick - ptick));
ptick = tick;
length += me.getMessage().getLength();
i++;
}
return length;
}
示例10: exportMidiSequence
import javax.sound.midi.Track; //導入依賴的package包/類
/**
* Exports the location of each slice into a MIDI file
*/
public Sequence exportMidiSequence(final File file, final int ppq) throws IOException {
final double tempoBps = (double) getTempo() / 60.0;
final MidiSequenceBuilder builder = new MidiSequenceBuilder(ppq);
final Track track = builder.getTrack();
final int n = markers.size();
int startTick = 0;
int key = 35;
for (int i = 0; i < n; i++) {
final int location = getLocation(i);
startTick = (int) Math.round(ppq * tempoBps * location / samplingRate);
int tickLength = 32;
builder.addNote(track, startTick, tickLength, key++);
}
if (file != null) {
builder.save(file);
}
return builder.getSequence();
}
示例11: addMidiNote
import javax.sound.midi.Track; //導入依賴的package包/類
/**
* Add the given MidiNote into the {@link #sequence}.
*
* @param note The note to add.
*
* @throws InvalidMidiDataException If the MidiNote contains invalid Midi data.
*/
public void addMidiNote(MidiNote note) throws InvalidMidiDataException {
int correctVoice = note.getCorrectVoice();
// Pad with enough tracks
while (sequence.getTracks().length <= correctVoice) {
sequence.createTrack();
}
// Get the correct track
Track track = sequence.getTracks()[correctVoice];
ShortMessage noteOn = new ShortMessage();
noteOn.setMessage(ShortMessage.NOTE_ON | correctVoice, note.getPitch(), note.getVelocity());
MidiEvent noteOnEvent = new MidiEvent(noteOn, note.getOnsetTick());
ShortMessage noteOff = new ShortMessage();
noteOff.setMessage(ShortMessage.NOTE_OFF | correctVoice, note.getPitch(), 0);
MidiEvent noteOffEvent = new MidiEvent(noteOff, note.getOffsetTick());
track.add(noteOnEvent);
track.add(noteOffEvent);
}
示例12: getMicrosecondsPerQuarterNote
import javax.sound.midi.Track; //導入依賴的package包/類
/**
* Gets the number of microseconds per quarter note for a sequence, used to
* determine its BPM.
*
* @param sequence
* @return
*/
private static int getMicrosecondsPerQuarterNote(Sequence sequence) {
// Check all MIDI tracks for MIDI_SET_TEMPO message
for (Track track : sequence.getTracks()) {
for (int i = 0; i < track.size(); i++) {
MidiEvent event = track.get(i);
MidiMessage message = event.getMessage();
if (message instanceof MetaMessage) {
MetaMessage m = (MetaMessage) message;
byte[] data = m.getData();
int type = m.getType();
if (type == MIDI_SET_TEMPO) {
return ((data[0] & 0xff) << 16) | ((data[1] & 0xff) << 8) | (data[2] & 0xff);
}
}
}
}
return 0;
}
示例13: render
import javax.sound.midi.Track; //導入依賴的package包/類
/**
* Called from Score
*
* Calls render in SectionInfo
*
* @param seq
* @param time
* @param track
* @param transposition
* @param useDrums
* @param endLimitIndex
* @param constantBass
* @return
* @throws InvalidMidiDataException
*/
public long render(MidiSequence seq,
long time,
Track track,
Transposition transposition,
boolean useDrums,
int endLimitIndex,
boolean constantBass)
throws InvalidMidiDataException
{
// to trace sequencing info:
// System.out.println("ChordPart time = " + time + ", endLimitIndex = " + endLimitIndex);
long result = sectionInfo.render(seq,
time,
track,
transposition,
useDrums,
endLimitIndex,
constantBass);
return result;
}
示例14: render
import javax.sound.midi.Track; //導入依賴的package包/類
/**
* Adds this Note at the specified time on the specified Track and
* channel in the specified Sequence, then returns the time that a
* sequential Note should be added.
* @param seq the Sequence to which to add this Note
* @param track the Track in the Sequence to which to add this Note
* @param time the time at which to start this Note
* @param ch the channel on which to put this Note
* @param transposition amount by which to transpose this note in semitones
* @param sendBankSelect
* @return
* @throws javax.sound.midi.InvalidMidiDataException
*/
public long render(Sequence seq,
Track track,
long time,
int ch,
int transposition,
boolean sendBankSelect)
throws InvalidMidiDataException
{
if( sendBankSelect )
{
}
int dur = getRhythmValue();
long offTime = time + dur * seq.getResolution() / BEAT;
render(seq, track, time, offTime, ch, transposition);
return offTime;
}
示例15: track2polylist
import javax.sound.midi.Track; //導入依賴的package包/類
static public Polylist track2polylist(Track track)
{
PolylistBuffer buffer = new PolylistBuffer();
buffer.append(Polylist.list("ticks", track.ticks()));
long len = track.size();
buffer.append(Polylist.list("events", len));
for( int i = 0; i < len; i++ )
{
buffer.append(midiEvent2polylist(i, track.get(i)));
}
return buffer.toPolylist();
}