Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local tArgs = {...}
- if #tArgs ~= 1 then
- error("Usage: score <filename>")
- end
- term.setBackgroundColor(colors.black)
- term.clear()
- local w, h = term.getSize()
- local staffline = "| | | | | | | | | | | | | | | | | | | | | | | | |"
- local location = 0
- local song = {} --make this global for debugging
- local notetype = nil
- local tempo = 80
- local filename = tArgs[1]
- function importSong()
- local linenum = 0
- for line in io.lines(filename) do
- linenum = linenum + 1
- if linenum > 1 then
- song[linenum - 1] = {}
- for i = 1, 24 do
- song[linenum - 1][i] = tonumber(line:sub(i, i))
- end
- end
- end
- end
- if fs.exists(filename) then
- importSong()
- end
- --[[if not pcall(importSong()) then
- error("ERROR: Invalid song file")
- end]]--
- function saveFile()
- mSave = fs.open(tostring(filename), "w")
- mSave.writeLine("tempo = " .. tostring(tempo))
- for i, v in pairs(song) do
- local line = ""
- for k, e in pairs(v) do
- line = line .. e
- end
- mSave.writeLine(line)
- end
- mSave.close()
- end
- function initializeMain()
- term.setBackgroundColor(colors.lightBlue)
- term.setTextColor(colors.white)
- for i = 1, h do
- term.setCursorPos(1, i)
- term.write(staffline)
- end
- term.setBackgroundColor(colors.blue)
- term.setCursorPos(w - 1, 1)
- term.write(" ")
- term.setBackgroundColor(colors.yellow)
- term.setCursorPos(w - 1, 2)
- term.write(" ")
- term.setBackgroundColor(colors.white)
- term.setCursorPos(w - 1, 3)
- term.write(" ")
- term.setBackgroundColor(colors.brown)
- term.setCursorPos(w - 1, 4)
- term.write(" ")
- term.setBackgroundColor(colors.gray)
- term.setCursorPos(w - 1, 5)
- term.write(" ")
- term.setBackgroundColor(colors.black)
- term.setCursorPos(w - 1, 6)
- term.write("XX")
- end
- initializeMain()
- while true do
- local flag = true
- for i, v in pairs(song) do
- if i > location and i <= location + h then
- term.setCursorPos(1, i - location)
- term.setBackgroundColor(colors.lightBlue)
- term.write(staffline)
- flag = true
- for k, e in pairs(v) do
- term.setCursorPos(i, k - location)
- if e > 0 then
- flag = false
- if e == 1 then --note
- term.setBackgroundColor(colors.blue)
- elseif e == 2 then --kick
- term.setBackgroundColor(colors.yellow)
- elseif e == 3 then --click
- term.setBackgroundColor(colors.white)
- elseif e == 4 then --bass
- term.setBackgroundColor(colors.brown)
- elseif e == 5 then --snare
- term.setBackgroundColor(colors.gray)
- end
- term.setCursorPos(k * 2, i - location)
- term.write(" ")
- end
- end
- end
- if flag then --rest
- term.setCursorPos(1, i - location)
- term.setBackgroundColor(colors.black)
- term.write(staffline)
- end
- end
- if song then
- for i = #song, 1, -1 do
- local flag = false
- for k, e in pairs(song[i]) do
- if e ~= 0 then
- flag = true
- break
- end
- end
- if flag == true then
- break
- else
- song[i] = nil
- end
- end
- end
- term.setCursorPos(1, #song - location + 1)
- term.setBackgroundColor(colors.lightBlue)
- term.write(staffline)
- term.setCursorPos(1, h)
- term.setBackgroundColor(colors.blue)
- term.clearLine()
- term.setCursorPos(w - 1 - #tostring(location), h)
- term.write(location)
- term.setCursorPos(1, h)
- term.write("CTRL for menu")
- if notetype == 1 then --note
- term.setBackgroundColor(colors.blue)
- elseif notetype == 2 then --kick
- term.setBackgroundColor(colors.yellow)
- elseif notetype == 3 then --click
- term.setBackgroundColor(colors.white)
- elseif notetype == 4 then --bass
- term.setBackgroundColor(colors.brown)
- elseif notetype == 5 then --snare
- term.setBackgroundColor(colors.gray)
- elseif notetype == 6 then --rest
- term.setBackgroundColor(colors.black)
- term.setCursorPos(w - 1, h)
- term.write("XX")
- end
- if notetype and notetype ~= 6 then
- term.setCursorPos(w - 1, h)
- term.write(" ")
- end
- events = {os.pullEvent()}
- if events[1] == "mouse_scroll" then
- local dir = math.abs(events[2]) / events[2]
- location = location - dir
- if location < 0 then location = 0 end
- end
- if events[1] == "mouse_click" and events[2] == 1 and events[3] >= w - 1 and events[4] <= 6 then
- notetype = events[4]
- end
- if notetype and events[1] == "mouse_click" and events[2] == 1 and events[3] <= w - 2 and events[3] % 2 == 0 and events[4] < h then
- for i = 1 + location, events[4] + location do
- if song[i] == nil then
- song[i] = {}
- for n = 1, 24 do
- song[i][n] = 0
- end
- end
- end
- if notetype ~= 6 then
- song[events[4] + location][events[3] / 2] = notetype
- else
- song[events[4] + location] = {}
- for i = 1, 24 do
- song[events[4] + location][i] = 0
- end
- end
- end
- if events[1] == "key" and events[2] == 29 then
- local broken = false
- while true do
- term.setTextColor(colors.white)
- paintutils.drawFilledBox(1, h - 9, 6, h - 1, colors.blue)
- term.setCursorPos(1, h - 9)
- term.write("Tempo")
- term.setCursorPos(4, h - 7)
- term.write("npm")
- term.setCursorPos(1, h - 4)
- term.write("Save")
- term.setCursorPos(1, h - 2)
- term.write("Exit")
- term.setCursorPos(1, h - 7)
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.black)
- term.write(tempo)
- term.setCursorPos(1, h - 8)
- term.setBackgroundColor(colors.gray)
- term.setTextColor(colors.white)
- term.write("^")
- term.setCursorPos(1, h - 6)
- term.write("v")
- local events = {os.pullEvent()}
- if events[1] == "key" and events[2] == 29 then
- events = nil
- initializeMain()
- break
- end
- if events[1] == "mouse_click" and events[2] == 1 and events[3] <= 4 then
- if events[4] == h - 8 and events[3] == 1 and tempo <= 178 then
- term.setCursorPos(1, h - 8)
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.black)
- term.write("^")
- tempo = tempo + 1
- sleep(.1)
- elseif events[4] == h - 6 and events[3] == 1 and tempo >= 22 then
- term.setCursorPos(1, h - 6)
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.black)
- term.write("v")
- tempo = tempo - 1
- sleep(.1)
- elseif events[4] == h - 4 then
- term.setBackgroundColor(colors.lightBlue)
- term.setTextColor(colors.yellow)
- term.setCursorPos(1, h - 4)
- term.write("Save")
- saveFile()
- sleep(.2)
- elseif events[4] == h - 2 then
- term.setBackgroundColor(colors.lightBlue)
- term.setTextColor(colors.yellow)
- term.setCursorPos(1, h - 2)
- term.write("Exit")
- broken = true
- sleep(.2)
- term.setBackgroundColor(colors.black)
- term.clear()
- term.setCursorPos(1, 1)
- break
- end
- end
- end
- if broken then break end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement