Old 09-16-2016, 07:05 PM   #1
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 3,714
Default 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?
juliansader is offline   Reply With Quote
Old 09-17-2016, 03:26 AM   #2
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 9,900
Default

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.
X-Raym is offline   Reply With Quote
Old 09-17-2016, 04:15 AM   #3
planetnine
Human being with feelings
 
planetnine's Avatar
 
Join Date: Oct 2007
Location: Lincoln, UK
Posts: 7,942
Default

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



>
__________________
Nathan, Lincoln, UK. | Item Marker Tool. (happily retired) | Source Time Position Tool. | CD Track Marker Tool. | Timer Recording Tool. | dB marks on MCP faders FR.
planetnine is online now   Reply With Quote
Old 09-17-2016, 04:50 AM   #4
Xenakios
Human being with feelings
 
Xenakios's Avatar
 
Join Date: Feb 2007
Location: Oulu, Finland
Posts: 8,062
Default

Quote:
Originally Posted by planetnine View Post
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.
Xenakios is offline   Reply With Quote
Old 09-18-2016, 01:44 AM   #5
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 3,714
Default

Thanks for the replies!

Quote:
Originally Posted by X-Raym View Post
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.
juliansader is offline   Reply With Quote
Old 09-18-2016, 01:57 AM   #6
Xenakios
Human being with feelings
 
Xenakios's Avatar
 
Join Date: Feb 2007
Location: Oulu, Finland
Posts: 8,062
Default

Quote:
Originally Posted by juliansader View Post
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.
Xenakios is offline   Reply With Quote
Old 06-20-2018, 02:19 PM   #7
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 3,714
Default

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;
}
juliansader is offline   Reply With Quote
Old 06-20-2018, 05:01 PM   #8
Xenakios
Human being with feelings
 
Xenakios's Avatar
 
Join Date: Feb 2007
Location: Oulu, Finland
Posts: 8,062
Default

Quote:
Originally Posted by juliansader View Post
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.
Xenakios 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 06:43 AM.


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