本文整理匯總了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++;
}
}
}
示例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());
}
示例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
}