AudioBlock::copyTo issue after upgrade to 5.4.4

Hello,

I am using in my code juce::dsp::AudioBlock::copyTo method, because I need a temporary copy of the input signal. After upgrading JUCE to 5.4.4 I got an error while compiling:

Error	C2664	'const juce::dsp::AudioBlock<const float> &juce::dsp::AudioBlock<const float>::copyTo(juce::AudioBuffer<const float> &,size_t,size_t,size_t) const': cannot convert argument 1 from 'juce::AudioBuffer<float>' to 'juce::AudioBuffer<const float> &'	AudioBlockCopyToIssue_SharedCode	c:\users\mateusz\workspace\small_projects\audioblockcopytoissue\source\pluginprocessor.cpp	138	

I have prepared an example project: https://gitlab.com/mateusz.salski/audioblockcopytoissue/
There are exporters for Visual Studio and XCode.

The problem is illustrated in method:

void AudioBlockCopyToIssueAudioProcessor::processBlock (AudioBuffer<float>& buffer, MidiBuffer& /*midiMessages*/)
{
    ScopedNoDenormals noDenormals;

	juce::dsp::AudioBlock<float> block{ buffer };
	juce::dsp::ProcessContextReplacing<float> context{ block };
    
	auto& inBlock = context.getInputBlock();
	inBlock.copyTo(tempBuffer); // <---- Compile error
}

tempBuffer is of type AudioBuffer<float>, but for some reason AudioBlock::copyTo expects AudioBlock<const float>, if I understand the error message correctly. What does not make sense because copyTo would modify buffer.
IMHO the problem is return type of context.getInputBlock().

I double checked on Windows that this code compiles with JUCE 5.4.3. On MacOSX I only checked that this is not compiling with 5.4.4.

Could you please help me to resolve this? I have no idea how could I fix it on my own.

Change

The AudioBlock class now differentiates between const and non-const data.

Possible Issues

The return type of the getInputBlock() method of the ProcessContextReplacing
and ProcessContextNonReplacing classes has changed from AudioBlock to
AudioBlock.

Workaround

For ProcessContextReplacing you should use getOutputBlock() instead of
getInputBlock(). For ProcessContextNonReplacing attempting to modify the input
block is very likely an error.

Rationale

This change makes the intent of the code much clearer and means that we can
remove some const_cast operations.

Actually, that does look like a mistake - copyTo should take a templated destination type rather than the same sample type as the object itself - thanks, we’ll sort that out!

Thank you @MBO and @jules.
I will track dev branch for fix and use above workaround if necessary.

Thanks - yes, this has raised a few issues, we’re going to review that class to try to give it more obvious behaviour!

The fix works great. Thank you. :slight_smile: