Win a copy of The Way of the Web Tester: A Beginner's Guide to Automating Tests this week in the Testing forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Head first Java: chapter 11

Marga ter Heide
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to get the MiniMusicCmdLine object to work using a different logic than is explained in the book. Instead of creating new shortmessage and MidiEvent object for every individual track, I have tried reusing the objects in the following way:

Sequencer player = MidiSystem.getSequencer();;
Sequence seq = new Sequence(Sequence.PPQ,4);
Track track = seq.createTrack();

MidiEvent event = null;

ShortMessage sm = new ShortMessage();
sm.setMessage(192, 1, instrument, 0);
MidiEvent me = new MidiEvent(sm,1);

sm.setMessage(144, 1, note, 100);
me = null;
me = new MidiEvent(sm,1);

sm.setMessage(128, 1, note, 100);
me = null;
me = new MidiEvent(sm,16);


If I use the logic described in the book it works. But I thought it would also work the way I programmed it. I am obviously making a thinking error, but I can not see what it is. can someone explain please.

  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic