readBusLayoutFromXml doesn't works

Hi, on my host I used the same algorithm to restore layout of plugins I used, but while (WITH THE SAME CODE) restoring a plugin like kontakt saved with 4 LR bus in input and 4 LR bus in output in AudioPluginHost works fine in my app readBusLayoutFromXml returns after ** if (! plugin.addBus (isInput))

This is the xml passed on both func (mine and of audioPluginHost) for plugin KONTAKT:

    <LAYOUT>
      <INPUTS>
        <BUS index="0" layout="L R"/>
        <BUS index="1" layout="L R"/>
        <BUS index="2" layout="L R"/>
        <BUS index="3" layout="L R"/>
      </INPUTS>
      <OUTPUTS>
        <BUS index="0" layout="L R"/>
        <BUS index="1" layout="L R"/>
        <BUS index="2" layout="L R"/>
        <BUS index="3" layout="L R"/>
      </OUTPUTS>
    </LAYOUT>

As you can see code is exactly the same:

static void readBusLayoutFromXml (AudioProcessor::BusesLayout& busesLayout, AudioProcessor& plugin,
                                  const XmlElement& xml, bool isInput)
{
    auto& targetBuses = (isInput ? busesLayout.inputBuses
                                 : busesLayout.outputBuses);
    int maxNumBuses = 0;

    if (auto* buses = xml.getChildByName (isInput ? "INPUTS" : "OUTPUTS"))
    {
        if (buses->hasTagName("INPUTS")) { DBG("INPUTS"); } else { DBG("OUTPUTS"); }
        for (auto* e : buses->getChildWithTagNameIterator ("BUS"))
        {
            const int busIdx = e->getIntAttribute ("index");
            maxNumBuses = jmax (maxNumBuses, busIdx + 1);

            for (int actualIdx = plugin.getBusCount (isInput) - 1; actualIdx < busIdx; ++actualIdx)
                if (! plugin.addBus (isInput))
                    return; //this is called after evaluating "index 1"

            for (int actualIdx = targetBuses.size() - 1; actualIdx < busIdx; ++actualIdx)
                targetBuses.add (plugin.getChannelLayoutOfBus (isInput, busIdx));

            auto layout = e->getStringAttribute ("layout");

            if (layout.isNotEmpty())
                targetBuses.getReference (busIdx) = AudioChannelSet::fromAbbreviatedString (layout);
        }
    }

    while (maxNumBuses < targetBuses.size())
    {
        if (! plugin.removeBus (isInput))
            return;

        targetBuses.removeLast();
    }
}

there’s something I’m missing on plugin to set before passing it to this func?

Are you using the same plugin format (AU/VST2/VST3) for Kontakt in both cases? Adding and removing buses is only supported for some plugin formats.

Your best path forwards is probably to stick a breakpoint on the line calling addBus, then stepping in and finding out why adding the bus fails.

1 Like

Yes, they’re both AudioUnit…

I tried and addBus return false in

    if (! canApplyBusCountChange (isInput, true, busesProps))
        return false;

I really don’t want to bother… but I can’t figure out where could be the problem… could it be that AudioPluginHost is a basic gui application while mine is a plugin application that exports stand alone AU and VST3 ? really don’t know where and how to debug this problem, code is simple and it’s really the same of AudioPluginHost and xml that is captured by readBusLayoutFromXml contains right infos and is parsed well…

Found… it’s really stupid to fix but maybe could be helpful for someone else:

Graph must be suspended

So before calling

    readBusLayoutFromXml (layout, *processor, layoutEntity, true);
    readBusLayoutFromXml (layout, *processor, layoutEntity, false);

    processor->setBusesLayout (layout);

I call

graph.suspendProcessing(true);
graph.releaseResources();

and after:

graph.prepareToPlay (getSampleRate(), getBlockSize());
graph.suspendProcessing(false);
1 Like