filloax

Untitled

Nov 12th, 2014
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 9.32 KB | None | 0 0
  1.    
  2.  
  3.     --get arguments
  4.      
  5.     local tArgs = { ... }
  6.     musicplaylist = false
  7.     selectedsong = nil
  8.     displaynotes = ""
  9.     mute = {{ },{ },{ },{ },{ }}
  10.     i = 1
  11.     j = 1
  12.     selectedi = 1
  13.     selectedj = 1
  14.     ptoggle = 0
  15.     debug = false
  16.     --attaching ironblocks
  17.     ironblock1 = peripheral.wrap("left")
  18.     ironblock2 = peripheral.wrap("right")
  19.     ironblock3 = peripheral.wrap("back")
  20.     ironblock4 = peripheral.wrap("top")
  21.     ironblock5 = peripheral.wrap("bottom")
  22.      
  23.     function round(num, idp)
  24.       local mult = 10^(idp or 0)
  25.       return math.floor(num * mult + 0.5) / mult
  26.     end
  27.      
  28.     input = function(evt, arg1, arg2)
  29.             if debug and evt == "key" and arg1 == 41 then
  30.                     debug = false
  31.             elseif evt == "key" and arg1 == 41 then
  32.                     debug = true
  33.             end
  34.            
  35.             if debug then
  36.                     if evt == "key" and arg1 == 17 and selectedi < 5 then
  37.                             selectedi = selectedi + 1
  38.                     elseif evt == "key" and arg1 == 31 and selectedi > 1  then
  39.                             selectedi = selectedi - 1
  40.                     elseif evt == "key" and arg1 == 32 and selectedj < 5 then
  41.                             selectedj = selectedj + 1
  42.                     elseif evt == "key" and arg1 == 30 and selectedj > 1 then
  43.                             selectedj = selectedj - 1
  44.                     end
  45.                    
  46.                     if evt == "key" and arg1 == 57 and mute[selectedi][selectedj] ~= 0 then
  47.                             mute[selectedi][selectedj] = 0
  48.                     elseif evt == "key" and arg1 == 57 and mute[selectedi][selectedj] == 0 then
  49.                             mute[selectedi][selectedj] = 1
  50.                     end
  51.             end
  52.      
  53.             if evt == "key" and arg1 == 15 and ptoggle ~= 0 then
  54.                     ptoggle = 0
  55.             elseif evt == "key" and arg1 == 15 and ptoggle == 0 then
  56.                     ptoggle = 1
  57.             end
  58.      
  59.             if evt == "key" and arg1 >= 2 and arg1 <= 12 then
  60.                     factor = allNotes / 10
  61.                     i =  round(factor * (arg1 - 2), 0)
  62.             end
  63.     end
  64.      
  65.     playnotes = function(noteblockside, channle, int)
  66.     displaynotes = displaynotes .. "("
  67.     if song[i][channle] then
  68.      
  69.     if song[i][channle][1] and mute[channle][1] ~= 0 then
  70.     note = song[i][channle][1]
  71.     noteblockside.playNote(int,note)
  72.     displaynotes = displaynotes .. note .. ","
  73.     end
  74.     if song[i][channle][2] and mute[channle][2] ~= 0 then
  75.     note = song[i][channle][2]
  76.     noteblockside.playNote(int,note)
  77.     displaynotes = displaynotes .. note .. ","
  78.     end
  79.     if song[i][channle][3] and mute[channle][3] ~= 0 then
  80.     note = song[i][channle][3]
  81.     noteblockside.playNote(int,note)
  82.     displaynotes = displaynotes .. note .. ","
  83.     end
  84.     if song[i][channle][4] and mute[channle][4] ~= 0 then
  85.     note = song[i][channle][4]
  86.     noteblockside.playNote(int,note)
  87.     displaynotes = displaynotes .. note .. ","
  88.     end
  89.     if song[i][channle][5] and mute[channle][5] ~= 0 then
  90.     note = song[i][channle][5]
  91.     noteblockside.playNote(int,note)
  92.     displaynotes = displaynotes .. note .. ","
  93.     end
  94.     end
  95.     displaynotes = displaynotes .. ")"
  96.     end
  97.      
  98.     -- Song selection stuff
  99.     if fs.exists("playlist") and #tArgs < 1 then
  100.       local file = fs.open("playlist", "r")
  101.        playlist = {}
  102.                        toltal = 0
  103.                       while true do
  104.                      local songque = file.readLine()
  105.                      if songque == nil then --if reached end of file
  106.        break end
  107.                        table.insert(playlist, songque)
  108.                        toltal = toltal + 1
  109.                        musicplaylist = true
  110.       end
  111.       selectedsong = playlist[1]
  112.     elseif #tArgs < 1 then
  113.        shell.run("clear")
  114.        print( "Use the arrows and enter to chose.  " )
  115.        songlist = fs.list("Music")
  116.        i = 0
  117.        max = -1
  118.        while true do
  119.                i = i + 1
  120.                max = max + 1
  121.                        if songlist[i] == nil then break end
  122.        end
  123.                        pointer = 1
  124.                        term.setCursorPos(1, 10)
  125.       term.clearLine(none)
  126.                        print( "->" .. pointer .. ": " .. songlist[pointer])
  127.               while true do
  128.              
  129.                                             list = 1
  130.                                             while list < 9 do
  131.                                              term.setCursorPos(1, 10 - list)
  132.                                              term.clearLine(none)
  133.                                              if songlist[pointer - (list)] then
  134.                                              write( "  " .. pointer - (list) .. ": " .. songlist[pointer - (list)])  
  135.                                              end
  136.                                              list = list + 1
  137.                                             end                      
  138.                                             term.setCursorPos(1, 10)
  139.                                             term.clearLine(none)
  140.                                             print( "->" .. pointer .. ": " .. songlist[pointer])
  141.     list = 1
  142.     while list < 10 do
  143.                                              term.setCursorPos(1, 10 + list)
  144.                                              term.clearLine(none)
  145.                                              if songlist[pointer + (list)] then
  146.                                              write( "  " .. pointer + (list) .. ": " .. songlist[pointer + (list)])  
  147.                                              end
  148.                                              list = list + 1
  149.                                             end
  150.     local evt, arg1, arg2 = os.pullEvent()
  151.                                             if arg1 == 28 then break end
  152.                                             if arg1 == 200 and pointer > 1 then
  153.                                                             pointer = pointer - 1
  154.                                             elseif arg1 == 208 and pointer < max then
  155.                                                             pointer = pointer + 1
  156.                                             end
  157.                                            
  158.              end
  159.              
  160.     selectedsong = songlist[pointer]
  161.     else
  162.     selectedsong = tArgs[1]
  163.     end
  164.      
  165.     que = 0
  166.     while true do
  167.     if musicplaylist then
  168.     if que >= toltal then
  169.     que = 1
  170.     else
  171.     que = que + 1
  172.     end
  173.     selectedsong = playlist[que]
  174.     end
  175.      
  176.     -- Playing The Music
  177.      
  178.     --opening file
  179.     shell.run( "clear" )
  180.     if fs.exists("Instrument/" .. selectedsong) then
  181.     shell.run( "Instrument/" .. selectedsong )
  182.     else
  183.     int1 = 0
  184.     int2 = 0
  185.     int3 = 0
  186.     int4 = 0
  187.     int5 = 0
  188.     end
  189.     file = io.open( "Music/" .. selectedsong )
  190.     filedata = file:read()
  191.     file:close()
  192.     --converting file to table
  193.     song = textutils.unserialize(filedata)
  194.     allNotes = song["lenght"] / song["delay"]
  195.     -- Song info
  196.     term.setCursorPos(1,1)
  197.     print("Song:" .. song["name"] )
  198.     print("Author:" .. song["author"] )
  199.     print("Original Author:" .. song["original_author"] )
  200.     -- Start playing
  201.     i = 0
  202.     line1 = ""
  203.     line2 = ""
  204.     line3 = ""
  205.     line4 = ""
  206.     line5 = ""
  207.     line6 = ""
  208.     line7 = ""
  209.     line8 = ""
  210.     line9 = ""
  211.     line10 = ""
  212.     while i * song["delay"] < song["lenght"] + 1 do
  213.     term.setCursorPos(1,4)
  214.     if ptoggle ~= 1 then
  215.             term.clearLine()
  216.             print(i * song["delay"]  .."/" .. song["lenght"] .. " Seconds" )
  217.     else
  218.             term.clearLine()
  219.             print(i .."/" .. allNotes .. " Notes" )
  220.     end
  221.     if debug then
  222.             print("[" .. selectedi .. "," .. selectedj .. "]")
  223.     else
  224.             term.clearLine()
  225.     end
  226.     --clear all notes
  227.     displaynotes = "["
  228.      
  229.     -- read notes for up to 5 parts
  230.     i = i + 1
  231.     if song[i] then
  232.     if ironblock1 then playnotes(ironblock1, 1, int1) end
  233.     if ironblock2 then playnotes(ironblock2, 2, int2) end
  234.     if ironblock3 then playnotes(ironblock3, 3, int3) end
  235.     if ironblock4 then playnotes(ironblock4, 4, int4) end
  236.     if ironblock5 then playnotes(ironblock5, 5, int5) end
  237.     end
  238.     displaynotes = displaynotes .. "]                                  "
  239.     line1 = line2
  240.     line2 = line3
  241.     line3 = line4
  242.     line4 = line5
  243.     line5 = line6
  244.     line6 = line7
  245.     line7 = line8
  246.     line8 = line9
  247.     line9 = line10
  248.     line10 = displaynotes
  249.     term.setCursorPos(1,9)
  250.     term.clearLine()
  251.     print(line1)
  252.     term.clearLine()
  253.     print(line2)
  254.     term.clearLine()
  255.     print(line3)
  256.     term.clearLine()
  257.     print(line4)
  258.     term.clearLine()
  259.     print(line5)
  260.     term.clearLine()
  261.     print(line6)
  262.     term.clearLine()
  263.     print(line7)
  264.     term.clearLine()
  265.     print(line8)
  266.     term.clearLine()
  267.     print(line9)
  268.     term.clearLine()
  269.     print(line10)
  270.      
  271.      
  272.      
  273.     os.startTimer(song["delay"])
  274.     evt, arg1, arg2 = os.pullEvent()
  275.     input(evt, arg1, arg2)
  276.     if evt ~= "timer" then
  277.             os.sleep(song["delay"])
  278.     end
  279.      
  280.     end
  281.      
  282.     if musicplaylist == false then break end
  283.     end
  284.     -- End Playing
Advertisement
Add Comment
Please, Sign In to add comment