Win a copy of React Cookbook: Recipes for Mastering the React Framework this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Rob Spoor
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Holloway
  • Piet Souris
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Himai Minh

beatbox (Headfirst ch 13)

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Since I can't attach my code here, understanding the context of this question depends on having the Headfirst Java book.

In reference to the BeatBox code in HeadFirst Java, I followed the code from the first edition book, but in J2EE 5. (Edition 1 was written for 1.3 by the looks of it.) The program is supposed to restart the midi sequence after beat 16, but it seems to get stuck and doesn't respond to anything. To be more specific, it seems like the Meta event handler gets called recursively.

I've had a spot of bother (alright it's driving me nuts! ) in that the code for chapter 13 beatbox goes through once and fails to restart the sequence. I inserted a system.out.println("..."); line in the 'meta' method, and it seems that this is being called recursively. I need to break the recursive nature of this evident loop, but I don't know how.

I'd appreciate any help y'all can offer.
 
Paul Paskin
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I nailed it! I went hunting down the api for sequencer @ javax.sound.midi, found a method called setTickPosition.
So, in the event that anyone else gets stuck at this point (and by some miracle can find my post), the last method should look like this:

The key was that the sequencer figured that it had played on past tick position 16, and wasn't looking at messages before that point. Resetting the tick position essentially made the sequencer rewind to the beginning.
 
I think she's lovely. It's this tiny ad that called her crazy:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic