Old 01-10-2025, 07:42 PM   #1
rekkandevar
Human being with feelings
 
rekkandevar's Avatar
 
Join Date: Jan 2020
Posts: 171
Default gmem not connecting properly: what am i doing wrong?

I am trying to write a script which will transmit a media item's notes to the video processor to use as a subtitle. The roadblock I have encountered is that no matter what I do, none of the gmem values I'm writing inside the Reascript are being read from the video processor. Please let me know what I'm doing wrong here.

Here is the ReaScript:
Code:
local memory_start = 0
local max_tracks = 16
local max_text_length = 256

reaper.gmem_attach("Subtitles")
for i = memory_start, memory_start + (max_tracks * max_text_length) - 1 do
    reaper.gmem_write(i, i) --gmem should contain 1, 2, 3, etc.
end


local function store_text_in_memory(track_index, text)
    local memory_index = memory_start + (track_index * max_text_length)
    for i = 1, max_text_length do
        char_code = 0 <= #text and text:byte(i) or 0
        reaper.gmem_write(memory_index + i - 1, char_code)
    end
end

local function update_global_memory()
    local playhead_position = reaper.GetPlayPosition()
    for track_index = 0, 0 do --limited to track 1 for testing
        track = reaper.GetTrack(0, track_index)
        did = 0
        if track then
            local item_count = reaper.CountTrackMediaItems(track)
            local text = ""

            for item_index = 0, item_count - 1 do
                local item = reaper.GetTrackMediaItem(track, item_index)
                local item_start = reaper.GetMediaItemInfo_Value(item, "D_POSITION")
                local item_length = reaper.GetMediaItemInfo_Value(item, "D_LENGTH")
                local item_end = item_start + item_length
                if playhead_position >= item_start and playhead_position <= item_end then
                    --local take = reaper.GetActiveTake(item)
                    if item then
                        retval, note = reaper.GetSetMediaItemInfo_String(item, "P_NOTES", "", false)
                        text = note
                        did = 1
                    end
                end
            end
            if did == 0 then
              text = ""
            end

            store_text_in_memory(track_index, text)
        else
            store_text_in_memory(track_index, "")
        end
    end
   
end

local function main()
    update_global_memory()
    gfx.update()
    reaper.defer(main)
end

gfx.init("Subtitle Sync", 1, 1, 0, 0, 0)
main()
and here is the video processor preset I've written (heavily adapted from the default text overlay):
Code:
//@param1:size 'text height' 0.05 0.01 0.2 0.1 0.001
//@param2:ypos 'y position' 0.95 0 1 0.5 0.01
//@param3:xpos 'x position' 0.5 0 1 0.5 0.01
//@param4:border 'bg pad' 0.1 0 1 0.5 0.01
//@param5:fgc 'text bright' 1.0 0 1 0.5 0.01
//@param6:fga 'text alpha' 1.0 0 1 0.5 0.01
//@param7:bgc 'bg bright' 0.75 0 1 0.5 0.01
//@param8:bga 'bg alpha' 0.5 0 1 0.5 0.01
//@param9:bgfit 'fit bg to text' 0 0 1 0.5 1
//@param10:ignoreinput 'ignore input' 0 0 1 0.5 1

//@param12:tc 'show timecode' 0 0 1 0.5 1
//@param13:tcdf 'dropframe timecode' 0 0 1 0.5 1
//@param14:chn 'current track' 0 0 8 1 1
//@gmem:Subtitles

font = "Arial";
index = chn;

track = chn;
max_text_length = 256;
memory_start = 0;


input = ignoreinput ? -2:0;
project_wh_valid===0 ? input_info(input,project_w,project_h);
gfx_a2=0;
gfx_blit(input,1);
gfx_setfont(size*project_h,font);
i=0;
#text = "";
memory_index = memory_start + track * max_text_length;
gfx_str_measure(#text,txtw,txth);
b = (border*txth)|0;
yt = ((project_h - txth - b*2)*ypos)|0;
xp = (xpos * (project_w-txtw))|0;
gfx_set(bgc,bgc,bgc,bga);
bga>0?gfx_fillrect(bgfit?xp-b:0, yt, bgfit?txtw+b*2:project_w, txth+b*2);
gfx_set(fgc,fgc,fgc,fga);
#text = "";
loop(10,
  value = gmem[memory_index + i];
  sprintf(#text, "gmem[%d] = %d", memory_index + i, value);
  gfx_str_draw(#text, 10, gfx_y);
  gfx_y += 20;
  i+=1;
);
I'm pretty clueless at this point. It really seems like gmem isn't working at all and I have no idea how to debug that. Thank you
rekkandevar is offline   Reply With Quote
Old 01-10-2025, 08:11 PM   #2
rekkandevar
Human being with feelings
 
rekkandevar's Avatar
 
Join Date: Jan 2020
Posts: 171
Default

it had to be
Code:
//@gmem=Subtitles
instead of
Code:
//@gmem:Subtitles
rekkandevar is offline   Reply With Quote
Old 01-11-2025, 05:16 AM   #3
mschnell
Human being with feelings
 
mschnell's Avatar
 
Join Date: Jun 2013
Location: Krefeld, Germany
Posts: 16,592
Default

Thanks for letting us know !
mschnell 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 09:45 PM.


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