From 51538bbe205592d0a79d1f64892655650cc16664 Mon Sep 17 00:00:00 2001 From: Jeff0S Date: Mon, 30 Mar 2015 20:57:23 +0200 Subject: [PATCH] ReaScript function export: updated python function wrapper generator --- reascript_helper.pl | 25 ++++++++++++++----------- reascript_python.pl | 28 ++++++++++++++++------------ whatsnew.txt | 1 + 3 files changed, 31 insertions(+), 23 deletions(-) mode change 100644 => 100755 reascript_python.pl diff --git a/reascript_helper.pl b/reascript_helper.pl index 600232b6e..984b7a2c9 100644 --- a/reascript_helper.pl +++ b/reascript_helper.pl @@ -1,14 +1,15 @@ -# Original script by Cockos (http://landoleet.org/dev/sws/), also see http://code.google.com/p/sws-extension/issues/detail?id=432 -# JFB mods: tailored for the SWS/S&M extension, i.e. process ./ReaScript.cpp rather than ../plugin.cpp - #!/usr/bin/perl +# Original script by Cockos (http://landoleet.org/dev/sws/) +# JFB mods: tailored for the SWS/S&M extension: process ./ReaScript.cpp rather than ../plugin.cpp sub ReadAPIFuncs { @funclist=(); %rtype={}; %ptypes={}; + %pnames={}; + %callfuncs={}; open INFILE, "ReaScript.cpp" or die "Can't read ReaScript.cpp"; while () @@ -16,36 +17,38 @@ sub ReadAPIFuncs if (/\s*\{\s*APIFUNC/) { $fname=""; + $callfunc=""; if (/APIFUNC\((.+?)\),\s*(.*)/) { - $fname=$1; + $callfunc=$fname=$1; $_=$2; } elsif (/APIFUNC_NAMED\((.+?)\,(.+?)\),\s*(.*)/) { $fname=$1; + $callfunc=$2; $_=$3; } $fname or die "Can't parse function name"; push @funclist, $fname; + $callfuncs{$fname}=$callfunc; - (/\"(.+?)\"\,\s*(.*)/) or die "Can't parse return type"; + (/\"(.+?)\"\s*\,\s*(.*)/) or die "Can't parse return type"; $rtype{$fname}=$1; $_=$2; - (/\"(.*?)\"\,\s*(.*)/) or die "Can't parse parameter types"; + (/\"(.*?)\"\s*\,\s*(.*)/) or die "Can't parse parameter types"; $ptypes{$fname}=$1; $_=$2; - # not using these - #(/\"(.*?)\"/) or die "Can't parse parameter names"; - #$pnames{$fname}=$1; + (/\"(.*?)\"/) or die "Can't parse parameter names"; + $pnames{$fname}=$1; } } close INFILE; @funclist=sort {lc $a cmp lc $b} @funclist; - return (\@funclist, \%rtype, \%ptypes); + return (\@funclist, \%rtype, \%ptypes, \%pnames, \%callfuncs); } sub IsInt @@ -92,4 +95,4 @@ sub UnderlyingType -1; \ No newline at end of file +1; diff --git a/reascript_python.pl b/reascript_python.pl old mode 100644 new mode 100755 index d1c98874d..a434132ba --- a/reascript_python.pl +++ b/reascript_python.pl @@ -1,8 +1,11 @@ -# Original script by Cockos (http://landoleet.org/dev/sws/), also see http://code.google.com/p/sws-extension/issues/detail?id=432 -# JFB mods: tailored for the SWS/S&M extension, i.e. simplified (use a reaper_python import), gets function pointers with rpr_getfp(), removed "RPR_" prefix - #!/usr/bin/perl +# Original script by Cockos (http://landoleet.org/dev/sws/) +# JFB mods: tailored for the SWS/S&M extension: +# - re-use rpr_ internal functions from reaper_python import +# - gets function pointers with rpr_getfp() +# - removed "RPR_" prefix + require "reascript_helper.pl"; $arg=shift @ARGV; @@ -35,7 +38,8 @@ sub PyPack { my ($t, $v)=@_; IsPlainData($t) and return sprintf "%s(%s)", PyType($t), $v; - $t eq "const char*" and return sprintf "rpr_packsc(%s)", $v; + ($t eq "const char*" && $v ne "bytestr") and return sprintf "rpr_packsc(%s)", $v; + ($t eq "const char*" && $v eq "bytestr") and return sprintf "c_char_p(%s)", $v; $t eq "char*" and return sprintf "rpr_packs(%s)", $v; # todo handle char** IsPlainDataPtr($t) and return sprintf "%s(%s)", PyType(UnderlyingType($t)), $v; @@ -48,10 +52,9 @@ sub PyUnpack my ($t, $ov, $v)=@_; (IsPlainData($t) || IsOpaquePtr($t) || $t eq "const char*") and return $ov; $t eq "char*" and return sprintf "rpr_unpacks(%s)", $v; - ($t eq "bool*" || $t eq "char*" || IsInt(UnderlyingType($t))) and - return sprintf "int(%s.value)", $v; - ($t eq "float*" || $t eq "double*") and return sprintf "float(%s.value)", $v; # todo handle char** + ($t eq "bool*" || IsInt(UnderlyingType($t))) and return sprintf "int(%s.value)", $v; + ($t eq "float*" || $t eq "double*") and return sprintf "float(%s.value)", $v; IsPlainDataPtr($t) and return PyUnpack(UnderlyingType($t), $v); die "unknown type $t"; } @@ -70,6 +73,7 @@ sub PyRetUnpack foreach $fname (@$funclist) { $fname eq "ValidatePtr" and next; + $fname eq "GetAudioAccessorSamples" and next; @inparms=(); @proto=(); @@ -83,14 +87,14 @@ sub PyRetUnpack $i=0; foreach $t (split(",", $ptypes->{$fname})) { - $isptr=IsPlainDataPtr($t); - + ($t ne "const char*") and $t =~ s/const //; + push @inparms, "p$i"; push @proto, PyType($t); push @pack, PyPack($t, "p$i"); - push @cparms, (($isptr && $t ne "char*") ? "byref(t[$i])" : "t[$i]"); + push @cparms, (IsPlainDataPtr($t) && !IsString($t) ? "byref(t[$i])" : "t[$i]"); push @unpack, PyUnpack($t, "p$i", "t[$i]"); - $isptr and $byref=1; + IsPlainDataPtr($t) and $byref=1; ++$i; } @@ -114,5 +118,5 @@ sub PyRetUnpack } -warn "Parsed " . @$funclist . " functions\n"; +print STDERR "Parsed " . @$funclist . " functions\n"; diff --git a/whatsnew.txt b/whatsnew.txt index 7c0cdc295..0530cea30 100644 --- a/whatsnew.txt +++ b/whatsnew.txt @@ -22,6 +22,7 @@ Added actions - SWS/BR: Play from edit cursor position and solo active item for the duration (perform until shortcut released) ReaScript ++Improved Python function wrappers (sws_python*.py) +Added functions to convert track/item/take from and to GUID: - BR_GetMediaItemByGUID - BR_GetMediaItemGUID