Old 03-15-2024, 11:06 AM   #1
jkooks
Human being with feelings
 
Join Date: May 2020
Posts: 190
Default Getting Project from MediaItem or MediaTrack

Hey all!

Is there any way to get the ReaProject object that a respective track or media item exist in? I know that the parameter "P_PROJECT" exists for MediaTracks but that just gives a number value, and to the best of my knowledge I don't know how to associate that with a ReaProject. Anyone know of a way to get this information from the track or item? Or do I just have to check every project's tracks/items to see if the track or item are in it, then break early when the track/item is found?

Last edited by jkooks; 03-15-2024 at 12:04 PM.
jkooks is offline   Reply With Quote
Old 03-15-2024, 12:11 PM   #2
Fabian
Human being with feelings
 
Fabian's Avatar
 
Join Date: Sep 2008
Location: Sweden
Posts: 7,416
Default

Quote:
Originally Posted by jkooks View Post
Hey all!

Is there any way to get the ReaProject object that a respective track or media item exist in? I know that the parameter "P_PROJECT" exists for MediaTracks but that just gives a number value, and to the best of my knowledge I don't know how to associate that with a ReaProject. Anyone know of a way to get this information from the track or item? Or do I just have to check every project's tracks/items to see if the track or item are in it, then break early when the track/item is found?
Looking at the API, GetMediaTrackInfo_Value(track, "P_PROJECT") should return (a pointer to, hence the "P") the ReaProject object. Are you saying that this is not the case?
__________________
// MVHMF
I never always did the right thing, but all I did wasn't wrong...
Fabian is offline   Reply With Quote
Old 03-15-2024, 04:44 PM   #3
jkooks
Human being with feelings
 
Join Date: May 2020
Posts: 190
Default

I don't believe it does - in Lua, for example, it returns a number value and not a userdata type. Wasn't sure if there was an extra step I had to do to get the appropriate ReaProject object that was associated with the number value.
jkooks is offline   Reply With Quote
Old 03-15-2024, 04:56 PM   #4
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,621
Default

Quote:
Originally Posted by jkooks View Post
I don't believe it does - in Lua, for example, it returns a number value and not a userdata type. Wasn't sure if there was an extra step I had to do to get the appropriate ReaProject object that was associated with the number value.
Just use the returned number as ReaProject-parameter.
For instance, the following code gets the project of the first track and writes a text into the project's notes:

Code:
A,B,C=reaper.GetMediaTrackInfo_Value(reaper.GetTrack(0,0), "P_PROJECT")

reaper.GetSetProjectNotes(B, true, "Set this to the notes")
Never noticed this, btw but since the function returns a number all the time it probably is logical that it uses a number to describe the project.
Though I don't know, how the number is created. It's not the opened project-tab so it must be something else.

At least it looks like from my tests...
__________________
Use you/she/her.Ultraschall-Api Lua Api4Reaper - Donate, if you wish

On vacation for the time being...
Meo-Ada Mespotine is offline   Reply With Quote
Old 03-15-2024, 06:25 PM   #5
jkooks
Human being with feelings
 
Join Date: May 2020
Posts: 190
Default

Oh, interesting, I will check that out then! I tried to get the actual ReaProject using EnumProjects and passing the number as the index, but as I expected it didn't actually work like that and just returned an empty ReaProject. I will test just passing the number to each function by itself and see how that works.
jkooks is offline   Reply With Quote
Old 03-15-2024, 06:30 PM   #6
nofish
Human being with feelings
 
nofish's Avatar
 
Join Date: Oct 2007
Location: home is where the heart is
Posts: 12,096
Default

Quote:
Originally Posted by Meo-Ada Mespotine View Post
Though I don't know, how the number is created. It's not the opened project-tab so it must be something else.
It's the same memory location, just either in decimal or hex.
nofish is offline   Reply With Quote
Old 03-16-2024, 11:24 AM   #7
jkooks
Human being with feelings
 
Join Date: May 2020
Posts: 190
Default

Curious as to why there is no similar value for media items and only tracks. I assume it is because it is easy enough to write a function that grabs the track for the item and gets the project from the track, but curious if there is a deeper technical reason why items don't have project associations (or at least exposed ones).
jkooks is offline   Reply With Quote
Old 03-16-2024, 12:07 PM   #8
Fabian
Human being with feelings
 
Fabian's Avatar
 
Join Date: Sep 2008
Location: Sweden
Posts: 7,416
Default

Quote:
Originally Posted by jkooks View Post
Curious as to why there is no similar value for media items and only tracks. I assume it is because it is easy enough to write a function that grabs the track for the item and gets the project from the track, but curious if there is a deeper technical reason why items don't have project associations (or at least exposed ones).
You can write your own function:
Code:
local function ItemToProject(item)
    local mediatrack = reaper.GetMediaItem_Track(tem)
    return reaper.GetMediaTrackInfo_Value(mediatrack, "P_PROJECT")
end
I do not see much use in the API having a specific function for this two-line code.
__________________
// MVHMF
I never always did the right thing, but all I did wasn't wrong...
Fabian 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 04:47 AM.


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