Win a copy of Programmers Guide to Apache Thrift this week in the Open Source forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

JavaMidi doesn't make a tone  RSS feed

 
Greenhorn
Posts: 12
Eclipse IDE Linux Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


To replicate:
1. Put this code in a file called MiniMusicCmdLine.java
2. run javac MiniMusicCmdLine.java
3. get no errors
4. run java MiniMusicCmdLine
5. NOTHING

As you can see, I get NO errors from the compiler. I, however, get no feedback from running it. The code is from HeadFirst Java 2nd Edition 2005. Page 346. Sorry if my style is not very good.
 
Marshal
Posts: 64471
225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you sure you copied the code right? Line 12: should read args[1]. Not that it helped when I corrected that. I am getting no sound either. Sorry I can't help any more.
 
Saloon Keeper
Posts: 2566
323
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have never used the MIDI API before, but this line looks problematic: a.setMessage(192, 1, instrument, 0);

I replaced it will a NOTE_ON message  using the specified note and a velocity of 100, and it did play-out:
    a.setMessage(ShortMessage.NOTE_ON, 1, note, 100);

References:
    Summary of MIDI Messages - Note On event
    javax.sound.midi.ShortMessage
 
Ranch Hand
Posts: 62
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think the MIDI commands are wrong, for note on you need to change it from 192 to 144 and you should hear something
Also, the program ends before you can hear anything so you need to add something like Thread.sleep() after player.start()
 
Ron McLeod
Saloon Keeper
Posts: 2566
323
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Adrian Grabowski wrote:I think the MIDI commands are wrong, for note on you need to change it from 192 to 144 and you should hear something


That is part of the problem.  Also instrument is being used for note, and the velocity is being set to zero - which I believe is equivalent to not pressing the key.

 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!