JDK-4685396 : method Synthesizer.remapInstrument() does not work
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.sound
  • Affected Version: 1.4.1
  • Priority: P2
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2002-05-15
  • Updated: 2017-05-16
  • Resolved: 2006-07-19
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 6
6 b80Fixed
Related Reports
Duplicate :  
Relates :  
Description
Name: vtR10009			Date: 05/15/2002


  Spec for Synthesizer.remapInstrument() from the package
javax.sound.midi reads:
" Remaps an instrument. Instrument to takes the place of instrument from. 
For example, if from was located at bank number 2, program number 11, 
remapping causes that bank and program location to be occupied instead 
by to. Instrument from is unloaded.
  Parameters:
     from - instrument to be replaced
     to - new instrument to be used in place of the old instrument
  Returns:
     true if the instrument could be remapped, false otherwise."

But default synthesizer does not unload "from" instrument and load "to"
instead. Such behavior contradicts to the spec.

This bug causes failure of new JCK test:
  api/javax_sound/midi/Synthesizer/index.html#remap
  
To reproduce the bug run the following test with JDK build with 1.4.1-beta-b11:
------------------------------- test.java --------------------------------
import javax.sound.midi.*;

public class test{
    public static boolean isInstrumentExist(Instrument inst, Instrument[] 
instArr) {
        for (int i = 0; i < instArr.length; i++) {
            if (inst.equals(instArr[i])) return true;
        }
        return false;
    }
    public static void main(String args[]) {
        boolean failed = false;
        Synthesizer synth = null;
    
        Instrument[] instrs, avInstrs;
        Instrument from, to;
        Soundbank sBank;
    
        try {
            synth = MidiSystem.getSynthesizer();
            synth.open();
    
            instrs = synth.getLoadedInstruments();
            for (int i = 0; i < instrs.length; i++) {
                synth.unloadInstrument(instrs[i]);
            }
    
            if (instrs.length != 0) {
                System.err.println(" Non-zero length array!");
                failed = true;
                for (int i = 0; i < instrs.length; i++) {
                    System.err.println("Instrument: " + instrs[i]);
                }
            }
            
            sBank = synth.getDefaultSoundbank();
            if (sBank == null) {
                System.err.println("No default bank. Ok.");
                System.exit(1);
            }
    
            instrs = sBank.getInstruments();
            if (synth.loadAllInstruments(sBank)) {
                synth.unloadInstrument(instrs[instrs.length - 1]);
                from = instrs[0];
                to = instrs[instrs.length - 1];
                if (!synth.remapInstrument(from, to)) {
                    System.err.println(" Instrument does not mapped!");
                    failed = true;
                } else {
                    if (isInstrumentExist(from, synth.getLoadedInstruments())) {
                        System.err.println(" Instrument from is not unloaded.");
                        failed = true;
                    }
                    if (!isInstrumentExist(to, synth.getLoadedInstruments())) {
                        System.err.println(" Instrument to is not correctly" +
                                   mapped.");
                        failed = true;
                    }
                }
            }
            
    
        } catch (MidiUnavailableException mue) {
            System.err.println("MidiUnavailableException was thrown: " + mue);
            System.exit(1);
        } finally {
            if (synth != null) synth.close();
        }
    
        if (failed == true) {
            System.exit(1);
        } else {
            System.exit(0);
        }
    }
}
---------------------------Logs-------------------------------------------
novo101:templates$ javac test.java ; java -showversion test
java version "1.4.1-beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1-beta-b11)
Java HotSpot(TM) Client VM (build 1.4.1-beta-b11, mixed mode)

 Instrument from is not unloaded.
 Instrument to is not correctly mapped.

--------------------------------------------------------------------------
======================================================================

Comments
EVALUATION It looks like native code remaps the instrument and after remap new instrument sounds instead replaced one, but java implementation doesn't change its instrument list accordingly. Also implementation doesn't unload "from" instrument. It's too risky to fix in mustang, retargeting to dolphin.
07-10-2005

CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: dragon
14-06-2004

PUBLIC COMMENTS method ramapInstrument does not work
10-06-2004

EVALUATION ###@###.### 2002-05-15 Implementations should have the possibility to not implement this feature. Committing to Mantis. ###@###.### 2002-11-25 Further investigation showed that this is really an implementation problem - it seems that the implementation does not really remaps the instrument, but reports true. Committing to Tiger. The TCK test should be adapted to not fail when remapIntrument returns false. ###@###.### 2003-09-22 No time for tiger. Commit to dragon.
22-09-2003