@@ -824,186 +824,37 @@ std::optional<std::pair<double, double>> admplug::ReaperAPIImpl::getTrackAudioBo
824
824
return std::optional<std::pair<double , double >>();
825
825
}
826
826
827
- std::vector<std::pair<int , std::string>> admplug::ReaperAPIImpl::GetVSTElementsFromTrackStateChunk (const std::string& fullChunk) const
828
- {
829
- std::vector<std::pair<int , std::string>> vst3Elements;
830
-
831
- const std::vector<char > quoteMarks{ ' \' ' , ' `' , ' "' };
832
- int elmStart = -1 ;
833
-
834
- for (int pos = 0 ; pos < fullChunk.length (); ++pos) {
835
-
836
- bool escapedQuote = false ;
837
- for (auto quote : quoteMarks) {
838
- if (fullChunk[pos] == quote) {
839
- // Entered a quote mark
840
- if (pos == fullChunk.length () - 1 ) {
841
- // Already at EOF - don't attempt to find
842
- escapedQuote = true ;
843
- break ;
844
- }
845
- // Find end quote mark
846
- auto newPos = fullChunk.find (quote, pos + 1 );
847
- if (newPos == std::string::npos) {
848
- // End not found to EOF - abort
849
- escapedQuote = true ;
850
- break ;
851
- }
852
- pos = newPos;
853
- }
854
- }
855
- if (escapedQuote) {
856
- break ;
857
- }
858
-
859
- if (elmStart == -1 ) {
860
- // Not in an element - check if at start of one
861
- if (fullChunk.substr (pos, 5 ) == " <VST " ) {
862
- elmStart = pos;
863
- }
864
- }
865
- else {
866
- // In an element - check if at end
867
- if (fullChunk.substr (pos, 1 ) == " >" ) {
868
- vst3Elements.push_back (std::make_pair (
869
- elmStart,
870
- fullChunk.substr (elmStart, pos - elmStart + 1 ))
871
- );
872
- elmStart = -1 ;
873
- }
874
- }
875
- }
876
-
877
- return vst3Elements;
878
- }
879
-
880
- std::vector<std::string> admplug::ReaperAPIImpl::SplitVSTElement (const std::string& elm, bool stripBoundingQuotes, bool includeSeperators) const
881
- {
882
- std::vector<std::string> sec;
883
-
884
- const std::vector<char > quoteMarks{ ' \' ' , ' `' , ' "' };
885
- const std::vector<char > splitMarks{ ' ' , ' \r ' , ' \n ' };
886
- int secStart = 5 ;
887
-
888
- for (int pos = 5 ; pos < elm.length (); ++pos) {
889
-
890
- bool escapedQuote = false ;
891
- for (auto quote : quoteMarks) {
892
- if (elm[pos] == quote) {
893
- // Entered a quote mark
894
- if (pos == elm.length () - 1 ) {
895
- // Already at EOF - don't attempt to find
896
- escapedQuote = true ;
897
- break ;
898
- }
899
- // Find end quote mark
900
- auto newPos = elm.find (quote, pos + 1 );
901
- if (newPos == std::string::npos) {
902
- // End not found to EOF - abort
903
- escapedQuote = true ;
904
- break ;
905
- }
906
- pos = newPos;
907
- }
908
- }
909
- if (escapedQuote) {
910
- break ;
911
- }
912
-
913
- for (auto splitMark : splitMarks) {
914
- if (elm[pos] == splitMark) {
915
- // Close this section and start a new one
916
- sec.push_back (elm.substr (secStart, pos - secStart));
917
- if (includeSeperators) {
918
- sec.push_back (std::string{ splitMark });
919
- }
920
- secStart = pos + 1 ;
921
- break ;
922
- }
923
- }
924
- }
925
-
926
- if (stripBoundingQuotes) {
927
- for (auto & s : sec) {
928
- if (s.length () >= 2 ) {
929
- for (auto quote : quoteMarks) {
930
- if (s[0 ] == quote && s[s.length () - 1 ] == quote) {
931
- s = s.substr (1 , s.length () - 2 );
932
- break ;
933
- }
934
- }
935
- }
936
- }
937
- }
938
-
939
- return sec;
940
- }
941
-
942
- std::string admplug::ReaperAPIImpl::GetTrackStateChunkStr (MediaTrack* track) const
943
- {
944
- const size_t chunkMaxLen = 65535 ; // Should be plenty
945
- char chunk[chunkMaxLen];
946
- auto res = GetTrackStateChunk (track, chunk, chunkMaxLen, false );
947
- if (!res) return std::string ();
948
- std::string fullChunk{ chunk, strnlen (chunk, chunkMaxLen) };
949
- return fullChunk;
950
- }
951
-
952
827
int admplug::ReaperAPIImpl::GetDawChannelCount () const
953
828
{
954
829
return GetReaperChannelCount (GetAppVersion ());
955
830
}
956
831
957
- bool admplug::ReaperAPIImpl::TrackFX_GetActualFXName (MediaTrack* track, int fx , std::string& name) const
832
+ bool admplug::ReaperAPIImpl::TrackFX_GetActualFXName (MediaTrack* track, int fxNum , std::string& name) const
958
833
{
959
- // Note that;
960
- // TrackFX_GetNamedConfigParm( track, 0, "fx_name" )
961
- // can get the pre-aliased name but is only supported from v6.37
962
- // Also does not support FX renamed in FX selection window
963
- // (although neither does this)
964
-
965
- auto chunk = GetTrackStateChunkStr (track);
966
-
967
- auto vst3Elements = GetVSTElementsFromTrackStateChunk (chunk);
968
- if (fx >= vst3Elements.size ()) {
969
- return false ;
970
- }
971
-
972
- const int nameSectionNum = 0 ;
973
-
974
- auto vst3Sections = SplitVSTElement (vst3Elements[fx].second , true , false );
975
- if (vst3Sections.size () <= nameSectionNum) {
976
- return false ;
977
- }
978
-
979
- name = vst3Sections[nameSectionNum];;
834
+ const size_t fxNameMaxLen = 1024 ; // Should be plenty
835
+ char fxName[fxNameMaxLen];
836
+ auto fxNameRes = TrackFX_GetNamedConfigParm (track, fxNum, " fx_name" , fxName, fxNameMaxLen);
837
+ if (!fxNameRes) return false ;
838
+ name = std::string{ fxName, strnlen (fxName, fxNameMaxLen) };
980
839
return true ;
981
840
}
982
841
983
842
std::vector<std::string> admplug::ReaperAPIImpl::TrackFX_GetActualFXNames (MediaTrack* track) const
984
843
{
985
- // Only gets and parses state chunk once
986
- // More efficient when you want to query every plugin on the track
987
-
988
- std::vector<std::string> names;
989
-
990
- auto chunk = GetTrackStateChunkStr (track);
991
-
992
- auto vst3Elements = GetVSTElementsFromTrackStateChunk (chunk);
993
-
994
- const int nameSectionNum = 0 ;
995
-
996
- for (auto const & elmPair : vst3Elements) {
997
- auto vst3Sections = SplitVSTElement (elmPair.second , true , false );
998
- if (vst3Sections.size () <= nameSectionNum) {
999
- names.push_back (" " );
844
+ std::vector<std::string> fxNames;
845
+ auto numFx = TrackFX_GetCount (track);
846
+ for (int fxNum = 0 ; fxNum < numFx; fxNum++) {
847
+ const size_t fxNameMaxLen = 1024 ; // Should be plenty
848
+ char fxName[fxNameMaxLen];
849
+ auto fxNameRes = TrackFX_GetNamedConfigParm (track, fxNum, " fx_name" , fxName, fxNameMaxLen);
850
+ if (fxNameRes) {
851
+ fxNames.push_back (std::string{ fxName, strnlen (fxName, fxNameMaxLen) });
1000
852
}
1001
853
else {
1002
- names .push_back (vst3Sections[nameSectionNum] );
854
+ fxNames .push_back (" " );
1003
855
}
1004
856
}
1005
-
1006
- return names;
857
+ return fxNames;
1007
858
}
1008
859
1009
860
void admplug::ReaperAPIImpl::CleanFXName (std::string& fxName) const
0 commit comments