Click to view contents
-------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------
---METRON
-------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------
VPD_MTR_CLR = { {000,000,000},{229,160,032},{170,070,000} }
--miliseconds
function vpd_mtr_ms( var, lat, rns, bps, lps, nol, ms )
var = vws["VPD_MTR_VB_BEATS"].value
lat = vws["VPD_MTR_VB_LATENCY"].value
rns = renoise.song()
bps = rns.transport.bpm / 60
lps = rns.transport.lpb * bps
nol = rns.selected_pattern.number_of_lines
ms = ( 960 + lat ) * ( 1 / lps ) * ( nol / var )
return ms
end
--timer
img_count = 1
but_count = 1
function vpd_mtr_timer( val, acc, img )
val = vws["VPD_MTR_VB_TRAVEL"].value
acc = vws["VPD_MTR_VB_ACCENT"].value
img = "./icons/metron/metron_x"..img_count.."_ico.png"
--images
if val == 2 then
vws["VPD_MTR_BM_METRON"].bitmap = img
if img_count > 3 then img_count = 2 end
end
---
if val == 3 then
vws["VPD_MTR_BM_METRON"].bitmap = img
if img_count == 5 then img_count = 2 end
end
---
if val == 4 then
vws["VPD_MTR_BM_METRON"].bitmap = img
if img_count == 4 then img_count = 0 end
end
---
if val == 5 then
vws["VPD_MTR_BM_METRON"].bitmap = img
if img_count == 5 then img_count = 0 end
end
---
if val == 6 then
vws["VPD_MTR_BM_METRON"].bitmap = img
if img_count == 2 then img_count = 0 end
if but_count == 4 then img_count = 2 end
if img_count == 4 then img_count = 0 end
end
img_count = img_count + 1
--buttons
if ( but_count > val ) then but_count = 1 end
for i = 1, val do
vws["VPD_MTR_BT_X"..val.."_"..i].color = VPD_MTR_CLR[1]
end
if ( acc == but_count ) then
vws["VPD_MTR_BT_X"..val.."_"..but_count].color = VPD_MTR_CLR[3]
else
vws["VPD_MTR_BT_X"..val.."_"..but_count].color = VPD_MTR_CLR[2]
end
but_count = but_count + 1
--start timer (after the first step)
if not rnt:has_timer( vpd_mtr_timer ) then
rnt:add_timer( vpd_mtr_timer, vpd_mtr_ms() ) --start timer
end
end
--invoque vpd_mtr_timer
function vpd_mtr_invoque_timer( com )
com = vws["VPD_MTR_VB_TRAVEL"].value
if ( com == 2 ) then img_count = 3 end
if ( com == 3 ) then img_count = 5 end
if ( com == 4 ) then img_count = 1 end
if ( com == 5 ) then img_count = 1 end
if ( com == 6 ) then img_count = 1 end
but_count = 1
vpd_mtr_timer()
end
--sequence control
local vpd_current_sequence
function vpd_mtr_seq_idx( spi, com )
spi = renoise.song().selected_sequence_index
if ( vpd_current_sequence ~= spi ) then
vpd_current_sequence = spi
print( "vpd_current_sequence",vpd_current_sequence )
---
if rnt:has_timer( vpd_mtr_timer ) then
rnt:remove_timer( vpd_mtr_timer ) --stop timer
--invoque vpd_mtr_timer
vpd_mtr_invoque_timer()
end
---
else
return
end
end
--start
function vpd_mtr_start()
--play song
play_mode = renoise.Transport.PLAYMODE_RESTART_PATTERN
renoise.song().transport:start( play_mode )
--invoque vpd_mtr_timer
vpd_mtr_invoque_timer()
if not rnt:has_timer( vpd_mtr_seq_idx ) then
rnt:add_timer( vpd_mtr_seq_idx, 5 ) --start timer seq
end
end
--remove timer
function vpd_mtr_remove_timer()
if rnt:has_timer( vpd_mtr_timer ) then
rnt:remove_timer( vpd_mtr_timer ) --stop timer
end
end
--reset buttons color
function vpd_mtr_reset_buttons()
for i = 1, 2 do
vws["VPD_MTR_BT_X2_"..i].color = VPD_MTR_CLR[1]
end
for i = 1, 3 do
vws["VPD_MTR_BT_X3_"..i].color = VPD_MTR_CLR[1]
end
for i = 1, 4 do
vws["VPD_MTR_BT_X4_"..i].color = VPD_MTR_CLR[1]
end
for i = 1, 5 do
vws["VPD_MTR_BT_X5_"..i].color = VPD_MTR_CLR[1]
end
for i = 1, 6 do
vws["VPD_MTR_BT_X6_"..i].color = VPD_MTR_CLR[1]
end
end
--reset all
function vpd_mtr_reset_all()
vpd_mtr_remove_timer()
vpd_mtr_reset_buttons()
vws["VPD_MTR_BM_METRON"].bitmap = "./icons/metron/metron_x0_ico.png"
end
--stop
function vpd_mtr_stop()
if rnt:has_timer( vpd_mtr_seq_idx ) then
rnt:remove_timer( vpd_mtr_seq_idx ) --stop timer seq
end
vpd_mtr_reset_all()
renoise.song().transport:stop()
renoise.song().selected_line_index = 1
end
--buttons monitor '1,2...2,1,3...3,1,2,4...'
function vpd_mtr_monitor( value )
vpd_mtr_reset_all()
for i = 2, 6 do
vws["VPD_MTR_RW_X"..i].visible = (value == i)
end
end
--[[
function vpd_mtr_monitor( value )
vpd_mtr_reset_all()
for i = 2, 6 do
if ( value == i ) then
vws["VPD_MTR_RW_X"..value].visible = true
else
vws["VPD_MTR_RW_X"..i].visible = false
end
end
end
]]
--reset values
function vpd_mtr_reset_values()
vws["VPD_MTR_VB_BEATS"].value = 16
vws["VPD_MTR_VB_TRAVEL"].value = 4
vws["VPD_MTR_TX_REPEAT"].text = "4.000"
vws["VPD_MTR_VB_ACCENT"].value = 1
vws["VPD_MTR_VB_LATENCY"].value = 40
end
--repeat
function vpd_mtr_repeat( trv, bts )
bts = vws["VPD_MTR_VB_BEATS"].value
trv = vws["VPD_MTR_VB_TRAVEL"].value
vws["VPD_MTR_TX_REPEAT"].text = ( "%.3f" ):format( bts / trv )
end
--accent
function vbp_mtr_accent( value )
vws["VPD_MTR_VB_ACCENT"].value = 1
vws["VPD_MTR_VB_ACCENT"].max = value
end
--GUI
---------------------------------------------------------------
metron_content = vb:row { margin = 4,
vb:column { margin = 4, style = "plain",
vb:row {
vb:column { height = 101, width = 131,
vb:bitmap { id = "VPD_MTR_BM_METRON", mode = "button_color", bitmap = "./icons/metron/metron_x0_ico.png" }
},
vb:column { spacing = -3,
vb:row {
vb:text { height = 21, width = 50, align = "right", text = "Beats" },
vb:valuebox { id = "VPD_MTR_VB_BEATS", height = 21, width = 50, min = 2, max = 96, value = 16, notifier = function() vpd_mtr_repeat() end,
tooltip = "Beats Per Pattern\n"..
"Divide the pattern according to its number of lines and the Metronome Travel\n[Range 2 to 96]"
}
},
vb:row { height = 6 },
vb:row {
vb:text { height = 21, width = 50, align = "right", text = "Travel" },
vb:valuebox { id = "VPD_MTR_VB_TRAVEL", height = 21, width = 50, min = 2, max = 6, value = 4, notifier = function( value ) vpd_mtr_monitor( value ) vpd_mtr_repeat() vbp_mtr_accent( value ) end,
tooltip = "Metronome Travel (Steps)\n[Range 2 to 6 steps]"
}
},
vb:row {
vb:text { height = 21, width = 50, align = "right", text = "Repeat" },
vb:row { tooltip = "Repetitions in the pattern\nNumber of times that the metronome repeats its travel for each pattern.\n"..
"For correct synchronization, it is necessary that this number is an integer",
vb:text { id = "VPD_MTR_TX_REPEAT", height = 21, width = 50, font = "bold", align = "center", text = "4.000",
}
}
},
vb:row {
vb:text { height = 21, width = 46, align = "right", text = "Accent" },
vb:row { spacing = -3,
vb:button {height = 21, width = 7, color = VPD_MTR_CLR[3], active = false },
vb:valuebox { id = "VPD_MTR_VB_ACCENT", height = 21, width = 50, min = 1, max = 4, value = 1,
tooltip = "Metronome Accent\n[Range 1 to 6]"
}
}
},
vb:space { height = 6 },
vb:row {
vb:text { height = 21, width = 50, align = "right", text = "Latency" },
vb:valuebox { id = "VPD_MTR_VB_LATENCY", height = 21, width = 50, min = 0, max = 80, value = 40,
tooltip = "Metronome Latency\n"..
"This value increases or decreases the numerator of the division (~1000ms), so that the separation between beats is shorter or longer. Lowers the value if the CPU is slow (Metron will work faster).\n"..
"[Range: 0ms .. +40ms .. +80ms. Default = +40ms (960ms +40ms = 1s)]"
}
}
}
},
vb:row { id = "VPD_MTR_RW_X2", spacing = -3, visible = false,
vb:button { id = "VPD_MTR_BT_X2_1", height = 21, width = 117, text = "1", active = false },
vb:button { id = "VPD_MTR_BT_X2_2", height = 21, width = 117, text = "2", active = false },
},
vb:row { id = "VPD_MTR_RW_X3", spacing = -3, visible = false,
vb:button { id = "VPD_MTR_BT_X3_2", height = 21, width = 79, text = "2", active = false },
vb:button { id = "VPD_MTR_BT_X3_1", height = 21, width = 79, text = "1", active = false },
vb:button { id = "VPD_MTR_BT_X3_3", height = 21, width = 79, text = "3", active = false },
},
vb:row { id = "VPD_MTR_RW_X4", spacing = -3, visible = true,
vb:button { id = "VPD_MTR_BT_X4_3", height = 21, width = 60, text = "3", active = false },
vb:button { id = "VPD_MTR_BT_X4_1", height = 21, width = 60, text = "1", active = false },
vb:button { id = "VPD_MTR_BT_X4_2", height = 21, width = 60, text = "2", active = false },
vb:button { id = "VPD_MTR_BT_X4_4", height = 21, width = 60, text = "4", active = false },
},
vb:row { id = "VPD_MTR_RW_X5", spacing = -3, visible = false,
vb:button { id = "VPD_MTR_BT_X5_3", height = 21, width = 49, text = "3", active = false },
vb:button { id = "VPD_MTR_BT_X5_1", height = 21, width = 48, text = "1", active = false },
vb:button { id = "VPD_MTR_BT_X5_5", height = 21, width = 49, text = "5", active = false },
vb:button { id = "VPD_MTR_BT_X5_2", height = 21, width = 48, text = "2", active = false },
vb:button { id = "VPD_MTR_BT_X5_4", height = 21, width = 49, text = "4", active = false },
},
vb:row { id = "VPD_MTR_RW_X6", spacing = -3, visible = false,
vb:button { id = "VPD_MTR_BT_X6_5", height = 21, width = 41, text = "5", active = false },
vb:button { id = "VPD_MTR_BT_X6_3", height = 21, width = 41, text = "3", active = false },
vb:button { id = "VPD_MTR_BT_X6_1", height = 21, width = 41, text = "1", active = false },
vb:button { id = "VPD_MTR_BT_X6_2", height = 21, width = 41, text = "2", active = false },
vb:button { id = "VPD_MTR_BT_X6_4", height = 21, width = 41, text = "4", active = false },
vb:button { id = "VPD_MTR_BT_X6_6", height = 21, width = 41, text = "6", active = false },
},
vb:row {
vb:row { spacing = -3,
vb:button { id = "VPD_MTR_BT_START", height = 21, width = 78, bitmap = "./icons/metron/play_ico.png", notifier = function() vpd_mtr_start() end,
tooltip = "Start Metron from the beginning of the pattern"
},
vb:button { id = "VPD_MTR_BT_STOP", height = 21, width = 78, bitmap = "./icons/metron/stop_first_ico.png", notifier = function() vpd_mtr_stop() end,
tooltip = "Stop Metron / Jump to first line of the pattern"
}
},
vb:button { id = "VPD_MTR_BT_RESET", height = 21, width = 78, bitmap = "./icons/metron/reset_ico.png", notifier = function() vpd_mtr_reset_values() end,
tooltip = "Reset Metron with the default values"
}
}
}
}
--dialog
function vpd_invokes_metron_window()
dialog_metron()
end
metron_dialog = nil
function dialog_metron()
if ( metron_dialog and metron_dialog.visible ) then metron_dialog:show() return metron_dialog:close() , foreground_dialog() end
metron_dialog = renoise.app():show_custom_dialog( " ▛ VPDpro. Metron", metron_content, key_handler )
end
I share the code again in case someone sees something that can be further optimized and he wants to comment…