Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- devMode = false
- operations = {}
- operations[1] = 'setTempo'
- operations[2] = 'setInstrument'
- operations[3] = 'playNote'
- operations[4] = 'hold'
- operations[5] = 'beginChunk'
- operations[6] = 'goToLine'
- operations[7] = 'runChunk'
- operations[8] = 'endChunk'
- --operations[9] = 'setVar'
- --operations[10] = 'changeVar'
- --operations[11] = 'ifVar'
- --operations[12] = 'ifVarEnd'
- --[[ getInfs
- function getInfs(infc,infnum)
- if devMode == true then
- print('trying to extract '.. infnum ..' values from ['.. infc ..']')
- end
- ret = {}
- ret[1] = false
- reqlen = infnum * 2 - 1
- sepps = {}
- seppAmnt = infnum - 1
- seppNum = 0
- if string.len(infc) > reqlen - 1 then
- for i = 1, string.len(infc) do
- if string.sub(infc,i,i) == ',' then
- if i > seppNum + 1 and i < string.len(infc) and i > 1 then
- sepps[seppNum + 1] = i
- seppNum = seppNum + 1
- end
- end
- end
- if seppNum == seppAmnt then
- for i = 1, seppAmnt do
- if i == 1 then
- begp = 1
- endp = sepps[1] - 1
- elseif i == seppAmnt then
- begp = sepps[seppAmnt] + 1
- endp = -1
- else
- begp = sepps[seppAmnt] + 1
- endp = sepps[seppAmnt + 1] - 1
- end
- ret[i] = string.sub(infc,begp,endp)
- end
- end
- end
- return(ret)
- end
- --]]
- function ifVar(line,linenum) --not finished
- end
- function changeVar(line,linenum) --not finished
- end
- function setVar(line,linenum) --not finished
- if string.len(line) > 8 then
- inf = string.sub(line,8,-2)
- --sepps = getInfs(inf,2)
- if string.len(inf) > 2 then
- if string.sub(inf,1,1) == ',' or string.sub(inf,-1,-1) == ',' then
- repErr('Information Provided Is Not Valid',linenum)
- else
- end
- else
- repErr('Not Enough Information Provided',linenum)
- end
- else
- repErr('No Information Provided',linenum)
- end
- end
- function goToLine(line,linenum)
- if string.len(line) > 10 then
- linen = string.sub(line,10,-2)
- linen = convNumber(linen,false)
- if linen > 0 and linen < #flines + 1 then
- linenumt = linen
- went = true
- else
- repErr('Line Does Not Exist',linenum)
- end
- else
- repErr('No Information Provided',linenum)
- end
- end
- function runChunk(line,linenum)
- if string.len(line) > 10 then
- name = string.sub(line,10,-2)
- exists = false
- for i = 1, #chunkLbls do
- if chunkLbls[i] == name then
- exists = i
- end
- end
- if exists == false then
- repErr('Chunk Does not Exist',linenum)
- else
- cline = linenum
- rline = chunkBegs[exists]
- repeat
- line = flines[rline]
- es = 0
- got = false
- for i = 1, string.len(line) do
- if string.sub(line,i,i) == ' ' then
- else
- if got == false then
- es = i
- got = true
- end
- end
- end
- line = string.sub(line,es,-1)
- runLine(line,rline)
- rline = rline + 1
- until rline == chunkEnds[exists] + 1
- end
- else
- repErr('No Information Provided',linenum)
- end
- end
- function beginChunk(line,linenum)
- if string.len(line) > 12 then
- name = string.sub(line,12,-2)
- exists = false
- for i = 1, #chunkLbls do
- if chunkLbls[i] == name then
- exists = true
- end
- end
- if exists == true then
- repErr('Chunk Label Already Taken',linenum)
- else
- chunkNum = #chunkLbls + 1
- chunkBegs[chunkNum] = linenum + 1
- ends = false
- for i = linenum, #flines do
- linec = flines[i]
- es = 0
- got = false
- for i = 1, string.len(linec) do
- if string.sub(linec,i,i) == ' ' then
- else
- if got == false then
- es = i
- got = true
- end
- end
- end
- linec = string.sub(linec,es,-1)
- if linec == 'endChunk('.. name ..')' then
- ends = i
- end
- end
- if ends == false then
- repErr('Chunk Does Not End',linenum)
- else
- chunkEnds[chunkNum] = ends - 1
- chunkLbls[chunkNum] = name
- goToLine('goToLine('.. ends + 1 ..')')
- end
- end
- else
- repErr('No Information Provided',linenum)
- end
- end
- function repErr(message,linenum)
- if term.isColor() then
- term.setTextColor(colors.red)
- else
- term.setTextColor(colors.black)
- end
- print('Error on line: '.. linenum ..' - '.. message)
- term.setTextColor(colors.black)
- kill = true
- end
- function checkOp(operation,line)
- ret = false
- leng = string.len(operation)
- if string.len(line) > leng then
- if string.sub(line,1,leng) == operation then
- if string.sub(line,leng + 1,leng + 1) == '(' then
- if string.sub(line,-1,-1) == ')' then
- ret = true
- end
- end
- end
- end
- return(ret)
- end
- function runLine(line,linenum)
- roperation = 'none'
- for oper = 1, #operations do
- if checkOp(operations[oper],line) == true then
- roperation = operations[oper]
- end
- end
- if string.sub(line,1,2) == '--' then
- else
- if roperation == 'none' then
- repErr('That Is Not A Valid Operation',linenum)
- else
- if devMode == true then
- print('running '.. roperation ..' on line '.. linenum)
- end
- if roperation == 'setTempo' then
- setTempo(line,linenum)
- elseif roperation == 'setInstrument' then
- setInstrument(line,linenum)
- elseif roperation == 'playNote' then
- playNote(line,linenum)
- elseif roperation == 'hold' then
- hold(line,linenum)
- elseif roperation == 'beginChunk' then
- beginChunk(line,linenum)
- elseif roperation == 'goToLine' then
- goToLine(line,linenum)
- elseif roperation == 'runChunk' then
- runChunk(line,linenum)
- elseif roperation == 'setVar' then
- setVar(line,linenum)
- elseif roperation == 'changeVar' then
- changeVar(line,linenum)
- elseif roperation == 'ifVar' then
- ifVar(line,linenum)
- end
- end
- end
- end
- function convNumber(num,dec)
- nnum = 0
- nums = {}
- nums[1] = '0'
- nums[2] = '1'
- nums[3] = '2'
- nums[4] = '3'
- nums[5] = '4'
- nums[6] = '5'
- nums[7] = '6'
- nums[8] = '7'
- nums[9] = '8'
- nums[10] = '9'
- gnums = {}
- gl = 0
- for i = 1, string.len(num) do
- for cnum = 1, #nums do
- if string.sub(num,i,i) == nums[cnum] then
- anum = cnum - 1
- gnums[gl + 1] = anum
- gl = gl + 1
- end
- end
- end
- place = 1
- for i = gl, 1, -1 do
- nnum = nnum + gnums[i] * place
- place = place * 10
- end
- if dec == true then
- nnum = '.'.. nnum
- nnum = tonumber(nnum)
- end
- return(nnum)
- end
- function setTempo(line,linenum)
- if string.len(line) > 10 then
- number = string.sub(line,10,-2)
- number = convNumber(number,true)
- tempo = number
- else
- repErr('No Information Provided',linenum)
- end
- end
- function setInstrument(line,linenum)
- if string.len(line) > 15 then
- str = string.sub(line,15,-2)
- if str == 'piano' then
- instrument = 0
- elseif str == 'base' then
- instrument = 1
- elseif str == 'snare' then
- instrument = 2
- elseif str == 'base2' then
- instrument = 3
- elseif str == 'snare2' then
- instrument = 4
- else
- repErr('Instrument Is Not Valid',linenum)
- end
- else
- repErr('No Information Provided',linenum)
- end
- end
- function playNote(line,linenum)
- if string.len(line) > 10 then
- number = string.sub(line,10,-2)
- number = convNumber(number,false)
- if number > -1 and number < 25 then
- for i = 1, notenum do
- peripheral.call(notes[i],'playNote',instrument,number)
- end
- if devMode == true then
- print('Playing note '.. number ..' on instrument '.. instrument)
- end
- playedNote = true
- if tempo == 0 then
- else
- sleep(tempo)
- end
- else
- repErr('Got['.. number ..'] Note Must Be A Number 0-24',linenum)
- end
- else
- repErr('No Information Provided',linenum)
- end
- end
- function hold(line,linenum)
- if string.len(line) > 6 then
- number = string.sub(line,6,-2)
- number = '.'.. number
- number = convNumber(number,true)
- sleep(number)
- else
- repErr('No Information Provided',linenum)
- end
- end
- function options(opt1,opt2,opt3,sx,sy)
- opt = 1
- term.setCursorPos(sx,sy)
- print('Arrow keys to switch, Enter to select.')
- sy = sy + 2
- repeat
- term.setCursorPos(sx,sy)
- print(' '.. opt1 ..' ')
- term.setCursorPos(sx + 3 + string.len(opt1),sy)
- print(' '.. opt2 ..' ')
- term.setCursorPos(sx + 6 + string.len(opt1) + string.len(opt2),sy)
- print(' '.. opt3 ..' ')
- if term.isColor() then
- term.setTextColor(colors.red)
- else
- term.setTextColor(colors.black)
- end
- if opt == 1 then
- term.setCursorPos(sx,sy)
- print('[')
- term.setCursorPos(sx + string.len(opt1) + 1,sy)
- print(']')
- elseif opt == 2 then
- term.setCursorPos(sx + 3 + string.len(opt1),sy)
- print('[')
- term.setCursorPos(sx + 4 + string.len(opt1) + string.len(opt2),sy)
- print(']')
- elseif opt == 3 then
- term.setCursorPos(sx + 6 + string.len(opt1) + string.len(opt2),sy)
- print('[')
- term.setCursorPos(sx + 7 + string.len(opt1) + string.len(opt2) + string.len(opt3),sy)
- print(']')
- end
- term.setTextColor(colors.black)
- eve, key = os.pullEvent()
- if eve == 'key' then
- if key == 205 then
- if opt == 1 then
- opt = 2
- elseif opt == 2 then
- opt = 3
- end
- elseif key == 203 then
- if opt == 2 then
- opt = 1
- elseif opt == 3 then
- opt = 2
- end
- end
- end
- until eve == 'key' and key == 28
- return(opt)
- end
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.black)
- repeat
- peris = peripheral.getNames()
- notes = {}
- notenum = 0
- for i = 1, #peris do
- if peripheral.getType(peris[i]) == 'modem' then
- rednet.open(peris[i])
- end
- end
- peris = peripheral.getNames()
- for i = 1, #peris do
- if peripheral.getType(peris[i]) == 'noteBlock' then
- notenum = notenum + 1
- notes[notenum] = peris[i]
- end
- end
- if notenum > 0 then
- repeat
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.black)
- term.clear()
- term.setCursorPos(1,1)
- print('Loading jogOS Music Mixer version 1.2')
- print('Select an option:')
- sel = options('Edit Song','Play Song','Reload Note Blocks',1,4)
- term.setCursorPos(1,8)
- if sel == 1 then
- print('Enter the name of the song you would like to edit:')
- term.setCursorPos(1,10)
- print('Enter guide, to view a simple tutorial')
- term.setCursorPos(1,9)
- song = io.read()
- shell.run('edit musics/'.. song)
- elseif sel == 2 then
- print('Enter the name of the song you would like to play:')
- song = io.read()
- if song == '' then
- else
- if fs.exists('musics/'.. song) then
- file = io.open('musics/'.. song,'r')
- file2 = io.open('musics/'.. song,'r')
- num = 0
- flines = {}
- lineAmnt = 0
- for line in file2:lines() do
- lineAmnt = lineAmnt + 1
- end
- pCount = 100 / lineAmnt
- for line in file:lines() do
- num = num + 1
- flines[num] = line
- term.clear()
- term.setCursorPos(1,1)
- print('Loading '.. song)
- compl = num * pCount
- print(compl ..'% complete')
- end
- print('File loaded')
- if lineAmnt > 0 then
- term.clear()
- term.setCursorPos(1,1)
- print('Apply a redstone signal to the top of the computer to stop the song at anytime')
- tempo = .1
- instrument = 0
- kill = false
- chunkLbls = {}
- chunkBegs = {}
- chunkEnds = {}
- varLbls = {}
- varVals = {}
- linenumt = 1
- repeat
- went = false
- playedNote = false
- if kill == false then
- line = flines[linenumt]
- es = 0
- got = false
- for i = 1, string.len(line) do
- if string.sub(line,i,i) == ' ' then
- else
- if got == false then
- es = i
- got = true
- end
- end
- end
- line = string.sub(line,es,-1)
- runLine(line,linenumt)
- end
- if went == false then
- linenumt = linenumt + 1
- end
- if rs.getInput('top') == true then
- linenumt = num + 1
- end
- until linenumt > num
- if devMode == true then
- io.read()
- end
- if kill == true then
- print('Hit enter to continue')
- io.read()
- end
- else
- print('That file is empty')
- sleep(2)
- end
- else
- print('That file could not be found on this computer')
- sleep(2)
- end
- end
- elseif sel == 3 then
- repeat
- peris = peripheral.getNames()
- notes = {}
- notenum = 0
- for i = 1, #peris do
- if peripheral.getType(peris[i]) == 'modem' then
- rednet.open(peris[i])
- end
- end
- peris = peripheral.getNames()
- for i = 1, #peris do
- if peripheral.getType(peris[i]) == 'noteBlock' then
- notenum = notenum + 1
- notes[notenum] = peris[i]
- end
- end
- if notenum == 0 then
- term.clear()
- term.setCursorPos(1,1)
- print('Make sure that you have an iron noteblock from the peripherals++ mod attached to the computer and try again')
- print('Press the enter key to continue')
- io.read()
- end
- until notenum > 0
- end
- until 1 == 2
- else
- term.clear()
- term.setCursorPos(1,1)
- print('Make sure that you have an iron noteblock from the peripherals++ mod attached to the computer and try again')
- print('Press the enter key to continue')
- io.read()
- end
- until 1 == 2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement