|
|
|
11-16-2018, 03:14 PM
|
#1
|
Human being with feelings
Join Date: Mar 2016
Posts: 1,239
|
Noobie scripter with question
Hi all
I'm beginning to learn Lua scripting with the help of X-Raym's videos and articles. Early days.
However, among the scripts I'm keen to develop, I'd like to be able to move items and fades etc depending on Zoom Level eg one application of the script moves an item by one pixel, rather than a fixed amount of time.
This way, I can move items a long way quickly when zoomed out, but zoom in and use the same script/hotkey to adjust the position very precisely.
I can see how to move items by fixed time units with the Position parameter, but how can a script know what length of time one pixel on the screen represents?
Many thanks
Andy
|
|
|
11-16-2018, 03:35 PM
|
#2
|
Human being with feelings
Join Date: Apr 2011
Posts: 3,451
|
Welcome
1.
Code:
start_time, end_time = reaper.GetSet_ArrangeView2( 0, false, 0, 0 )
Gives the start and end times of the arrange view.
2.
However, the Nudge Dialog (Action List _> Item edit: Close nudge/set dialog) has a setting for pixels, if you would like to use this.
3.
Code:
reaper.ApplyNudge( 0, nudgeflag, nudgewhat, 19, value, reverse, 0)
nudgeflag: &1=set to value (otherwise nudge by value), &2=snap
nudgewhat: 0=position, 1=left trim, 2=left edge, 3=right edge, 4=contents, 5=duplicate, 6=edit cursor
nudgeunit: 0=ms, 1=seconds, 2=grid, 3=256th notes, ..., 15=whole notes, 16=measures.beats (1.15 = 1 measure + 1.5 beats), 17=samples, 18=frames, 19=pixels, 20=item lengths, 21=item selections
value: amount to nudge by, or value to set to
reverse: in nudge mode, nudges left (otherwise ignored)
copies: in nudge duplicate mode, number of copies (otherwise ignored)
Last edited by amagalma; 11-16-2018 at 03:43 PM.
|
|
|
11-16-2018, 11:30 PM
|
#3
|
Human being with feelings
Join Date: Apr 2013
Location: France
Posts: 9,875
|
Note that there is already an action for that, Its called Move items left/right a little bit if I remember well, or maybe even look for "move items pixel", (Im away from reaper, but these are natives).
|
|
|
11-17-2018, 02:25 AM
|
#4
|
Human being with feelings
Join Date: Mar 2016
Posts: 1,239
|
Thank you both!
I'm sure I will be back with more questions in the coming months 😀
Andy
|
|
|
11-17-2018, 01:39 PM
|
#5
|
Human being with feelings
Join Date: Mar 2016
Posts: 1,239
|
Can't see those actions you refer to X-Raym....
Nothing comes up in the Action list for "pixel" except cursor moves.
"Move Item" doesn't seem to bring up any native actions related to this, either.
Any other thoughts on what they might be called?
Cheers
Andy
|
|
|
11-17-2018, 02:25 PM
|
#6
|
Human being with feelings
Join Date: Aug 2012
Location: Finland
Posts: 2,668
|
This might help:
Code:
function msg(m)
reaper.ShowConsoleMsg(tostring(m) .. "\n")
end
function show_arrange_view_size_data()
-- arrange view start and end in seconds
local arr_start, arr_end = reaper.GetSet_ArrangeView2(0, false, 0,0)
-- arrange view length in seconds
local arr_len = arr_end-arr_start
-- arrange view length in pixels
local arr_len_in_pixels = reaper.GetHZoomLevel()*arr_len
-- one pixel to seconds
local one_pixel_to_seconds = arr_len/arr_len_in_pixels
msg("arrange view start: " .. arr_start)
msg("arrange view end: " .. arr_end)
msg("arrange view length in seconds: " .. arr_len)
msg("arrange view length in pixels: " .. arr_len_in_pixels)
msg("one pixel represents: " .. one_pixel_to_seconds .. " seconds")
msg("\n")
end
show_arrange_view_size_data()
Here's something related - Scroll view horizontally by X pixels (mousewheel): https://forum.cockos.com/showthread....81#post2022281
Last edited by spk77; 11-17-2018 at 03:05 PM.
|
|
|
11-17-2018, 03:02 PM
|
#7
|
Human being with feelings
Join Date: Apr 2013
Location: France
Posts: 9,875
|
Quote:
Can't see those actions you refer to X-Raym....
|
You are right, what I thought was Envelopes: Move selected points right a little bit and View: Move cursor right one pixel, but it is the Item edit: Move items/envelope points right do what you need :P
Else, use spk77 code to try, or the cursor action to make a custom one !
|
|
|
11-17-2018, 03:23 PM
|
#8
|
Human being with feelings
Join Date: Mar 2016
Posts: 1,239
|
Quote:
Originally Posted by amagalma
Welcome
1.
Code:
start_time, end_time = reaper.GetSet_ArrangeView2( 0, false, 0, 0 )
Gives the start and end times of the arrange view.
2.
However, the Nudge Dialog (Action List _> Item edit: Close nudge/set dialog) has a setting for pixels, if you would like to use this.
3.
Code:
reaper.ApplyNudge( 0, nudgeflag, nudgewhat, 19, value, reverse, 0)
nudgeflag: &1=set to value (otherwise nudge by value), &2=snap
nudgewhat: 0=position, 1=left trim, 2=left edge, 3=right edge, 4=contents, 5=duplicate, 6=edit cursor
nudgeunit: 0=ms, 1=seconds, 2=grid, 3=256th notes, ..., 15=whole notes, 16=measures.beats (1.15 = 1 measure + 1.5 beats), 17=samples, 18=frames, 19=pixels, 20=item lengths, 21=item selections
value: amount to nudge by, or value to set to
reverse: in nudge mode, nudges left (otherwise ignored)
copies: in nudge duplicate mode, number of copies (otherwise ignored)
|
Thanks amagalma
I'm experimenting with the Nudge function here, and I think I'll be able to do at least one of the tasks I need with it.
Two questions, please:
1) what is the meaning of the &1, &2 in the nudgeflag parameter? I've got the nudge working on an item by entering 0 in this field, but putting '&1' there gave me an error, so it's obviously meant to mean something else. Can you explain please?
2) there is no parameter for which ITEM the function should act on... only the project parameter... does it mean this function will automatically act on all selected items? If not, what?
Many thanks for any help.
Andy
|
|
|
11-18-2018, 01:52 AM
|
#9
|
Human being with feelings
Join Date: Mar 2016
Posts: 1,239
|
Quote:
Originally Posted by X-Raym
You are right, what I thought was Envelopes: Move selected points right a little bit and View: Move cursor right one pixel, but it is the Item edit: Move items/envelope points right do what you need :P
Else, use spk77 code to try, or the cursor action to make a custom one !
|
Yeah, thanks. I'll experiment!
Andy
|
|
|
11-18-2018, 04:40 AM
|
#10
|
Human being with feelings
Join Date: Aug 2012
Location: Finland
Posts: 2,668
|
Here's Move item(s) by X pixels.lua (Note: undo point handling should be added)
Code:
local reaper = reaper
function msg(m)
reaper.ShowConsoleMsg(tostring(m) .. "\n")
end
function move_items_by_pixels(pixel_count)
pixel_count = pixel_count or 1 -- move by 1 pixel to the right (if no arguments passed)
-- arrange view start and end in seconds
local arr_start, arr_end = reaper.GetSet_ArrangeView2(0, false, 0,0)
-- arrange view length in seconds
local arr_len = arr_end-arr_start
-- arrange view length in pixels
local arr_len_in_pixels = reaper.GetHZoomLevel()*arr_len
-- one pixel to seconds
local one_pixel_to_seconds = arr_len/arr_len_in_pixels
local sel_items = reaper.CountSelectedMediaItems(0)
if sel_items == 0 then
return
end
-- It's better to collect the selected items first, because they are moved around
local items = {}
for i=1, sel_items do
local item = reaper.GetSelectedMediaItem(0, i-1)
if item then
items[i] = item
end
end
-- Move items
local len_items = #items
for i=1, len_items do
local item = items[i]
local item_pos = reaper.GetMediaItemInfo_Value(item, "D_POSITION")
reaper.SetMediaItemInfo_Value(item, "D_POSITION", item_pos + one_pixel_to_seconds*pixel_count)
end
end
-----------------------------------
-- This is how to use the function:
-----------------------------------
move_items_by_pixels(1) -- Move selected items 1 pixel to the right
--move_items_by_pixels(-1) -- Move selected items 1 pixel to the left
--move_items_by_pixels(10) -- Move selected items 10 pixels to the right
|
|
|
11-18-2018, 04:49 AM
|
#11
|
Human being with feelings
Join Date: Mar 2016
Posts: 1,239
|
Thanks spk77
I'll check this out.
At the moment, I get a bit confused by all the local variable stuff (the last time I did any coding was the 1980s!) but I'm sure I'll figure it out in the end :-)
Andy
|
|
|
11-25-2018, 09:22 AM
|
#12
|
Human being with feelings
Join Date: Mar 2016
Posts: 1,239
|
Hi
Another very basic question....
How do I get the next media item on a track from a selected one, into a variable?
I can see how to get a media item directly from an ID number (GetMediaItem (o, itemidx), but I can't see how to return the itemidx value from a selected item so I can then add one to it and alter properties of the "neighbour" of the selected one.
Help please?
Many thanks
Andy
|
|
|
11-26-2018, 04:41 AM
|
#13
|
Human being with feelings
Join Date: Apr 2013
Location: France
Posts: 9,875
|
Code:
next_item = reaper.GetTrackMediaItem(track, item_id + 1)
|
|
|
11-26-2018, 07:25 AM
|
#14
|
Human being with feelings
Join Date: Mar 2016
Posts: 1,239
|
Hi Raymond
Thanks for answering. What I can't see is how to know the itemID of the CURRENT item, so that I can add 1 to it to get the next one.
What function returns the item ID of the currently selected item (or at least, the item I've currently got stored in a variable)?
Cheers
Andy
|
|
|
11-26-2018, 08:11 AM
|
#15
|
Human being with feelings
Join Date: Apr 2013
Location: France
Posts: 9,875
|
Check the doc of reaper.GetMediaItemInfo_Value, it has a parameter for item ID on track.
Also, a good place to start is too checking simple scripts source code right from the action list with REAPER IDE. Look for Next items, or Previous items, you will have some code snippet to extract here and there.
|
|
|
11-26-2018, 08:20 AM
|
#16
|
Human being with feelings
Join Date: Mar 2016
Posts: 1,239
|
Gosh, how embarrassing. I'd been looking in exactly that function, but somehow failed to see the IP-ITEMNUMBER attribute.... :-(
Thanks for your patience, Raymond.
I will indeed try checking out some other scripts to see what I can understand and adapt.
Cheers
Andy
|
|
|
Thread Tools |
|
Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -7. The time now is 11:58 PM.
|