Old 11-14-2020, 10:29 AM   #161
daniellumertz
Human being with feelings
 
daniellumertz's Avatar
 
Join Date: Dec 2017
Location: Brazil
Posts: 1,992
Default

I havent tried so It is just a guess:

Code:
 
      Item[i] = reaper.GetSelectedMediaItem( 0, i )
      Item[i] = {}
      Item[i].length = reaper.GetMediaItemInfo_Value(Item[i], 'D_LENGTH')
could you try this ? I might be wrong hehe
daniellumertz is offline   Reply With Quote
Old 11-14-2020, 11:34 AM   #162
sonictim
Human being with feelings
 
sonictim's Avatar
 
Join Date: Feb 2020
Location: Los Angeles
Posts: 463
Default

Quote:
Originally Posted by cool View Post
Thank you! But i get error " attempt to index a userdata value (field '?')" in the
Code:
Item[i].length = reaper.GetMediaItemInfo_Value(Item[i], 'D_LENGTH')
string. What could be the problem?
Sorry, I totally goofed that up... should not have replied while not in front of my computer....

ignore what I wrote... for your purposes, that will come later, and I did it TOTALLY wrong...

if you are simply trying to fade a bunch of items, there's really no need to build the table first, but if the exercise is "learn how to build a function that creates a table" then lets go for it...

Here's how I'd do what you're trying to do:

Code:
function GetItems() -- builds and returns 2 tables

      local item = {}
      local length = {}
      
      local itemcount = reaper.CountSelectedMediaItems()
      if itemcount then
      
          for i = 1, itemcount do
            item[i] = reaper.GetSelectedMediaItem( 0, i-1 )
            length[i] =  reaper.GetMediaItemInfo_Value(item[i], "D_LENGTH")
          end
       else  
      end

return item, length

end -- end of function


function Main()

      local item, it_len = GetItems() --uses above function to retrieve values for these newly created tables
      
      if #item > 0 then
      
        for i = 1, #item do
            reaper.SetMediaItemInfo_Value(item[i], "D_FADEOUTLEN", (it_len[i]/2))
        end
      
      end
end


Main()
reaper.UpdateArrange()
if you're curious... the method I previously described is accomplished as follows, but with only 2 variables.. it's a bit silly....

Code:
      local items = {}

      local itemcount = reaper.CountSelectedMediaItems()
      
      if itemcount > 0 then
      
          for i=1, itemcount do
              local info = {}
              info.ID = reaper.GetSelectedMediaItem( 0, i-1) -- since selected items starts at 0, we adjust here
              info.length = reaper.GetMediaItemInfo_Value(info.ID, "D_LENGTH")
              items[i] =  info
          end
      
      end
      
      
      if #items > 0 then
      
        for i = 1, #items do   -- this loop starts at 1
            reaper.SetMediaItemInfo_Value(items[i].ID, "D_FADEOUTLEN", (items[i].length/2))
        end
      
      end
      reaper.UpdateArrange()
__________________
My Reapack Repository: I write scripts for my own personal use.
I offer no support, but if you find one that helps you, go for it!
sonictim is offline   Reply With Quote
Old 11-14-2020, 11:38 AM   #163
sonictim
Human being with feelings
 
sonictim's Avatar
 
Join Date: Feb 2020
Location: Los Angeles
Posts: 463
Default

Quote:
Originally Posted by daniellumertz View Post
I havent tried so It is just a guess:

Code:
 
      Item[i] = reaper.GetSelectedMediaItem( 0, i )
      Item[i] = {}
      Item[i].length = reaper.GetMediaItemInfo_Value(Item[i], 'D_LENGTH')
could you try this ? I might be wrong hehe

I totally goofed that.. Item[I] has to point to a table.. so you'd have..

item[I] = table
Item[I].ID = item ID
Item[I].length = item length
__________________
My Reapack Repository: I write scripts for my own personal use.
I offer no support, but if you find one that helps you, go for it!
sonictim is offline   Reply With Quote
Old 11-14-2020, 05:37 PM   #164
dsyrock
Human being with feelings
 
dsyrock's Avatar
 
Join Date: Sep 2018
Location: China
Posts: 565
Default

Quote:
Originally Posted by daniellumertz View Post
I think
gfx.mouse_wheel is a variable that return the M wheel

If
gfx.mouse_wheel > 0 then it is up
If
gfx.mouse_wheel < 0 then it is down
if
gfx.mouse_wheel == 0 then nothing

also I think you "need" to reset its value at the end defer cycle to return to 0

like
gfx.mouse_wheel = 0
Ah thanks!
dsyrock is offline   Reply With Quote
Old 11-14-2020, 06:00 PM   #165
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,621
Default

Resetting this variable is only necessary if you want to have it working relative.
For instance: If you want to scroll something piece by piece only when the mousewheel changes, then reset it.
If you want to use the mousewheel to kick off scrolling and control the speed of the ongoing scrolling(e. g. roll further, scroll faster) then don't reset.
__________________
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 11-14-2020, 07:25 PM   #166
cool
Human being with feelings
 
Join Date: Dec 2017
Location: Sunny Siberian Islands
Posts: 957
Default

Quote:
Originally Posted by sonictim View Post
Sorry, I totally goofed that up... should not have replied while not in front of my computer....

ignore what I wrote... for your purposes, that will come later, and I did it TOTALLY wrong...

if you are simply trying to fade a bunch of items, there's really no need to build the table first, but if the exercise is "learn how to build a function that creates a table" then lets go for it...

Here's how I'd do what you're trying to do:

Code:
function GetItems() -- builds and returns 2 tables

      local item = {}
      local length = {}
      
      local itemcount = reaper.CountSelectedMediaItems()
      if itemcount then
      
          for i = 1, itemcount do
            item[i] = reaper.GetSelectedMediaItem( 0, i-1 )
            length[i] =  reaper.GetMediaItemInfo_Value(item[i], "D_LENGTH")
          end
       else  
      end

return item, length

end -- end of function


function Main()

      local item, it_len = GetItems() --uses above function to retrieve values for these newly created tables
      
      if #item > 0 then
      
        for i = 1, #item do
            reaper.SetMediaItemInfo_Value(item[i], "D_FADEOUTLEN", (it_len[i]/2))
        end
      
      end
end


Main()
reaper.UpdateArrange()
if you're curious... the method I previously described is accomplished as follows, but with only 2 variables.. it's a bit silly....

Code:
      local items = {}

      local itemcount = reaper.CountSelectedMediaItems()
      
      if itemcount > 0 then
      
          for i=1, itemcount do
              local info = {}
              info.ID = reaper.GetSelectedMediaItem( 0, i-1) -- since selected items starts at 0, we adjust here
              info.length = reaper.GetMediaItemInfo_Value(info.ID, "D_LENGTH")
              items[i] =  info
          end
      
      end
      
      
      if #items > 0 then
      
        for i = 1, #items do   -- this loop starts at 1
            reaper.SetMediaItemInfo_Value(items[i].ID, "D_FADEOUTLEN", (items[i].length/2))
        end
      
      end
      reaper.UpdateArrange()
Thanks for the detailed answer! Yes, it helped me figure out how tables work.
cool is offline   Reply With Quote
Old 11-15-2020, 10:17 AM   #167
sonictim
Human being with feelings
 
sonictim's Avatar
 
Join Date: Feb 2020
Location: Los Angeles
Posts: 463
Default

Quote:
Originally Posted by cool View Post
Thanks for the detailed answer! Yes, it helped me figure out how tables work.
If you don’t know the number of items you want to add to your table, there’s also the lua function table.insert()

This is useful for things like, (using your example) making a table of selected items you want to fade that are longer than 2 seconds in length.
__________________
My Reapack Repository: I write scripts for my own personal use.
I offer no support, but if you find one that helps you, go for it!
sonictim is offline   Reply With Quote
Old 11-15-2020, 10:49 AM   #168
_Stevie_
Human being with feelings
 
_Stevie_'s Avatar
 
Join Date: Oct 2017
Location: Black Forest
Posts: 5,054
Default

Another way to set multiple values at once (as a multidimensional array) is:

Code:
table = {item_id, length}
table_pos = 1 -- tables start at 1

for i = 0, num_items-1 do
   item_table[table_pos] = {
      item_id = reaper.GetSelectedMediaItem(0, i)
      length =  reaper.GetMediaItemInfo_Value(item[i], "D_LENGTH")
   }
   table_pos = table_pos + 1
end
That would result in
Code:
item_table[table_pos].item_id
item_table[table_pos].length
__________________
My Reascripts forum thread | My Reascripts on GitHub
If you like or use my scripts, please support the Ukraine: Ukraine Crisis Relief Fund | DirectRelief | Save The Children | Razom
_Stevie_ is offline   Reply With Quote
Old 11-15-2020, 12:56 PM   #169
sonictim
Human being with feelings
 
sonictim's Avatar
 
Join Date: Feb 2020
Location: Los Angeles
Posts: 463
Default

Quote:
Originally Posted by _Stevie_ View Post
Another way to set multiple values at once (as a multidimensional array) is:

Code:
table = {item_id, length}
table_pos = 1 -- tables start at 1

for i = 0, num_items-1 do
   item_table[table_pos] = {
      item_id = reaper.GetSelectedMediaItem(0, i)
      length =  reaper.GetMediaItemInfo_Value(item[i], "D_LENGTH")
   }
   table_pos = table_pos + 1
end
That would result in
Code:
item_table[table_pos].item_id
item_table[table_pos].length
Thanks! I knew that was possible but I’ve been having a hard time figuring out the syntax!
__________________
My Reapack Repository: I write scripts for my own personal use.
I offer no support, but if you find one that helps you, go for it!
sonictim is offline   Reply With Quote
Old 11-15-2020, 01:19 PM   #170
_Stevie_
Human being with feelings
 
_Stevie_'s Avatar
 
Join Date: Oct 2017
Location: Black Forest
Posts: 5,054
Default

Tell me about it! Tables were a mystery to me for a long time, as well
__________________
My Reascripts forum thread | My Reascripts on GitHub
If you like or use my scripts, please support the Ukraine: Ukraine Crisis Relief Fund | DirectRelief | Save The Children | Razom
_Stevie_ is offline   Reply With Quote
Old 11-15-2020, 10:35 PM   #171
cool
Human being with feelings
 
Join Date: Dec 2017
Location: Sunny Siberian Islands
Posts: 957
Default

daniellumertz, sonictim, _Stevie_, thank you! This is very useful information. By the way, I remembered the test of different tables algorithms from Amagalma: https://forum.cockos.com/showpost.ph...65&postcount=7

Am I getting it right that Steve's variant has better performance?
cool is offline   Reply With Quote
Old 11-16-2020, 07:11 PM   #172
sonictim
Human being with feelings
 
sonictim's Avatar
 
Join Date: Feb 2020
Location: Los Angeles
Posts: 463
Default

Quote:
Originally Posted by cool View Post
daniellumertz, sonictim, _Stevie_, thank you! This is very useful information. By the way, I remembered the test of different tables algorithms from Amagalma: https://forum.cockos.com/showpost.ph...65&postcount=7

Am I getting it right that Steve's variant has better performance?
The slower example from Amagalma counts the table with each iteration so every time it runs it has an extra step for filling the table. As all the examples we gave fill the table by number count, my guess is the difference in time wouldn’t be that dramatic. That said, someone should test and find out.
__________________
My Reapack Repository: I write scripts for my own personal use.
I offer no support, but if you find one that helps you, go for it!
sonictim is offline   Reply With Quote
Old 11-17-2020, 02:35 AM   #173
_Stevie_
Human being with feelings
 
_Stevie_'s Avatar
 
Join Date: Oct 2017
Location: Black Forest
Posts: 5,054
Default

That’s correct, #table (table length) makes iterating slower because it calls the API.
That’s something ama pointed out here, too:

https://forum.cockos.com/showpost.ph...45&postcount=5

With my test project of 1500 items it definitely showed a difference.
__________________
My Reascripts forum thread | My Reascripts on GitHub
If you like or use my scripts, please support the Ukraine: Ukraine Crisis Relief Fund | DirectRelief | Save The Children | Razom
_Stevie_ is offline   Reply With Quote
Old 11-17-2020, 09:25 PM   #174
dsyrock
Human being with feelings
 
dsyrock's Avatar
 
Join Date: Sep 2018
Location: China
Posts: 565
Default

Hi, is it possible to move the mouse cursor to a selected item, like the left edge of it? I'm not sure if there is a way to get the coordinate of an item on screen so that I can use JS_Mouse_SetPosition to set the mouse position.
dsyrock is offline   Reply With Quote
Old 11-18-2020, 04:08 AM   #175
cool
Human being with feelings
 
Join Date: Dec 2017
Location: Sunny Siberian Islands
Posts: 957
Default

Hi guys! Thanks for your help, but I'm asking questions again.

So, I have a simplified code that draws an envelope from the points that are taken from the table. For example, this is now just a project grid step. I want to further develop the code, but I don't know some things. My unresolved questions now:

If I want to draw points between two existing ones (even if they are at different distances), how can I do that? An example in the picture. Logic tells me what to do: add the length to the two nearest points and divide by two. (pos + next_pos) / 2 Is this the right direction? If so, how do I get the value of the "next" point?

Second question: Now the very first point is not in the table, I draw it on a separate line. I understand the BR_GetNextGridDivision command only recalculates the next points, but not the first one. How can I add the first point to this table?

Code:
 --------------------------------initial------------------------------------
reaper.Main_OnCommand(reaper.NamedCommandLookup("_S&M_TAKEENVSHOW1"),0) --create take envelope
local item = reaper.GetSelectedMediaItem(0,0)
take  = reaper.GetActiveTake(item)
envelope = reaper.GetTakeEnvelope(take, 0)
rate = reaper.GetMediaItemTakeInfo_Value(take,'D_PLAYRATE')
sel_start = reaper.GetMediaItemInfo_Value(item, "D_POSITION")
sel_end = sel_start + reaper.GetMediaItemInfo_Value(item, "D_LENGTH")
sel_len = sel_end - sel_start

-----------------------collect and store grid points-------------------------
Grid_Points = {}
local grid_p = sel_start 
  while (grid_p <= sel_end) do
      grid_p = reaper.BR_GetNextGridDivision(grid_p)
      Grid_Points[#Grid_Points+1] = grid_p
  end 

------------------------create envelope points-------------------------------------------------------------
if envelope then
            Gain = 0 -- level of lower points
    local mode = reaper.GetEnvelopeScalingMode(envelope)
            Gain = reaper.ScaleToEnvelopeMode(mode,  Gain)
            G_1 = reaper.ScaleToEnvelopeMode(mode, 1)     --  1 - gain

    reaper.DeleteEnvelopePointRange( envelope, 0, (sel_start + sel_len)*rate ) -- initial delete all points
    reaper.InsertEnvelopePoint(envelope, 0, G_1, 5, 0, 1, true) -- insert the first point

            for i=1, #Grid_Points do
                    if i<#Grid_Points then pos = (sel_start + (Grid_Points[i]))*rate end
                    if Grid_Points then 
                        reaper.InsertEnvelopePoint(envelope, (pos)-(sel_start*2*rate)-0.01,  Gain, 5, 0, 1, true)-- lower points 
                        reaper.InsertEnvelopePoint(envelope, (pos)-(sel_start*2*rate), G_1, 5, 0, 1, true)  -- higher points 
                    end
            end
end
reaper.UpdateArrange()
cool is offline   Reply With Quote
Old 11-18-2020, 10:25 AM   #176
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 dsyrock View Post
Hi, is it possible to move the mouse cursor to a selected item, like the left edge of it? I'm not sure if there is a way to get the coordinate of an item on screen so that I can use JS_Mouse_SetPosition to set the mouse position.
https://forum.cockos.com/showthread.php?t=47409
https://forum.cockos.com/showthread.php?t=32738

(that's doing it with actions)
nofish is offline   Reply With Quote
Old 11-18-2020, 10:55 AM   #177
dsyrock
Human being with feelings
 
dsyrock's Avatar
 
Join Date: Sep 2018
Location: China
Posts: 565
Default

Quote:
Originally Posted by nofish View Post
Thanks. But I mean moving the mouse cursor, not the edit cursor.
dsyrock is offline   Reply With Quote
Old 11-18-2020, 11:16 AM   #178
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 dsyrock View Post
Thanks. But I mean moving the mouse cursor, not the edit cursor.
As you wrote in your original post, I overread that, sorry.
nofish is offline   Reply With Quote
Old 11-18-2020, 12:37 PM   #179
jkooks
Human being with feelings
 
Join Date: May 2020
Posts: 190
Default

Quote:
Originally Posted by cool View Post
If I want to draw points between two existing ones (even if they are at different distances), how can I do that? An example in the picture. Logic tells me what to do: add the length to the two nearest points and divide by two. (pos + next_pos) / 2 Is this the right direction? If so, how do I get the value of the "next" point?
Not too sure if this does what you want, but getting the average between the two points seems like it is what you want to do. Also, you can get those points relatively easily if you loop through all of the original points (before you adjust/delete them) and just reference their info as you create the new ones.

I modified your code in order to add the points your picture showed between any already existing points.

Code:
 --------------------------------initial------------------------------------
reaper.Main_OnCommand(reaper.NamedCommandLookup("_S&M_TAKEENVSHOW1"),0) --create take envelope
local item = reaper.GetSelectedMediaItem(0,0)
take  = reaper.GetActiveTake(item)
envelope = reaper.GetTakeEnvelope(take, 0)
rate = reaper.GetMediaItemTakeInfo_Value(take,'D_PLAYRATE')
sel_start = reaper.GetMediaItemInfo_Value(item, "D_POSITION")
sel_end = sel_start + reaper.GetMediaItemInfo_Value(item, "D_LENGTH")
sel_len = sel_end - sel_start


--stores info for all of the original points
points = {}
if envelope then
	local pointNum = reaper.CountEnvelopePoints(envelope)
	for i = 1, pointNum do
		points[i] = {}
		local retval, pos, val, shape, tension = reaper.GetEnvelopePoint(envelope, i-1)
	
		points[i] = {
			val = val,
			pos = pos,
			shape = shape,
			tension = tension
		}
	end
end


-----------------------collect and store grid points-------------------------
Grid_Points = {}
local grid_p = sel_start 
while (grid_p <= sel_end) do
  grid_p = reaper.BR_GetNextGridDivision(grid_p)
  Grid_Points[#Grid_Points+1] = grid_p
end 

------------------------create envelope points-------------------------------------------------------------
if envelope and points then --makes it only run if there are existing points
    Gain = 0 -- level of lower points
    local mode = reaper.GetEnvelopeScalingMode(envelope)
    Gain = reaper.ScaleToEnvelopeMode(mode,  Gain)
    G_1 = reaper.ScaleToEnvelopeMode(mode, 1)     --  1 - gain

    reaper.DeleteEnvelopePointRange( envelope, 0, (sel_start + sel_len)*rate ) -- initial delete all points

    --only inserts the begining point if needed
    if points and points[1].pos ~= 0.0 then
	    reaper.InsertEnvelopePoint(envelope, 0, G_1, 5, 0, 1, true) -- insert the first point
    end


    local pointLen = #points 

    --adds all of the points
    for i=1, pointLen do
    	--add the lower points if there are still recorded points after this one
	if i < pointLen then    	
	    	local pos = (points[i].pos + points[i+1].pos)/2 --get the length between the points

	        reaper.InsertEnvelopePoint(envelope, pos,  Gain, 5, 0, 1, true)-- lower points
	        reaper.InsertEnvelopePoint(envelope, points[i+1].pos, Gain, 5, 0, 1, true)  -- lower point at same time as the original one
        end

        reaper.InsertEnvelopePoint(envelope, points[i].pos, points[i].val, points[i].shape, points[i].tension, 1, true)  -- original point 
    end

    reaper.Envelope_SortPoints(envelope) --sorts all of the newly added points
end

reaper.UpdateArrange()
Quote:
Originally Posted by cool View Post
Second question: Now the very first point is not in the table, I draw it on a separate line. I understand the BR_GetNextGridDivision command only recalculates the next points, but not the first one. How can I add the first point to this table?
If you need to add the point into an array/table, you can just use the Lua function table.insert to do that.
jkooks is offline   Reply With Quote
Old 11-19-2020, 05:56 AM   #180
cool
Human being with feelings
 
Join Date: Dec 2017
Location: Sunny Siberian Islands
Posts: 957
Default

Quote:
Originally Posted by jkooks View Post
Not too sure if this does what you want, but getting the average between the two points seems like it is what you want to do. Also, you can get those points relatively easily if you loop through all of the original points (before you adjust/delete them) and just reference their info as you create the new ones.

I modified your code in order to add the points your picture showed between any already existing points.

Thanks! It turned out to be more difficult than I thought
cool is offline   Reply With Quote
Old 11-29-2020, 05:51 AM   #181
daniellumertz
Human being with feelings
 
daniellumertz's Avatar
 
Join Date: Dec 2017
Location: Brazil
Posts: 1,992
Default

Is it possible to a script prompt an windows, to user select an file?

then have the item location
daniellumertz is offline   Reply With Quote
Old 11-29-2020, 07:09 AM   #182
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 daniellumertz View Post
Is it possible to a script prompt an windows, to user select an file?

then have the item location
Could this help?

https://mespotin.uber.space/Ultrasch...ileNameForRead
__________________
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 11-29-2020, 08:15 AM   #183
daniellumertz
Human being with feelings
 
daniellumertz's Avatar
 
Join Date: Dec 2017
Location: Brazil
Posts: 1,992
Default

ahhhh yes that hahaha thanksss didn't imagine that this would have in the API thought it would need an Lua trick :P thanks!!
daniellumertz is offline   Reply With Quote
Old 12-19-2020, 03:39 PM   #184
daniellumertz
Human being with feelings
 
daniellumertz's Avatar
 
Join Date: Dec 2017
Location: Brazil
Posts: 1,992
Default

Is possible to get the last time an item have its chunk modified ?
daniellumertz is offline   Reply With Quote
Old 12-19-2020, 04:22 PM   #185
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,621
Default

Nope. Unless you store it yourself but then you can only get your changes, not the ones done by 3rd party scripts.
__________________
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 12-19-2020, 07:04 PM   #186
daniellumertz
Human being with feelings
 
daniellumertz's Avatar
 
Join Date: Dec 2017
Location: Brazil
Posts: 1,992
Default

thanks mespotine I was just wondering, is not for some script specifically.

that could be useful for triggering scripts when something is changed. Now the way to that would be store the chunk in a variable and compare next defer cycle right? I don't know if there would be much performance gain doing the other way....

thanks for the response.
daniellumertz is offline   Reply With Quote
Old 12-24-2020, 05:05 PM   #187
daniellumertz
Human being with feelings
 
daniellumertz's Avatar
 
Join Date: Dec 2017
Location: Brazil
Posts: 1,992
Default

How do I trim an item at position X?

for now I am doing :

Code:
function TrimStart(item, pos)
    local new_item = reaper.SplitMediaItem(item, pos)
    local reaper.DeleteTrackMediaItem(track, item)
    return new_item
end
the thing it deletes the old and create a new, not a problem for now but must be other way.
daniellumertz is offline   Reply With Quote
Old 12-24-2020, 05:14 PM   #188
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,621
Default

Use
https://mespotin.uber.space/Ultrasch...ItemInfo_Value

and set the length via D_LENGTH.

You probably need to subtract the value for D_POSITION using
https://mespotin.uber.space/Ultrasch...ItemInfo_Value

from pos first.
__________________
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 12-24-2020, 05:23 PM   #189
daniellumertz
Human being with feelings
 
daniellumertz's Avatar
 
Join Date: Dec 2017
Location: Brazil
Posts: 1,992
Default

Hi mespotine happy Xmas, nice to read you

I was trying somethings here did it:

Code:
function TrimStart(item, amount, pos, is_pos)
    local len = reaper.GetMediaItemInfo_Value( item, 'D_LENGTH' )
    local start = reaper.GetMediaItemInfo_Value( item, 'D_POSITION' )
    local take = reaper.GetMediaItemTake( item, 0 )
    local off = reaper.GetMediaItemTakeInfo_Value( take, 'D_STARTOFFS' )
    if is_pos == true then
        amount = pos - start
    end
    reaper.SetMediaItemInfo_Value( item, 'D_POSITION' , start + amount )
    reaper.SetMediaItemTakeInfo_Value( take, 'D_STARTOFFS', off + amount )
    reaper.SetMediaItemInfo_Value( item, 'D_LENGTH' , (len-amount) )
end
Thanks!!!

Will try using how you suggested just a moment

Edit: corrected the code !
Edit Edit: Edit the code to have an option of position
Edit Edit Edit

I benchmark and TrimEnd (changing info) Was faster than TrimEnd2 ( using split)
Code:
function TrimEnd(item, amount, pos, is_pos)
    local len = reaper.GetMediaItemInfo_Value( item, 'D_LENGTH' )
    if is_pos == true then
        local start = reaper.GetMediaItemInfo_Value( item, 'D_POSITION' )
        amount = (len + start) - pos
    end
    reaper.SetMediaItemInfo_Value( item, 'D_LENGTH' , len-amount )
end

function TrimEnd2(item, amount, pos, is_pos)
    del = reaper.SplitMediaItem(item, pos)
    tr = reaper.GetMediaItem_Track( del )
    reaper.DeleteTrackMediaItem(tr, del)
end

Last edited by daniellumertz; 12-24-2020 at 06:12 PM.
daniellumertz is offline   Reply With Quote
Old 01-01-2021, 05:51 AM   #190
daniellumertz
Human being with feelings
 
daniellumertz's Avatar
 
Join Date: Dec 2017
Location: Brazil
Posts: 1,992
Default

Hey people using

reaper.SetMediaItemInfo_Value(item, 'D_LENGTH', some_lenght )

To extend Items I notices reaper creates these fellas here



They are placed in the old end of the item.

Wondering how I can take them off, I know I can glue items and then rename "as the naming is important for this script", any other solutions?


happy 2021!
daniellumertz is offline   Reply With Quote
Old 01-01-2021, 06:17 AM   #191
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,621
Default

They signal, that the old media source end there.
Do you use a Midiitem here?
__________________
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 01-01-2021, 06:26 AM   #192
daniellumertz
Human being with feelings
 
daniellumertz's Avatar
 
Join Date: Dec 2017
Location: Brazil
Posts: 1,992
Default

Yes I used an MIDI Item.

The thing is I can't edit MIDI ( manually ) after these things, wish I can remove this in my script.

For removing manually I just change the track end and it updates
daniellumertz is offline   Reply With Quote
Old 01-01-2021, 07:24 AM   #193
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,621
Default

I think that this could qualify as a bug, that the function was designed with audio items in mind and the devs forgot, that Midiitems don't have a fixed end as a flac or wav-file has.
__________________
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 01-01-2021, 07:57 AM   #194
daniellumertz
Human being with feelings
 
daniellumertz's Avatar
 
Join Date: Dec 2017
Location: Brazil
Posts: 1,992
Default

Yeah I thought i could be a bug hahaha will make a thread thanks mespotine!
daniellumertz is offline   Reply With Quote
Old 01-01-2021, 08:40 AM   #195
_Stevie_
Human being with feelings
 
_Stevie_'s Avatar
 
Join Date: Oct 2017
Location: Black Forest
Posts: 5,054
Default

No, it’s not a bug, for MIDI items you have to additionally use https://www.extremraym.com/cloud/rea...SetItemExtents
__________________
My Reascripts forum thread | My Reascripts on GitHub
If you like or use my scripts, please support the Ukraine: Ukraine Crisis Relief Fund | DirectRelief | Save The Children | Razom
_Stevie_ is offline   Reply With Quote
Old 01-01-2021, 11:02 AM   #196
daniellumertz
Human being with feelings
 
daniellumertz's Avatar
 
Join Date: Dec 2017
Location: Brazil
Posts: 1,992
Default

woooo, thaks a lot Stevie
daniellumertz is offline   Reply With Quote
Old 01-01-2021, 08:54 PM   #197
_Stevie_
Human being with feelings
 
_Stevie_'s Avatar
 
Join Date: Oct 2017
Location: Black Forest
Posts: 5,054
Default

You’re welcome, gave me some headache in the past, too
__________________
My Reascripts forum thread | My Reascripts on GitHub
If you like or use my scripts, please support the Ukraine: Ukraine Crisis Relief Fund | DirectRelief | Save The Children | Razom
_Stevie_ is offline   Reply With Quote
Old 01-02-2021, 11:01 PM   #198
daniellumertz
Human being with feelings
 
daniellumertz's Avatar
 
Join Date: Dec 2017
Location: Brazil
Posts: 1,992
Default

So to make MIDI Items be an pooled copy of the another I can copy paste this chunk line. Is there other way?

POOLEDEVTS {SOME GUID HERE}
daniellumertz is offline   Reply With Quote
Old 01-04-2021, 10:25 AM   #199
Coachz
Human being with feelings
 
Coachz's Avatar
 
Join Date: Oct 2010
Location: Charleston, SC
Posts: 12,770
Default

Does anyone know how to explicitly set midi editor grid visible or not ? not toggle
__________________
Track Freezing Scripts

Coachz Repo
Coachz is offline   Reply With Quote
Old 01-06-2021, 12:40 AM   #200
daniellumertz
Human being with feelings
 
daniellumertz's Avatar
 
Join Date: Dec 2017
Location: Brazil
Posts: 1,992
Default

is there a way to get if the there was some change in track order ?

In a script I am making I have to constantly updates de GUI with the track ID the user selected . So if a track is added or change the ID it gets updated in the GUI also. It is already working, but uses more CPU than I wanted. ( not much tho...)

It would be peferct if I could get an input when something that affects tracks ID happen so only then I ask my GUI to repick the selected tracks ID


Thanks
daniellumertz 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 12:58 AM.


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