aspose file tools*
The moose likes Beginning Java and the fly likes Head first Java: chapter 11 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Head first Java: chapter 11" Watch "Head first Java: chapter 11" New topic
Author

Head first Java: chapter 11

Marga ter Heide
Greenhorn

Joined: May 15, 2005
Posts: 1
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();
player.open();
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);
track.add(me);

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

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

player.setSequence(seq);
player.start();

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.

Thanks
Marga
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Head first Java: chapter 11
 
Similar Threads
midi player when used from commandline does not work
Running Java Command LIne
Changing Instruments in Midi
Head First Java Chapter 11, example on page 346
Head First Java - Chapter 11 - MiniMusicCmdLine Error