Add Sidechain to mix

I’m trying to get the audio from the sidechain input to mix with the main input of my audio plugin but I can never hear it. When I load the plugin in Cubase, I can see that Cubase is sending the audio signal to the sidechain input via the “setup sidechain inputs” tab so at the moment I’m presuming it is getting in.

My fader works for the main incoming audio but nothing for the sidechain

I’m trying this

: AudioProcessor(BusesProperties()
    .withInput("Stereo In", juce::AudioChannelSet::stereo(), true)
    .withOutput("Stereo Out", juce::AudioChannelSet::stereo(), true)
    .withInput("Sidechain", juce::AudioChannelSet::stereo(), true)

	auto* channelData1 = buffer.getWritePointer(0); 
	for (int sample = 0; sample < buffer.getNumSamples(); ++sample)
		channelData1[sample] = channelData1[sample] * juce::Decibels::decibelsToGain(gain_CH01);
	auto* channelData2 = buffer.getWritePointer(1);
	for (int sample = 0; sample < buffer.getNumSamples(); ++sample)
		channelData2[sample] = channelData2[sample] * juce::Decibels::decibelsToGain(gain_CH01);

	auto* channelData3 = buffer.getWritePointer(2);
	for (int sample = 0; sample < buffer.getNumSamples(); ++sample)
		channelData3[sample] = channelData3[sample] * juce::Decibels::decibelsToGain(gain_CH01);

	auto* channelData4 = buffer.getWritePointer(3);
	for (int sample = 0; sample < buffer.getNumSamples(); ++sample)
		channelData4[sample] = channelData4[sample] * juce::Decibels::decibelsToGain(gain_CH01);

I know this can be written better with for loops but I’m trying to break it down a bit so I can understand what is (isn’t) happening.

Any help appreciated.

-Edited - Formatting

In the code snippet above, where would you actually expect the mixing (e.g. adding up channels 0 and 1 with channels 2 and 3) expect to happen? All you do is applying some gain to the side chain and then let it end somewhere in the nowhere afterwards – or did you forget some piece of code?

Side note: Please always surround all your code snippets with a line of ``` above and below the code, this will make it appear in a better readable way.

Thanks, edited as requested.

Yes, I’m definitely missing something, this is my issue, I’m trying to work out where it goes next. I’ve only included the fader to make it easy for me to know that audio is passing through my plugin.
In the original example, I can see that ChannelData[sample] is updated but I can’t see how it makes its way out of the plugin.

void CompressorAudioProcessor::processBlock (AudioBuffer& buffer, MidiBuffer& midiMessages)
auto mainBuffer = getBusBuffer(buffer, true, 0);
auto sidechainBuffer = getBusBuffer(buffer, true, 1);

I’ve only just started working with sidechains but this is working nicely for me. This will give each input type as a separate buffer so you can work with.

You would need to add the side chain samples to the main buffer as these are the ones that are actually output - you have 4 inputs, 2 outputs with that bus layout. As PluginPenguin said, you are only applying gain to each channel, not routing them to the correct output channel.

Thanks both

Turns out all I was after was

channelData1[sample] += channelData3[sample] etc