File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes javax.sound.midi problems Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "javax.sound.midi problems" Watch "javax.sound.midi problems" New topic
Author

javax.sound.midi problems

Eric Larsen
Ranch Hand

Joined: Mar 28, 2009
Posts: 35
I'm reading Head First Java, and in chapter 11, there's an excercise where you write a class to play a single MIDI note using javax.sound.midi.Sequencer, Track, ShortMessage, and MidiEvent. I typed in the code, compiled it, and ran it, but I heard no sound, and the program never terminates. I put in statements to watch the progression of the program. It runs all the way through, but it never plays a sound and it never terminates. Thanks in advance.

Eric Larsen
Ranch Hand

Joined: Mar 28, 2009
Posts: 35
Just bumping this post to see if anyone knows anything about it. I'd really appreciate some help on this one. Thank you in advance.
Brian Legg
Ranch Hand

Joined: Nov 07, 2008
Posts: 488
You should probably post this in the Games section, but my guess would be that usually when you open up a resource (any type of stream of data to or from a part of your computer) that afterwords you need to close it. I don't see anything horrible in your code so I'm guessing the program is opening up the resource and for some reason it is getting stuck in an infinite loop just waiting for the resource to close so it can move on.

When you run that code do you get ANY printed output to the consol at all or does it instantly lock?


SCJA
~Currently preparing for SCJP6
Eric Larsen
Ranch Hand

Joined: Mar 28, 2009
Posts: 35
Thanks, Brian. The program now terminates, but it still doesn't play any sound. How do you post the same thread in a different forum, by the way? Is that privilege reserved for moderators?
Brian Legg
Ranch Hand

Joined: Nov 07, 2008
Posts: 488
That was mostly a note for the future, but there are a lot of moderators around here if you want to ask one to move this for you. As for your sound not playing.... let me look at some code I have at home and see if I can spot any differences. Sound is usually the only area of game design that I completely hack it in and use other peoples code. I don't understand all the terminology that goes along with music coding, nor do I want to... so I'll have to look it up when I get home.

Is this for a game/project or is this just testing something out of a book? I don't want to post a bunch of code that gives you sound capability if you are only interested in your piece of code.
W. Joe Smith
Ranch Hand

Joined: Feb 10, 2009
Posts: 710
Eric Larsen wrote:I'm reading Head First Java, and in chapter 11, there's an excercise where you write a class to play a single MIDI note using javax.sound.midi.Sequencer, Track, ShortMessage, and MidiEvent. I typed in the code, compiled it, and ran it, but I heard no sound, and the program never terminates. I put in statements to watch the progression of the program. It runs all the way through, but it never plays a sound and it never terminates. Thanks in advance.



ShortMessage a = new ShortMessage();
a.setMessage (144, 1, 44, 100);

The bolded change will make your code play sound. I'm not sure why it never terminates though.


SCJA
When I die, I want people to look at me and say "Yeah, he might have been crazy, but that was one zarkin frood that knew where his towel was."
Eric Larsen
Ranch Hand

Joined: Mar 28, 2009
Posts: 35
Is this for a game/project or is this just testing something out of a book? I don't want to post a bunch of code that gives you sound capability if you are only interested in your piece of code.


The book starts the chapter out with this example, but midi sequencing is used prominently in THE main example project for the book, a percussion mixer that will also be used to demonstrate gui/swing, networking, and file I/O, so I'd really like to be able to follow along with that. Thanks for the help, by the way, Brian! People like you give this place its reputation for friendliness.

P.S. You don't have to take any special interest in this if you don't want to. I'm going to download the code for this from HeadFirst.com after I finish posting this, and see if that works.
Eric Larsen
Ranch Hand

Joined: Mar 28, 2009
Posts: 35
Joe,

THANK YOU!!!
So obvious I couldn't see it.... I hate logic errors.
Anyway thanks for the help!!!



EDIT - Nevermind, it didn't work I'll download the code from the site now.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: javax.sound.midi problems