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


Java Track.get方法代碼示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: findFirstTempo

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

示例5: calcLastNoteTick

import javax.sound.midi.Track; //導入方法依賴的package包/類
public long calcLastNoteTick()
{
	long lastNoteTick = 0;
	for (Track t : sequence.getTracks())
	{
		for (int j = t.size() - 1; j >= 0; j--)
		{
			MidiEvent evt = t.get(j);
			MidiMessage msg = evt.getMessage();
			if (msg instanceof ShortMessage)
			{
				ShortMessage m = (ShortMessage) msg;
				if (m.getCommand() == ShortMessage.NOTE_OFF)
				{
					if (evt.getTick() > lastNoteTick)
					{
						lastNoteTick = evt.getTick();
					}
					break;
				}
			}
		}
	}

	return lastNoteTick;
}
 
開發者ID:digero,項目名稱:maestro,代碼行數:27,代碼來源:SequenceInfo.java

示例6: 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 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:cfriedt,項目名稱:classpath,代碼行數:24,代碼來源:MidiFileWriter.java

示例7: writeToTrack

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

示例8: main

import javax.sound.midi.Track; //導入方法依賴的package包/類
public static void main(String argv[]) throws Exception {
    Sequence seq = new Sequence(Sequence.PPQ, 240);
    Track t = seq.createTrack();

    log("add 10 events in random order");
    t.add(createEvent(10, 5));
    t.add(createEvent(0, 0));
    t.add(createEvent(10, 6));
    t.add(createEvent(11, 8));
    t.add(createEvent(10, 7));
    t.add(createEvent(0, 1));
    t.add(createEvent(0, 2));
    t.add(createEvent(15, 9));
    t.add(createEvent(0, 3));
    t.add(createEvent(1, 4));

    // now compare the events.
    // The note param will tell us the
    // the expected position
    long lastTick = 0;
    for (int i = 0; i < t.size(); i++) {
        MidiEvent ev = t.get(i);
        if (ev.getMessage() instanceof ShortMessage) {
            ShortMessage msg = (ShortMessage) ev.getMessage();
            log(""+i+": ShortMessage at tick "+ev.getTick()
                +" with expected position "+msg.getData1());
            if (ev.getTick() < lastTick) {
                log("  FAILED: last tick is larger than this event's tick!");
                failed = true;
            }
            if (i != msg.getData1()) {
                log("  FAILED: Track did not order correctly.");
                failed = true;
            }
        }
    }

    if (failed) throw new Exception("Test FAILED!");
    log("Test passed.");
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:41,代碼來源:TrackAddSameTick.java

示例9: writeTrack

import javax.sound.midi.Track; //導入方法依賴的package包/類
/**
 * Write a track to an output stream.
 *
 * @param track the track to write
 * @param dos a MidiDataOutputStream to write to
 * @return the number of bytes written
 */
private int writeTrack(Track track, MidiDataOutputStream dos)
  throws IOException
{
  int i = 0, elength = track.size(), trackLength;
  MidiEvent pme = null;
  dos.writeInt(0x4d54726b); // "MTrk"
  trackLength = computeTrackLength(track, dos);
  dos.writeInt(trackLength);
  while (i < elength)
    {
      MidiEvent me = track.get(i);
      int dtime = 0;
      if (pme != null)
        dtime = (int) (me.getTick() - pme.getTick());
      dos.writeVariableLengthInt(dtime);
      // FIXME: use running status byte
      byte msg[] = me.getMessage().getMessage();
      dos.write(msg);
      pme = me;
      i++;
    }

  // We're done if the last event was an End of Track meta message.
  if (pme != null && (pme.getMessage() instanceof MetaMessage))
    {
      MetaMessage mm = (MetaMessage) pme.getMessage();
      if (mm.getType() == 0x2f) // End of Track message
        return trackLength + 8;
    }

  // Write End of Track meta message
  dos.writeVariableLengthInt(0); // Delta time of 0
  dos.writeByte(0xff); // Meta Message
  dos.writeByte(0x2f); // End of Track message
  dos.writeVariableLengthInt(0); // Length of 0

  return trackLength + 8 + 4;
}
 
開發者ID:vilie,項目名稱:javify,代碼行數:46,代碼來源:MidiFileWriter.java

示例10: writeTrack

import javax.sound.midi.Track; //導入方法依賴的package包/類
/**
  * Write a track to an output stream.
  *
  * @param track the track to write
  * @param dos a MidiDataOutputStream to write to
  * @return the number of bytes written
  */
 private int writeTrack(Track track, MidiDataOutputStream dos)
   throws IOException
 {
   int i = 0, elength = track.size(), trackLength;
   MidiEvent pme = null;
   dos.writeInt(0x4d54726b); // "MTrk"
   trackLength = computeTrackLength(track, dos);
   dos.writeInt(trackLength);
   while (i < elength)
     {
MidiEvent me = track.get(i);
int dtime = 0;
if (pme != null)
  dtime = (int) (me.getTick() - pme.getTick());
dos.writeVariableLengthInt(dtime); 
// FIXME: use running status byte
byte msg[] = me.getMessage().getMessage();
dos.write(msg);
pme = me;
i++;
     } 

   // We're done if the last event was an End of Track meta message.
   if (pme != null && (pme.getMessage() instanceof MetaMessage))
     {
MetaMessage mm = (MetaMessage) pme.getMessage();
if (mm.getType() == 0x2f) // End of Track message
  return trackLength + 8;
     }

   // Write End of Track meta message
   dos.writeVariableLengthInt(0); // Delta time of 0
   dos.writeByte(0xff); // Meta Message
   dos.writeByte(0x2f); // End of Track message
   dos.writeVariableLengthInt(0); // Length of 0

   return trackLength + 8 + 4;
 }
 
開發者ID:nmldiegues,項目名稱:jvm-stm,代碼行數:46,代碼來源:MidiFileWriter.java

示例11: ChangeResolution

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

import javax.sound.midi.Track; //導入方法依賴的package包/類
public void setSequence(Sequence sequence) {
	this.sequence = sequence;
	// calculate length in beats and notes count
	Track track = getTrack();
	notesCount = 0;
	long start = -1;
	long end = -1;
	int size = track.size();
	if (size > 0) {
		for (int i = 0; i < size; i++) {
			MidiEvent ev = track.get(i);
			MidiMessage msg = ev.getMessage();
			if ((msg instanceof ShortMessage) && (((ShortMessage)msg).getCommand() == ShortMessage.NOTE_ON)) {
				notesCount++;
				if (start == -1) {
					start = ev.getTick();
				}
				end = ev.getTick();
			}
		}
		int resolution = sequence.getResolution();
		long b1 = (start + (resolution/4)) / resolution; // +res/2: allow notes to start a bit earlier but still be counted to other bar
		long b2 = (end - (resolution/4)) / resolution; // - res/2: ...
		lengthInBeats = (int)(b2 - b1 + 1);
		length = lengthInBeats * resolution;
	} else {
		length = 0;
	}
}
 
開發者ID:petersalomonsen,項目名稱:frinika,代碼行數:30,代碼來源:GroovePatternFromSequence.java

示例13: findNearest

import javax.sound.midi.Track; //導入方法依賴的package包/類
private long findNearest(long tick, int[] v) {
	if (notesCount == 0) return tick;
	Track track = getTrack();
	int size = track.size();
	
	int shift = 4 * sequence.getResolution(); // pattern starts at 4 * ppq
	
	long t = tick % length; // tick inside pattern, to be (de-)quantized
	t = tick + shift;
	
	int i = 0;
	long nearest = -1;
	v[0] = 100;
	long tt = t;
	MidiEvent ev;
	boolean isNote;
	do {
		ev = track.get(i++);
		tt = ev.getTick();
		MidiMessage msg = ev.getMessage();
		isNote = (msg instanceof ShortMessage) && (((ShortMessage)msg).getCommand() == ShortMessage.NOTE_ON); 
		if ((isNote) && (  ( tt < t ) || ( (tt-t) < (t-nearest) ) ) ) {
			nearest = tt;
			v[0] = ((ShortMessage)msg).getData2();
		}
	} while ((i < size) && ((!isNote) || (tt < t))); // stops after first note imediately following after (tt<t) no longer is true 
	return nearest - shift;
}
 
開發者ID:petersalomonsen,項目名稱:frinika,代碼行數:29,代碼來源:GroovePatternFromSequence.java

示例14: calcFirstNoteTick

import javax.sound.midi.Track; //導入方法依賴的package包/類
public long calcFirstNoteTick()
{
	long firstNoteTick = Long.MAX_VALUE;
	for (Track t : sequence.getTracks())
	{
		for (int j = 0; j < t.size(); j++)
		{
			MidiEvent evt = t.get(j);
			MidiMessage msg = evt.getMessage();
			if (msg instanceof ShortMessage)
			{
				ShortMessage m = (ShortMessage) msg;
				if (m.getCommand() == ShortMessage.NOTE_ON)
				{
					if (evt.getTick() < firstNoteTick)
					{
						firstNoteTick = evt.getTick();
					}
					break;
				}
			}
		}
	}
	if (firstNoteTick == Long.MAX_VALUE)
		return 0;
	return firstNoteTick;
}
 
開發者ID:digero,項目名稱:maestro,代碼行數:28,代碼來源:SequenceInfo.java

示例15: convertToType1

import javax.sound.midi.Track; //導入方法依賴的package包/類
/**
 * Separates the MIDI file to have one track per channel (Type 1).
 */
public static void convertToType1(Sequence song)
{
	if (song.getTracks().length == 1)
	{
		Track track0 = song.getTracks()[0];
		Track[] tracks = new Track[CHANNEL_COUNT];

		int trackNumber = 1;
		int i = 0;
		while (i < track0.size())
		{
			MidiEvent evt = track0.get(i);
			if (evt.getMessage() instanceof ShortMessage)
			{
				int chan = ((ShortMessage) evt.getMessage()).getChannel();
				if (tracks[chan] == null)
				{
					tracks[chan] = song.createTrack();
					String trackName = (chan == DRUM_CHANNEL) ? "Drums" : ("Track " + trackNumber);
					trackNumber++;
					tracks[chan].add(MidiFactory.createTrackNameEvent(trackName));
				}
				tracks[chan].add(evt);
				if (track0.remove(evt))
					continue;
			}
			i++;
		}
	}
}
 
開發者ID:digero,項目名稱:maestro,代碼行數:34,代碼來源:SequenceInfo.java


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