I have tried out the (almost) initial code for the music machine in Chap. 11; the piano note plays very nicely but then the program doesn't seem to know that it is finished.
I am using emacs as my editor and running the code from the cmd prompt in MS Windows XP. The only way that I can convince the command shell that the program is done is cntl-C. What should I add to the code in the book to say "stop now"? (of course, "sensible" procedural languages like the ones I grew up with have statements like STOP or CALL EXIT ...) ;-)
Thanks for any ideas!
At the end of the try block (immediately after calling player.start();), try adding the following...
This will cause a 2-second pause (which should be long enough for the player to play the note you specified), after which it will close the Sequencer and exit the program.
There's probably a "better" way, but I think this will work.
Thank you thank you! It works beautifully - unfortunately it also leaves me with a batch of further questions.
I have been crawling through the API docs for MidiEvent and Sequencer and have found that all of the time parameters used in these classes are in "MIDI ticks" - but I can't figure out from what I'm reading how a MIDI tick translates into "real" time in seconds or milliseconds or anything that I could use to set the thread sleep time for "playing around". Is there somewhere else I should look? Or do I just not understand what I'm reading?
Originally posted by Jinny Morris:
...I can't figure out from what I'm reading how a MIDI tick translates into "real" time in seconds or milliseconds...
Well, despite being a musician (and somewhat of a geek), I know very little about MIDI.
The documentation for MidiEvent says, "The duration of a tick is specified by the timing information contained in the MIDI file or Sequence object." And the constructor Sequence(float divisionType, int resolution)...
Constructs a new MIDI sequence with the specified timing division type and timing resolution. The division type must be one of the recognized MIDI timing types. For tempo-based timing, divisionType is PPQ (pulses per quarter note) and the resolution is specified in ticks per beat. For SMTPE timing, divisionType specifies the number of frames per second and the resolution is specified in ticks per frame.
So a Sequence looks like the entry point for controlling this, but I think I need some fundamentals about how MIDI tempo works before understanding how to use it. I found this MIDI Timing Concepts page that looks pretty good. See if that helps...
I've come across the program termination problem, too. At least for GUI you can use
(where frame is declared JFrame object).
Hope this helps!
[ May 28, 2007: Message edited by: Paul Paskin ]
Thanks much! So I will be patient until I get to bpm ...
Yes, I am just now playing w/ the "very simple GUI" in chapter 11 so have now met "exit on close" (of frame) - but we weren't using GUIs yet when we first met the sound generator.
Occasionally I regret my decision to do this w/out benefit of IDE
- Jinny Morris