Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- term.setBackgroundColor(colors.lightGray)
- term.clear()
- addedKeys = {}
- current_octave = 1
- current_page = 1
- current_instrument = "Piano/Harp"
- timestamp = 0.25
- function instCode(access)
- if access == "Piano/Harp" then
- return colors.green
- elseif access == "Bass Drum" then
- return colors.red
- elseif access == "Clicks/Sticks" then
- return colors.cyan
- elseif access == "Bass Guitar" then
- return colors.purple
- elseif access == "Snare Drum" then
- return colors.orange
- end
- end
- function blockMissing()
- term.setCursorPos(2,13)
- term.setTextColor(colors.red)
- term.setBackgroundColor(colors.lightGray)
- term.write("Iron Noteblck Missing")
- sleep(2)
- term.setTextColor(colors.lightGray)
- term.write(" ")
- end
- function maxKeys()
- term.setCursorPos(2,13)
- term.setTextColor(colors.red)
- term.setBackgroundColor(colors.lightGray)
- term.write("Exceeded Chord Limit")
- sleep(2)
- term.setTextColor(colors.lightGray)
- term.write(" ")
- end
- function checkNotes()
- local checkID = 1
- local foundNotes = 0
- for i=1,49 do
- for i,v in pairs(addedKeys) do
- if v.key == checkID then
- foundNotes = foundNotes + 1
- if foundNotes == 5 then
- return false, checkID
- end
- checkID = checkID + 1
- end
- end
- end
- return true
- end
- function playNotes()
- local music = nil -- Calls local variable
- for i,v in pairs(peripheral.getNames()) do -- Find iron noteblock
- if peripheral.getType(v) == "iron_note" then
- music = peripheral.wrap(v)
- end
- end
- local currentPos = 1
- local currentPage = 1
- local marked = true
- if music ~= nil then
- for i=1,9 do
- for i=1,49 do
- marked = true
- for i,v in pairs(addedKeys) do
- if v.pos == currentPos and v.page == currentPage then
- if v.octave == 1 then
- music.playNote(numInst(v.instrument),v.key)
- else
- music.playNote(numInst(v.instrument),v.key+8)
- end
- marked = false
- end
- end
- if marked == false then
- sleep(timestamp)
- end
- currentPos = currentPos + 1
- end
- currentPage = currentPage + 1
- end
- else
- blockMissing()
- end
- end
- function clearNotes()
- term.setTextColor(colors.black)
- term.setBackgroundColor(colors.white)
- term.setCursorPos(1,1)
- print(string.rep("-", 51 * 12))
- end
- function loadPage()
- clearNotes()
- for i,v in pairs(addedKeys) do
- if v.page == current_page then
- term.setCursorPos(v.pos + 2,v.key)
- term.setBackgroundColor(colors.white)
- term.setTextColor(instCode(v.instrument))
- term.write("o")
- end
- end
- end
- function numInst(key)
- if key == "Piano/Harp" then
- return 0
- elseif key == "Bass Drum" then
- return 1
- elseif key == "Snare Drum" then
- return 2
- elseif key == "Clicks/Sticks" then
- return 3
- elseif key == "Bass Guitar" then
- return 4
- end
- end
- function nextInst()
- if current_instrument == "Piano/Harp" then
- return "Bass Drum"
- elseif current_instrument == "Bass Drum" then
- return "Clicks/Sticks"
- elseif current_instrument == "Clicks/Sticks" then
- return "Bass Guitar"
- elseif current_instrument == "Bass Guitar" then
- return "Snare Drum"
- elseif current_instrument == "Snare Drum" then
- return "Piano/Harp"
- end
- end
- function noteList(position)
- if position == 1 then
- return "G "
- elseif position == 2 then
- return "G#"
- elseif position == 3 then
- return "A "
- elseif position == 4 then
- return "A#"
- elseif position == 5 then
- return "B "
- elseif position == 6 then
- return "C "
- elseif position == 7 then
- return "C#"
- elseif position == 8 then
- return "D "
- elseif position == 9 then
- return "D#"
- elseif position == 10 then
- return "E "
- elseif position == 11 then
- return "F "
- elseif position == 12 then
- return "F#"
- end
- end
- function spaced()
- local word = {}
- for i=1,#current_instrument do
- table.insert(word, string.sub(current_instrument, i, i))
- end
- if #word < #"Clicks/Sticks" then
- repeat table.insert(word, " ") until #word == #"Clicks/Sticks"
- end
- return table.concat(word)
- end
- function note(pos, key)
- local foundNote = false
- local deleteNote = nil
- for i, v in pairs(addedKeys) do
- if v.key == key and v.pos == pos - 2 and v.page == current_page then
- term.setCursorPos(pos,key)
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.black)
- term.write("-")
- foundNote = true
- deleteNote = i
- end
- end
- if foundNote == false then
- local template = {
- key = "1",
- pos = "1",
- page = 1,
- instrument = "Piano/Harp",
- octave = 1
- }
- template.key = key
- template.pos = pos - 2
- template.page = current_page
- template.instrument = current_instrument
- template.octave = current_octave
- table.insert(addedKeys,template)
- term.setCursorPos(pos,key)
- term.setBackgroundColor(colors.white)
- term.setTextColor(instCode(current_instrument))
- if template.octave == 1 then
- term.write("o")
- elseif template.octave == 2 then
- term.write("q")
- end
- elseif foundNote == true then
- table.remove(addedKeys, deleteNote)
- end
- end
- function removeNotes()
- for i=1,#addedKeys do
- table.remove(addedKeys)
- end
- end
- function drawGUI()
- for i=1,12 do
- term.setBackgroundColor(colors.gray)
- term.setTextColor(colors.white)
- term.setCursorPos(1,i)
- term.write(noteList(i))
- end
- term.setBackgroundColor(colors.lightGray)
- term.setTextColor(colors.lightGray)
- term.setCursorPos(1,13)
- print(string.rep(" ", 51))
- term.setCursorPos(2,14)
- term.setTextColor(colors.white)
- term.setBackgroundColor(colors.gray)
- term.write("Page : "..current_page)
- term.setCursorPos(2,15)
- if #tostring(timestamp) == 4 then
- term.write("Tempo : "..timestamp)
- elseif #tostring(timestamp) == 3 then
- term.write("Tempo : "..timestamp.."0")
- elseif #tostring(timestamp) == 1 then
- term.write("Tempo : "..timestamp..".00")
- end
- term.setCursorPos(2,16)
- term.write("Octave "..current_octave)
- term.setCursorPos(2,17)
- term.write("Clear Notes")
- term.setCursorPos(2,18)
- term.setTextColor(instCode(current_instrument))
- term.write(spaced())
- term.setTextColor(colors.white)
- end
- function inputGUI()
- term.setBackgroundColor(colors.lightGray)
- term.clear()
- term.setCursorPos(16,7)
- term.setTextColor(colors.lightGray)
- term.setBackgroundColor(colors.black)
- term.write(" File Name Here ")
- term.setCursorPos(16,7)
- term.setTextColor(colors.white)
- local input = read()
- return input
- end
- function save()
- local filename = inputGUI()
- local file = fs.open(filename, "w")
- file.write("addedKeys = "..textutils.serialize(addedKeys))
- file.close()
- term.setCursorPos(18,8)
- term.write("File Saved")
- sleep(2)
- drawGUI()
- clearNotes()
- loadPage()
- end
- function loadSave()
- local filename = inputGUI()
- if fs.exists(filename) then
- fs.move(filename, "Loading")
- os.loadAPI("Loading")
- addedKeys = Loading.addedKeys
- term.setCursorPos(18,8)
- term.write("File Loaded")
- os.unloadAPI("Loading")
- fs.move("Loading",filename)
- sleep(2)
- drawGUI()
- clearNotes()
- loadPage()
- else
- term.setCursorPos(18,8)
- term.setTextColor(colors.red)
- term.write("File not found")
- sleep(2)
- drawGUI()
- clearNotes()
- loadPage()
- end
- end
- drawGUI()
- clearNotes()
- loadPage()
- -- Event Handler Code --
- while true do
- loadPage()
- drawGUI()
- event, button, xClick, yClick = os.pullEvent()
- if event == "mouse_click" then
- if yClick < 13 and 2 < xClick and button ~= 3 then
- note(xClick, yClick)
- end
- if xClick > 1 and xClick < 14 and yClick == 18 then
- current_instrument = nextInst()
- end
- if xClick > 1 and xClick < 12 and yClick == 17 then
- removeNotes()
- clearNotes()
- loadPage()
- end
- if xClick > 1 and xClick < 10 and yClick == 14 and button == 1 then
- if current_page < 9 then
- current_page = current_page + 1
- loadPage()
- end
- elseif xClick > 1 and xClick < 10 and yClick == 14 and button == 2 then
- if 1 < current_page then
- current_page = current_page - 1
- loadPage()
- end
- end
- if xClick > 1 and xClick < 10 and yClick == 16 then
- if current_octave == 1 then
- current_octave = 2
- elseif current_octave == 2 then
- current_octave = 1
- end
- end
- if button == 3 then
- playNotes()
- end
- elseif event == "key" or event == "char" then
- if event == "key" then
- if button == keys.q then
- playNotes()
- end
- if button == keys.left then
- if 1 < current_page then
- current_page = current_page - 1
- loadPage()
- end
- end
- if button == keys.right then
- if current_page < 9 then
- current_page = current_page + 1
- loadPage()
- end
- end
- if button == keys.e then
- save()
- elseif button == keys.e then
- loadSave()
- end
- if button == keys.up then
- if timestamp < 9.75 then
- timestamp = timestamp + 0.25
- end
- elseif button == keys.down then
- if timestamp > 0.25 then
- timestamp = timestamp - 0.25
- end
- end
- elseif event == "char" then
- if button == "q" then
- playNotes()
- end
- if button == "e" then
- save()
- elseif button == "r" then
- loadSave()
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement