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


Java Track.remove方法代碼示例

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


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

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

示例2: test_size

import javax.sound.midi.Track; //導入方法依賴的package包/類
/**
 * test method size()
 * @throws Exception
 */
public void test_size() throws Exception {
    /*
     * create an empty Track
     */
    Sequence seq = new Sequence(Sequence.SMPTE_24, 67, 9);
    Track tr = seq.createTrack();
    assertEquals(1, tr.size());
    MidiEvent event1 = new MidiEvent(new MidiMessage1(new byte[] {1, 2, 3}), 10L);
    MidiEvent event2 = new MidiEvent(new MidiMessage1(new byte[] {23, -16, 4}), 0);
    MidiEvent event3 = new MidiEvent(new MidiMessage1(new byte[] {3, -67, -1}), 6L);
    tr.add(event1);
    tr.add(event2); 
    tr.add(event3);
    assertEquals(4, tr.size());
    tr.add(event1); //false; it contains already
    assertEquals(4, tr.size());
    tr.remove(event1);
    tr.remove(event2);
    assertEquals(2, tr.size());
    tr.remove(event3);
    tr.remove(tr.get(0));
    assertEquals(0, tr.size());
    tr.add(new MidiEvent(new MidiMessage1(new byte[] {-1, 47, 0}), 6L));
    assertEquals(1, tr.size());
    tr.remove(tr.get(0));
    assertEquals(0, tr.size());
    try {
        tr.add(event1);
        fail("ArrayIndexOutOfBoundsException expected");
    } catch (ArrayIndexOutOfBoundsException e) {}
    assertEquals(1, tr.size());
}
 
開發者ID:shannah,項目名稱:cn1,代碼行數:37,代碼來源:TrackTest.java

示例3: test_ticks

import javax.sound.midi.Track; //導入方法依賴的package包/類
/**
 * test method ticks()
 * @throws Exception
 */
public void test_ticks() throws Exception {
    /*
     * create an empty Track
     */
    Sequence seq = new Sequence(Sequence.SMPTE_24, 67, 9);
    Track tr = seq.createTrack();
    assertEquals(0, tr.ticks());
    MidiEvent event1 = new MidiEvent(new MidiMessage1(new byte[] {1, 2, 3}), -10L);
    MidiEvent event2 = new MidiEvent(new MidiMessage1(new byte[] {23, -16, 4}), 2L);
    MidiEvent event3 = new MidiEvent(new MidiMessage1(new byte[] {3, -67, -1}), 6L);
    /*
     * values of Track.ticks() only positive;
     * value of Track.ticks() is the biggest value of ticks of events that
     * contain in the Track; 
     * if I remove event with the biggest value of 
     * tick, value that return method Track.ticks() will be the same
     */
    tr.add(event1);
    assertEquals(0, tr.ticks());
    tr.add(event2);
    assertEquals(2, tr.ticks());
    tr.add(event3);
    assertEquals(6, tr.ticks());
    tr.remove(event3); //I remove event with the biggest tick,...
    assertEquals(6, tr.ticks()); //...but value that return method Track.ticks() the same
    tr.remove(event2);
    tr.remove(event1);
    assertEquals(6, tr.ticks()); //and even now...
    tr.add(event2);
    assertEquals(6, tr.ticks()); //and now...
    tr.remove(tr.get(1));
    tr.remove(event2);
    assertEquals(0, tr.size()); //Track is empty
    assertEquals(0, tr.ticks()); //Track is empty, value that return Track.ticks() equals 0
}
 
開發者ID:shannah,項目名稱:cn1,代碼行數:40,代碼來源:TrackTest.java


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