The Java Developers Almanac 1.4


Order this book from Amazon.

   
Home > List of Packages > javax.sound.midi  [7 examples] > Properties  [4 examples]

e721. Setting the Volume of Playing Midi Audio

    // To create a Sequencer object, see e716 Loading and Playing Midi Audio
    
    if (sequencer instanceof Synthesizer) {
        Synthesizer synthesizer = (Synthesizer)sequencer;
        MidiChannel[] channels = synthesizer.getChannels();
    
        // gain is a value between 0 and 1 (loudest)
        double gain = 0.9D;
        for (int i=0; i<channels.length; i++) {
            channels[i].controlChange(7, (int)(gain * 127.0));
        }
    }

 Related Examples
e718. Determining the File Format of a Midi Audio File
e719. Determining the Duration of a Midi Audio File
e720. Determining the Position of a Midi Sequencer

See also: Events    Playing   


© 2002 Addison-Wesley.