當前位置: 首頁>>代碼示例>>Java>>正文


Java Sequence.getTracks方法代碼示例

本文整理匯總了Java中javax.sound.midi.Sequence.getTracks方法的典型用法代碼示例。如果您正苦於以下問題:Java Sequence.getTracks方法的具體用法?Java Sequence.getTracks怎麽用?Java Sequence.getTracks使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.sound.midi.Sequence的用法示例。


在下文中一共展示了Sequence.getTracks方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getMidiFileTypes

import javax.sound.midi.Sequence; //導入方法依賴的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: getMidiFileTypes

import javax.sound.midi.Sequence; //導入方法依賴的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

示例3: resetTracks

import javax.sound.midi.Sequence; //導入方法依賴的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

示例4: getMicrosecondsPerQuarterNote

import javax.sound.midi.Sequence; //導入方法依賴的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

示例5: findFirstTempo

import javax.sound.midi.Sequence; //導入方法依賴的package包/類
/**
 * Find the first tempo meta message and return the tempo value
 * @return
 */
public static float findFirstTempo(Sequence sequence) throws Exception
{
		for(Track track : sequence.getTracks())
		{
			for(int n=0;n<track.size();n++)
			{
				MidiEvent event = track.get(n);

				if(event.getMessage() instanceof MetaMessage
						&& ((MetaMessage)event.getMessage()).getType()==0x51)
				{
					float tempo = new TempoMessage((MetaMessage)event.getMessage()).getBpm();
					System.out.println("Found tempomessage "+tempo+" bpm");
					return tempo;
				}
			}
		}
		throw new Exception("No tempo message found");
}
 
開發者ID:petersalomonsen,項目名稱:frinika,代碼行數:24,代碼來源:MidiSequenceConverter.java

示例6: getSequence

import javax.sound.midi.Sequence; //導入方法依賴的package包/類
/** Create a sequence from an InputStream.
 *  This is the counterpart of {@link MidiSystem#getSequence(InputStream)}
 *  for MUS format.
 *
 * @param is MUS data (this method does not try to auto-detect the format.)
 */
public static Sequence getSequence(InputStream is)
throws IOException, InvalidMidiDataException {
    DataInputStream dis = new DataInputStream(is);
    dis.skip(6);
    int rus = dis.readUnsignedShort();
    short scoreStart = Swap.SHORT((char) rus);
    dis.skip(scoreStart - 8);
    Sequence sequence = new Sequence(Sequence.SMPTE_30, 14, 1);
    Track track = sequence.getTracks()[0];
    int[] chanVelocity = new int[16];
    Arrays.fill(chanVelocity, 100);
    EventGroup eg;
    long tick = 0;
    while ((eg = nextEventGroup(dis, chanVelocity)) != null) {
        tick = eg.appendTo(track, tick);
    }
    MetaMessage endOfSequence = new MetaMessage();
    endOfSequence.setMessage(47, new byte[] {0}, 1);
    track.add(new MidiEvent(endOfSequence, tick));
    return sequence;
}
 
開發者ID:AXDOOMER,項目名稱:mochadoom,代碼行數:28,代碼來源:MusReader.java

示例7: isTrackActive

import javax.sound.midi.Sequence; //導入方法依賴的package包/類
/**
 * Takes into account both muting and solo.
 */
public boolean isTrackActive(int track)
{
	Sequence song = sequencer.getSequence();

	if (song == null)
		return true;

	if (sequencer.getTrackSolo(track))
		return true;

	for (int i = song.getTracks().length - 1; i >= 0; --i)
	{
		if (i != track && sequencer.getTrackSolo(i))
			return false;
	}

	return !sequencer.getTrackMute(track);
}
 
開發者ID:digero,項目名稱:maestro,代碼行數:22,代碼來源:SequencerWrapper.java

示例8: writeToTrack

import javax.sound.midi.Sequence; //導入方法依賴的package包/類
/**
 * Loads and adds the effects to the given midi track
 *
 * @param track   The track to write to
 * @param channel The channel to write to
 */
@Override
public void writeToTrack(Track track, int channel) {
    long lastEnd = 0;
    for (String name : effects.keySet()) {
        Sequence sequence = FileUtils.LoadMidiFile("effects/" + name + ".mid");
        if (sequence != null) {
            int start =// Position effect in track
                    (int) (QUARTER * tempo.averageBpm / 60.0 *  //beats per second
                            15 * //because 15 seconds
                            effects.get(name)  //i-th word in text
                    );
            if (start < lastEnd)
                start = (int) lastEnd;
            if (sequence.getMicrosecondLength() / 1000000.0 + TicksInSecs(start, tempo.resolution) > 15.0) {
                start -= SecsInTicks(TicksInSecs(start, tempo.resolution) + sequence.getMicrosecondLength() / 1000000.0 - 15, tempo.resolution);
            }

            float scale = tempo.resolution / (float) sequence.getResolution(); // Make the tempo fit
            for (Track t : sequence.getTracks()) {
                for (int i = 0; i < t.size(); i++) {
                    MidiEvent event = t.get(i);
                    byte[] data = event.getMessage().getMessage();//(command & 0xF0) | (channel & 0x0F)
                    data[0] += 2; // Keep channel 1 and 2 free
                    long tick = (long) (event.getTick() * scale) + start;
                    MidiEvent ev = new MidiEvent(new MidiMessage(data) {
                        @Override
                        public Object clone() {
                            return null;
                        }
                    }, tick);
                    track.add(ev);
                    if (tick > lastEnd)
                        lastEnd = tick;
                }
            }
        }
    }
}
 
開發者ID:AudiophileDev,項目名稱:T2M,代碼行數:45,代碼來源:EffectTrack.java

示例9: setSequence

import javax.sound.midi.Sequence; //導入方法依賴的package包/類
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;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:15,代碼來源:RealTimeSequencer.java

示例10: getMidiFileTypes

import javax.sound.midi.Sequence; //導入方法依賴的package包/類
public int[] getMidiFileTypes(Sequence sequence)
{
  if (sequence.getTracks().length == 1)
    return new int[]{0};
  else
    return new int[]{1};
}
 
開發者ID:vilie,項目名稱:javify,代碼行數:8,代碼來源:MidiFileWriter.java

示例11: ChangeResolution

import javax.sound.midi.Sequence; //導入方法依賴的package包/類
/**
 * Change resolution (TPQN) and retiming events.
 * @param seq Sequence to be processed.
 * @param resolution Ticks per quarter note of new sequence.
 * @return New sequence with new resolution.
 * @throws InvalidMidiDataException throw if MIDI data is invalid.
 */
public static Sequence ChangeResolution(Sequence sourceSeq, int resolution) throws InvalidMidiDataException
{
	// sequence must be tick-based
	if (sourceSeq.getDivisionType() != Sequence.PPQ)
	{
		throw new UnsupportedOperationException("SMPTE is not supported.");
	}

	Sequence seq = new Sequence(sourceSeq.getDivisionType(), resolution);

	// process all input tracks
	for (int trackIndex = 0; trackIndex < sourceSeq.getTracks().length; trackIndex++)
	{
		Track sourceTrack = sourceSeq.getTracks()[trackIndex];
		Track track = seq.createTrack();

		// process all events
		double timingRate = (double) resolution / sourceSeq.getResolution();
		for (int eventIndex = 0; eventIndex < sourceTrack.size(); eventIndex++)
		{
			MidiEvent sourceEvent = sourceTrack.get(eventIndex);
			MidiEvent event = new MidiEvent(sourceEvent.getMessage(), Math.round(sourceEvent.getTick() * timingRate));
			track.add(event);
		}
	}

	// if the target resolution is shorter than source resolution,
	// events at different timing might be located at the same timing.
	// As a result, there might be zero-length note and/or
	// same control changes at the same timing.
	// 
	// Probably, they should be removed for better conversion.
	// I do not remove them anyway at the moment,
	// because it does not cause any major problems.

	return seq;
}
 
開發者ID:loveemu,項目名稱:petitemm,代碼行數:45,代碼來源:MidiUtil.java

示例12: sequence2polylist

import javax.sound.midi.Sequence; //導入方法依賴的package包/類
static public Polylist sequence2polylist(Sequence seq)
{
Track track[] = seq.getTracks();

PolylistBuffer buffer = new PolylistBuffer();

for( int i = 0; i < track.length; i++ )
{
    buffer.append(track2polylist(track[i]).cons(i).cons("track"));
}

return buffer.toPolylist();
}
 
開發者ID:Impro-Visor,項目名稱:Impro-Visor,代碼行數:14,代碼來源:MidiFormatting.java

示例13: FrinikaSequence

import javax.sound.midi.Sequence; //導入方法依賴的package包/類
public FrinikaSequence(Sequence sequence) throws InvalidMidiDataException
{
	super(sequence.getDivisionType(),sequence.getResolution());
    
	for(Track track : sequence.getTracks())
       {
           FrinikaTrackWrapper trackWrapper = new FrinikaTrackWrapper(track);
           trackWrapper.setSequence(this);
           tracks.add(track);
           frinikaTrackWrappers.add(trackWrapper);  
       }
    
}
 
開發者ID:petersalomonsen,項目名稱:frinika,代碼行數:14,代碼來源:FrinikaSequence.java

示例14: createFastPrototypes

import javax.sound.midi.Sequence; //導入方法依賴的package包/類
/**
   * A hack to get a real FastShortMessage that can be cloned, e.g. Prototype
   */
  private static void createFastPrototypes() {
      try {
       // create a sequence with a ShortMessage
  	    Sequence sequence = new Sequence(Sequence.PPQ, 10);
	Track track = sequence.createTrack();
          track.add(new MidiEvent(new ShortMessage(), 0l));
      	// save the sequence
          try {
           File file = File.createTempFile("FSMhack", "mid");
  	        MidiSystem.write(sequence, 0, file);
        // load the sequence and get back the FastShortMessage
              sequence = MidiSystem.getSequence(file);
              track = sequence.getTracks()[0];
        MidiMessage msg = null;
              for ( int i = 0; i < track.size(); i++ ) {
                  msg = track.get(i).getMessage();
                  Class clazz = msg.getClass();
                  if ( fastShortPrototype == null &&
                       	clazz.getCanonicalName().equals("com.sun.media.sound.FastShortMessage") ) {
				fastShortPrototype = msg;
                  }
              }
              file.delete();
          } catch ( IOException ioe ) {
          }

} catch ( InvalidMidiDataException imde ) {
      }
  }
 
開發者ID:petersalomonsen,項目名稱:frinika,代碼行數:33,代碼來源:ShortMsg.java

示例15: appendTo

import javax.sound.midi.Sequence; //導入方法依賴的package包/類
long appendTo(Sequence sequence, int trackNum, long pos) {
    Track track = sequence.getTracks()[trackNum];
    for (MidiMessage msg: messages) {
        track.add(new MidiEvent(msg, pos));
    }
    return pos + delay * 3;
}
 
開發者ID:AXDOOMER,項目名稱:mochadoom,代碼行數:8,代碼來源:FinnwMusicModule.java


注:本文中的javax.sound.midi.Sequence.getTracks方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。