fix + whitespace reformat
This commit is contained in:
parent
2e9367b524
commit
78ef09ebf6
|
@ -43,12 +43,15 @@ matrix = iup.matrix{numcol=32, numlin=9, widthdef=10}
|
|||
matrix.resizematrix = "YES"
|
||||
|
||||
function print_instruments()
|
||||
for i=1,32 do
|
||||
matrix:setcell(0,i,i)
|
||||
end
|
||||
for i=1,#instruments do
|
||||
matrix:setcell(i,0,instruments[i][1])
|
||||
end
|
||||
for i=1,32 do
|
||||
matrix:setcell(0,i,i)
|
||||
end
|
||||
for i=1,8 do
|
||||
matrix:setcell(i,0,"")
|
||||
end
|
||||
for i=1,#instruments do
|
||||
matrix:setcell(i,0,instruments[i][1])
|
||||
end
|
||||
end
|
||||
|
||||
matrix:setcell(0,0,"DRUMsheet")
|
||||
|
@ -305,93 +308,93 @@ function pat_save:action()
|
|||
end
|
||||
|
||||
function explode(div,str) -- credit: http://richard.warburton.it
|
||||
if (div=='') then return false end
|
||||
local pos,arr = 0,{}
|
||||
-- for each divider found
|
||||
for st,sp in function() return string.find(str,div,pos,true) end do
|
||||
table.insert(arr,string.sub(str,pos,st-1)) -- Attach chars left of current divider
|
||||
pos = sp + 1 -- Jump past current divider
|
||||
end
|
||||
table.insert(arr,string.sub(str,pos)) -- Attach chars right of last divider
|
||||
return arr
|
||||
if (div=='') then return false end
|
||||
local pos,arr = 0,{}
|
||||
-- for each divider found
|
||||
for st,sp in function() return string.find(str,div,pos,true) end do
|
||||
table.insert(arr,string.sub(str,pos,st-1)) -- Attach chars left of current divider
|
||||
pos = sp + 1 -- Jump past current divider
|
||||
end
|
||||
table.insert(arr,string.sub(str,pos)) -- Attach chars right of last divider
|
||||
return arr
|
||||
end
|
||||
|
||||
function sheet_read(fname)
|
||||
local data = { instruments={}, patterns = {} }
|
||||
local mode = ""
|
||||
local is_header = {bpm=true, factor=true, len=true}
|
||||
local i = 0
|
||||
local patno = 0
|
||||
for line in io.lines(fname) do
|
||||
local fields = explode(',', line)
|
||||
-- reads header:
|
||||
if mode=="DRUMSHEET" and is_header[fields[1]] then
|
||||
data[fields[1]] = tonumber(fields[2])
|
||||
end
|
||||
local data = { instruments={}, patterns = {} }
|
||||
local mode = ""
|
||||
local is_header = {bpm=true, factor=true, len=true}
|
||||
local i = 0
|
||||
local patno = 0
|
||||
for line in io.lines(fname) do
|
||||
local fields = explode(',', line)
|
||||
-- reads header:
|
||||
if mode=="DRUMSHEET" and is_header[fields[1]] then
|
||||
data[fields[1]] = tonumber(fields[2])
|
||||
end
|
||||
|
||||
-- switch to PAT mode in INSTRUMENTS
|
||||
if mode=="INSTRUMENTS" and fields[1]=="PAT" then
|
||||
mode = "PAT"
|
||||
end
|
||||
-- switch to PAT mode in INSTRUMENTS
|
||||
if mode=="INSTRUMENTS" and fields[1]=="PAT" then
|
||||
mode = "PAT"
|
||||
end
|
||||
|
||||
-- reads instruments:
|
||||
if mode=="INSTRUMENTS" and fields[1]~="PAT" then
|
||||
i = i + 1
|
||||
data.instruments[i] = {fields[1], tonumber(fields[2])}
|
||||
end
|
||||
-- reads instruments:
|
||||
if mode=="INSTRUMENTS" and fields[1]~="PAT" then
|
||||
i = i + 1
|
||||
data.instruments[i] = {fields[1], tonumber(fields[2])}
|
||||
end
|
||||
|
||||
-- read patterns:
|
||||
if mode=="PAT" and fields[1]=="PAT" then
|
||||
patno = tonumber(fields[2])
|
||||
data.patterns[patno] = {}
|
||||
i = 0
|
||||
elseif mode=="PAT" then
|
||||
i = i + 1
|
||||
data.patterns[patno][i] = fields
|
||||
end
|
||||
-- read patterns:
|
||||
if mode=="PAT" and fields[1]=="PAT" then
|
||||
patno = tonumber(fields[2])
|
||||
data.patterns[patno] = {}
|
||||
i = 0
|
||||
elseif mode=="PAT" then
|
||||
i = i + 1
|
||||
data.patterns[patno][i] = fields
|
||||
end
|
||||
|
||||
if mode=="" and fields[1]=="DRUMSHEET" then
|
||||
-- todo - kontrolovat verzi drumsheetu
|
||||
if not fields[2] or not tonumber(fields[2]) then
|
||||
return nil, "File version not found!"
|
||||
end
|
||||
if tonumber(fields[2])>FILEFORMAT_VERSION then
|
||||
return nil, "File too new!"
|
||||
end
|
||||
mode = "DRUMSHEET"
|
||||
if mode=="" and fields[1]=="DRUMSHEET" then
|
||||
-- todo - kontrolovat verzi drumsheetu
|
||||
if not fields[2] or not tonumber(fields[2]) then
|
||||
return nil, "File version not found!"
|
||||
end
|
||||
if tonumber(fields[2])>FILEFORMAT_VERSION then
|
||||
return nil, "File too new!"
|
||||
end
|
||||
mode = "DRUMSHEET"
|
||||
|
||||
end
|
||||
if mode=="DRUMSHEET" and fields[1]=="INSTRUMENTS" then
|
||||
mode = "INSTRUMENTS"
|
||||
i = 0
|
||||
end
|
||||
end
|
||||
return data
|
||||
end
|
||||
if mode=="DRUMSHEET" and fields[1]=="INSTRUMENTS" then
|
||||
mode = "INSTRUMENTS"
|
||||
i = 0
|
||||
end
|
||||
end
|
||||
return data
|
||||
end
|
||||
|
||||
function pat_load:action()
|
||||
local fname, status = iup.GetFile("./*.csv")
|
||||
if status > -1 then
|
||||
local data, error = sheet_read(fname)
|
||||
if error then
|
||||
iup.Message("File not loaded", error)
|
||||
else
|
||||
bpm.value = data.bpm
|
||||
factor.value = data.factor
|
||||
len.value = data.len
|
||||
adjust_time(data.bpm, data.factor)
|
||||
adjust_len(data.len)
|
||||
instruments = data.instruments or {}
|
||||
print_instruments()
|
||||
patterns = data.patterns or { {}, {}, {}, {} }
|
||||
if patterns[1] then
|
||||
pat_a.fontstyle="Bold"; pat_b.fontstyle=""; pat_c.fontstyle=""; pat_d.fontstyle=""
|
||||
pat_recall(1)
|
||||
end
|
||||
local fname, status = iup.GetFile("./*.csv")
|
||||
if status > -1 then
|
||||
local data, error = sheet_read(fname)
|
||||
if error then
|
||||
iup.Message("File not loaded", error)
|
||||
else
|
||||
bpm.value = data.bpm
|
||||
factor.value = data.factor
|
||||
len.value = data.len
|
||||
adjust_time(data.bpm, data.factor)
|
||||
adjust_len(data.len)
|
||||
instruments = data.instruments or {}
|
||||
print_instruments()
|
||||
patterns = data.patterns or { {}, {}, {}, {} }
|
||||
if patterns[1] then
|
||||
pat_a.fontstyle="Bold"; pat_b.fontstyle=""; pat_c.fontstyle=""; pat_d.fontstyle=""
|
||||
pat_recall(1)
|
||||
end
|
||||
|
||||
matrix.redraw = "YES"
|
||||
end
|
||||
end
|
||||
matrix.redraw = "YES"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue