[FR] AudioProcessorGraph addConnections/removeConnections

Okay a report back… I made the changes and it’s dramatically improved the profiling of my plug-in… Since I rarely just make a single connection at a time… I added methods to use OwnedArray::add() instead of OwnedArray::addSorted() and defer buildRenderingSequence() like:

 bool AudioProcessorGraph::addConnectionUnsorted (const uint32 sourceNodeId,
                                                  const int sourceChannelIndex,
                                                  const uint32 destNodeId,
                                                  const int destChannelIndex)
 {
     const ScopedLock sl (buildLock);

     if (! canConnect (sourceNodeId, sourceChannelIndex, destNodeId, destChannelIndex))
         return false;

     connections.add (new Connection (sourceNodeId, sourceChannelIndex, destNodeId, destChannelIndex));

     return true;
 }

After I make all the connections I call another new method:

  void AudioProcessorGraph::sortConnections()
 {
     GraphRenderingOps::ConnectionSorter sorter;

     connections.sort (sorter);

     if (isPrepared)
         triggerAsyncUpdate();
 }

For other methods I added an extra parameter with a default value for backward compatibility:

   void AudioProcessorGraph::removeConnection (const int index, bool triggerUpdate /* = true */)
  {
      connections.remove (index);

      if (isPrepared && triggerUpdate)
          triggerAsyncUpdate();
  }

(I did this for addNode() and removeNode() as well).

This change has reduced the time to reload a preset, where the connections are created dynamically, by more than 50% and made other functions in the plug-in much more responsive if they involve changing connections.

My testers have had it for 2 weeks with no reports of any issues.


I’ve also added another change to AudioProcessorGraph::Node to have a boolean class variable (named bypassed) which is used to easily bypass hosted plugins in the graph simply by changing the Node’s flag which is then checked in (float and double versions)

void callProcess (AudioBuffer<float>& buffer, MidiBuffer& midiMessages)
{
    if (node->isBypassed())
        processor->processBlockBypassed (buffer, midiMessages);
    else
        processor->processBlock (buffer, midiMessages);
}

I also still have my previous changes for PDC described in this thread:

Cheers,

Rail