View Single Post
Old 12-10-2018, 06:52 AM   #19
mespotine
Human being with feelings
 
mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig, Germany
Posts: 1,401
Default

5 days, until you can finally

get all MediaItems by time and tracks, using GetAllMediaItemsBetween:
Code:
integer count, array MediaItemArray, array MediaItemStateChunkArray = ultraschall.GetAllMediaItemsBetween(number startposition, number endposition, string trackstring, boolean inside)
, the way you are used from doing in the arrange-view:

Code:
-- Ultraschall-API demoscript by Meo Mespotine 30.11.2018
-- 
-- shows the MediaItems within time-selection and within selected tracks
-- also shows the number of found items
-- if no time-selection exists, it will display the found items at editcursorposition in selected tracks


dofile(reaper.GetResourcePath().."/UserPlugins/ultraschall_api.lua")

function main()
  -- get selected tracks and time-selection(loop)
  selected_trackstring = ultraschall.CreateTrackString_SelectedTracks()
  loopstart, loopend = reaper.GetSet_LoopTimeRange(false, false, 0, 0, false)
  if loopstart==0 and loopend==0 then loopstart=reaper.GetCursorPosition() loopend=reaper.GetCursorPosition() end
  
  -- get the MediaItems within selected tracks and time-selection
  count, MediaItemArray, MediaItemStateChunkArray = ultraschall.GetAllMediaItemsBetween(loopstart, loopend, selected_trackstring, false)
  
  -- if the selection has changed, show the currently found items in the ReaConsole-window
  if oldcount~=count or oldloopstart~=loopstart or oldloopend~=loopend or oldselected_trackstring~=selected_trackstring then
    reaper.ClearConsole()
    reaper.ShowConsoleMsg("Found Items: "..count.."\n\nList of Items:\n")
    for i=1, count do
      reaper.ShowConsoleMsg(tostring(MediaItemArray[i]).."\n")
    end
  end
  
  -- keep the old values to check next defer-cycle, whether anything has changed
  oldcount=count
  oldloopstart=loopstart
  oldloopend=loopend
  oldselected_trackstring=selected_trackstring
  
  -- start the next defer-cycle
  reaper.defer(main)
end

main()



or do ripple-cut the way you want:

Code:
-- Ultraschall-API demoscript by Meo Mespotine 30.11.2018
-- 
-- Apply Ripple-Cut of MediaItems only on selected tracks and time-selection

dofile(reaper.GetResourcePath().."/UserPlugins/ultraschall_api.lua")

selection_start, selection_end = reaper.GetSet_LoopTimeRange(false, false, 0, 0, 0)
trackstring = ultraschall.CreateTrackString_SelectedTracks()
number_items, MediaItemArray_StateChunk = ultraschall.RippleCut(selection_start, selection_end, trackstring, true, false)
selection_start, selection_end = reaper.GetSet_LoopTimeRange(true, false, reaper.GetCursorPosition(), reaper.GetCursorPosition(), 0)


or manipulate multiple MediaItems at the same time(like length in this example)

Code:
-- Ultraschall-API demoscript by Meo Mespotine 29.10.2018
-- 
-- Change length of MediaItems by a value, in selected Tracks and Time-Selection
-- MediaItems must be fully within the time-selection, at least in this demo, though you
-- can choose to use MediaItems only partially within time-selection as well
-- see functions-reference-docs for more details on GetAllMediaItemsBetween()

dofile(reaper.GetResourcePath().."/UserPlugins/ultraschall_api.lua")

selection_start, selection_end = reaper.GetSet_LoopTimeRange(false, false, 0, 0, 0)
trackstring = ultraschall.CreateTrackString_SelectedTracks()
count, MediaItemArray = ultraschall.GetAllMediaItemsBetween(selection_start, selection_end, trackstring, true)

if count>0 then
  retval, deltalength = reaper.GetUserInputs("Alter by length(in seconds):", 1, "", "")
  if type(tonumber(deltalength))=="number" then
    retval = ultraschall.ChangeDeltaLengthOfMediaItems_FromArray(MediaItemArray, tonumber(deltalength))
  else
    reaper.MB("Must be a number", "Number needed", 0)
  end
end
__________________
Ultraschall-API - a Lua-functions-library4Reaper: https://forum.cockos.com/showthread....98#post2067798
Reaper Internals - Developerdocs4Reaper: https://forum.cockos.com/showthread.php?t=207635
mespotine is offline   Reply With Quote