Last active
August 17, 2022 11:23
-
-
Save ginjo/de9cf9397b28908c68a8947be219f237 to your computer and use it in GitHub Desktop.
Convert Reaper file (.rpp) to YAML
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### Converts Reaper data file (.rpp) to YAML, using Awk. | |
### All scalar values will be enclosed in single quotes. | |
### | |
### Usage: (with standard input) cat <reaper-data-file.rpp> | <this-script-file> | |
### (with filename as first arg) <this-script-file> <reaper-data-file.rpp> | |
### | |
### Returns: formatted YAML document | |
### | |
### Example usage with yq (shell-based yaml parser): | |
### | |
### Returns all track names. | |
### ./convert_rpp_to_yaml.sh example.rpp | yq e '.REAPER_PROJECT.TRACK[].NAME' - | |
### | |
### Returns all source file names. | |
### ./convert_rpp_to_yaml.sh example.rpp | yq e '.REAPER_PROJECT.TRACK[].ITEM[].SOURCE.FILE' - | |
### | |
### Example usage with ruby: | |
### | |
### ./convert_rpp_to_yaml.sh example.rpp | ruby -r 'yaml' -e 'puts YAML.load(STDIN).to_yaml' | |
### | |
### Example ruby script to iterate through tracks, gathering names (from jamulus user) | |
### and actual file paths. This can be expanded to rename wav files with the jamulus user name. | |
### | |
### jamulus_rpp_converted_to_yaml['REAPER_PROJECT']['TRACK'].each do |track| | |
### puts track['NAME'] | |
### track['ITEM'].each do |item| | |
### puts item['SOURCE']['FILE'] | |
### end | |
### end | |
### | |
### Tested on OSX 10.14, Debian 9, Alpine Linux 3.14 (BusyBox 1.33) | |
if [ "$1" ]; then | |
cat "$1" | |
else | |
cat - | |
fi | | |
awk -v items=0 -v tracks=0 -v printline=1 ' | |
BEGIN {print "---"} | |
# removes angle brackets. | |
/[><]/ {gsub("[><]", "")} | |
# prints root node key, adds 2nd line for metadata. | |
/REAPER_PROJECT[ ]/ {printline=0; print "REAPER_PROJECT:"; print " META: \047" substr($0,index($0,$2)) "\047"} | |
# prints track node key and/or inserts '-' to denote array member. | |
/TRACK[ ]/ {items=0; printline=0; if(tracks==0) {print " TRACK:"} {print " -"}; ++tracks} | |
# prints item node key and/or inserts '-' to denote array member. | |
/ITEM[ ]/ {printline=0; if(items==0) {print " ITEM:"} {print " -"}; ++items} | |
# prints source node key, adds 2nd line for type. | |
/SOURCE[ ]/ {printline=0; print " SOURCE:"; print " TYPE: \047"$2"\047"} | |
# skips empty lines. | |
/^[ ]*$/ {next;} | |
# prints regular key:value lines. | |
printline==1 {gsub($1" ", $1": \047"); print $0"\047"} | |
# resets printline to 1. | |
{printline=1} | |
# prints a final line-feed. | |
END {print "\n"} | |
' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment