Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local tArgs = {...}
- local nb = "right"
- local nb2 = "left"
- block = peripheral.wrap(nb)
- fallback = peripheral.wrap(nb2)
- if #tArgs<1 then
- print("Usage: "..shell.getRunningProgram().." <file>")
- error()
- end
- function iter( tTable, nIndex )
- local tVals = {}
- for k,v in pairs(tTable) do
- if type(k)=="number" and k>nIndex then
- table.insert(tVals,k)
- end
- end
- if #tVals>0 then
- return math.min(unpack(tVals)), tTable[math.min(unpack(tVals))]
- end
- end
- function ipairs2( tTable )
- return iter, tTable, 0
- end
- local itn = {
- ["p"]=0,
- ["d"]=1,
- ["b"]=2,
- ["s"]=3,
- ["c"]=4,
- ["x"]=5
- }
- function format(sStr)
- local tbl={}
- for n in string.gmatch(sStr,"[^:]+") do
- -- write(n:sub(1,1))
- table.insert(tbl,{itn[n:sub(1,1)],n:sub(2,#n)})
- end
- return tbl
- end
- file = fs.open(tArgs[1],"r")
- --piano = file.readLine()
- --doublebass = file.readLine()
- --bassdrum = file.readLine()
- --snaredrum = file.readLine()
- --click = file.readLine()
- if not file then error("Invalid File") end
- lines = {}
- done = {}
- --lnn = {}
- tempo=1/tonumber(file.readLine())
- repeat
- ln=file.readLine()
- if ln then
- table.insert(lines,format(ln))
- table.insert(done,false)
- end
- until not ln
- function dne()
- for i=1,#done do
- if done[i]==false then return false end
- end
- return true
- end
- function len(t)
- local tbl = {}
- for i=1,#t do
- table.insert(tbl,#t[i])
- end
- return tbl
- end
- if lines[1] then
- print("Playing: "..tArgs[1])
- print("Length: "..math.max(unpack(len(lines)))*tempo.." seconds.")
- _,py = term.getCursorPos()
- index=1
- while not dne() do
- term.setCursorPos(1,py)
- term.clearLine()
- write(math.floor((index-1)*tempo).."/"..math.floor(math.max(unpack(len(lines)))*tempo))
- local npt = 0
- for i=1,#lines do
- if #lines[i]>=index then
- if lines[i][index][1]~=5 then
- if npt < 5 then
- block.playNote(tonumber(lines[i][index][1]),tonumber(lines[i][index][2]))
- npt = npt+1
- else
- fallback.playNote(tonumber(lines[i][index][1]),tonumber(lines[i][index][2]))
- npt = npt+1
- end
- end
- -- print(lines[i][index][1])
- -- print(lines[i][index][2])
- else
- done[i]=true
- end
- end
- index=index+1
- sleep(tempo)
- end
- else
- error("File is blank... -.-")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement