问题
Can someone show me how to control the volume of an MIDI sequencer without using a sound bank or synthesizer?
I want to make the MIDI fade out before continuing to the next MIDI in sequence
if(midiplay)
{
midi = s + savereq;
try {
//System.out.println("Play MIDI " + midi);
if (musicSr != null)
{
/* This is where I want it to fade out*/
musicSr.stop(); //stop sequencer
musicSr.close(); //close sequencer
}
musicSr = null;
musicS = null;
File music = new File(midi);
if(music.exists())
{
musicS = MidiSystem.getSequence(music);
}
// Create a sequencer for the sequence
musicSr = MidiSystem.getSequencer();
musicSr.open();
musicSr.setSequence(musicS);
musicSr.setLoopCount(musicSr.LOOP_CONTINUOUSLY);
musicSr.start();
} catch (Exception ex) {
ex.printStackTrace();
}
midiplay = false;
}
回答1:
- Call getSequence to get the Sequence;
- call getTracks to get the list of tracks;
in each track, for each channel used in the track, call add to add multiple events at the appropriate time positions:
track.add(new MidiEvent( new ShortMessage(ShortMessage.CONTROL_CHANGE, channel, 7, volume), tick));
- maybe remove other volume change events (that would interfere with your fadeout) from the track;
- wait a little time for the fadeout to happen.
来源:https://stackoverflow.com/questions/18992815/whats-the-method-to-control-volume-in-an-midi-sequencer