• Post Reply Bookmark Topic Watch Topic
  • New Topic

Midi Problems with Head First Java code on Ubuntu  RSS feed

 
Benjamin Wolfe
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everybody! First-time poster here. I'm walking through Head First Java. I also switched to Ubuntu from Windows not too long ago -- part of the whole "I'm gonna be hardcore and learn Java and use Linux" thing.

A number of chapters of the book use Midi to teach coding concepts. I have yet to get my computer to produce a sound.

Here is the most recent code I tried. It compiled just fine, but when I ran it it just sat there: no sound, no nothing. It didn't even stop; I had to hit Control+C to stop it from running.



More details... folks on forums like details... um, I'm using OpenJDK Java 6 but I've also tried on OpenJDK 7. I'm on Ubuntu 12.04 (Precise Pangolin), but the last code I tried didn't work and I was still on Ubuntu 11. And I'm on a Dell Inspiron N5110 laptop. I've been going old-school for everything in Head First Java -- no Eclipse or NetBeans, just a text editor (gedit) -- and then using the command line to compile (eg "javac MiniMusicPlayer1.java") and run (eg "java MiniMusicPlayer1"). Old-school has been working so far, though, (except for Midi) and I'm on page three-hundred-and-something. Oh, and mute is definitely *not* on.
 
William P O'Sullivan
Ranch Hand
Posts: 859
Chrome IBM DB2 Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy Pardner, Welcome to the ranch.

Congratulations on diving head first into Java and Linux!

To fix your Ctrl-C, not-stopping issue insert the follow code after sequencer.start()


On windoze I am able to hear the progression of notes, then the app ends gracefully.

As for why you can't hear anything, I suspect it's the MIDI interface in Ubuntu that may be at fault.

WP

 
Benjamin Wolfe
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
William P O'Sullivan wrote:As for why you can't hear anything, I suspect it's the MIDI interface in Ubuntu that may be at fault.


Ha! Well that's what I was worried about, but it turned out to be way simpler than that. There were two places to hit mute, and I'd missed one. I swear, switching OS's can make you feel like an old lady.

As for the app not ending gracefully, Thread.sleep didn't fix it... I mean if it really needs to be fixed. I only cared because I thought it was a clue to the sound issue. Hard to work through tutorial examples, when you can't hear if the examples worked!

So thanks for sending me on my way!
 
William P O'Sullivan
Ranch Hand
Posts: 859
Chrome IBM DB2 Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well done!

As for not ending... I gave you a clue in the comment ;)
TIP: If you're using Eclipse or other content helper type IDE, look at the api, in this case the Sequencer object.

Lo and behold, there's a "stop()" method.

Here's the complete block to add...


Enjoy..

WP
 
Benjamin Wolfe
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Aha! That's awesome! I actually *found* the stop() method by tinkering around... but I *hadn't* thought of close(). It's only natural....

You da best. And I think I found me a new home in the Java world....
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!