How to control the volume of a MIDI channel

I have this code:

Synthesizer synthesizer = MidiSystem.getSynthesizer();
synthesizer.open();
Instrument[] instrument = synthesizer.getDefaultSoundbank().getInstruments();
synthesizer.loadInstrument(instrument[29]);
MidiChannel[] channels = synthesizer.getChannels();
MidiChannel channel = channels[1];
channel.programChange(29);
channel.noteOn(noteNumber, 127);
Teszthang.sleep(2000);
channel.noteOff(noteNumber);

so this is an example to play the sound in maximum volume (127) for 2 seconds. but I want to control the volume of the channel, as after 2 seconds, the volume disappears after another 2 seconds. How could I do this? I know these methods:

channel.controlChange(controller, value);
channel.setPolyPressure(noteNumber, pressure);

but they do not change any volume! I do not know how to use these methods. How can I change the channel volume after noteOn()during playback?

+4
source share
2 answers

You can use CC 7 to adjust the channel volume.

channel.controlChange(7, value);

see http://improv.sapp.org/doc/class/MidiOutput/controllers/controllers.html

+6
source

midi , . :

Track[] tracks = sequence.getTracks();
for (Track track : tracks){
for(int i = 0; i < track.size(); i++){
    if(!track.remove(track.get(i))){
        System.out.println("MIDI Event not removed");
    }
}}
0

All Articles