|
|
|
09-16-2016, 07:05 PM
|
#1
|
Human being with feelings
Join Date: Jul 2009
Posts: 3,714
|
Converting "reaper object" pointers to strings and back
Does anyone perhaps know if it is possible to convert "reaper object" pointers (to MIDI editors or takes, for example) to strings and back?
This is to save the pointers as ExtState strings that can be recalled later.
Turning a pointer into a string is easy: tostring(editor) gives something like "userdata: 0000DA3EF". But can this string be turned back into a pointer?
|
|
|
09-17-2016, 03:26 AM
|
#2
|
Human being with feelings
Join Date: Apr 2013
Location: France
Posts: 9,900
|
I don't think there is a reaperobject = toreaperobject("string") kinf of function,
A dirty solution would be to chck your string against all other object of the same type also converted to string, and if there is a match, then get the object.
|
|
|
09-17-2016, 04:15 AM
|
#3
|
Human being with feelings
Join Date: Oct 2007
Location: Lincoln, UK
Posts: 7,942
|
Might be a useless exercise anyway, saving them in ExtState, as the IDs of object pointers change between project instantiations.
I saved take GUIDs in Project Marker descriptions so that they reconnected after project reloads. There was no Project ExtState at the time and I needed an "Item Marker" script to track the markers to user moved items -this allowed marker<==>take association data to survive project reloads and even be stored in REAPER's marker/region manager
If I read your intentions correctly, Julian, I'd go for saving GUIDs as strings in ExtState/ProjectExtState and building back to (newly ID'd) objects from there.
Hope this is relevant and we're not at cross-purposes
>
|
|
|
09-17-2016, 04:50 AM
|
#4
|
Human being with feelings
Join Date: Feb 2007
Location: Oulu, Finland
Posts: 8,062
|
Quote:
Originally Posted by planetnine
Might be a useless exercise anyway, saving them in ExtState, as the IDs of object pointers change between project instantiations.
|
Not just "might", serializing and deserializing pointers is in 99% of cases useless to do. (I've maybe once done that in some C++ code, because the code didn't depend on the pointers being the same later when the program was quit and restarted. And I think I later changed that to use a "unique identifier" system anyway.)
__________________
I am no longer part of the REAPER community. Please don't contact me with any REAPER-related issues.
|
|
|
09-18-2016, 01:44 AM
|
#5
|
Human being with feelings
Join Date: Jul 2009
Posts: 3,714
|
Thanks for the replies!
Quote:
Originally Posted by X-Raym
A dirty solution would be to chck your string against all other object of the same type also converted to string, and if there is a match, then get the object.
|
Would it be possible to access a list of all objects of type "HWND midieditor"? (I doubt it, but I hope so!)
The reason why I asked about saving pointers as ExtStates, is so that I can access all pointers to all MIDI editors, in order to apply and coordinate actions (such as zooming) between multiple editors.
|
|
|
09-18-2016, 01:57 AM
|
#6
|
Human being with feelings
Join Date: Feb 2007
Location: Oulu, Finland
Posts: 8,062
|
Quote:
Originally Posted by juliansader
The reason why I asked about saving pointers as ExtStates, is so that I can access all pointers to all MIDI editors, in order to apply and coordinate actions (such as zooming) between multiple editors.
|
This would appear to be a legitimate use case for serializing pointers/object handles, you just need to take care the pointers/handles don't stick around in the persistent storage, causing confusion after Reaper has been quit and restarted.
__________________
I am no longer part of the REAPER community. Please don't contact me with any REAPER-related issues.
|
|
|
06-20-2018, 02:19 PM
|
#7
|
Human being with feelings
Join Date: Jul 2009
Posts: 3,714
|
In C++, converting the "userdata" to a HWND requires nothing more than a typecast!
It seems that, in REAPER's " "userdata: 0000000590C44"", the hex numbers are the actual address, so this works:
Code:
void* JS_CastAddressToHWND(int address)
{
return (HWND)address;
}
|
|
|
06-20-2018, 05:01 PM
|
#8
|
Human being with feelings
Join Date: Feb 2007
Location: Oulu, Finland
Posts: 8,062
|
Quote:
Originally Posted by juliansader
In C++, converting the "userdata" to a HWND requires nothing more than a typecast!
It seems that, in REAPER's " "userdata: 0000000590C44"", the hex numbers are the actual address, so this works:
Code:
void* JS_CastAddressToHWND(int address)
{
return (HWND)address;
}
|
Be extremely careful with that kind of stuff. ints are 32 bit, HWNDs and void*'s (and pointers in general) are 64 bit in 64 bit builds.
__________________
I am no longer part of the REAPER community. Please don't contact me with any REAPER-related issues.
Last edited by Xenakios; 06-20-2018 at 08:23 PM.
|
|
|
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 06:43 AM.
|