当前位置: 首页>>代码示例>>Java>>正文


Java Track类代码示例

本文整理汇总了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;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:24,代码来源:StandardMidiFileWriter.java

示例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));
        }
    }

}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:RealTimeSequencer.java

示例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;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:25,代码来源:StandardMidiFileWriter.java

示例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
}
 
开发者ID:cemfi,项目名称:meico,代码行数:23,代码来源:Msm.java

示例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)
        }
    }
 
开发者ID:cemfi,项目名称:meico,代码行数:30,代码来源:Msm.java

示例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));
    }
}
 
开发者ID:cemfi,项目名称:meico,代码行数:22,代码来源:Msm.java

示例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();
	}
}
 
开发者ID:theokyr,项目名称:TuxGuitar-1.3.1-fork,代码行数:18,代码来源:MidiSequencerImpl.java

示例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;
}
 
开发者ID:vilie,项目名称:javify,代码行数:24,代码来源:MidiFileWriter.java

示例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;
 }
 
开发者ID:nmldiegues,项目名称:jvm-stm,代码行数:24,代码来源:MidiFileWriter.java

示例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();
}
 
开发者ID:cyriux,项目名称:mpcmaid,代码行数:22,代码来源:Markers.java

示例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);
}
 
开发者ID:apmcleod,项目名称:voice-splitting,代码行数:30,代码来源:MidiWriter.java

示例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;
}
 
开发者ID:TaylorPeer,项目名称:AI-909,代码行数:27,代码来源:MidiUtilities.java

示例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;
  }
 
开发者ID:Impro-Visor,项目名称:Impro-Visor,代码行数:37,代码来源:ChordPart.java

示例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;
  }
 
开发者ID:Impro-Visor,项目名称:Impro-Visor,代码行数:33,代码来源:Note.java

示例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();
}
 
开发者ID:Impro-Visor,项目名称:Impro-Visor,代码行数:18,代码来源:MidiFormatting.java


注:本文中的javax.sound.midi.Track类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。