Ableton Live VST output channels not work after changing

We noticed a special behavior in ableton live 11. I have an instrument plugin with 16 stereo outputs.

Reproduction steps:

  1. Load the plugin. Set the output of a pad to output for example to 6
  2. I choose an audio channel in ableton live and choose audio from output 6 like in the image below
    → all works ok so far. Audio is received by abletons audio channel 6
  3. When I now choose a higher audio output channel for example output 7 only in ableton
    → it outputs the audio that we output in output 7, even we still have output 6 selected in the plugin.
  4. I now change the output channel in the plugin to 7
    → Ableton outputs no audio anymore or on a different channel, also when i try to switch back to channel 6.

image

The code that assigns the pad outputs to the channels (i do this in the process block before processing the audio buffer):

        if (numberOfOutputChannels >= 2)
        {
            for (int i = 0; i < TalSampler::NumberOfPads; i++)
            {
                TalPad& talPad = talSampler.getPad(i);

                int padOutputIndex = talPad.getOutputIndex() * 2;

                int smallestPossibleIndex = numberOfOutputChannels - 1;
                if (padOutputIndex >= smallestPossibleIndex)
                {
                    padOutputIndex = smallestPossibleIndex - 1;
                }

                float *samples0 = buffer.getWritePointer(padOutputIndex);
                float *samples1 = buffer.getWritePointer(padOutputIndex + 1);

                talPad.setStereoOutput(samples0, samples1, sampleCounter);
            }
        }

Any help welcome. I didn’t notice any problems in other hosts so far.

It looks like ableton’s output write pointers change when i change the channels in the ableton UI.
Do i need to access the write pointers through the audio processor? Something like getBusBuffer()?

Could anyone reproduce?

Hmmm I cannot seem to reproduce this and it’s hard to see what your code is exactly doing without seeing the full AudioProcessor class. For example, where does numberOfOutputChannels come from?

I tried to create a quick pad instrument derived from the MultiOutSynthPlugInDemo. You can see the modified code below. Loading this into Ableton Live 11 and everything works as expected:

/*
  ==============================================================================

   This file is part of the JUCE examples.
   Copyright (c) 2022 - Raw Material Software Limited

   The code included in this file is provided under the terms of the ISC license
   http://www.isc.org/downloads/software-support-policy/isc-license. Permission
   To use, copy, modify, and/or distribute this software for any purpose with or
   without fee is hereby granted provided that the above copyright notice and
   this permission notice appear in all copies.

   THE SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES,
   WHETHER EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR
   PURPOSE, ARE DISCLAIMED.

  ==============================================================================
*/

/*******************************************************************************
 The block below describes the properties of this PIP. A PIP is a short snippet
 of code that can be read by the Projucer and used to generate a JUCE project.

 BEGIN_JUCE_PIP_METADATA

 name:                  MultiOutSynthPlugin
 version:               1.0.0
 vendor:                JUCE
 website:               http://juce.com
 description:           Multi-out synthesiser audio plugin.

 dependencies:          juce_audio_basics, juce_audio_devices, juce_audio_formats,
                        juce_audio_plugin_client, juce_audio_processors,
                        juce_audio_utils, juce_core, juce_data_structures,
                        juce_events, juce_graphics, juce_gui_basics, juce_gui_extra
 exporters:             xcode_mac, vs2022

 moduleFlags:           JUCE_STRICT_REFCOUNTEDPOINTER=1

 type:                  AudioProcessor
 mainClass:             MultiOutSynth

 useLocalCopy:          1

 pluginCharacteristics: pluginIsSynth, pluginWantsMidiIn

 END_JUCE_PIP_METADATA

*******************************************************************************/

#pragma once

#include "DemoUtilities.h"

class MutliOutEditor;

//==============================================================================
class MultiOutSynth  : public AudioProcessor
{
public:
    enum
    {
        maxMidiChannel    = 16,
        maxNumberOfVoices = 5
    };

    //==============================================================================
    MultiOutSynth()
        : AudioProcessor (BusesProperties()
                          .withOutput ("Output #1",  AudioChannelSet::stereo(), true)
                          .withOutput ("Output #2",  AudioChannelSet::stereo(), false)
                          .withOutput ("Output #3",  AudioChannelSet::stereo(), false)
                          .withOutput ("Output #4",  AudioChannelSet::stereo(), false)
                          .withOutput ("Output #5",  AudioChannelSet::stereo(), false)
                          .withOutput ("Output #6",  AudioChannelSet::stereo(), false)
                          .withOutput ("Output #7",  AudioChannelSet::stereo(), false)
                          .withOutput ("Output #8",  AudioChannelSet::stereo(), false)
                          .withOutput ("Output #9",  AudioChannelSet::stereo(), false)
                          .withOutput ("Output #10", AudioChannelSet::stereo(), false)
                          .withOutput ("Output #11", AudioChannelSet::stereo(), false)
                          .withOutput ("Output #12", AudioChannelSet::stereo(), false)
                          .withOutput ("Output #13", AudioChannelSet::stereo(), false)
                          .withOutput ("Output #14", AudioChannelSet::stereo(), false)
                          .withOutput ("Output #15", AudioChannelSet::stereo(), false)
                          .withOutput ("Output #16", AudioChannelSet::stereo(), false))
    {
        // initialize other stuff (not related to buses)
        formatManager.registerBasicFormats();

        for (int midiChannel = 0; midiChannel < maxMidiChannel; ++midiChannel)
        {
            synth.add (new Synthesiser());

            for (int i = 0; i < maxNumberOfVoices; ++i)
                synth[midiChannel]->addVoice (new SamplerVoice());
        }

        loadNewSample (createAssetInputStream ("singing.ogg"), "ogg");
    }

    //==============================================================================
    bool canAddBus    (bool isInput) const override   { return false; }
    bool canRemoveBus (bool isInput) const override   { return false; }

    //==============================================================================
    void prepareToPlay (double newSampleRate, int samplesPerBlock) override
    {
        ignoreUnused (samplesPerBlock);
		notesFromGUI.clear();

        for (auto* s : synth)
            s->setCurrentPlaybackSampleRate (newSampleRate);
    }

    void releaseResources() override {}

    void processBlock (AudioBuffer<float>& buffer, MidiBuffer& midiBuffer) override
    {
        auto busCount = getBusCount (false);
		
		MidiBuffer copy;
		copy.addEvents(midiBuffer, 0, -1, 0);
		
		{
			ScopedLock lock(midiBufferLock);
			copy.addEvents(notesFromGUI, 0, buffer.getNumSamples(), 0);
			
			MidiBuffer newShiftedGuiNotes;
			newShiftedGuiNotes.addEvents(notesFromGUI, buffer.getNumSamples(), -1, buffer.getNumSamples() * -1);
			notesFromGUI.swapWith (newShiftedGuiNotes);
		}

        for (auto busNr = 0; busNr < busCount; ++busNr)
        {
            if (synth.size() <= busNr)
                continue;

            auto midiChannelBuffer = filterMidiMessagesForChannel (copy, busNr + 1);
            auto audioBusBuffer = getBusBuffer (buffer, false, busNr);

            // Voices add to the contents of the buffer. Make sure the buffer is clear before
            // rendering, just in case the host left old data in the buffer.
            audioBusBuffer.clear();

            synth [busNr]->renderNextBlock (audioBusBuffer, midiChannelBuffer, 0, audioBusBuffer.getNumSamples());
        }
    }

    using AudioProcessor::processBlock;

    //==============================================================================
	AudioProcessorEditor* createEditor() override;
    bool hasEditor() const override                        { return true; }

    //==============================================================================
    const String getName() const override                  { return "Multi Out Synth PlugIn"; }
    bool acceptsMidi() const override                      { return false; }
    bool producesMidi() const override                     { return false; }
    double getTailLengthSeconds() const override           { return 0; }
    int getNumPrograms() override                          { return 1; }
    int getCurrentProgram() override                       { return 0; }
    void setCurrentProgram (int) override                  {}
    const String getProgramName (int) override             { return "None"; }
    void changeProgramName (int, const String&) override   {}

    bool isBusesLayoutSupported (const BusesLayout& layout) const override
    {
        const auto& outputs = layout.outputBuses;

        return layout.inputBuses.isEmpty()
            && 1 <= outputs.size()
            && std::all_of (outputs.begin(), outputs.end(), [] (const auto& bus)
               {
                   return bus == AudioChannelSet::stereo();
               });
    }

    //==============================================================================
    void getStateInformation (MemoryBlock&) override {}
    void setStateInformation (const void*, int) override {}

private:
	friend class MutliOutEditor;
    //==============================================================================
    static MidiBuffer filterMidiMessagesForChannel (const MidiBuffer& input, int channel)
    {
        MidiBuffer output;

        for (const auto metadata : input)
        {
            const auto message = metadata.getMessage();

            if (message.getChannel() == channel)
                output.addEvent (message, metadata.samplePosition);
        }

        return output;
    }

    void loadNewSample (std::unique_ptr<InputStream> soundBuffer, const char* format)
    {
        std::unique_ptr<AudioFormatReader> formatReader (formatManager.findFormatForFileExtension (format)->createReaderFor (soundBuffer.release(), true));

        BigInteger midiNotes;
        midiNotes.setRange (0, 126, true);
        SynthesiserSound::Ptr newSound = new SamplerSound ("Voice", *formatReader, midiNotes, 0x40, 0.0, 0.0, 10.0);

        for (auto* s : synth)
            s->removeSound (0);

        sound = newSound;

        for (auto* s : synth)
            s->addSound (sound);
    }

    //==============================================================================
    AudioFormatManager formatManager;
    OwnedArray<Synthesiser> synth;
    SynthesiserSound::Ptr sound;
	
	CriticalSection midiBufferLock;
	MidiBuffer notesFromGUI;

    //==============================================================================
    JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MultiOutSynth)
};

class MutliOutEditor : public AudioProcessorEditor, private Button::Listener
{
public:
	MutliOutEditor (MultiOutSynth& parent)
		: AudioProcessorEditor(parent), owner (parent),
	      buttons {TextButton{"1"}, TextButton{"2"}, TextButton{"3"}, TextButton{"4"}, TextButton{"5"}, TextButton{"6"}, TextButton{"7"}, TextButton{"8"}, TextButton{"9"}, TextButton{"10"}, TextButton{"11"}, TextButton{"12"}, TextButton{"13"}, TextButton{"14"}, TextButton{"15"}, TextButton{"16"} }
	{
		for (auto& btn : buttons)
		{
			addAndMakeVisible(btn);
			btn.addListener(this);
		}
		
		setSize (640, 40);
	}
	
	void resized() override
	{
		auto r = getLocalBounds();
		const auto width = r.getWidth() / buttons.size();
		for (auto& btn : buttons)
			btn.setBounds(r.removeFromLeft((int)width));
	}
	
private:
	MultiOutSynth& owner;
	std::array<TextButton, 16> buttons;
	
	void buttonClicked (Button* sender) override{
		if (auto it = std::find_if (buttons.begin(), buttons.end(), [sender] (const auto& btn) { return &btn == sender; }); it != buttons.end())
		{
			const int midiChannel = (int) std::distance(buttons.begin(), it);
			ScopedLock lock(owner.midiBufferLock);
			owner.notesFromGUI.addEvent (MidiMessage::noteOn (midiChannel + 1, 0x40, 1.f), 0);
			owner.notesFromGUI.addEvent (MidiMessage::noteOff (midiChannel + 1, 0x40, 1.f), static_cast<int>(std::round(owner.getSampleRate() * 2.)));
		}
	}
};

AudioProcessorEditor* MultiOutSynth::createEditor()
{
	return new MutliOutEditor (*this);
}

Edit: btw: obviously, don’t copy the above code verbatim in any real project. It contains multiple bad coding practices.

Thanks for looking at it. Your example helped a lot. I was able to find the problem. It looks like unused buses do not have channels in ableton and accessing the write pointer on the main buffer with buffer.getWritePointer(padOutputIndex); is dangerous and does not work in the VST3 case. I now also use getBusBuffer() instead:

    static AudioBuffer<float> getAudioBufferForBus(const AudioProcessor &audioProcessor, AudioSampleBuffer &buffer, int padOutputIndex)
    {
        auto audioBuffer = audioProcessor.getBusBuffer(buffer, false, padOutputIndex);
        int availableChannels = audioBuffer.getNumChannels();

        if (availableChannels < RequiredChannels)
        {
            audioBuffer = audioProcessor.getBusBuffer(buffer, false, 0);
        }
        
        return audioBuffer;
    }

This way I only send data to valid buses with stereo channels.

The behavior in ableton live is still not 100% clear to me. Ableton Live does not offer channels for a bus that is not used by a consumer channel. In this case, our plugin now takes the first stereo output that is always available. Unfortunately, the preview meter in ableton does show nothing when you want to select the right input bus because we can’t send anything to that bus.

Otherwise, all works now as expected.

All that works with the VST2 where we have fixed assigned outputs that are always available.

1 Like