IPatch[] createPatches(javax.sound.midi.SysexMessage[] msgs)

Is an important method from Driver for your BankDriver.
(Driver inherits the method from IPatchDriver.)


Creates an array of patches from an array of SysexMessage for the driver. Returns an array of patches because Converter may be used. This is used for SysexMessages received by using requestPatchDump(int, int).
Parameters: msgs - an array of SysexMessage.
Returns: an array of IPatch value.
See Also: requestPatchDump(int, int), SysexGetDialog

If it doesn't work, try this advice that's found in the source:
        // Maybe you don't get the expected patch!
        // Check all devices/drivers again! Call fixpatch() if supportsPatch
        // returns false.
        // XXX Why don't we simply cause error? Hiroo

This is the part of the source of Driver where we find some action:

public IPatch[] createPatches(SysexMessage[] msgs) {
    byte[] sysex = MidiUtil.sysexMessagesToByteArray(msgs);
MidiUtil.sysexMessagesToByteArray(msgs) converts the SysexMessages that came from the synth
into a byte array that we name sysex.
    IPatch[] patarray = DriverUtil.createPatches(sysex, getDevice());
DriverUtil.createPatches returns an array of Patches with the given byte array sysex,
and the device that returns from Driver's getDevice() method. The device of a driver is set when you call the addDriver method in your synthDevice class.
The array of Patches is named patarray. The patches in the array contain the driver they are for because DriverUtil.createPatches(sysex, device) calls DriverUtil chooseDriver(sysex, device).
chooseDriver iterates over all drivers from the device, checking if the driver supports the sysex.
If it does, the driver is returned.
So you have to make sure that each driver that your bankDriver uses has a different sysexID!

Maybe you don't get the expected patch! Check all devices/drivers again! Call fixpatch() if supportsPatch returns false. (Why don't we simply cause error? Hiroo)
    for (int k = 0; k < patarray.length; k++) { // for each Patch in the array:
        IPatch pk = patarray[k]; // copy the Patch in a new Patch named "pk"
        String patchString = pk.getPatchHeader(); // get the PatchHeader from pk, name it "patchString"
So now we have one new Patch pk, and a hexadecimal String patchString.
From that patch, we get the driver: pk.getDriver(),
Then we pass patchString and sysex to that driver to
get a boolean by using that driver's method supportsPatch(PatchHeader patchString, byte[] sysex).
This method compares the hexadecimals in patchString to the bytes of sysex, checking if they are the same (=return true). If they are not the same, fixPatch makes them the same.
        if (!(pk.getDriver().supportsPatch(patchString, pk.getByteArray()))) { // If they are not the same,
            patarray[k] = fixPatch((Patch) pk, patchString); // fix pk with the right PatchHeader
        }
That's one Patch, repeat the above until patarray is finished. That means all Patches in patarray have these attributes set to the right value:
... tbc
    }
    return patarray;
}

All P

This are constructors of creatPatches in DriverUtil:


    /**
     * Factory method of Patch. Look up the driver for sysex byte array, and
     * create a patch by using the driver found. This is used for a byte array
     * read from a Sysex file, for which a Driver is not known.
     */
    public static IPatch[] createPatches(byte[] sysex) {
        return createPatches(sysex, chooseDriver(sysex));
    }
 
    /**
     * Factory method of Patch. Look up the driver of the specified Device for
     * sysex byte array, and create a patch by using the driver found.
     * @param device Device whose driver is looked up.
     */
    public static IPatch[] createPatches(byte[] sysex, Device device) {
        return createPatches(sysex, chooseDriver(sysex, device));
    }
 
    private static IPatch[] createPatches(byte[] sysex, IDriver driver) {
        if (driver == null)
            return null;
        else if (driver.isConverter())
            return ((IConverter) driver).createPatches(sysex);
        else
            return new IPatch[] { ((IPatchDriver) driver).createPatch(sysex) };
    }