Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix backwards compatibility with 64ch REAPER versions #267

Merged
merged 7 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
#include "variable_block_adapter.hpp"
#include <version/eps_version.h>
#include <helper/resource_paths_juce-file.hpp>
#include <daw_channel_count.h>
#include "reaper_vst3_interfaces.h"
#include "reaper_integration.hpp"

#include <cassert>

#define DEFAULT_OSC_PORT 8000

Expand Down Expand Up @@ -45,7 +48,13 @@ using namespace ear::plugin;

//==============================================================================
EarBinauralMonitoringAudioProcessor::EarBinauralMonitoringAudioProcessor()
: AudioProcessor(_getBusProperties()) {
: AudioProcessor(BusesProperties()
.withInput("Input",
AudioChannelSet::discreteChannels(MAX_DAW_CHANNELS),
true)
.withOutput("Output",
AudioChannelSet::discreteChannels(MAX_DAW_CHANNELS),
true)) {

dataFileManager.onSelectedDataFileChange(
[this](ear::plugin::DataFileManager::DataFile const& df) {
Expand Down Expand Up @@ -198,17 +207,6 @@ void EarBinauralMonitoringAudioProcessor::timerCallback() {
processor_->setIsPlaying(false);
}

//==============================================================================
juce::AudioProcessor::BusesProperties
EarBinauralMonitoringAudioProcessor::_getBusProperties() {
auto ret = BusesProperties().withInput(
"Input", AudioChannelSet::discreteChannels(MAX_DAW_CHANNELS), true);
ret = ret.withOutput("Left Ear", AudioChannelSet::mono(), true);
ret = ret.withOutput("Right Ear", AudioChannelSet::mono(), true);
ret = ret.withOutput("(Unused)", AudioChannelSet::discreteChannels(MAX_DAW_CHANNELS-2), true);
return ret;
}

void EarBinauralMonitoringAudioProcessor::restartBearProcessor(
bool onlyOnConfigChange) {
std::lock_guard<std::mutex> lock(processorMutex_);
Expand Down Expand Up @@ -329,23 +327,10 @@ void EarBinauralMonitoringAudioProcessor::releaseResources() {
bool EarBinauralMonitoringAudioProcessor::isBusesLayoutSupported(
const BusesLayout& layouts) const {

// Must accept default config specified in ctor

if(layouts.inputBuses.size() != 1)
return false;
if (layouts.inputBuses[0] !=
AudioChannelSet::discreteChannels(MAX_DAW_CHANNELS))
return false;

if(layouts.outputBuses.size() != 3)
return false;
if(layouts.outputBuses[0] != AudioChannelSet::mono())
return false;
if(layouts.outputBuses[1] != AudioChannelSet::mono())
return false;
if (layouts.outputBuses[2] !=
AudioChannelSet::discreteChannels(MAX_DAW_CHANNELS - 2))
return false;
auto i = layouts.getMainInputChannels();
if (i != numDawChannels_) return false;
auto o = layouts.getMainOutputChannels();
if (o != numDawChannels_) return false;

return true;
}
Expand Down Expand Up @@ -526,6 +511,23 @@ void EarBinauralMonitoringAudioProcessor::setStateInformation(const void* data,
}
}

void EarBinauralMonitoringAudioProcessor::setIHostApplication(
Steinberg::FUnknown* unknown) {
auto reaperHost = dynamic_cast<IReaperHostApplication*>(unknown);
VST3ClientExtensions::setIHostApplication(unknown);
if (reaperHost) {
numDawChannels_ = DetermineChannelCount(reaperHost);
auto retI = setChannelLayoutOfBus(
true, 0, AudioChannelSet::discreteChannels(numDawChannels_));
auto retO = setChannelLayoutOfBus(
false, 0, AudioChannelSet::discreteChannels(numDawChannels_));
assert(retI && retO);
backend_ = std::make_unique<ear::plugin::BinauralMonitoringBackend>(
nullptr, numDawChannels_);
connector_->setListenerOrientationInstance(backend_->listenerOrientation);
}
}

//==============================================================================
// This creates new instances of the plugin..
AudioProcessor* JUCE_CALLTYPE createPluginFilter() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#include "bear_data_files.hpp"
#include "orientation_osc.hpp"

#include <daw_channel_count.h>

namespace ear {
namespace plugin {
namespace ui {
Expand All @@ -26,7 +28,8 @@ class BinauralMonitoringAudioProcessor;
class EarBinauralMonitoringAudioProcessor
: private AudioProcessorParameter::Listener,
Timer,
public AudioProcessor {
public AudioProcessor,
public VST3ClientExtensions {
public:
EarBinauralMonitoringAudioProcessor();
~EarBinauralMonitoringAudioProcessor();
Expand Down Expand Up @@ -59,6 +62,8 @@ class EarBinauralMonitoringAudioProcessor
void getStateInformation(MemoryBlock& destData) override;
void setStateInformation(const void* data, int sizeInBytes) override;

void setIHostApplication(Steinberg::FUnknown* unknown) override;

std::weak_ptr<ear::plugin::LevelMeterCalculator> getLevelMeter() {
return levelMeter_;
};
Expand Down Expand Up @@ -93,8 +98,6 @@ class EarBinauralMonitoringAudioProcessor
void timerCallback() override;

private:
BusesProperties _getBusProperties();

AudioParameterBool* bypass_;
AudioParameterFloat* yaw_;
AudioParameterFloat* pitch_;
Expand All @@ -119,6 +122,7 @@ class EarBinauralMonitoringAudioProcessor

int samplerate_{48000};
int blocksize_{512};
int numDawChannels_{MAX_DAW_CHANNELS};

std::shared_ptr<ear::plugin::LevelMeterCalculator> levelMeter_;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
#include "monitoring_plugin_editor.hpp"
#include "variable_block_adapter.hpp"

#include <daw_channel_count.h>
#include "reaper_vst3_interfaces.h"
#include "reaper_integration.hpp"

#include <cassert>

namespace ear {
namespace plugin {
Expand Down Expand Up @@ -52,27 +55,36 @@ ear::Layout const& layout() {
}
}

juce::AudioProcessor::BusesProperties
EarMonitoringAudioProcessor::_getBusProperties() {
numOutputChannels_ = layout().channelNames().size();
auto ret = BusesProperties().withInput(
"Input", AudioChannelSet::discreteChannels(MAX_DAW_CHANNELS), true);
for (const std::string& name : layout().channelNames()) {
ret = ret.withOutput(name, AudioChannelSet::mono(), true);
}
ret = ret.withOutput(
"(Unused)",
AudioChannelSet::discreteChannels(MAX_DAW_CHANNELS - numOutputChannels_),
true);
return ret;
void EarMonitoringAudioProcessor::setIHostApplication(
Steinberg::FUnknown* unknown) {
auto reaperHost = dynamic_cast<IReaperHostApplication*>(unknown);
VST3ClientExtensions::setIHostApplication(unknown);
if (reaperHost) {
numDawChannels_ = DetermineChannelCount(reaperHost);
auto retI = setChannelLayoutOfBus(
true, 0, AudioChannelSet::discreteChannels(numDawChannels_));
auto retO = setChannelLayoutOfBus(
false, 0, AudioChannelSet::discreteChannels(numDawChannels_));
assert(retI && retO);
backend_ = std::make_unique<ear::plugin::MonitoringBackend>(
nullptr, layout(), numDawChannels_);
}
}

//==============================================================================
EarMonitoringAudioProcessor::EarMonitoringAudioProcessor()
: AudioProcessor(_getBusProperties()) {
: AudioProcessor(
BusesProperties()
.withInput("Input",
AudioChannelSet::discreteChannels(MAX_DAW_CHANNELS),
true)
.withOutput("Output",
AudioChannelSet::discreteChannels(MAX_DAW_CHANNELS),
true)) {
auto speakerLayout = layout();
numOutputChannels_ = speakerLayout.channels().size();
backend_ = std::make_unique<ear::plugin::MonitoringBackend>(
nullptr, speakerLayout, MAX_DAW_CHANNELS);
nullptr, speakerLayout, numDawChannels_);
levelMeter_ = std::make_shared<ear::plugin::LevelMeterCalculator>(0, 0);
ProcessorConfig newConfig{getTotalNumInputChannels(),
getTotalNumOutputChannels(), 512,
Expand Down Expand Up @@ -131,24 +143,11 @@ void EarMonitoringAudioProcessor::releaseResources() {
bool EarMonitoringAudioProcessor::isBusesLayoutSupported(
const BusesLayout& layouts) const {

// Must accept default config specified in ctor

if(layouts.inputBuses.size() != 1)
auto i = layouts.getMainInputChannels();
if (i != numDawChannels_)
return false;
if (layouts.inputBuses[0] !=
AudioChannelSet::discreteChannels(MAX_DAW_CHANNELS))
return false;

auto outputBusCount = layouts.outputBuses.size();
auto expectedOutputBusCount = numOutputChannels_ + 1;
if(outputBusCount != expectedOutputBusCount)
return false;
for(int i = 0; i < numOutputChannels_; ++i) {
if(layouts.outputBuses[i] != AudioChannelSet::mono())
return false;
}
if (layouts.outputBuses[numOutputChannels_] !=
AudioChannelSet::discreteChannels(MAX_DAW_CHANNELS - numOutputChannels_))
auto o = layouts.getMainOutputChannels();
if (o != numDawChannels_)
return false;

return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <memory>

#include "components/level_meter_calculator.hpp"
#include <daw_channel_count.h>

namespace ear {
namespace plugin {
Expand Down Expand Up @@ -33,7 +34,8 @@ inline bool operator!=(ProcessorConfig const& lhs, ProcessorConfig const rhs) {
return !(lhs == rhs);
}

class EarMonitoringAudioProcessor : public AudioProcessor {
class EarMonitoringAudioProcessor : public AudioProcessor,
public VST3ClientExtensions {
public:
EarMonitoringAudioProcessor();
~EarMonitoringAudioProcessor();
Expand Down Expand Up @@ -70,15 +72,17 @@ class EarMonitoringAudioProcessor : public AudioProcessor {
return levelMeter_;
};

void setIHostApplication(Steinberg::FUnknown* unknown) override;

private:
BusesProperties _getBusProperties();
void configureProcessor(const ProcessorConfig& config);
ProcessorConfig processorConfig_{};
std::unique_ptr<ear::plugin::MonitoringBackend> backend_;
std::unique_ptr<ear::plugin::MonitoringAudioProcessor> processor_;

int samplerate_;
int numOutputChannels_;
int numDawChannels_{MAX_DAW_CHANNELS};
int numOutputChannels_{0};
std::shared_ptr<ear::plugin::LevelMeterCalculator> levelMeter_;

JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(EarMonitoringAudioProcessor)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@
#include "scene_plugin_editor.hpp"
#include <adm/write.hpp>
#include "programme_store_adm_serializer.hpp"
#include <future>
#include <programme_store.pb.h>
#include "scene_backend.hpp"
#include "metadata_event_dispatcher.hpp"
#include "pending_store.hpp"
#include "restored_pending_store.hpp"
#include <daw_channel_count.h>
#include "reaper_vst3_interfaces.h"
#include "reaper_integration.hpp"

#include <future>
#include <cassert>

SceneAudioProcessor::SceneAudioProcessor()
: AudioProcessor(
Expand All @@ -35,7 +38,7 @@ SceneAudioProcessor::SceneAudioProcessor()
}

levelMeter_ = std::make_shared<ear::plugin::LevelMeterCalculator>(
MAX_DAW_CHANNELS, samplerate_);
numDawChannels_, samplerate_);

samplesSocket = new SamplesSender();
samplesSocket->open();
Expand Down Expand Up @@ -122,18 +125,9 @@ void SceneAudioProcessor::releaseResources() {}
bool SceneAudioProcessor::isBusesLayoutSupported(
const BusesLayout& layouts) const {

// Must accept default config specified in ctor

if(layouts.inputBuses.size() != 1)
return false;
if (layouts.inputBuses[0] !=
AudioChannelSet::discreteChannels(MAX_DAW_CHANNELS))
return false;

if(layouts.outputBuses.size() != 0)
return false;
auto i = layouts.getMainInputChannels();
return i == numDawChannels_;

return true;
}

void SceneAudioProcessor::processBlock(AudioBuffer<float>& buffer,
Expand Down Expand Up @@ -162,9 +156,12 @@ void SceneAudioProcessor::processBlock(AudioBuffer<float>& buffer,
int bufferChannels = buffer.getNumChannels();
int bufferSamplesPerChannel = buffer.getNumSamples();

// TODO: We could do with a better system than sending channels of blanks,
// but at least this way we don't need to worry about DAW channel limits
// and routings in to the Scene.
for (int sample = 0; sample < bufferSamplesPerChannel; ++sample) {
for (int channel = 0; channel < numChannels; ++channel) {
curSample = buffer.getSample(channel, sample);
curSample = channel < bufferChannels? buffer.getSample(channel, sample) : 0.f;
assert(msgPosOffset + sampleSize <= msg_size);
memcpy(msgPosPtr + msgPosOffset, &curSample, sampleSize);
msgPosOffset += sampleSize;
Expand Down Expand Up @@ -212,7 +209,7 @@ void SceneAudioProcessor::doSampleRateChecks() {
auto curSampleRate = static_cast<int>(getSampleRate());
if (samplerate_ != curSampleRate) {
samplerate_ = curSampleRate;
levelMeter_->setup(MAX_DAW_CHANNELS, samplerate_);
levelMeter_->setup(numDawChannels_, samplerate_);
}
}

Expand Down Expand Up @@ -264,7 +261,7 @@ void SceneAudioProcessor::incomingMessage(std::shared_ptr<NngMsg> msg) {
future.get();

} else if (cmd == commandSocket->Command::GetConfig) {
uint8_t numChannels = MAX_DAW_CHANNELS;
uint8_t numChannels = numDawChannels_;
uint32_t sampleRate = samplerate_;
commandSocket->sendInfo(numChannels, samplerate_);

Expand Down Expand Up @@ -296,6 +293,18 @@ void SceneAudioProcessor::setupBackend() {
}
}

void SceneAudioProcessor::setIHostApplication(Steinberg::FUnknown* unknown) {
auto reaperHost = dynamic_cast<IReaperHostApplication*>(unknown);
VST3ClientExtensions::setIHostApplication(unknown);
if (reaperHost) {
numDawChannels_ = DetermineChannelCount(reaperHost);
auto ret = setChannelLayoutOfBus(
true, 0, AudioChannelSet::discreteChannels(numDawChannels_));
assert(ret);
levelMeter_->setup(numDawChannels_, samplerate_);
}
}

ear::plugin::Metadata &SceneAudioProcessor::metadata() {
return metadata_;
}
Expand Down
Loading
Loading