zmena delky trasy, ukladani
This commit is contained in:
parent
affea562da
commit
872e4c5c08
|
@ -4,13 +4,12 @@ dead simple drum machine
|
|||
|
||||
## todo
|
||||
|
||||
- factor
|
||||
- split
|
||||
- saving & loading
|
||||
- loading
|
||||
- MIDI connection
|
||||
- demos
|
||||
- manual!!!
|
||||
- vymyslket lepší jméno
|
||||
- lepší vzhled
|
||||
- vymyslet lepší jméno
|
||||
|
||||
## resources
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ require "midiwire"
|
|||
-- now, this can actually play Blue monday!
|
||||
-- see https://www.youtube.com/watch?v=Y_hk5P1X7sc&t=164s
|
||||
|
||||
LEN = 33
|
||||
step = 1
|
||||
mout = midiwire.open_out(0)
|
||||
active_pat = 1
|
||||
|
@ -29,14 +30,14 @@ pat_a = iup.button{title="PAT A", fontstyle="Bold"}
|
|||
pat_b = iup.button{title="PAT B"}
|
||||
pat_c = iup.button{title="PAT C"}
|
||||
pat_d = iup.button{title="PAT D"}
|
||||
pat_rec = iup.button{title="PAT REC"}
|
||||
pat_rec = iup.button{title="REC"}
|
||||
pat_load = iup.button{title="load"}
|
||||
pat_save = iup.button{title="save"}
|
||||
|
||||
matrix = iup.matrix{numcol=32, numlin=9, widthdef=10}
|
||||
matrix.resizematrix = "YES"
|
||||
|
||||
matrix:setcell(0,0,"Drumsheet")
|
||||
matrix:setcell(0,0,"DRUMsheet")
|
||||
for i=1,32 do
|
||||
matrix:setcell(0,i,i)
|
||||
end
|
||||
|
@ -47,15 +48,19 @@ end
|
|||
playbtn = iup.button{title="play"}
|
||||
stopbtn = iup.button{title="stop"}
|
||||
|
||||
bpm = iup.text{spin="YES", value="120"}
|
||||
-- TODO - maskovat tyhle věci a validovat ať to necrashuje
|
||||
|
||||
bpm = iup.text{spin="YES", value="120", spinmin=30, spinmax=240} -- todo: min max sensible
|
||||
factor = iup.text{spin="YES", value="4", spinmin=1, spinmax=8}
|
||||
len = iup.text{spin="YES", value="32", spinmin=8, spinmax=32}
|
||||
|
||||
dlg = iup.dialog{
|
||||
iup.vbox{
|
||||
iup.hbox{pat_a, pat_b, pat_c, pat_d, pat_rec ,pat_load, pat_save; gap=5},
|
||||
iup.hbox{matrix},
|
||||
iup.hbox{playbtn, stopbtn, iup.label{title="tempo: "} , bpm; alignment="ACENTER", gap="5"}
|
||||
iup.hbox{playbtn, stopbtn, iup.label{title="tempo: "} , bpm, iup.label{title="/"}, factor, iup.label{title=" || len: "}, len; alignment="ACENTER", gap="5"}
|
||||
}
|
||||
; title = "Drumsheets", size = "560x170"
|
||||
; title = "DRUMsheet", size = "560x170"
|
||||
}
|
||||
|
||||
-- GUI actions
|
||||
|
@ -64,8 +69,9 @@ timer = iup.timer{time=500}
|
|||
timer.run="NO"
|
||||
|
||||
function timer:action_cb()
|
||||
-- ONE STEP of sequencer
|
||||
if step==1 then
|
||||
matrix:setcell(9, 32, "")
|
||||
matrix:setcell(9, LEN-1, "")
|
||||
else
|
||||
matrix:setcell(9, step-1, "") -- clean from previous step
|
||||
end
|
||||
|
@ -77,11 +83,7 @@ function timer:action_cb()
|
|||
end
|
||||
end
|
||||
|
||||
if matrix:getcell(1, step)=="x" then
|
||||
midiwire.drum(mout, 39)
|
||||
end
|
||||
|
||||
step = ((step + 1) % 33)
|
||||
step = ((step + 1) % LEN)
|
||||
if step==0 then
|
||||
step=1
|
||||
end
|
||||
|
@ -89,13 +91,20 @@ function timer:action_cb()
|
|||
end
|
||||
|
||||
function playbtn:action()
|
||||
bpm.active="NO"
|
||||
factor.active="NO"
|
||||
len.active="NO"
|
||||
timer.run="YES"
|
||||
end
|
||||
|
||||
function stopbtn:action()
|
||||
bpm.active="YES"
|
||||
factor.active="YES"
|
||||
len.active="YES"
|
||||
timer.run="NO"
|
||||
-- todo - tohle lépe
|
||||
if step==1 then
|
||||
matrix:setcell(9, 32, "")
|
||||
matrix:setcell(9, LEN-1, "")
|
||||
else
|
||||
matrix:setcell(9, step-1, "") -- clean from previous step
|
||||
end
|
||||
|
@ -103,30 +112,39 @@ function stopbtn:action()
|
|||
step = 1
|
||||
end
|
||||
|
||||
function adjust_time(bpm, factor)
|
||||
timer.time = math.floor((1000*60) / (bpm*factor) )
|
||||
end
|
||||
|
||||
function bpm:valuechanged_cb()
|
||||
if tonumber(bpm.value) then
|
||||
-- this is weird, i know
|
||||
timer.time = math.floor((1000*60) / (tonumber(bpm.value)*4) )
|
||||
if tonumber(bpm.value) and tonumber(factor.value) then
|
||||
adjust_time(tonumber(bpm.value), tonumber(factor.value))
|
||||
end
|
||||
end
|
||||
|
||||
-- easier changing of patterns
|
||||
|
||||
--[[
|
||||
function matrix:click_cb(x, y, status)
|
||||
if x<1 or y<1 then
|
||||
return
|
||||
function factor:valuechanged_cb()
|
||||
if tonumber(bpm.value) and tonumber(factor.value) then
|
||||
adjust_time(tonumber(bpm.value), tonumber(factor.value))
|
||||
end
|
||||
print(iup.GetFocus())
|
||||
if matrix:getcell(x, y)=="x" then
|
||||
matrix:setcell(x, y, "")
|
||||
else
|
||||
matrix:setcell(x, y, "x")
|
||||
end
|
||||
matrix.redraw="YES"
|
||||
return iup.IGNORE
|
||||
end
|
||||
]]
|
||||
|
||||
function len:valuechanged_cb()
|
||||
if tonumber(len.value) then
|
||||
LEN = tonumber(len.value) + 1
|
||||
for i=1,LEN do
|
||||
matrix:setcell(0, i, i)
|
||||
end
|
||||
if LEN<33 then
|
||||
for i=LEN,32 do
|
||||
matrix:setcell(0, i, "")
|
||||
end
|
||||
end
|
||||
matrix.redraw="YES"
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
-- easier editing of patterns
|
||||
|
||||
function matrix:action_cb(key, x, y, edition, value)
|
||||
if key==iup.K_SP then
|
||||
|
@ -141,7 +159,7 @@ function matrix:action_cb(key, x, y, edition, value)
|
|||
end
|
||||
|
||||
|
||||
-- changing patterns
|
||||
-- patterns changing, saving and loading
|
||||
|
||||
function pat_rec:action()
|
||||
patterns[active_pat] = {}
|
||||
|
@ -195,23 +213,30 @@ end
|
|||
|
||||
-- saving & loading
|
||||
|
||||
function _pat_write(fh, patno)
|
||||
fh:write("PAT,"..patno.."\n")
|
||||
for i=1,#patterns[patno] do
|
||||
fh:write(table.concat(patterns[patno][i],",") .. "\n")
|
||||
end
|
||||
end
|
||||
|
||||
function pat_save:action()
|
||||
local fname, status = iup.GetFile("./*.csv")
|
||||
if status > -1 then
|
||||
local fh = io.open(fname, "w+")
|
||||
fh:write("DRUMSHEET\n")
|
||||
fh:write("tempo,"..bpm.value.."\n")
|
||||
fh:write("factor,"..factor.value.."\n")
|
||||
fh:write("len,"..len.value.."\n")
|
||||
fh:write("INSTRUMENTS\n")
|
||||
for i=1,#instruments do
|
||||
fh:write(instruments[i][1] .. "," .. instruments[i][2] .. "\n")
|
||||
end
|
||||
-- todo pat_write nebo loop
|
||||
if #patterns[1] > 1 then
|
||||
fh:write("PAT A\n")
|
||||
for i=1,#patterns[1] do
|
||||
fh:write(table.concat(patterns[1][i],",") .. "\n")
|
||||
end
|
||||
end
|
||||
if #patterns[1]>1 then _pat_write(fh, 1) end
|
||||
if #patterns[2]>1 then _pat_write(fh, 2) end
|
||||
if #patterns[3]>1 then _pat_write(fh, 3) end
|
||||
if #patterns[4]>1 then _pat_write(fh, 4) end
|
||||
fh:close()
|
||||
end
|
||||
end
|
||||
|
@ -219,6 +244,7 @@ end
|
|||
|
||||
-- main program
|
||||
|
||||
adjust_time(120, 4)
|
||||
dlg:showxy( iup.CENTER, iup.CENTER )
|
||||
|
||||
if (iup.MainLoopLevel()==0) then
|
||||
|
|
Loading…
Reference in New Issue