helgoboss / reaper-rs

Rust bindings for the REAPER C++ API
MIT License
80 stars 8 forks source link

Write a chunk parser using nom parser combinators #51

Open helgoboss opened 3 years ago

helgoboss commented 3 years ago

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).

GavinRay97 commented 3 years ago

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? 👀

helgoboss commented 3 years ago

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).

baadc0de commented 2 years ago

I've made a first pass at it.

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

helgoboss commented 2 years ago

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

GavinRay97 commented 2 years ago

@baadc0de This is awesome, thank you!