Frage

I use the following code to load and play a MIDI file with JFugue:

import java.io.File;

import org.jfugue.Pattern;
import org.jfugue.Player;

public class PlayMidiFromFile {

    public static void main(final String[] args) {
        try {
            final Player player = new Player();
            final Pattern pattern = player.loadMidi(new File("sample.mid"));
            player.play(pattern);
        } catch (final Exception e) {
            e.printStackTrace();
        }
    }
}

The file was generated with ChordPulse and playback with other programs works fine.

It contains multiple tracks with a different instrument for each, but the Player only uses piano for all and some tracks seem to be missing.

How to fix this? Are there certain MIDI messages, that are not recognized by the parser? Are there any precondition about how the song is using tracks and channels or other known limitations or neccessary initialization steps?

War es hilfreich?

Lösung

The tuba part is still played by the piano, but, apart from that, the MIDI support obviously has been improved in the beta version 5.

An update of the snippet above (reflecting the API changes):

import java.io.File;

import org.jfugue.midi.MidiFileManager;
import org.jfugue.pattern.Pattern;
import org.jfugue.player.Player;

public class PlayMidiFromFile {

    public static void main(final String[] args) {
        try {
            final Player player = new Player();
            final Pattern pattern = MidiFileManager.loadPatternFromMidi(new File("sample.mid"));
            player.play(pattern);
        } catch (final Exception e) {
            e.printStackTrace();
        }
    }
}
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top