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


Java Sequence.createTrack方法代碼示例

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


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

示例1: go

import javax.sound.midi.Sequence; //導入方法依賴的package包/類
public void go() {
	setUpGui();

	try {
		Sequencer sequencer = MidiSystem.getSequencer();
		sequencer.open();
		sequencer.addControllerEventListener(ml, new int[] {127});
		Sequence seq = new Sequence(Sequence.PPQ, 4);
		Track track = seq.createTrack();

		int r = 0;
		for (int i = 0; i < 60; i+=4) {
			r = (int) ((Math.random() * 50) + 1);
			track.add(makeEvent(144, 1, r, 100, i));
			track.add(makeEvent(176, 1, 127, 0, i));
			track.add(makeEvent(128, 1, r, 100, i + 2));
		} // end loop

		sequencer.setSequence(seq);
		sequencer.start();
		sequencer.setTempoInBPM(120);
	} catch (Exception ex) {ex.printStackTrace();}
}
 
開發者ID:miguelalba-old,項目名稱:Head-First-Java,代碼行數:24,代碼來源:MiniMusicPlayer3.java

示例2: go

import javax.sound.midi.Sequence; //導入方法依賴的package包/類
public void go() {
	try {
		Sequencer sequencer = MidiSystem.getSequencer();
		sequencer.open();

		int[] eventsIWant = {127};
		sequencer.addControllerEventListener(this, eventsIWant);

		Sequence seq = new Sequence(Sequence.PPQ, 4);
		Track track = seq.createTrack();

		for (int i = 5; i < 60; i+= 4) {
			track.add(makeEvent(144, 1, i, 100, i));

			track.add(makeEvent(176, 1, 127, 0, i));

			track.add(makeEvent(128, 1, i, 100, i + 2));
		} // end loop

		sequencer.setSequence(seq);
		sequencer.setTempoInBPM(220);
		sequencer.start();
	} catch (Exception ex) {ex.printStackTrace();}
}
 
開發者ID:miguelalba-old,項目名稱:Head-First-Java,代碼行數:25,代碼來源:MiniMusicPlayer2.java

示例3: main

import javax.sound.midi.Sequence; //導入方法依賴的package包/類
public static void main(String[] args) {
	try {
		// make and open a sequencer
		Sequencer sequencer = MidiSystem.getSequencer();
		sequencer.open();

		// make a sequence and a track
		Sequence seq = new Sequence(Sequence.PPQ, 4);
		Track track = seq.createTrack();

		// make a bunch of events to make the notes keep going up
		// (from piano note 5 to piano note 61)
		for (int i = 5; i < 61; i+=4) {
			track.add(makeEvent(144, 1, i, 100, i));
			track.add(makeEvent(128, 1, i, 100, i + 2));
		} // end loop

		sequencer.setSequence(seq);
		sequencer.setTempoInBPM(220);
		sequencer.start();
	} catch (Exception ex) {ex.printStackTrace();}
}
 
開發者ID:miguelalba-old,項目名稱:Head-First-Java,代碼行數:23,代碼來源:MiniMusicPlayer1.java

示例4: export

import javax.sound.midi.Sequence; //導入方法依賴的package包/類
/**
 * Returns a clone of this sequence suitable for Midi file export. What it does is to map the FTW channel setting to all the midi events
 * for the corresponding tracks
 * @return
 * @throws InvalidMidiDataException 
 */
public Sequence export() throws InvalidMidiDataException
{
    Sequence newSeq = new Sequence(getDivisionType(),getResolution());
    for(FrinikaTrackWrapper ftw : frinikaTrackWrappers)
    {
        Track track = newSeq.createTrack();
        for(int n=0;n<ftw.size();n++)
        {

                    MidiEvent sourceMidiEvent = ftw.get(n);
            MidiMessage msg = sourceMidiEvent.getMessage();
            if(msg instanceof ShortMessage)
            {
                ShortMessage shm = (ShortMessage)msg;
                ShortMessage nshm = new ShortMessage();
                nshm.setMessage(shm.getCommand(),ftw.getMidiChannel(),shm.getData1(),shm.getData2());
                msg = nshm;
            }
            MidiEvent newEvent = new MidiEvent(msg,sourceMidiEvent.getTick());
            track.add(newEvent);
        }
    }
    return newSeq;
}
 
開發者ID:petersalomonsen,項目名稱:frinika,代碼行數:31,代碼來源:FrinikaSequence.java

示例5: main

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

示例6: MetaCallback

import javax.sound.midi.Sequence; //導入方法依賴的package包/類
MetaCallback() throws Exception {

        sequencer=MidiSystem.getSequencer();
        sequence=new Sequence(Sequence.PPQ,240);
        track=sequence.createTrack();
        sequencer.addMetaEventListener(this);

        byte[] data = new byte[1];

        track.add(new MidiEvent(MidiMsg3(ShortMessage.NOTE_ON+0,45,100),0));
        track.add(new MidiEvent(MidiMsg3(ShortMessage.NOTE_ON+0,45,0),0 + 240));
        int c;
        for(c=0; c < TOTAL_COUNT; c++) {
            data[0]=(byte)(c+1);
            MetaMessage meta = new MetaMessage();
            meta.setMessage(1, data, 1); // type, data, length
            track.add(new MidiEvent(meta,c*20));
        }
        track.add(new MidiEvent(MidiMsg3(ShortMessage.NOTE_ON+9,45,100),c*20));
        track.add(new MidiEvent(MidiMsg3(ShortMessage.NOTE_ON+9,45,0),c*20 + 10));

        sequencer.setSlaveSyncMode(Sequencer.SyncMode.INTERNAL_CLOCK);
        sequencer.setMasterSyncMode(Sequencer.SyncMode.INTERNAL_CLOCK);
        sequencer.open();
        sequencer.setSequence(sequence);
        sequencer.setTempoInBPM(100);
        System.out.println("Starting playback...");
        this.start();
        while (!finished && sequencer.getTickPosition() < sequencer.getTickLength()) {
            System.out.println("Tick "+sequencer.getTickPosition()+"...");
            Thread.sleep(1000);
        }
        System.out.println("Stopping playback...");
        this.stop();
        if (metaCount != TOTAL_COUNT) {
            throw new Exception("Expected "+TOTAL_COUNT+" callbacks, but got "+metaCount+"!");
        }
    }
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:39,代碼來源:MetaCallback.java

示例7: MidiWriter

import javax.sound.midi.Sequence; //導入方法依賴的package包/類
/**
 * Create a new MidiWriter to write out to the given File.
 * 
 * @param outFile {@link #outFile}
 * @param tt {@link #timeTracker}
 * 
 * @throws InvalidMidiDataException If somehow the TimeTracker has an invalid PPQ value. 
 */
public MidiWriter(File outFile, TimeTracker tt) throws InvalidMidiDataException {
	this.outFile = outFile;
	timeTracker = tt;
	
	sequence = new Sequence(Sequence.PPQ, (int) timeTracker.getPPQ());
	sequence.createTrack();
	
	writeTimeTracker();
}
 
開發者ID:apmcleod,項目名稱:voice-splitting,代碼行數:18,代碼來源:MidiWriter.java

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

示例9: MidiSequence

import javax.sound.midi.Sequence; //導入方法依賴的package包/類
public MidiSequence(int ppqn)
{
try
  {
  sequence = new Sequence(Sequence.PPQ, ppqn); 
  trackDrums = new Track[MIDIBeast.spacelessDrumName.length];
  trackChords = sequence.createTrack();
  trackBass   = sequence.createTrack();
  trackMelody = sequence.createTrack();
  }
catch( Exception e )
  {
  ErrorLog.log(ErrorLog.WARNING, "something wrong in MidiSequence");
  }
}
 
開發者ID:Impro-Visor,項目名稱:Impro-Visor,代碼行數:16,代碼來源:MidiSequence.java

示例10: setUpMidi

import javax.sound.midi.Sequence; //導入方法依賴的package包/類
public void setUpMidi() {
	try {
		sequencer = MidiSystem.getSequencer();
		sequencer.open();
		sequence = new Sequence(Sequence.PPQ, 4);
		track = sequence.createTrack();
		sequencer.setTempoInBPM(120);
	} catch (Exception e) {e.printStackTrace();}
}
 
開發者ID:miguelalba-old,項目名稱:Head-First-Java,代碼行數:10,代碼來源:BeatBoxSaveOnly.java

示例11: play

import javax.sound.midi.Sequence; //導入方法依賴的package包/類
public void play(int instrument, int note) {
	try {
		Sequencer player = MidiSystem.getSequencer();
		player.open();
		Sequence seq = new Sequence(Sequence.PPQ, 4);
		Track track = seq.createTrack();

		MidiEvent event = null;

		ShortMessage first = new ShortMessage();
		first.setMessage(192, 1, instrument, 0);
		MidiEvent changeInstrument = new MidiEvent(first, 1);
		track.add(changeInstrument);

		ShortMessage a = new ShortMessage();
		a.setMessage(144, 1, note, 100);
		MidiEvent noteOn = new MidiEvent(a, 1);
		track.add(noteOn);

		ShortMessage b = new ShortMessage();
		b.setMessage(128, 1, note, 100);
		MidiEvent noteOff = new MidiEvent(b, 16);
		track.add(noteOff);
		player.setSequence(seq);
		player.start();
	} catch (Exception ex) {ex.printStackTrace();}
}
 
開發者ID:miguelalba-old,項目名稱:Head-First-Java,代碼行數:28,代碼來源:MiniMusicCmdLine.java

示例12: play

import javax.sound.midi.Sequence; //導入方法依賴的package包/類
public void play() {
	try {
		// Get a sequencer and open it
		Sequencer player = MidiSystem.getSequencer();
		player.open();

		// Set up sequence
		Sequence seq = new Sequence(Sequence.PPQ, 4);

		// Ask the sequence for a Track
		Track track = seq.createTrack();

		// Put some MidiEvents into the Track
		ShortMessage a = new ShortMessage();
		a.setMessage(144, 1, 44, 100);
		MidiEvent noteOn = new MidiEvent(a, 1);
		track.add(noteOn);

		ShortMessage b = new ShortMessage();
		b.setMessage(128, 1, 44, 100);
		MidiEvent noteOff = new MidiEvent(b, 16);
		track.add(noteOff);

		// Give the sequence to the sequencer
		player.setSequence(seq);

		// Start() the sequencer
		player.start();

	} catch (Exception ex) {
		ex.printStackTrace();
	}
}
 
開發者ID:miguelalba-old,項目名稱:Head-First-Java,代碼行數:34,代碼來源:MiniMiniMusicApp.java

示例13: setUpMidi

import javax.sound.midi.Sequence; //導入方法依賴的package包/類
public void setUpMidi() {
	try {
		sequencer = MidiSystem.getSequencer();
		sequencer.open();
		sequence = new Sequence(Sequence.PPQ, 4);
		track = sequence.createTrack();
		sequencer.setTempoInBPM(120);
	} catch(Exception e) {e.printStackTrace();}
}
 
開發者ID:miguelalba-old,項目名稱:Head-First-Java,代碼行數:10,代碼來源:BeatBox.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: convertToType1

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