function main()
local i_cnt= reaper.CountSelectedMediaItems(0) if i_cnt == 0 then return end
local ret, cur, ret2, new = reaper.GetUserInputs('bpm converter', 1, 'Original BPM', 120)
if ret and tonumber (cur) then ret2, new = reaper.GetUserInputs('bpm converter', 1, 'Target BPM', 120) end
if ret2 and tonumber (new) then
for i =1 , i_cnt do
it = reaper.GetSelectedMediaItem(0,i-1)
len = reaper.GetMediaItemInfo_Value( it, 'D_LENGTH' )
reaper.SetMediaItemInfo_Value( it, 'D_LENGTH',len*cur/new )
take = reaper.GetActiveTake(it)
rate = reaper.GetMediaItemTakeInfo_Value( take, 'D_PLAYRATE' )
reaper.SetMediaItemTakeInfo_Value( take, 'D_PLAYRATE',rate*new/cur )
end
end
end
reaper.Undo_BeginBlock()
main()
reaper.UpdateArrange()
reaper.Undo_EndBlock( 'convert BPM', 0 )