Skip to content

Commit

Permalink
Enforce use of AdmPresetDefinitionsHelper as singleton using reference
Browse files Browse the repository at this point in the history
  • Loading branch information
firthm01 committed Feb 29, 2024
1 parent c16a1ae commit 5567fd2
Show file tree
Hide file tree
Showing 30 changed files with 76 additions and 88 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include "ear-plugin-base/export.h"
#include "scene_gains_calculator.hpp"
#include "listener_orientation.hpp"
#include "helper/adm_preset_definitions_helper.h"

#include <string>
#include <memory>
Expand Down Expand Up @@ -103,9 +102,6 @@ class BinauralMonitoringBackend {
std::unique_ptr<communication::MonitoringMetadataReceiver> metadataReceiver_;
communication::MonitoringControlConnection controlConnection_;

std::mutex commonDefinitionHelperMutex_;
AdmPresetDefinitionsHelper commonDefinitionHelper{};

bool isExporting_{ false };
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "helper/protobuf_utilities.hpp"
#include "helper/adm_preset_definitions_helper.h"
#include <string>
#include <memory>
#include <adm/detail/id_parser.hpp>

namespace ear {
Expand Down Expand Up @@ -54,11 +55,9 @@ struct EpsToEarMetadataConverter {
return earMetadata;
}
static ear::HOATypeMetadata convert(
const proto::HoaTypeMetadata &epsMetadata,
AdmPresetDefinitionsHelper &commonDefinitionHelper) {
auto pfData = commonDefinitionHelper.getPackFormatData(
const proto::HoaTypeMetadata &epsMetadata) {
auto pfData = AdmPresetDefinitionsHelper::getSingleton().getPackFormatData(
4, epsMetadata.packformatidvalue());

ear::HOATypeMetadata earMetadata;

if (pfData) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include <map>
#include <string>
#include <vector>
#include "helper/adm_preset_definitions_helper.h"

namespace ear {
namespace plugin {
Expand Down Expand Up @@ -44,9 +43,6 @@ class SceneGainsCalculator {
ear::GainCalculatorHOA hoaCalculator_;

std::map<communication::ConnectionId, ItemGains> routingCache_;

std::mutex commonDefinitionHelperMutex_;
AdmPresetDefinitionsHelper commonDefinitionHelper_{};
};

} // namespace plugin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,15 +150,12 @@ BinauralMonitoringBackend::getLatestHoaTypeMetadata(ConnId id) {
if (!epsMD || !epsMD->has_hoa_metadata()) {
return std::optional<HoaEarMetadataAndRouting>();
}
{
std::lock_guard<std::mutex> lock(commonDefinitionHelperMutex_);
setInMap<ConnId, HoaEarMetadataAndRouting>(
latestHoaTypeMetadata, id,
HoaEarMetadataAndRouting{
epsMD->has_routing() ? epsMD->routing() : -1,
EpsToEarMetadataConverter::convert(epsMD->hoa_metadata(),
commonDefinitionHelper)});
}

setInMap<ConnId, HoaEarMetadataAndRouting>(
latestHoaTypeMetadata, id,
HoaEarMetadataAndRouting{
epsMD->has_routing() ? epsMD->routing() : -1,
EpsToEarMetadataConverter::convert(epsMD->hoa_metadata())});

earMD = getValuePointerFromMap<ConnId, HoaEarMetadataAndRouting>(
latestHoaTypeMetadata, id);
Expand Down Expand Up @@ -226,15 +223,14 @@ void BinauralMonitoringBackend::onSceneReceived(proto::SceneStore store) {
}
if (item.has_hoa_metadata()) {
auto hoaId = item.hoa_metadata().packformatidvalue();
{
std::lock_guard<std::mutex> lock(commonDefinitionHelperMutex_);
// TODO: May need to revisit later -
// this is a high-frequency call but may be slow to to execute
auto pfData = commonDefinitionHelper.getPackFormatData(4, hoaId);
if (pfData) {
auto cfCount = pfData->relatedChannelFormats.size();
totalHoaChannels += cfCount;
}
// TODO: May need to revisit later -
// this is a high-frequency call but may be slow to to execute
auto pfData =
AdmPresetDefinitionsHelper::getSingleton().getPackFormatData(4,
hoaId);
if (pfData) {
auto cfCount = pfData->relatedChannelFormats.size();
totalHoaChannels += cfCount;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@ namespace proto {

proto::DirectSpeakersTypeMetadata* convertPackFormatToEpsMetadata(
int packFormatIdValue) {
auto commonDefinitionHelper = AdmPresetDefinitionsHelper::getSingleton();

auto ds_metadata = new proto::DirectSpeakersTypeMetadata();
ds_metadata->set_packformatidvalue(packFormatIdValue);

auto pfData = commonDefinitionHelper->getPackFormatData(1, packFormatIdValue);
auto pfData = AdmPresetDefinitionsHelper::getSingleton().getPackFormatData(
1, packFormatIdValue);
if (pfData) {
for (auto const& cfData : pfData->relatedChannelFormats) {
auto newSpeaker = ds_metadata->add_speakers();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -387,10 +387,10 @@ void ProgrammeStoreAdmSerializer::createTopLevelObject(
adm::TypeDefinition::HOA,
adm::AudioPackFormatIdValue(
metadata.hoa_metadata().packformatidvalue()));
}
}

auto presets = AdmPresetDefinitionsHelper::getSingleton();
auto objectHolder = presets->addPresetDefinitionObjectTo(
auto objectHolder = AdmPresetDefinitionsHelper::getSingleton()
.addPresetDefinitionObjectTo(
doc, metadata.name(), audioPackFormatID);
setInteractivity(*objectHolder.audioObject, object);
setImportance(*objectHolder.audioObject, object);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,7 @@ void SceneGainsCalculator::addOrUpdateItem(const proto::MonitoringItemMetadata &

if(item.has_hoa_metadata()) {
ear::HOATypeMetadata earMetadata;
{
std::lock_guard<std::mutex> lock(commonDefinitionHelperMutex_);
earMetadata = EpsToEarMetadataConverter::convert(item.hoa_metadata(), commonDefinitionHelper_);
}
earMetadata = EpsToEarMetadataConverter::convert(item.hoa_metadata());
routing->inputStartingChannel = item.routing();
int inputChannelCount = static_cast<int>(earMetadata.degrees.size());
resizeGainTables(*routing, inputChannelCount, totalOutputChannels);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class ChannelMeterLayout : public Component {
void setSpeakerSetupPackFormat(int pfId) {
clearSpeakerSetup();
auto pfData =
AdmPresetDefinitionsHelper::getSingleton()->getPackFormatData(1, pfId);
AdmPresetDefinitionsHelper::getSingleton().getPackFormatData(1, pfId);
if (pfData) {
for (int i = 0; i < pfData->relatedChannelFormats.size(); ++i) {
auto cfData = pfData->relatedChannelFormats[i];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ void DirectSpeakersJuceFrontendConnector::setSpeakerSetupPackFormat(
if (auto speakerSetupsComboBoxLocked = speakerSetupsComboBox_.lock())
speakerSetupsComboBoxLocked->setSelectedId(speakerSetupPackFormatIdValue,
dontSendNotification);
auto pfData = AdmPresetDefinitionsHelper::getSingleton()->getPackFormatData(
auto pfData = AdmPresetDefinitionsHelper::getSingleton().getPackFormatData(
1, cachedPackFormatId_);
if (auto routingComboBoxLocked = routingComboBox_.lock()) {
int layoutSize = pfData ? pfData->relatedChannelFormats.size() : 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class ValueBoxMain : public Component {
addAndMakeVisible(speakerSetupLabel_.get());
speakerSetupsComboBox_->setDefaultText("Select speaker layout");

auto tdData = AdmPresetDefinitionsHelper::getSingleton()->getTypeDefinitionData(1);
auto tdData = AdmPresetDefinitionsHelper::getSingleton().getTypeDefinitionData(1);
auto pfDatas = tdData->relatedPackFormats;
std::stable_sort(
pfDatas.begin(), pfDatas.end(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ void HoaJuceFrontendConnector::setHoaType(int hoaType) {

auto packFormatIdValue = p_->getPackFormatIdValue()->get();
if (auto routingComboBoxLocked = routingComboBox_.lock()) {
auto pfData = AdmPresetDefinitionsHelper::getSingleton()->getPackFormatData(
auto pfData = AdmPresetDefinitionsHelper::getSingleton().getPackFormatData(
4, packFormatIdValue);
size_t cfCount{0};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ class ValueBoxMain : public Component {
hoaTypeLabel_->setJustificationType(Justification::right);
addAndMakeVisible(hoaTypeLabel_.get());

auto commonDefinitionHelper = AdmPresetDefinitionsHelper::getSingleton();
for (auto const& pfData : commonDefinitionHelper->getTypeDefinitionData(4)->relatedPackFormats) {
auto& admPresetDefinitions = AdmPresetDefinitionsHelper::getSingleton();
for (auto const& pfData :
admPresetDefinitions.getTypeDefinitionData(4)->relatedPackFormats) {
auto entry = hoaTypeComboBox_->addTextEntry(pfData->niceName, pfData->idValue);
entry->setLightFont(!pfData->isCommonDefinition());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ void ValueBoxOrderDisplay::clearHoaSetup() {

void ValueBoxOrderDisplay::setHoaType(int hoaId) {
clearHoaSetup();
auto commonDefinitionHelper = AdmPresetDefinitionsHelper::getSingleton();
auto pfData = commonDefinitionHelper->getPackFormatData(4, hoaId);
auto pfData =
AdmPresetDefinitionsHelper::getSingleton().getPackFormatData(4, hoaId);
size_t cfCount(0);
if (pfData) {
cfCount = static_cast<size_t>(pfData->relatedChannelFormats.size());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ EarMonitoringAudioProcessorEditor::EarMonitoringAudioProcessorEditor(
auto apfid = adm::parseAudioPackFormatId(AUDIO_PACK_FORMAT_ID);
auto idValue = apfid.get<adm::AudioPackFormatIdValue>().get();
auto typeDef = apfid.get<adm::TypeDescriptor>().get();
auto pfData = AdmPresetDefinitionsHelper::getSingleton()->getPackFormatData(
auto pfData = AdmPresetDefinitionsHelper::getSingleton().getPackFormatData(
typeDef, idValue);
if (pfData) {
for (int i = 0; i < pfData->relatedChannelFormats.size(); ++i) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,16 +224,16 @@ class ObjectView : public ElementView,
juce::String metadataLabelText;
if (data_.item.has_ds_metadata()) {
metadataLabelText = "DirectSpeakers";
auto commonDefinitionHelper = AdmPresetDefinitionsHelper::getSingleton();
auto pfData = commonDefinitionHelper->getPackFormatData(
auto pfData =
AdmPresetDefinitionsHelper::getSingleton().getPackFormatData(
1, data_.item.ds_metadata().packformatidvalue());
if (pfData) {
metadataLabelText = pfData->niceName;
}
} else if (data_.item.has_hoa_metadata()) {
metadataLabelText = "HOA";
auto commonDefinitionHelper = AdmPresetDefinitionsHelper::getSingleton();
auto pfData = commonDefinitionHelper->getPackFormatData(
auto pfData =
AdmPresetDefinitionsHelper::getSingleton().getPackFormatData(
4, data_.item.hoa_metadata().packformatidvalue());
if (pfData) {
int cfCount = pfData->relatedChannelFormats.size();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,9 +288,9 @@ void ear::plugin::ui::ProgrammesContainer::updateMeter(const proto::InputItemMet
oldItem.hoa_metadata().packformatidvalue() != item.hoa_metadata().packformatidvalue()) {
auto packFormatId = item.hoa_metadata().packformatidvalue();
if(packFormatId >= 0) {
auto commonDefinitionHelper = AdmPresetDefinitionsHelper::getSingleton();
auto pfData =
commonDefinitionHelper->getPackFormatData(4, packFormatId);
AdmPresetDefinitionsHelper::getSingleton().getPackFormatData(
4, packFormatId);
if(pfData) {
updateRequired = true;
channelCount =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,9 @@ class ItemBuilder {
ItemBuilder& withDsPackFormat(int pfId) {
auto dsMeta = metadata_.mutable_ds_metadata();
dsMeta->set_packformatidvalue(pfId);
auto commonDefinitionHelper = AdmPresetDefinitionsHelper::getSingleton();
auto pfData = commonDefinitionHelper->getPackFormatData(1, pfId);
auto pfData =
AdmPresetDefinitionsHelper::getSingleton().getPackFormatData(1,
pfId);
if (pfData) {
for (auto const& cfData : pfData->relatedChannelFormats) {
auto newSpeaker = dsMeta->add_speakers();
Expand Down
8 changes: 4 additions & 4 deletions reaper-adm-export-source-plugin/src/PluginEditor.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "PluginEditor.h"
#include "PluginProcessor.h"
#include "components/version_label.hpp"

#include <components/version_label.hpp>
#include <helper/adm_preset_definitions_helper.h>
#include <chrono>

using namespace ear::plugin::ui;
Expand Down Expand Up @@ -54,7 +54,7 @@ AdmStemPluginAudioProcessorEditor::AdmStemPluginAudioProcessorEditor (AdmStemPlu
channelFormatLabel.setJustificationType(Justification::right);
addAndMakeVisible(channelFormatLabel);

auto elementRelationships = processor.admPresetDefinitions.getElementRelationships();
auto elementRelationships = AdmPresetDefinitionsHelper::getSingleton().getElementRelationships();

for(auto const& tdData : elementRelationships) {
typeDefinitionSelector.addTextEntry(tdData->name, tdData->id);
Expand Down Expand Up @@ -175,7 +175,7 @@ void AdmStemPluginAudioProcessorEditor::updateComboBoxOptions(int tdId, int pfId
channelFormatSelector.setDefaultText("Select Pack Format");
}

auto typeDefinitionData = processor.admPresetDefinitions.getTypeDefinitionData(tdId);
auto typeDefinitionData = AdmPresetDefinitionsHelper::getSingleton().getTypeDefinitionData(tdId);

if(typeDefinitionData) {
for(auto& pfData : typeDefinitionData->relatedPackFormats) {
Expand Down
3 changes: 3 additions & 0 deletions reaper-adm-export-source-plugin/src/PluginProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "PluginProcessor.h"
#include <fstream>
#include <daw_channel_count.h>
#include <helper/adm_preset_definitions_helper.h>

AdmStemPluginAudioProcessor::AdmStemPluginAudioProcessor()
#ifndef JucePlugin_PreferredChannelConfigurations
Expand Down Expand Up @@ -209,6 +210,7 @@ int AdmStemPluginAudioProcessor::calcNumChannels()
auto selPf = admPackFormatParam->get();
auto selCf = admChannelFormatParam->get();

auto& admPresetDefinitions = AdmPresetDefinitionsHelper::getSingleton();
auto packFormatData = admPresetDefinitions.getPackFormatData(selTd, selPf);
if(!packFormatData) return 0;

Expand All @@ -235,6 +237,7 @@ void AdmStemPluginAudioProcessor::updateAdmParameters(bool force)
int valTypeDefinition = desiredTypeDefinition;
int valPackFormat = PACKFORMAT_UNSET_ID;
int valChannelFormat = CHANNELFORMAT_ALLCHANNELS_ID;
auto& admPresetDefinitions = AdmPresetDefinitionsHelper::getSingleton();

if(admPresetDefinitions.getPackFormatData(valTypeDefinition, desiredPackFormat)) {
valPackFormat = desiredPackFormat;
Expand Down
3 changes: 0 additions & 3 deletions reaper-adm-export-source-plugin/src/PluginProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

#include "helper/nng_wrappers.h"
#include "JuceHeader_Wrapper.h"
#include "helper/adm_preset_definitions_helper.h"
#include "PluginProcessorUtils.h"
#include <functional>
#include <memory>
Expand Down Expand Up @@ -80,8 +79,6 @@ class AdmStemPluginAudioProcessor : public AudioProcessor

void incomingMessage(std::shared_ptr<NngMsg> msg);

AdmPresetDefinitionsHelper admPresetDefinitions{};

private:
AdmStemPluginAudioProcessorEditor* editor();

Expand Down
2 changes: 1 addition & 1 deletion reaper-adm-extension/src/reaper_adm/admvstcontrol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ bool AdmVst::isUsingPresetDefinition()
{
auto td = getAdmTypeDefinition();
auto pfId = getAdmPackFormat();
auto pfData = AdmPresetDefinitionsHelper::getSingleton()->getPackFormatData(td, pfId);
auto pfData = AdmPresetDefinitionsHelper::getSingleton().getPackFormatData(td, pfId);
return pfData != nullptr;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -413,15 +413,15 @@ void AdmVstExporter::newAdmPresetDefinitionReference(ReaperAPI const& api, std::
int channelFormatIdValue = admExportVst->getAdmChannelFormat();
assert(packFormatIdValue != ADM_VST_PACKFORMAT_UNSET_ID);

auto presets = AdmPresetDefinitionsHelper::getSingleton();
auto pfData = presets->getPackFormatData(typeDefinitionValue, packFormatIdValue);
auto& presets = AdmPresetDefinitionsHelper::getSingleton();
auto pfData = presets.getPackFormatData(typeDefinitionValue, packFormatIdValue);

if (pfData) {
std::optional<int> specificCfIdValue;
if (channelFormatIdValue != ADM_VST_CHANNELFORMAT_ALLCHANNELS_ID)
specificCfIdValue = channelFormatIdValue;

auto holder = presets->setupPresetDefinitionObject(parentDocument, audioObject,
auto holder = presets.setupPresetDefinitionObject(parentDocument, audioObject,
pfData->packFormat->get<adm::AudioPackFormatId>(), specificCfIdValue);

audioPackFormat = holder.audioPackFormat;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ void EarVstExportSources::generateAdmAndChna(ReaperAPI const& api)
admElements->audioObject->set(adm::Duration{ duration });
}

const bool isPresetDef = AdmPresetDefinitionsHelper::getSingleton()->getPackFormatData(admElements->audioPackFormat) != nullptr;
const bool isPresetDef = AdmPresetDefinitionsHelper::getSingleton().getPackFormatData(admElements->audioPackFormat) != nullptr;
const bool isObjectType = admElements->typeDescriptor == adm::TypeDefinition::OBJECTS;

if (!isPresetDef) {
Expand Down
7 changes: 3 additions & 4 deletions reaper-adm-extension/src/reaper_adm/pluginsuite_ear.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ std::vector<int> determineUsedDirectSpeakersTrackMappingValues(PluginInstance& p
assert(packFormatId.has_value());

if (trackMapping.has_value() && *trackMapping >= 0 && packFormatId.has_value()) {
auto pfData = AdmPresetDefinitionsHelper::getSingleton()->getPackFormatData(1, *packFormatId);
auto pfData = AdmPresetDefinitionsHelper::getSingleton().getPackFormatData(1, *packFormatId);
if (pfData) {
int trackWidth = pfData->relatedChannelFormats.size();
for (int channelCounter = 0; channelCounter < trackWidth; channelCounter++) {
Expand All @@ -153,7 +153,7 @@ std::vector<int> determineUsedHoaTrackMappingValues(PluginInstance& plugin) {
assert(packFormatId.has_value());

if (trackMapping.has_value() && *trackMapping >= 0 && packFormatId.has_value()) {
auto pfData = AdmPresetDefinitionsHelper::getSingleton()->getPackFormatData(4, *packFormatId);
auto pfData = AdmPresetDefinitionsHelper::getSingleton().getPackFormatData(4, *packFormatId);
if(pfData) {
int trackWidth = pfData->relatedChannelFormats.size();
for (int channelCounter = 0; channelCounter < trackWidth; channelCounter++) {
Expand Down Expand Up @@ -419,8 +419,7 @@ void EARPluginSuite::onCreateDirectTrack(TrackElement & trackElement, const Reap
if(automationElements.size() > 0) {
auto channel = automationElements.front()->channel();
auto packFormat = channel.packFormat();
auto defs = AdmPresetDefinitionsHelper::getSingleton();
auto pfData = defs->getPackFormatData(packFormat);
auto pfData = AdmPresetDefinitionsHelper::getSingleton().getPackFormatData(packFormat);

if(pfData) {
int32_t routingToScene = -1;
Expand Down
Loading

0 comments on commit 5567fd2

Please sign in to comment.