-- Konfiguracja
local STEPS = 64
local MIDI_CHANNEL = 1
local NOTE = 60 -- C4
local CLOCK_BPM = 120
-- Inicjalizacja
local current_step = 1
local steps = {}
-- Inicjalizacja tabeli kroków
for i=1,STEPS do
steps[i] = {active = false}
end
-- Obsługa przycisków kroków
for i=1,STEPS do
local name = "step"..i
local control = controls[name]
if control then
control.onpress = function()
steps[i].active = not steps[i].active
end
end
end
-- Zegar
local interval = 60 / (CLOCK_BPM * 4) -- 16th notes
local timer = 0
function onTimer()
timer = timer + 1
if timer >= interval * 1000 then
timer = 0
current_step = current_step + 1
if current_step > STEPS then
current_step = 1
end
controls.current_step.text = "Step: "..current_step
-- Wyślij MIDI jeśli krok jest aktywny
if steps[current_step].active then
midi:send{
type = "note_on",
channel = MIDI_CHANNEL - 1, -- MIDI channels 0-15
note = NOTE,
velocity = 64
}
end
end
end
-- Uruchom zegar
timer_start()