Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --get arguments
- local tArgs = { ... }
- musicplaylist = false
- selectedsong = nil
- displaynotes = ""
- mute = {{ },{ },{ },{ },{ }}
- nodes = { }
- i = 1
- j = 1
- selectedi = 1
- selectedj = 1
- ptoggle = 0
- play = 1
- debug = false
- playerA = 1
- score = 0
- --attaching ironblocks
- ironblock1 = peripheral.wrap("left")
- ironblock2 = peripheral.wrap("right")
- ironblock3 = peripheral.wrap("back")
- ironblock4 = peripheral.wrap("top")
- ironblock5 = peripheral.wrap("bottom")
- function round(num, idp)
- local mult = 10^(idp or 0)
- return math.floor(num * mult + 0.5) / mult
- end
- input = function(evt, arg1, arg2)
- if evt == "key" and arg1 == 2 then
- if line3 == "|O| |-| | |" then
- line3 = "|X| |-| | |"
- elseif line4 == "|O| |-| | |" then
- line4 = "|X| |-| | |"
- elseif line2 == "|O| |-| | |" then
- line2 = "|X| |-| | |"
- else
- score = score - 1
- end
- end
- if evt == "key" and arg1 == 3 then
- if line3 == "| |O|-| | |" then
- line3 = "| |X|-| | |"
- elseif line4 == "| |O|-| | |" then
- line4 = "| |X|-| | |"
- elseif line2 == "| |O|-| | |" then
- line2 = "| |X|-| | |"
- else
- score = score - 1
- end
- end
- if evt == "key" and arg1 == 4 then
- if line3 == "| | |O| | |" then
- line3 = "| | |X| | |"
- elseif line4 == "| | |O| | |" then
- line4 = "| | |X| | |"
- elseif line2 == "| | |O| | |" then
- line2 = "| | |X| | |"
- else
- score = score - 1
- end
- end
- if evt == "key" and arg1 == 5 then
- if line3 == "| | |-|O| |" then
- line3 = "| | |-|X| |"
- elseif line4 == "| | |-|O| |" then
- line4 = "| | |-|X| |"
- elseif line2 == "| | |-|O| |" then
- line2 = "| | |-|X| |"
- else
- score = score - 1
- end
- end
- if evt == "key" and arg1 == 6 then
- if line3 == "| | |-| |O|" then
- line3 = "| | |-| |X|"
- elseif line4 == "| | |-| |O|" then
- line4 = "| | |-| |X|"
- elseif line2 == "| | |-| |O|" then
- line2 = "| | |-| |X|"
- else
- score = score - 1
- end
- end
- end
- keepScore = function()
- if line1 == "|O| |-| | |" or line1 == "| |O|-| | |" or line1 == "| | |O| | |" or line1 == "| | |-|O| |" or line1 == "| | |-| |O|" then
- score = score - 3
- elseif line1 == "|X| |-| | |" or line1 == "| |X|-| | |" or line1 == "| | |X| | |" or line1 == "| | |-|X| |" or line1 == "| | |-| |X|" then
- score = score + 5
- end
- end
- playnotes = function(noteblockside, channle, int)
- if song[i][channle] then
- if song[i][channle][1] and mute[channle][1] ~= 0 then
- note = song[i][channle][1]
- noteblockside.playNote(int,note)
- end
- if song[i][channle][2] and mute[channle][2] ~= 0 then
- note = song[i][channle][2]
- noteblockside.playNote(int,note)
- end
- if song[i][channle][3] and mute[channle][3] ~= 0 then
- note = song[i][channle][3]
- noteblockside.playNote(int,note)
- end
- if song[i][channle][4] and mute[channle][4] ~= 0 then
- note = song[i][channle][4]
- noteblockside.playNote(int,note)
- end
- if song[i][channle][5] and mute[channle][5] ~= 0 then
- note = song[i][channle][5]
- noteblockside.playNote(int,note)
- end
- end
- end
- -- Song selection stuff
- if fs.exists("playlist") and #tArgs < 1 then
- local file = fs.open("playlist", "r")
- playlist = {}
- toltal = 0
- while true do
- local songque = file.readLine()
- if songque == nil then --if reached end of file
- break end
- table.insert(playlist, songque)
- toltal = toltal + 1
- musicplaylist = true
- end
- selectedsong = playlist[1]
- elseif #tArgs < 1 then
- shell.run("clear")
- print( "Use the arrows and enter to chose. " )
- songlist = fs.list("Music")
- i = 0
- max = -1
- while true do
- i = i + 1
- max = max + 1
- if songlist[i] == nil then break end
- end
- pointer = 1
- term.setCursorPos(1, 10)
- term.clearLine(none)
- print( "->" .. pointer .. ": " .. songlist[pointer])
- while true do
- list = 1
- while list < 9 do
- term.setCursorPos(1, 10 - list)
- term.clearLine(none)
- if songlist[pointer - (list)] then
- write( " " .. pointer - (list) .. ": " .. songlist[pointer - (list)])
- end
- list = list + 1
- end
- term.setCursorPos(1, 10)
- term.clearLine(none)
- print( "->" .. pointer .. ": " .. songlist[pointer])
- list = 1
- while list < 10 do
- term.setCursorPos(1, 10 + list)
- term.clearLine(none)
- if songlist[pointer + (list)] then
- write( " " .. pointer + (list) .. ": " .. songlist[pointer + (list)])
- end
- list = list + 1
- end
- local evt, arg1, arg2 = os.pullEvent()
- if arg1 == 28 then break end
- if arg1 == 200 and pointer > 1 then
- pointer = pointer - 1
- elseif arg1 == 208 and pointer < max then
- pointer = pointer + 1
- end
- end
- selectedsong = songlist[pointer]
- else
- selectedsong = tArgs[1]
- end
- shell.run("clear")
- while true do
- print("What part? 1-5")
- local evt, arg1, arg2 = os.pullEvent()
- if arg1 >= 2 and arg1 <= 6 then
- playerA = arg1 - 1
- break
- end
- end
- shell.run("clear")
- que = 0
- while true do
- if musicplaylist then
- if que >= toltal then
- que = 1
- else
- que = que + 1
- end
- selectedsong = playlist[que]
- end
- -- Playing The Music
- --opening file
- shell.run( "clear" )
- if fs.exists("Instrument/" .. selectedsong) then
- shell.run( "Instrument/" .. selectedsong )
- else
- int1 = 0
- int2 = 0
- int3 = 0
- int4 = 0
- int5 = 0
- end
- file = io.open( "Music/" .. selectedsong )
- filedata = file:read()
- file:close()
- --converting file to table
- song = textutils.unserialize(filedata)
- allNotes = song["lenght"] / song["delay"]
- -- Song info
- term.setCursorPos(1,1)
- print("Song:" .. song["name"] )
- print("Author:" .. song["author"] )
- print("Original Author:" .. song["original_author"] )
- -- Start playing
- i = 0
- line1 = ""
- line2 = ""
- line3 = ""
- line4 = ""
- line5 = ""
- line6 = ""
- line7 = ""
- line8 = ""
- line9 = ""
- line10 = ""
- while i * song["delay"] < song["lenght"] + 1 and i * song["delay"] > -1 do
- term.setCursorPos(1,4)
- term.clearLine()
- print(i .. "/" .. allNotes .. " Notes" )
- term.clearLine()
- print("Score:" .. score)
- --Note Path
- nodes[1] = " "
- nodes[2] = " "
- nodes[3] = "-"
- nodes[4] = " "
- nodes[5] = " "
- n = 1
- rangeS = 1
- rangeE = 5
- while n <= 5 do
- rangeS = rangeS + 5
- rangeE = rangeE + 5
- if song[i + 8] then
- if song[i + 8][playerA] then
- if song[i + 8][playerA][1] then
- if song[i + 8][playerA][1] >= rangeS and song[i + 8][playerA][1] <= rangeE then
- nodes[n] = "O"
- end
- elseif song[i + 8][playerA][2] then
- if song[i + 8][playerA][2] >= rangeS and song[i + 8][playerA][2] <= rangeE then
- nodes[n] = "O"
- end
- elseif song[i + 8][playerA][3] then
- if song[i + 8][playerA][3] >= rangeS and song[i + 8][playerA][3] <= rangeE then
- nodes[n] = "O"
- end
- elseif song[i + 8][playerA][4] then
- if song[i + 8][playerA][4] >= rangeS and song[i + 8][playerA][4] <= rangeE then
- nodes[n] = "O"
- end
- elseif song[i + 8][playerA][5] then
- if song[i + 8][playerA][5] >= rangeS and song[i + 8][playerA][5] <= rangeE then
- nodes[n] = "O"
- end
- end
- end
- end
- n = n + 1
- end
- -- read notes for up to 5 parts
- i = i + play
- if song[i] then
- if ironblock1 then playnotes(ironblock1, 1, int1) end
- if ironblock2 then playnotes(ironblock2, 2, int2) end
- if ironblock3 then playnotes(ironblock3, 3, int3) end
- if ironblock4 then playnotes(ironblock4, 4, int4) end
- if ironblock5 then playnotes(ironblock5, 5, int5) end
- end
- displaynotes = "|" .. nodes[1] .. "|" .. nodes[2] .. "|" .. nodes[3] .. "|" .. nodes[4] .. "|" .. nodes[5] .. "|"
- line1 = line2
- line2 = line3
- line3 = line4
- line4 = line5
- line5 = line6
- line6 = line7
- line7 = line8
- line8 = line9
- line9 = line10
- line10 = displaynotes
- term.setCursorPos(1,8)
- term.clearLine()
- print(" " .. line10 .. " ")
- term.clearLine()
- print(" " .. line9 .. " ")
- term.clearLine()
- print(" " .. line8 .. " ")
- term.clearLine()
- print(" " .. line7 .. " ")
- term.clearLine()
- print(" " .. line6 .. " ")
- term.clearLine()
- print(" " .. line5 .. " ")
- term.clearLine()
- print(" " .. line4 .. " ")
- term.clearLine()
- print("->" .. line3 .. "<-")
- term.clearLine()
- print(" " .. line2 .. " ")
- term.clearLine()
- print(" " .. line1 .. " ")
- print(" |1|2|3|4|5| ")
- keepScore()
- timerID = os.startTimer(song["delay"])
- evt, arg1, arg2 = os.pullEvent()
- input(evt, arg1, arg2)
- if evt ~= "timer" then
- os.pullEvent("timer")
- end
- end
- score = 0
- if musicplaylist == false then break end
- end
- -- End Playing
Advertisement
Add Comment
Please, Sign In to add comment