Question

I would like to make use of the data coming from a MIDI in device. I need to be notified when certain events occur so that I can do things like transpose certain notes on the fly or call a method or whatever you can think of.

Although I'm quite new to programming in general and to java in particular I have already been able to play a sequence with the sequencer using javax.sound.midi. I can even add a listener that tells me when certain events are played by the sequencer. Now I was hoping to be able to do something similar with the MIDI IN stream but I don't know how.

Any ideas or workarounds would be welcome because I'm quite stuck at the moment.

No correct solution

OTHER TIPS

To record MIDI data, you have to

  • connect the input port's Transmitter to your Sequencer's Receiver by calling its setReceiver method,
  • create new Sequence/Track objects, and connect them to the Sequencer,
  • enable recording on your track(s), and
  • start recording on your Sequencer.

(see the documentation)

I finally found the solution and I'd like to clarify the question and add my solution in case it is helpful for anybody else.

The project I'm working on (which is way over my head by the way) is a midi keyboard arranger. In case you don't know what it is, it's a keyboard that plays patterns (styles) and changes the tone and the arrangement depending on the chord played. What I needed was what I think is called a dump from the midi in port so that my program can figure out what chord has been played so that it can have the sequencer respond in different ways.

So to respond my own original question to do this you need to create a new transmitter for your midi in port. Then create a new receiver to receive the data stream from the new transmitter. Finally have the receiver send the data to a PrintStream and then you can do what you want with the data stream!

Implement the send(javax.sound.midi.ShortMessage, long) method of the javax.sound.midi.Receiver interface in a class of your own and use the instances of the latter as you would with other Receiver objects.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top