• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Midi example from Head First Java

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everyone,
I am reading a book called "Head First Java" by Kathy Sierra and Bert Bates. One example piece of code uses a MIDI sequencer to generate a sound.
Unfortunately it doesn't work for me, even if I tried it both on Ubuntu and Windows. When I run it I only hear either a short piano note or a kind of knock.
Changing the arguments should give a different instrument and note, but it always plays the same sound when I execute it.
I don't know anything about sound and MIDI devices, so I don't know how to fix the problem.

I give the code below.
After compiling it I execute the command with different arguments:
java MiniMusicCmdLine 102 30
java MiniMusicCmdLine 80 20
java MiniMusicCmdLine 40 70

They're supposed to produce notes of different pitch, but I always hear the same short knock or sometime a piano note (but always of the same pitch).

I welcome any help at the beginner level.

----------------------
 
Ranch Hand
Posts: 859
IBM DB2 Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I just copied this into Eclipse and ran it.. I get the same little "knock".

Unfortunately, I don't know very much about the sound API, but I have helped others here before with similar issues.

Do a search here for midi or sound and take a look at some of the examples and fixes.


Pat.
 
Marshal
Posts: 79979
397
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch
I cannot comment because I haven’t got my copy of the book here, but it is worth comparing it very carefully to what is in the book.
 
Eubulide Megarico
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi both,
Thank you for your reply. The advice to check carefully the code from the book was right: I made a mistake in copying it! In fact line 36 should be "b.setMessage ..." instead of "a.setMessage ...". Now it works fine.
Thank you,
Eubulide
 
Campbell Ritchie
Marshal
Posts: 79979
397
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well done finding that error
 
Stop it! You're embarassing me! And you are embarrassing this tiny ad!
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic