• 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

Receiving a short message from a midi controller and printing the short message

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello all!

I'm very new to programming, especially when it comes to dealing with midi. As a starter I really want to make a simple program which can receive short messages from my midi keyboard and then print the resulting three bytes whenever I press a midi key. Ive gone through the Java midi overview and even looked at some Stack overflow examples. I found some examples on Stack which i could copy and paste and get certain results but didn't really understand any of it. What I am really after is an understanding of the process of receiving the information from my key board. Can anyone help me with this ? Thanks! Hope you all are doing well.

Best
Alex
 
Ranch Hand
Posts: 954
4
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what are your thoughts on it? Please share it.
 
Alex Acree
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I guess I understand how to set up a receiver, but am confused about how to get the midi info from my receiver and print it through System.out.println(). Ive got a basic idea of how the code I need to write might look, but am lost on certain concepts that I can't seem to find any information on The way I'm thinking of it is that I have a MyReceiver class which implements Receiver, and a MidiToPrint class which contains methods that are used to print the midi info, then in my main arguments ill create a MidiToPrint object which will call a printMidi method from the MidiToPrint class which I created. Im just really confused about how the information is supposed to flow from the receiver to my MidiToPrint object. These are all ideas I've thought up so I'm sure there might be a better way to think about it, but sadly i can't really find that much information on coding with midi other than examples of specific problems on stack overflow which are a little beyond the simple task I wish to accomplish
 
Sheriff
Posts: 28331
97
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yeah, well, Stack Overflow is great if you have a specific question but if you need a tutorial it's... what you found out, not so great.

And when I search the web for java midi tutorial I get a much more useful-looking list of resources starting with Overview of the MIDI Package. There's some sample code in the tutorials of which that's one, and it's probably better to work your way through those tutorials and play around with the sample code which they provide. That way you'll get a basic understanding of the classes you need, instead of starting in the middle of the learning process.
 
Paul Clapham
Sheriff
Posts: 28331
97
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And, welcome to the Ranch!
 
Alex Acree
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Paul

Thanks for the reply, and Im happy to be here ! Ive actually already gone through the Oracle article. Theres some good stuff, but I'm still unsure about how to accomplish my first midi goal. For one they didn't really talk about receiving data and then using it, but more so just about how to send midi data. What confuses me I guess is where the midi data comes into the program and how to extract it from that place. Also i was looking for books on the subject of writing code for midi and the most recent book I could find was Maximum Midi which was written in 1997, so if anyones heard of some decent writing on the subject  please let me know. Again thanks so much!
 
Paul Clapham
Sheriff
Posts: 28331
97
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay... you mentioned a "midi keyboard" and I'm not clear on whether that's some kind of hardware or something else. If it's hardware then the "Accessing MIDI System Resources" tutorial should have enabled you to get a reference to that device. And then, if I'm reading the tutorial right, you should be able to get a Receiver from that device. Have you got that far?
 
Paul Clapham
Sheriff
Posts: 28331
97
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, I think I'm mixed up. Your hardware keyboard (if that's what you have) should be able to provide you with a Transmitter which transmits data when a key is pressed.
 
Alex Acree
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Paul

I have a receiver which is connected to the transmitter from my midi controller, which is an external piece of hardware. What I'm having trouble with is the ability to access the information that the receiver is getting from my external hardware's transmitter. In the oracle article it talks about this scenario where my receiver is apart of a synth and in turn transforms the midi info into music. I guess my confusion lies in the fact that I only have my receiver on its own and don't wish to use a synth, but simply to take the info the receiver is receiving from the transmitter and print it as the corresponding 3 bytes in the note messages when i press the keys on the controller.
 
Alex Acree
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is what the code looks like that Im using to connect the receiver and the external transmitter.

Transmitter trans = null;
     
      try {
      trans= MidiSystem.getTransmitter();
      }
      catch(MidiUnavailableException e)
      {
          System.out.println("No Midi port Detected");
      }
   
   trans.setReceiver(receiver);
   
 
Alex Acree
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Again thanks for helping me out. This site seems to be pretty great.
 
Alex Acree
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Going through the Java I/O class at the moment...... maybe this is where the solution lies.
 
Alex Acree
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay ! I've almost figured it out. I think my problem lies in my understanding of the way methods work. Inside the method send in my receiver class which implements receiver, I set message = to an integer variable and printed it which my computer responded to when i pressed the midi controller! I am very close. All I need to do now is figure out how to get the entire short message instead of just the status byte or the length.
 
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Alex.  Just a note on the code you posted.  It's possible to get to the last line and trans will be null, in which case you'd get a NullPointerException (NPE).  I'd either move the last line into the try block or put an if statement around the last line.

One more thing, when you post code, please UseCodeTags (that's a link).
 
Rancher
Posts: 4801
50
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't know if this will help at all, but this is where I tend to go for Java sound stuff:
http://www.jsresources.org/

 
Alex Acree
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks everyone for responding ! I'm giving you all up votes
 
I don't like that guy. The tiny ad agrees with me.
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