 |
|
|
11-02-2009, 08:06 AM
|
#1
|
|
Mortal
Join Date: Dec 2006
Location: Leicestershire, England
Posts: 426
|
ReaScript: GetSetObjectState()
I've been playing with GetSetObjectState(), this is what I have so far.
Code:
#
# GetSetObjectState.pl
# ver 0.1
use strict;
use warnings;
use constant CURR_PROJ => 0;
use constant GET => 0;
use constant SET => 1;
my $tre = RPR_GetSelectedTrackEnvelope(CURR_PROJ);
if($tre == 0){
RPR_ShowConsoleMsg("No envelope selected\n");
# exit 0; # commented because $tre is always zero, grrr
}
my $chunk = RPR_GetSetObjectState($tre,GET);
RPR_ShowConsoleMsg("chunk=" . $chunk . "\n");
But... GetSelectedTrackEnvelope() is always returning zero
I'm testing this in Making Me Nervous and selecting the PAN envelope on track 8 - newsolo
Any thoughts?
__________________
Mike Lacey, Leicestershire, UK
|
|
|
11-02-2009, 08:18 AM
|
#2
|
|
Mortal
Join Date: Sep 2007
Location: Madison, WI
Posts: 359
|
CURR_PROJ should be set to -1, not to 0.
Also a reminder that the string buffers returned from GetSetObjectState and GetSelectedTrackEnvelope need to be freed with a call to FreeHeapPtr.
|
|
|
11-02-2009, 08:23 AM
|
#3
|
|
Mortal
Join Date: Feb 2007
Location: Oulu, Finland
Posts: 2,364
|
Quote:
Originally Posted by sws
CURR_PROJ should be set to -1, not to 0.
Also a reminder that the string buffers returned from GetSetObjectState and GetSelectedTrackEnvelope need to be freed with a call to FreeHeapPtr.
|
I doubt he will able to get anything back from GetSetObjectState in ReaScripts. At least I wasn't successful. (I did pass a valid media item into it etc...)
|
|
|
11-02-2009, 08:23 AM
|
#4
|
|
Mortal
Join Date: Dec 2006
Location: Leicestershire, England
Posts: 426
|
Thx sws, much appreciated
__________________
Mike Lacey, Leicestershire, UK
|
|
|
11-02-2009, 08:31 AM
|
#5
|
|
Mortal
Join Date: Dec 2006
Location: Leicestershire, England
Posts: 426
|
Hi xen, sws
Quite right about the FreeHeapPtr calls (you can tell I'm a Perl programmer and am not used to bothering my pretty head about such things)
Having a value of -1 for CURR_PROJ doesn't help... I'm going to try a different object type.
Code:
use strict;
use warnings;
use constant CURR_PROJ => -1;
use constant GET => 0;
use constant SET => 1;
my $tre = RPR_GetSelectedTrackEnvelope(CURR_PROJ);
if($tre == 0){
RPR_ShowConsoleMsg("No envelope selected\n");
# exit 0; # commented because $tre is always zero, grrr
}
my $chunk = RPR_GetSetObjectState($tre,GET);
RPR_ShowConsoleMsg("chunk=" . $chunk . "\n");
RPR_FreeHeapPtr($chunk);
RPR_FreeHeapPtr($tre);
__________________
Mike Lacey, Leicestershire, UK
|
|
|
11-02-2009, 08:40 AM
|
#6
|
|
Mortal
Join Date: Sep 2007
Location: Madison, WI
Posts: 359
|
OK  Now I'm confused, it's quite possible 0 is the correct "current project" argument. I was thinking of EnumProjects, try instead:
curProj = RPR_EnumProjects(-1, 0, 0), then use curProj as the argument to GetSelectedTrackEnvelope.
|
|
|
11-02-2009, 08:54 AM
|
#7
|
|
Mortal
Join Date: Dec 2006
Location: Leicestershire, England
Posts: 426
|
I might be a bit confused myself...
I'm using v3.13, not the pre-release, and it's clearing the selected envelope
Hmm..
Code:
# GetSetObjectState.pl
# ver 0.2
use strict;
use warnings;
use constant CURR_PROJ => 0;
use constant FIRST_SEL_ITEM => 0;
use constant GET => 0;
use constant SET => 1;
my $curProj = RPR_EnumProjects(-1, 0, 0);
RPR_ShowConsoleMsg("curProj=" . $curProj . "\n");
my $thing = RPR_GetSelectedTrackEnvelope($curProj);
if($thing == 0){
RPR_ShowConsoleMsg("Nothing selected\n");
# exit 0; # commented because $thing is always zero, grrr
}
my $chunk = RPR_GetSetObjectState($thing,GET);
RPR_ShowConsoleMsg("chunk=" . $chunk . "\n");
RPR_FreeHeapPtr($chunk);
RPR_FreeHeapPtr($thing);
__________________
Mike Lacey, Leicestershire, UK
Last edited by MikeLacey; 11-02-2009 at 08:58 AM.
Reason: typo
|
|
|
11-02-2009, 08:57 AM
|
#8
|
|
Mortal
Join Date: Dec 2006
Location: Leicestershire, England
Posts: 426
|
looks as if it's the call to GetSetObject that's clearing it
__________________
Mike Lacey, Leicestershire, UK
|
|
|
11-02-2009, 09:17 AM
|
#9
|
|
Mortal
Join Date: Dec 2006
Location: Leicestershire, England
Posts: 426
|
Now if everything just sits down and does as its told, no one will get hurt.
__________________
Mike Lacey, Leicestershire, UK
|
|
|
11-02-2009, 07:19 PM
|
#10
|
|
Administrator
Join Date: Mar 2007
Location: NY
Posts: 3,553
|
GetSetObjectState seems to work fine from ReaScript here -- probably the natural obfuscatory nature of the function is working its magic.
This unattractive, non-error-checking script adds an envelope point at time=1 second, value=1.0:
Code:
env = RPR_GetSelectedTrackEnvelope(0)
chunk = RPR_GetSetObjectState(env, 0)[0]
RPR_ShowConsoleMsg("input rppxml:\n"+chunk+"\n")
chunk = re.sub(">", "PT 1.0 1.0 0 0 1\n>", chunk)
RPR_ShowConsoleMsg("output rppxml:\n"+chunk+"\n")
RPR_GetSetObjectState(env, chunk)
Code:
$env = RPR_GetSelectedTrackEnvelope(0);
($chunk) = RPR_GetSetObjectState($env, "");
RPR_ShowConsoleMsg("input rppxml:\n" . $chunk . "\n");
$chunk =~ s/>/PT 1.0 1.0 0 0 1\n>/;
RPR_ShowConsoleMsg("output rppxml:\n" . $chunk . "\n");
RPR_GetSetObjectState($env, $chunk);
Last edited by schwa; 11-02-2009 at 07:39 PM.
|
|
|
11-02-2009, 07:36 PM
|
#11
|
|
Mortal
Join Date: Feb 2007
Location: Oulu, Finland
Posts: 2,364
|
Quote:
Originally Posted by schwa
GetSetObjectState seems to work fine from ReaScript here -- probably the natural obfuscatory nature of the function is working its magic.
This unattractive, non-error-checking script adds an envelope point at time=1 second, value=1.0:
Code:
env = RPR_GetSelectedTrackEnvelope(0)
chunk = RPR_GetSetObjectState(env, 0)[0]
RPR_ShowConsoleMsg("input rppxml:\n"+chunk+"\n")
chunk = re.sub(">", "PT 1.0 1.0 0 0 1\n>", chunk)
RPR_ShowConsoleMsg("output rppxml:\n"+chunk+"\n")
RPR_GetSetObjectState(env, chunk)
|
Have you tried GetSetObjectState() on media items and tracks? The last time I tried, I didn't seem to be able to get any text chunk out from it, so I just gave up and declared the function non-functional from ReaScript...
edit : Still doesn't work...
Code:
#itCount=RPR_CountSelectedMediaItems(0)
it=RPR_GetSelectedMediaItem(0,0)
chunk=RPR_GetSetObjectState(it,0)[0]
RPR_ShowConsoleMsg(chunk)
Script runs, but nothing appears on script console.
Last edited by Xenakios; 11-02-2009 at 07:44 PM.
|
|
|
11-02-2009, 07:44 PM
|
#12
|
|
Administrator
Join Date: Mar 2007
Location: NY
Posts: 3,553
|
Quote:
Originally Posted by Xenakios
Have you tried GetSetObjectState() on media items and tracks?
|
Ah, you're right, the ReaScript type checking is not letting MediaTrack* be passed to GetSetObjectState(void*). We'll have to add GetSetTrackState, GetSetItemState, GetSetEnvelopeState.
|
|
|
11-02-2009, 07:53 PM
|
#13
|
|
Mortal
Join Date: Feb 2007
Location: Oulu, Finland
Posts: 2,364
|
Quote:
Originally Posted by schwa
Ah, you're right, the ReaScript type checking is not letting MediaTrack* be passed to GetSetObjectState(void*). We'll have to add GetSetTrackState, GetSetItemState, GetSetEnvelopeState.
|
Sorry to generate more work for you...
|
|
|
11-02-2009, 07:53 PM
|
#14
|
|
Administrator
Join Date: Mar 2007
Location: NY
Posts: 3,553
|
Not much work, already done
|
|
|
11-03-2009, 03:09 AM
|
#15
|
|
Mortal
Join Date: Dec 2006
Location: Leicestershire, England
Posts: 426
|
schwa,
From your (elegant, attractive and, above all, working  ) examples. (Which will be in the API documentation before you can finish reading this)
chunk = RPR_GetSetObjectState(env, 0)[0]
and
($chunk) = RPR_GetSetObjectState($env, "");
Does this mean that GetSetObjectState() returns an array of one element?
Do all of the RPR_ calls, which just return one thing, do this?
Mike
__________________
Mike Lacey, Leicestershire, UK
Last edited by MikeLacey; 11-03-2009 at 03:18 AM.
Reason: after actually thinking
|
|
|
11-03-2009, 06:04 AM
|
#16
|
|
Administrator
Join Date: Mar 2007
Location: NY
Posts: 3,553
|
Quote:
Originally Posted by MikeLacey
Do all of the RPR_ calls, which just return one thing, do this?
|
No -- GetSetObjectState is a special enough case that (as Xenakios probably thought from the beginning) it's not appropriate to call from ReaScript. We'll make this function for extension use only, and make new object-type-specific functions for ReaScript (and extension) use.
<tech>
The array return is because GetSetObjectType takes a void* argument for the object, which ReaScript thinks (correctly) is a modifiable variable , and any time there are modifiable variables in the parameter list, the function will return an array (return, parm1, parm2, ...). (Specific Reaper type pointers like MediaItem* are not considered modifiable by ReaScript.) Another problem is that by the time the returned string gets back to ReaScript, it's not the same pointer that Reaper gave out (it's a local string copy), so the original heap string gets leaked.
</tech>
But that's all academic, like I said we'll add cleaner functions for ReaScript use and hide that one from ReaScript.
|
|
|
11-03-2009, 08:55 AM
|
#17
|
|
Mortal
Join Date: Dec 2006
Location: Leicestershire, England
Posts: 426
|
Ok, thanks, I'll remove it from the documentation.
Quote:
Originally Posted by schwa
The array return is because GetSetObjectType takes a void* argument for the object, which ReaScript thinks (correctly) is a modifiable variable , and any time there are modifiable variables in the parameter list, the function will return an array (return, parm1, parm2, ...). (Specific Reaper type pointers like MediaItem* are not considered modifiable by ReaScript.) Another problem is that by the time the returned string gets back to ReaScript, it's not the same pointer that Reaper gave out (it's a local string copy), so the original heap string gets leaked.
|
Good stuff... that helps quite a bit, thank you.
__________________
Mike Lacey, Leicestershire, UK
|
|
|
11-04-2009, 04:42 AM
|
#18
|
|
Mortal
Join Date: Feb 2009
Location: Melbourne, Australia
Posts: 59
|
Quote:
Originally Posted by schwa
We'll have to add GetSetTrackState, GetSetItemState, GetSetEnvelopeState.
|
That would be neat. The example you gave (adding an envelope point) wasn't as scary as what I first thought it would be. Hopefully others "chunks" are fairly easy to grasp also.
My immediate interest is in being able to set the "Section" start and "Length" properties for an Item's "Source" properties (as per my thread asking about these). Hopefully the addition of GetSetItemState will get me closer to that goal.
In the meantime, I'll have to dream up some uses for some scripted insertion of envelope points. Shouldn't be too hard...
|
|
|
11-04-2009, 04:48 AM
|
#19
|
|
Mortal
Join Date: Dec 2006
Location: Leicestershire, England
Posts: 426
|
"I'll have to dream up some uses for some scripted insertion of envelope points"
Ok then... Scary.
__________________
Mike Lacey, Leicestershire, UK
|
|
|
11-04-2009, 07:08 AM
|
#20
|
|
Mortal
Join Date: Feb 2007
Location: Oulu, Finland
Posts: 2,364
|
Quote:
Originally Posted by sfzgeek
My immediate interest is in being able to set the "Section" start and "Length" properties for an Item's "Source" properties (as per my thread asking about these). Hopefully the addition of GetSetItemState will get me closer to that goal.
|
Once the new script API is added, you will get a chunk like this from media items :
Code:
<ITEM
POSITION 5.50000000000000
SNAPOFFS 0.00000000000000
LENGTH 42.50000000000000
LOOP 1
ALLTAKES 0
SEL 1
FADEIN 1 0.010000 0.000000
FADEOUT 1 0.010000 0.000000
MUTE 0
IGUID {CADD95DC-0BDD-47B4-8A80-9C9CAC37D3ED}
NAME "Hanuri_textured_6.wav"
VOLPAN 1.000000 0.000000 1.000000 -1.000000
SOFFS 0.00000000000000
PLAYRATE 1.00000000000000 1 0.00000000000000 -65536
CHANMODE 0
GUID {EBBD8248-DF0A-42EA-B67A-15680F00C049}
<SOURCE SECTION
LENGTH 11.50000000000000
STARTPOS 4.00000000000000
OVERLAP 0.05500000000000
<SOURCE WAVE
FILE "H:\Pirun_Palkeet\jotani\Hanuri_textured_6.wav"
>
>
>
Then, what you need to do is to get to the <SOURCE SECTION part and the following lines and parse and change the values. It may sound tricky but it actually probably is pretty easy to do in a scripting language.
|
|
|
11-04-2009, 12:23 PM
|
#21
|
|
Mortal
Join Date: Feb 2009
Location: Melbourne, Australia
Posts: 59
|
Quote:
Originally Posted by Xenakios
It may sound tricky but it actually probably is pretty easy to do in a scripting language.
|
Ooh! Thanks for the preview!
I can't imagine that manipulating those values would be too hard using Perl. I'm not saying my solution would be elegant but I'm pretty sure I could write something that works.
Also, was that chunk pulled using a recent version of Reaper? I can't see a reverse flag in there.
|
|
|
11-04-2009, 12:30 PM
|
#22
|
|
Mortal
Join Date: Feb 2007
Location: Oulu, Finland
Posts: 2,364
|
Quote:
Originally Posted by sfzgeek
Ooh! Thanks for the preview!
I can't imagine that manipulating those values would be too hard using Perl. I'm not saying my solution would be elegant but I'm pretty sure I could write something that works.
Also, was that chunk pulled using a recent version of Reaper? I can't see a reverse flag in there.
|
The flag (MODE) that determines the reverse only appears there if it is needed :
Code:
<SOURCE SECTION
LENGTH 11.50000000000000
MODE 2
STARTPOS 4.00000000000000
OVERLAP 0.05500000000000
<SOURCE WAVE
FILE "H:\Pirun_Palkeet\jotani\Hanuri_textured_6.wav"
>
>
Which reminds me to remind you that don't assume things will for example appear at particular relative line numbers in the text chunks. As features are added and modified in Reaper, new lines might be added in the text formatted data, between old parameters too etc...
|
|
|
11-04-2009, 12:56 PM
|
#23
|
|
Mortal
Join Date: Feb 2009
Location: Melbourne, Australia
Posts: 59
|
Thanks for the heads-up, Xen. That tip will help me formulate my solution to parsing these properties for my own manipulation.
|
|
|
11-05-2009, 04:54 AM
|
#24
|
|
Mortal
Join Date: Feb 2009
Location: Melbourne, Australia
Posts: 59
|
I started thinking through how I might go about editing an Item's text chunk when the relevant APIs come online. (You can tell I'm getting excited about this...  )
I assume that once I've setup a way of parsing and later recontructing an Item's chunk, I could set all paramter changes is in one function call as opposed to calling "SetMediaItemInfo_Value" repeatedly for each individual parameter.
I'm also guessing that one way to parse chunks in Perl would be to use RegExs since then I wouldn't have to worry about knowing the specific order that parameters may present themselves in.
|
|
|
11-05-2009, 07:02 AM
|
#25
|
|
Mortal
Join Date: Dec 2006
Location: Leicestershire, England
Posts: 426
|
I'm wondering if one of the XML modules might be of help - I recall that the rpp format isn't quite XML but it does look close.
__________________
Mike Lacey, Leicestershire, UK
|
|
|
11-05-2009, 07:10 AM
|
#26
|
|
Mortal
Join Date: Feb 2007
Location: Oulu, Finland
Posts: 2,364
|
Quote:
Originally Posted by MikeLacey
I'm wondering if one of the XML modules might be of help - I recall that the rpp format isn't quite XML but it does look close.
|
Would probably be more work to adapt some existing XML parsing code than to just roll some custom parsing code from scratch...
|
|
|
11-05-2009, 10:06 AM
|
#27
|
|
Mortal
Join Date: Dec 2006
Location: Leicestershire, England
Posts: 426
|
Oh absolutely, we're not here to be busy fools.
Would we have problems if we were to treat the chunks we get back from the GetSet* functions as standard XML?
__________________
Mike Lacey, Leicestershire, UK
|
|
|
11-05-2009, 10:09 AM
|
#28
|
|
Mortal
Join Date: Feb 2007
Location: Oulu, Finland
Posts: 2,364
|
Quote:
Originally Posted by MikeLacey
Oh absolutely, we're not here to be busy fools.
Would we have problems if we were to treat the chunks we get back from the GetSet* functions as standard XML?
|
Problems, very likely yes, the Reaper data format simply isn't XML. Some XML libraries can be adapted to other, XML-like, documents. However, like I wrote above, I suspect such messing around with 3rd party code is probably gonna be more work than just doing the RPP format parsing directly with some code from scratch.
|
|
|
11-05-2009, 10:14 AM
|
#29
|
|
Mortal
Join Date: Dec 2006
Location: Leicestershire, England
Posts: 426
|
doh!
I read your post the other way around
I'll have a look in an rpp or two
__________________
Mike Lacey, Leicestershire, UK
|
|
|
11-05-2009, 10:48 AM
|
#30
|
|
Mortal
Join Date: Jun 2008
Posts: 1,070
|
if anyone does write some working parsing code pleeze don't forget to post for we less proficient...
|
|
|
11-06-2009, 04:52 AM
|
#31
|
|
Mortal
Join Date: Feb 2009
Location: Melbourne, Australia
Posts: 59
|
Nice! Just installed v3.14rc2 and started playing around with GetSetItemState. Took me a while to get the syntax right but that's only because my Perl is so rusty and I'm too impatient to take time out to do a refresher course rather than keep on bashing away.
The speed of development blows me away with Reaper. Reminds me of the glory days of the original freeware sfz player - seeing opcodes appear over night and getting stuck into testing and using them the next day. ReaScript has an obvious appeal for someone like me that dug the sfz sample definition concept so heavily. It's like having that flexibility and power at a DAW level.
I'm off to nut this Item chunk out. I think I'll soon achieve my intial ReaScript goal after this. But it won't end there... how could it?
A sincere thanks to all the help offered to me in this thread (and others). I'm achieving great new things in my everyday Reaper use thanks to the technology and assistance on offer here.
People, this is an online audio community to be proud of.
|
|
|
11-07-2009, 06:00 AM
|
#32
|
|
Mortal
Join Date: Mar 2008
Location: Sydney, Australia
Posts: 1,837
|
There's some python parsing code to get media item filename in the thread I posted in the dev forum yesterday - sorry on iPhone, can't post links.
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -7. The time now is 09:02 PM.
|