Skip to content

Commit

Permalink
Use TrackFX_GetNamedConfigParm over custom state chunk parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
firthm01 committed May 21, 2024
1 parent 41bcdb3 commit eea74ff
Showing 1 changed file with 16 additions and 40 deletions.
56 changes: 16 additions & 40 deletions reaper-adm-extension/src/reaper_adm/reaperapiimpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -954,56 +954,32 @@ int admplug::ReaperAPIImpl::GetDawChannelCount() const
return GetReaperChannelCount(GetAppVersion());
}

bool admplug::ReaperAPIImpl::TrackFX_GetActualFXName(MediaTrack* track, int fx, std::string& name) const
bool admplug::ReaperAPIImpl::TrackFX_GetActualFXName(MediaTrack* track, int fxNum, std::string& name) const
{
// Note that;
// TrackFX_GetNamedConfigParm( track, 0, "fx_name" )
// can get the pre-aliased name but is only supported from v6.37
// Also does not support FX renamed in FX selection window
// (although neither does this)

auto chunk = GetTrackStateChunkStr(track);

auto vst3Elements = GetVSTElementsFromTrackStateChunk(chunk);
if (fx >= vst3Elements.size()) {
return false;
}

const int nameSectionNum = 0;

auto vst3Sections = SplitVSTElement(vst3Elements[fx].second, true, false);
if (vst3Sections.size() <= nameSectionNum) {
return false;
}

name = vst3Sections[nameSectionNum];;
const size_t fxNameMaxLen = 1024; // Should be plenty
char fxName[fxNameMaxLen];
auto fxNameRes = TrackFX_GetNamedConfigParm(track, fxNum, "fx_name", fxName, fxNameMaxLen);
if (!fxNameRes) return false;
name = std::string{ fxName, strnlen(fxName, fxNameMaxLen) };
return true;
}

std::vector<std::string> admplug::ReaperAPIImpl::TrackFX_GetActualFXNames(MediaTrack* track) const
{
// Only gets and parses state chunk once
// More efficient when you want to query every plugin on the track

std::vector<std::string> names;

auto chunk = GetTrackStateChunkStr(track);

auto vst3Elements = GetVSTElementsFromTrackStateChunk(chunk);

const int nameSectionNum = 0;

for (auto const& elmPair : vst3Elements) {
auto vst3Sections = SplitVSTElement(elmPair.second, true, false);
if (vst3Sections.size() <= nameSectionNum) {
names.push_back("");
std::vector<std::string> fxNames;
auto numFx = TrackFX_GetCount(track);
for (int fxNum = 0; fxNum < numFx; fxNum++) {
const size_t fxNameMaxLen = 1024; // Should be plenty
char fxName[fxNameMaxLen];
auto fxNameRes = TrackFX_GetNamedConfigParm(track, fxNum, "fx_name", fxName, fxNameMaxLen);
if (fxNameRes) {
fxNames.push_back(std::string{ fxName, strnlen(fxName, fxNameMaxLen) });
}
else {
names.push_back(vst3Sections[nameSectionNum]);
fxNames.push_back("");
}
}

return names;
return fxNames;
}

void admplug::ReaperAPIImpl::CleanFXName(std::string& fxName) const
Expand Down

0 comments on commit eea74ff

Please sign in to comment.