Old 02-16-2019, 12:11 AM   #1
MusoBob
Human being with feelings
 
MusoBob's Avatar
 
Join Date: Sep 2014
Posts: 1,037
Default Sync Item to Tempo Map

If I drag a drum track that has an embedded tempo into a session with a tempo map it will not work, though it works in every other DAW.
https://forum.cockos.com/showthread.php?t=216497

So I will make a script to:

It will ask for the bpm of the selected item
set the playback rate of the item to match the current tempo
move to the next tempo marker and split the item
select the item after cursor and set the playback rate of the item to match the current tempo
move to the next tempo marker and split the item...
.......
.......

remove track crossfades

the user can then glue the split items if need be.

Unless someone knows of a script that will do this already ?
MusoBob is offline   Reply With Quote
Old 02-16-2019, 06:05 PM   #2
MusoBob
Human being with feelings
 
MusoBob's Avatar
 
Join Date: Sep 2014
Posts: 1,037
Default

This works okay but loops a section on the end when it changes playback rate, not sure how to avoid that so I just set it to not loop but the length is still added.

Here's some Drums to try
https://www.dropbox.com/s/iyc2il43za...pm120.wav?dl=1
just create a tempo map, drag the wav in, run the script on the selected item, set it to 120.

Here's the Lua

Code:
    -- Display a message in the console for debugging
    
    function Msg(variable)
      reaper.ShowConsoleMsg(tostring(variable).."\n")
    end
    cur_pos = reaper.GetCursorPosition()
    retval, org_bpm = reaper.GetUserInputs("Set Item's Original Tempo", 1, "Enter item's tempo (bpm):", "" )
    
    if retval then
    reaper.Main_OnCommand(40042,0) -- Transport: Go to start of project
    tempo_markers_count = reaper.CountTempoTimeSigMarkers(0)
    for i = 0, tempo_markers_count - 1 do
    
        reaper.Main_OnCommand(40759,0) --Item: Split items at edit cursor (select right)
        retval, timepos, measurepos, beatpos, bpm, timesig_num, timesig_denom, lineartempo = reaper.GetTempoTimeSigMarker(0, i)
        item = reaper.GetSelectedMediaItem(0, 0) 
        take = reaper.GetMediaItemTake(item, 0)
        playrate = bpm / org_bpm
        reaper.SetMediaItemTakeInfo_Value( take, "D_PLAYRATE", playrate )
        reaper.Main_OnCommand(41821,0) --Move edit cursor to next tempo or time signature change
        
    end    
        
    reaper.SetMediaItemInfo_Value(item, "B_LOOPSRC", 0)
    
    Info2 = [[
      
    "If you want to glue the items together"
    
    "make sure the end is correct"
      
    "else cancel out and adjust it"
    
    "then Remove fade in and fade out then glue" ]]
    
    reaper.MB(Info2, "Information", 0)
    
    
    retval,input  = reaper.GetUserInputs("Glue Items", 1, "This will glue split item", "")
    
    if retval then
       reaper.Main_OnCommand(40421,0) --Item: Select all items in track
       reaper.Main_OnCommand(41193,0) --Item: Remove fade in and fade out
       reaper.Main_OnCommand(41588,0) --Item: Glue items
    end
    reaper.SetEditCurPos(cur_pos, 1, 0)      
    
end

Last edited by MusoBob; 02-16-2019 at 09:55 PM.
MusoBob is offline   Reply With Quote
Old 02-19-2019, 08:44 PM   #3
MusoBob
Human being with feelings
 
MusoBob's Avatar
 
Join Date: Sep 2014
Posts: 1,037
Default

Download Script
https://www.dropbox.com/s/cc4or4jke8...20map.zip?dl=1
If you have ReaTrak put the script in that folder else Scripts folder.

MusoBob 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 08:02 PM.


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