• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

javax.sound.midi problems

 
Eric Larsen
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 488
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Eric Larsen
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 488
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Eric Larsen
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic