Last active
December 7, 2024 08:58
-
-
Save X-Raym/f515430e8117e6a87d6f to your computer and use it in GitHub Desktop.
ReaScript Lua Tutorial
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
---------------- Old Version : | |
vol_dB = 20 * ( math.log( vol_log, 10 ) ) | |
vol_log = math.exp( vol_dB * 0.115129254 ) | |
---------------- New Version : | |
-- Mod from SPK77 | |
-- http://forum.cockos.com/showpost.php?p=1608719&postcount=6 | |
function dBFromVal(val) return 20*math.log(val, 10) end | |
function ValFromdB(dB_val) return 10^(dB_val/20) end | |
-- test | |
some_dB_val = dBFromValue(2) -- should be ~6.02 dB | |
some_dB_val_to_val = ValFromdB(some_dB_val) -- should be "2" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
selected_items_count = reaper.CountSelectedMediaItems(0) | |
-- INITIALIZE loop through selected items | |
for i = 0, selected_items_count-1 do | |
-- GET ITEMS | |
item = reaper.GetSelectedMediaItem(0, i) -- Get selected item i | |
-- DO SOMETHING HERE | |
end -- ENDLOOP through selected items |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Msg(param) | |
reaper.ShowConsoleMsg(tostring(param).."\n") | |
end | |
function Main() | |
item_mouse, mouse_pos = reaper.BR_ItemAtMouseCursor() -- Get item under mouse | |
if item_mouse ~= nil then -- If no item under mouse | |
-- INSERT CODE HERE | |
end -- ENDIF no item under mouse | |
end | |
reaper.ShowConsoleMsg("") | |
Main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Msg(param) | |
reaper.ShowConsoleMsg(tostring(param).."\n") | |
end | |
function Main() | |
reaper.Main_OnCommand(40289, 0) | |
item_mouse, mouse_pos = reaper.BR_ItemAtMouseCursor() | |
if tostring(item_mouse) ~= "userdata: 0000000000000000" then | |
item_mouse_fadeout = reaper.GetMediaItemInfo_Value(item_mouse, "D_FADEOUTLEN") | |
start_time, end_time = reaper.GetSet_LoopTimeRange2(0, false, false, 0, 0, false) | |
if start_time ~= end_time then | |
Action() | |
end | |
end | |
end | |
function Action() | |
count_sel_tracks = reaper.CountSelectedTracks(0) | |
for j = 0, count_sel_tracks - 1 do | |
track = reaper.GetSelectedTrack(0, j) | |
count_items_on_track = reaper.CountTrackMediaItems(track) | |
for i = 0, count_items_on_track - 1 do | |
item = reaper.GetTrackMediaItem(track, i) | |
item_pos = reaper.GetMediaItemInfo_Value(item, "D_POSITION") | |
if item_pos > end_time then | |
break | |
else | |
item_len = reaper.GetMediaItemInfo_Value(item, "D_LENGTH") | |
item_end = item_pos + item_len | |
if (item_pos > start_time and item_pos < end_time) or (item_end > start_time and item_end < end_time) or (item_pos < start_time and item_end > end_time) then | |
reaper.SetMediaItemInfo_Value(item, "D_FADEOUTLEN", item_mouse_fadeout) | |
end | |
end | |
end | |
end | |
reaper.UpdateArrange() | |
end | |
reaper.ShowConsoleMsg("") | |
Main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- RUN A NATIVE ACTION | |
-- Base on it's command ID. | |
reaper.Main_OnCommand(40289, 0) -- Unselect all items | |
-- RUN AN ACTION FROM A EXTENSION, LIKE SWS | |
-- You will need another function to do that. | |
reaper.Main_OnCommand(reaper.NamedCommandLookup("_SWS_SELTRKWITEM"), 0) -- Select only track with selected items |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- A function to set an Item Fade-Out Length in security. | |
function SetItemFadeOut(item, item_len, fade_out_len) | |
fade_in_len = reaper.GetMediaItemInfo_Value(item, "D_FADEINLEN") | |
max_value = item_len - fade_in_len | |
if fade_out_len > max_value then | |
fade_out_len = max_value | |
end | |
--[[ Optionnal | |
if fade_out_len < 0 | |
fade_out_len = 0 | |
end | |
]] | |
reaper.SetMediaItemInfo_Value(item, "D_FADEOUTLEN", fade_out_len) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment