Java MIDI - getting data from piano?

前端 未结 2 1682
無奈伤痛
無奈伤痛 2020-12-14 12:55

I\'ve inherited a Java project that used an old C++ dll to receive MIDI data from a piano connected to the computer.

Now that Java has built-in support for MIDI devi

2条回答
  •  眼角桃花
    2020-12-14 13:28

    Yes, the JavaSound API can be used to read MIDI data from a MIDI device.

    JFugue is a Java API for music programming that uses the JavaSound API, and can help simplify your interaction with JavaSound. In JFugue 5.x, sample code to capture 10 seconds of MIDI data from a MIDI device is as follows:

    MidiDevice device = /* specify a MIDI device */
    MusicTransmitterToSequence transmitter = new MusicTransmitterToSequence(device); 
    transmitter.listenForMillis(10000); 
    Sequence music = transmitter.getSequence();
    

    You can also start and stop listening to a device:

    MidiDevice device = /* specify a MIDI device */
    MusicTransmitterToSequence transmitter = new MusicTransmitterToSequence(device); 
    transmitter.startListening(); 
    // Do stuff
    transmitter.stopListening(); 
    Sequence music = transmitter.getSequence();
    

提交回复
热议问题