how to control master midi volume with 1.5.0?

the following doesn’t work with 1.5

public void setVolume(float gain){
try {
  Synthesizer synthesizer = (Synthesizer) o;
  MidiChannel[] channels = synthesizer.getChannels();
  for (int i = 0; i < channels.length; i++) channels[i].controlChange(7, (int) (gain * 127.0));
}
catch (Exception ex) {ex.printStackTrace();}

better described here:
http://archives.java.sun.com/cgi-bin/wa?A2=ind0408&L=javasound-interest&F=&S=&P=5877

any solutions?
I have a little midiplayer with volume control in my game (esc, options screen, if u want to verify) :slight_smile:

YES!
solution by Andrew Davison:
http://fivedots.coe.psu.ac.th/~ad/jg/ch05/index.html

does NOT work with 1.5.0_02-b09
successfully tested with 1.5.0_04-b05 and 1.6.0-ea-b45

 private void initSequencer() 
  /* Set up the MIDI sequencer, the sequencer's meta-event
     listener, and its synthesizer. */
  {
    try {
      sequencer = obtainSequencer();

      if (sequencer == null) {
        System.out.println("Cannot get a sequencer");
        System.exit(0);
      }

      sequencer.open();
     // sequencer.addMetaEventListener(this);

      // maybe the sequencer is not the same as the synthesizer
      // so link sequencer --> synth (this is required in J2SE 1.5)
      if (!(sequencer instanceof Synthesizer)) {
        System.out.println("Linking the MIDI sequencer and synthesizer");
        synthesizer = MidiSystem.getSynthesizer();
	    synthesizer.open();  // new
        Receiver synthReceiver = synthesizer.getReceiver();
        Transmitter seqTransmitter = sequencer.getTransmitter();
        seqTransmitter.setReceiver(synthReceiver);
      }
      else 
        synthesizer = (Synthesizer) sequencer;
    }
    catch (MidiUnavailableException e){
      System.out.println("No sequencer available");
      System.exit(0);
    }
  } // end of initSequencer()


  private Sequencer obtainSequencer()
  /* This method handles a bug in J2SE 1.5.0 which retrieves
     the sequencer with getSequencer() but does not allow
     its volume to be changed. */
  {
    // return MidiSystem.getSequencer();   
    // okay in J2SE 1.4.2, but not in J2SE 1.5.0

    MidiDevice.Info[] mdi = MidiSystem.getMidiDeviceInfo();
    int seqPosn = -1;
    for(int i=0; i < mdi.length; i++) {
      System.out.println(mdi[i].getName());
      // if (mdi[i].getName().contains("Sequencer")) {
      if (mdi[i].getName().indexOf("Sequencer") != -1) {
        seqPosn = i;    // found the Sequencer
        System.out.println("  Found Sequencer");
      }
    }

    try {
      if (seqPosn != -1)
        return (Sequencer) MidiSystem.getMidiDevice( mdi[seqPosn] );
      else
        return null;
    }
    catch(MidiUnavailableException e)
    { return null; }
  }  // end of obtainSequencer()