View Single Post
Old 01-07-2016, 04:04 AM   #9
swiiscompos
Human being with feelings
 
swiiscompos's Avatar
 
Join Date: Mar 2011
Location: London
Posts: 1,211
Default

This is already an existing action, I don't think it would be very useful to rewrite the code... From my experience scoring, movies most of the time it's a target tempo that you have and you play around with time signatures and hit points to get as close from this target tempo as possible.

EDIT: Here is the existing code, very incomplete and with terrible formatting but it's fairly simple so you shouldn't have to much difficulty figuring it out.

Code:
function main()

t_sec = end_time-start_time --gives the time selection length in seconds  
a=0 -- 0 means only whole bars, 1 allows one shorter bar
t_tempo=121.00 --target tempo, user input
time_sig=4 --main time signature, user input (still have to include the denominator)
t_min=t_sec/60 --time in minutes


q = math.floor(t_tempo*t_min/time_sig)--number of whole bars we can fit, euclidean division.
r=t_tempo*t_min-q*time_sig --remainder of the eucliean division
inc_bar = math.floor(r + 0.5) --Round number, incomplete bar time sig


if a == 0 then
  if r<(time_sig/2) then
    tempo = q*time_sig/t_min
    n_bars_norm = q
    else 
    tempo = (q+1)*time_sig/t_min
    n_bars_norm = q+1
  end
  else
  tempo = (q*time_sig+inc_bar)/t_min
  n_bars_norm = q
end


reaper.ClearConsole()
reaper.ShowConsoleMsg(" Result="..q.." ".."Rest="..r.." ".."incomplete time sig="..inc_bar.." tempo="..tempo)
end

--RUN

-- GET TIME SELECTION EDGES
start_time, end_time = reaper.GetSet_LoopTimeRange(false, false, 0, 0, false)

-- IF TIME SELECTION
if start_time ~= end_time then
main()
end

Last edited by swiiscompos; 01-07-2016 at 04:47 AM.
swiiscompos is offline   Reply With Quote