ebu / ear-production-suite

The EAR Production Suite is a set of VST® plugins and tools for producing immersive and personalizable audio content suitable for any Next Generation Audio codec. It is based on the Audio Definition Model (ITU-R BS.2076) and the ITU ADM Renderer (ITU-R BS.2127) and enables monitoring on any ITU-R BS.2051 loudspeaker configuration.
https://ear-production-suite.ebu.io/
GNU General Public License v3.0
101 stars 19 forks source link

Support renamed FX #241

Closed firthm01 closed 1 year ago

firthm01 commented 1 year ago

Closes #240

rsjbailey commented 1 year ago

Looks good, couple of things I thought of:

bool is_space(unsigned char c) { return std::isspace(c); }

std::vector split_vst_chunk(std::string const& input) { std::vector tokens; std::optional outer_quote{}; std::stringstream ss; bool previous_char_was_whitespace = false; auto const add_token = [&](){ tokens.push_back(ss.str()); ss = {}; previous_char_was_whitespace = false; };

for(auto const c : input) { if(is_quote(c)) { if(!outer_quote) { outer_quote = c; if(previous_char_was_whitespace) { add_token(); } } else if(outer_quote == c) { outer_quote = {}; } else { ss << c; } } if(is_space(c)) { if(outer_quote) { ss << c; } else { previous_char_was_whitespace = true; } } if(!is_space(c) && !is_quote(c)) { if(previous_char_was_whitespace) { add_token(); } ss << c; } } if(!ss.str().empty()) { add_token(); } return tokens; }

firthm01 commented 1 year ago

Thanks for that :)

If the ability to rename is new, does that mean the state chunk has changed? What happens if this is run in a version with an old state chunk

Good point! I will check. I guess that does add some fragility to this solution in that we are relying on a consistent layout of the state chunk.

The first part of the parsing (stripping out the VST chunk) can be done with a regex I think, it's probably a bit slower and debatable as to whether it's clearer than doing it your way, not sure what you think?

Regex is scary. But other than that, I think I doing it step by step makes it easier to debug if it does need to be changed later on. I guess it's much more concise with regex though.

I wound up rewriting the second bit to get my head around it, I’m not sure if it’s any more clear and it’s certainly less flexible (it always strips out enclosing cruft rather than having that configurable)

Ideally I'd want the option to keep bounding quotes and separators. It just means that if we want to Set in future, we can just change the element we're interested in and concat all of the vector elements to reconstruct the chunk. This was my original motivation - I wanted to see how easy/not it would be to automatically rename plugins to show object names - then I realised the renaming functionality probably breaks export (which it did) and needs fixing anyway.

rsjbailey commented 1 year ago

Great, that all seems fair. Most of the regex scaryness is dealing with the fact that the c++ std lib regex implementation doesn't handle multi-line matches very well so you have to handle the line endings explicitly. I probably should have just given up when I realised that.

firthm01 commented 1 year ago

If the ability to rename is new, does that mean the state chunk has changed? What happens if this is run in a version with an old state chunk

Good point! I will check.

Turns out it's not that new. It's available at least as far back as v5.99 and the state chunk layout is the same.