Old 11-08-2017, 03:44 AM   #1
Garrick
Human being with feelings
 
Garrick's Avatar
 
Join Date: Jul 2009
Location: Wellington
Posts: 4,622
Default Rpp parser with JavaScript

I'm not sure whether here or the dev forum is apt for a javascript question.
bc dev is more c++ and whatnot and here is more lua and jsfx and what not.

I am trying to parse a rpp file to an object literal or JSON so I can use it for my own evil ends or something useful for the reap com, one of the two I can't remember which.

if you have node up n running on your machine, you could run
Code:
const fs = require('fs');

const rppPath = '/home/garrick/Documents/test/test.RPP';

or if on windows

const rppPath = 'path\\withextra\\backslash\\test.RPP';

const rppArray = fs.readFileSync(rppPath, 'utf8')
    .trim()
    .split("\r\n") // get rid of the \r if on win
    .map(line => line.split("  ")) // <-2 spaces in split

console.log(rppArray);
running this code should give you an easy visual idea of what i'm trying to achieve... and already the parent node of '<Reaper_project' is separated from the rest
Code:
[ [ '<REAPER_PROJECT', '0.1', '"4.78/x64"', '1510032077' ],​​​​​
​​​​​  [ '', '', 'RIPPLE', '0' ],​​​​​
​​​​​  [ '', '', 'GROUPOVERRIDE', '0', '0', '0' ],​​​​​
​​​​​  [ '', '', 'AUTOXFADE', '1' ],​​​​​
​​​​​  [ '', '', 'ENVATTACH', '1' ],​​​​​
​​​​​  [ '', '', 'MIXERUIFLAGS', '11', '48' ],​​​​​
​​​​​  [ '', '', 'PEAKGAIN', '1' ],​​​​​
​​​​​  [ '', '', 'FEEDBACK', '0' ],​​​​​
anyways this closer to where I am now
Code:
const fs = require('fs');

const rppPath = 'path/to/file';

const rppArray = fs.readFileSync(rppPath, 'utf8')
    .trim()
    .split("\r\n")
    .map(line => line.split(" ") // <- one space
    .map(piece => piece.split(" "))) // <- one space as well


console.log(rppArray)
this gives out put like
Code:
  [ [ '' ], [ '' ], [ 'RIPPLE' ], [ '0' ] ],​​​​​
​​​​​  [ [ '' ], [ '' ], [ 'GROUPOVERRIDE' ], [ '0' ], [ '0' ], [ '0' ] ],​​​​​
​​​​​  [ [ '' ], [ '' ], [ 'AUTOXFADE' ], [ '1' ] ],​​​​​
​​​​​  [ [ '' ], [ '' ], [ 'ENVATTACH' ], [ '1' ] ],​​​​​
​​​​​  [ [ '' ], [ '' ], [ 'MIXERUIFLAGS' ], [ '11' ], [ '48' ] ],​​​​​
​​​​​  [ [ '' ], [ '' ], [ 'PEAKGAIN' ], [ '1' ] ],​​​​​
​​​​​  [ [ '' ], [ '' ], [ 'FEEDBACK' ], [ '0' ] ],​​​​​
the idea is map out the children and grand-children nodes so I can do some fancy react/electron app that takes snap-shots of reaper projects with a flux/redux pattern.

fuck me, I almost forgot to ask a question
is there a way of doing
Code:
  .map(line => line.split(" ")
.. better with some fancy regex?

can you do regex then regex again on the last result in one expression?

Last edited by Garrick; 11-08-2017 at 03:49 AM.
Garrick is offline   Reply With Quote
Old 11-08-2017, 06:20 AM   #2
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 9,875
Default

Thanks to mrlimbic, I already made a RPP Parser in Javascript, but is is very different, it doesn't use JSON.


Coding a REAPER Projects Generator Desktop App for Electronic Arts with Electron


Being a full abstraction of the project, it allows complex tasks like "insert an item in track 2 between item 1 and 3".


I know it doesn't answer your question (I didn't share this rpp parser open source, as most of my other resources, like my scripts pack), but maybe it can help you anyay for creating your app.
X-Raym is offline   Reply With Quote
Old 11-08-2017, 11:10 AM   #3
Garrick
Human being with feelings
 
Garrick's Avatar
 
Join Date: Jul 2009
Location: Wellington
Posts: 4,622
Default

Hey x raym
that looks great, though probably a lot more complex for what I'm trying to do.

I'm just wanting to extract render info to make temp rpp to render from, plus extract project notes, to make a list of snapshots to show what a project sounded like and what were the notes at that time.

I also want the data you only go one way, so no manipulation of the original rpp

But any help you'd be willing to give would be most welcome. So who is mrlimbic?

Last edited by Garrick; 11-08-2017 at 11:26 AM.
Garrick is offline   Reply With Quote
Old 11-08-2017, 01:14 PM   #4
Garrick
Human being with feelings
 
Garrick's Avatar
 
Join Date: Jul 2009
Location: Wellington
Posts: 4,622
Default

ok the solution is stupidly simple
Code:
.map(line => line.split(" ")// <- just one space
ill go and read up on JSON for the last bit
Garrick is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 04:31 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.