reaper-rs icon indicating copy to clipboard operation
reaper-rs copied to clipboard

Write a chunk parser using nom parser combinators

Open helgoboss opened this issue 3 years ago • 5 comments

To finally get a robust and fast way to dive into chunks from Rust (e.g. for detecting FX parameter modulation and other stuff for which we don't have an API yet).

helgoboss avatar Aug 05 '21 21:08 helgoboss

Hey Benjamin, I've actually been interested in & working on this problem as well.

There's no high-performance chunk parser which is a barrier to being able to do any sort of near-realtime processing of project data from chunks.

Instead of parsing it into language-specific structs though, I've been working on converting it from not-quite-XML into valid XML, and exposing that through a C API + header.

The idea being your language (C++, Rust, D, whatever) passes the chunk or .rpp-file string into it and then the XML result is passed back in a struct field:

#include <stdint.h>

typedef struct rpp_parse_result {
  int error_code;
  const char *results;
  uint64_t len;
} rpp_parse_result;

rpp_parse_result RPPtoXML(const char *rpp_text, uint64_t length);

Then you can use a language-specific XML parser to serialize it into your language's structs/classes, which is more universal.

What do you think about this? 👀

GavinRay97 avatar Sep 14 '21 15:09 GavinRay97

Hi Gavin. Normalizing this to real XML sounds useful and would instantly make access to the chunk stuff easier from many languages! So I'm definitely intrigued. That said, I'm not sure if I would use it for reaper-rs because I would prefer building the parser directly in Rust (which I hope is not a big deal with a proper parser combinator library such as nom).

helgoboss avatar Sep 26 '21 13:09 helgoboss

I've made a first pass at it.

https://github.com/audiocloud/reaper-chunks

baadc0de avatar Dec 23 '21 20:12 baadc0de

Cool! Will try that as soon as I need to get down to chunk level again.

helgoboss avatar Dec 23 '21 21:12 helgoboss

@baadc0de This is awesome, thank you!

GavinRay97 avatar Dec 27 '21 16:12 GavinRay97