-
Bug
-
Resolution: Cannot Reproduce
-
P4
-
None
-
1.3.0
-
x86
-
windows_98
Name: rlT66838 Date: 06/21/2000
java version "1.3.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)
1) I fill a sequence with 100 MetaMessage events, handling meta messages by
printing a line of text to the screen.
2) The code below should print the line "got Meta #0" 100 times, once every
other beat at 100 BPM. The behavior is nondeterministic: sometimes I get one
callback, maybe 10 seconds from runtime, and other times no callback at all.
(Apologies for weird cruft, as I have torn this snippet out of a larger code
base. All I am trying to get here are my callbacks.)
3) n/a
4) n/a
5) SoundBlaster Live, not sure who's synth as I am just requesting the
MidiSystem.getSequencer().
************code:
import javax.sound.midi.*;
import java.lang.*;
import java.util.*;
import java.io.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class Demo2 {
static ShortMessage MidiMsg3(int a, int b, int c) {
try {
ShortMessage msg = new ShortMessage();
msg.setMessage((byte)a,(byte)b,(byte)c);
return msg;
} catch(InvalidMidiDataException ex) {
throw new RuntimeException();
}
}
class SequenceImprovisor implements MetaEventListener {
//Synthesizer synth;
Instrument[] instruments;
Sequencer sequencer;
Sequence sequence;
Track track;
SequenceImprovisor() {
try {
sequencer=MidiSystem.getSequencer();
sequence=new Sequence(Sequence.PPQ,10);
track=sequence.createTrack();
sequencer.addMetaEventListener(this);
ShortMessage smsg;
smsg = MidiMsg3(ShortMessage.NOTE_OFF+0,44,64);
track.add(new MidiEvent(smsg,10000));
smsg = MidiMsg3(ShortMessage.NOTE_ON+0,45,64);
track.add(new MidiEvent(smsg,10));
smsg = MidiMsg3(ShortMessage.NOTE_OFF+0,45,64);
track.add(new MidiEvent(smsg,20));
byte[] data = new byte[1];
for(int c=0; c<100; c++) {
MetaMessage meta;
data[0]=(byte)c;
meta = new MetaMessage();
//meta.setMessage(0,data,1); // type, data, length
track.add(new MidiEvent(meta,c*20));
}
sequencer.setSlaveSyncMode(Sequencer.SyncMode.INTERNAL_CLOCK);
sequencer.setMasterSyncMode(Sequencer.SyncMode.INTERNAL_CLOCK);
sequencer.open();
sequencer.setSequence(sequence);
sequencer.setTempoInBPM(100);
this.start();
}
catch(InvalidMidiDataException ex) {}
catch(MidiUnavailableException ex) {}
}
void start() {sequencer.start();}
void stop() {sequencer.stop();}
int noteNum=0;
void addNote(int pitch) {
ShortMessage msg;
byte[] data;
msg = MidiMsg3(ShortMessage.NOTE_ON+0,pitch,64);
track.add(new MidiEvent(msg,noteNum*10));
msg = MidiMsg3(ShortMessage.NOTE_OFF+0,pitch,64);
track.add(new MidiEvent(msg,noteNum*10+5));
noteNum++;
}
public void meta(MetaMessage msg) {
byte num=0; //msg.getData()[0];
System.out.println("got Meta #"+num);
}
}
SequenceImprovisor sequenceImprovisor;
Demo2() {
sequenceImprovisor = new SequenceImprovisor();
}
public static void main(String[] argv) {
Demo2 demo2=new Demo2();
}
}
(Review ID: 106361)
======================================================================
- relates to
-
JDK-4773012 RFE: Implement a new stand-alone sequencer
-
- Resolved
-