View Single Post
Old 05-12-2019, 08:16 AM   #486
Sexan
Human being with feelings
 
Sexan's Avatar
 
Join Date: Jun 2009
Location: Croatia
Posts: 4,602
Default



Instead of calling JS_Composite for every item in AS for example:
If there are 16 items JS_Composite will be called 16 times in loop, so if there are more items it will call it X times.

What I want is to minimize that and cpu usage and flickering (more items it has the flickering get more noticeable since it is looping it x times):
Build all items rectangles into one single image and then compose ONLY that one:

this is what I do atm:
Code:
for i = 1, x do
 item_bm = reaper.JS_LICE_CreateBitmap() -- create bitmap for item
 reaper.JS_Composite(item_bm) -- draw what bitmap
end
what I want is:
Code:
final_image = reaper.JS_LICE_CreateBitmap() -- bitmap where all the rectangles of all items will be
for i = 1, x do
 item_bm = reaper.JS_LICE_CreateBitmap() -- create bitmap for item
 reaper.JS_LICE_FillRect(item_bg) --fill that bitmap with rectangle
 reaper.JS_LICE_Blit(final_bm, item_bm) -- copy item bitmap to final image 
end
reaper.JS_Composite(final_bg) -- draw the final bitmap with all rectangles of all items, CALL IT ONLY ONCE
Since I'm still pretty bad with blitting, code above copies item_bm to final_mb?

this is the code I'm using now
Code:
local i_y, i_h, i_b = A[tostring(atrack)].t + t_h, A[tostring(atrack)].h + t_h, A[tostring(atrack)].b + t_h
        if not items_bm[i] then items_bm[i] = {} end
        for j = 1, #active_as.tracks[i].items do
          local item = active_as.tracks[i].items[j]
          if items_bm[i][j] == nil then items_bm[i][j] = reaper.JS_LICE_CreateBitmap(true, 1, 1); reaper.JS_LICE_Clear(items_bm[i][j], 0x66557788) end
          local new_item_start, new_item_lenght = as_item_position(item, active_as.sel_start, active_as.sel_end, mouse_time_pos)
          reaper.JS_Composite(track_window, math.floor(new_item_start * zoom_lvl) - Arr_pixel, (i_y - y_view_start), math.floor(new_item_lenght * zoom_lvl), i_b - i_y, items_bm[i][j], 0, 0, 1, 1)
        end
The code is available on my git,WIP folder draw_item_shadow() function so you can see what it does, just make selection over items

Last edited by Sexan; 05-12-2019 at 08:23 AM.
Sexan is online now   Reply With Quote