--[[================================================================== TIM TECHLOR / BPM2MS2HZ CALCULATOR (console edition) ==================================================================== Reads the project tempo and prints a table of all note values as durations in milliseconds and frequencies in Hz - for delay times, LFO rates, release and sidechain settings. ms = 60000 / BPM * beats (1 beat = 1 quarter note) Hz = 1000 / ms Variants: 1/4 plain 1/4. dotted (x 1.5) 1/4T triplet (x 2/3) Bar lengths assume 4/4. ====================================================================]] -------------------------------------------------------------------- -- Configuration -------------------------------------------------------------------- local DIVISIONS = { 1, 2, 4, 8, 16, 32 } -- note values 1/1 to 1/32 local BAR_COUNTS = { 1, 2, 4, 8, 16, 32 } -- bar lengths 1 to 32 bars local VARIANTS = { { suffix = "", factor = 1 }, -- plain { suffix = ".", factor = 1.5 }, -- dotted { suffix = "T", factor = 2 / 3 }, -- triplet } -------------------------------------------------------------------- -- Helpers -------------------------------------------------------------------- local function out(text) reaper.ShowConsoleMsg(text .. "\n") end -- Frame around the header lines (width adapts to the longest line) local function print_box(lines) local width = 0 for _, line in ipairs(lines) do width = math.max(width, #line) end local border = "+" .. string.rep("-", width + 4) .. "+" out(border) for _, line in ipairs(lines) do out(string.format("| %-" .. width .. "s |", line)) end out(border) end local function print_table_header(col1, col2, col3) out("") out(string.format(" %-8s %10s %10s", col1, col2, col3)) out(" " .. string.rep("-", 31)) end -------------------------------------------------------------------- -- Tables -------------------------------------------------------------------- -- All note values: duration in ms, frequency in Hz local function print_notes(beat_ms) print_table_header("NOTE", "MS", "HZ") for _, division in ipairs(DIVISIONS) do local beats = 4 / division for _, variant in ipairs(VARIANTS) do local ms = beat_ms * beats * variant.factor local label = "1/" .. division .. variant.suffix out(string.format(" %-8s %10.1f %10.3f", label, ms, 1000 / ms)) end end end -- Whole bars (4/4): duration in seconds, frequency in Hz local function print_bars(beat_sec) print_table_header("BARS", "SEC", "HZ") for _, count in ipairs(BAR_COUNTS) do local sec = beat_sec * 4 * count local label = (count == 1) and "1 bar" or (count .. " bars") out(string.format(" %-8s %10.3f %10.3f", label, sec, 1 / sec)) end end -------------------------------------------------------------------- -- Main -------------------------------------------------------------------- local function main() reaper.ClearConsole() local bpm = reaper.Master_GetTempo() if not bpm or bpm <= 0 then reaper.ShowConsoleMsg("No valid project tempo found.") return end local beat_ms = 60000 / bpm print_box({ "TIM TECHLOR / BPM2MS2HZ CALCULATOR", string.format("Tempo: %.3f BPM 1 Beat = %.2f ms", bpm, beat_ms), }) print_notes(beat_ms) print_bars(60 / bpm) out("") end main()