Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.loadAPI("gcapi")
- existsMonitor = false
- if peripheral.find("monitor") then
- os.loadAPI("nMon")
- existsMonitor = true
- end
- --peripheral.find() in Tekkit
- function findPeripheral(pType)
- pList = {}
- for _,pName in pairs(peripheral.getNames()) do
- if peripheral.getType(pName) == pType then
- table.insert(pList, peripheral.wrap(pName))
- end
- end
- return unpack(pList)
- end
- peripheral.find = findPeripheral
- --Split string
- function split(self, delimiter)
- result = {};
- for match in (self..delimiter):gmatch("(.-)"..delimiter) do
- table.insert(result, match);
- end
- return result;
- end
- string.split = split
- --------------------------------------------------------
- --> MUSIC <--
- --------------------------------------------------------
- local pitchs = {[0]=0, [1]=0.53, [2]=0.56, [3]=0.6, [4]=0.63, [5]=0.67, [6]=0.7, [7]=0.75,
- [8]=0.8,[9]=0.85,[10]=0.9,[11]=0.95,[12]=1,[13]=1.05,[14]=1.1,[15]=1.2,[16]=1.25,[17]=1.32,[18]=1.4,
- [19]=1.5,[20]=1.6,[21]=1.7,[22]=1.8,[23]=1.9,[24]=2}
- local instruments = {[1]="note.harp",[2]="note.bassattack",[3]="note.bd",[4]="note.snare",[5]="note.hat"}
- local song = nil
- local noteblocks = {peripheral.find("music")}
- function playNote(instrument, pitch, vol)
- if instrument and pitch and vol then
- for _,noteblock in pairs(noteblocks) do
- noteblock.playSound(instrument, pitch, vol)
- end
- end
- end
- --------------------------------------------------------
- --> Main programs <--
- --------------------------------------------------------
- function startSong()
- local delay = song["delay"]
- for i,tick in ipairs(song) do
- if existsMonitor then
- nMon.updateMonitor(i)
- end
- for instrumentID, notePitchs in pairs(tick) do
- for _,pitchID in pairs(notePitchs) do
- playNote(instruments[instrumentID], pitchs[pitchID], 0.7)
- end
- end
- sleep(delay)
- end
- end
- function clearTerminal()
- term.setCursorPos(1,1)
- term.clear()
- end
- if existsMonitor then
- nMon.setupMonitor()
- end
- userInput = ''
- while true do
- clearTerminal()
- print("= List of songs =")
- print(" - portal")
- print(" - nyancat")
- print(" - zelda")
- print(" - sas")
- print(" - tetris")
- print(" - banjo")
- print(" - evilmorty")
- print(" - jinglebells")
- write("Song name: ")
- if not arepeat then
- userInput = read()
- end
- listC = gcapi.split((userInput .. ' '), ' ')
- if table.contains(listC , '-r' ) then
- arepeat = true
- end
- if userInput then
- filePath = "/songs/" .. string.split(userInput .. " ", " ")[1]
- print()
- if filePath and fs.exists(filePath) then
- file = fs.open(filePath, "r")
- song = textutils.unserialize(file.readAll())
- file.close()
- if existsMonitor then
- nMon.setSong(song)
- end
- startSong()
- else
- print("Song not found")
- sleep(2)
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement