Nike622000

MF-Reader

Jun 18th, 2018
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.12 KB | None | 0 0
  1. local name = ...
  2. local Bcol = colors.lightGray
  3. local xMax,yMax = term.getSize()
  4. local line = {}
  5. local activeColors = {["bottom"] = 0, ["left"] = 0, ["right"] = 0, ["top"] = 0, ["back"] = 0}
  6.  
  7. function JoJa(xP,yP)
  8.   term.setCursorPos(xP,yP)
  9.   term.setBackgroundColor(colors.gray)
  10.   term.setTextColor(colors.cyan)
  11.   term.write("Jo")
  12.   term.setTextColor(colors.orange)
  13.   term.write("Ja ")
  14.   term.setTextColor(colors.lightGray)
  15.   term.write("Productions")
  16. end
  17.  
  18. function Background(col)
  19.   term.setBackgroundColor(col)
  20.   for xP = 1,xMax do
  21.     for yP = 1,yMax do
  22.       term.setCursorPos(xP,yP)
  23.       term.write(" ")
  24.     end
  25.   end
  26. end
  27.  
  28. function readFile(n)
  29.     if n ~= nil and fs.exists(n) then
  30.         print("file found.")
  31.         if string.find(n.."",".mf") then
  32.             print("reading file...")
  33.             local m = fs.open(n,"r")
  34.             local i = 1
  35.             local l = m.readLine()
  36.             while l ~= nil do
  37.                 print("Line: "..l)
  38.                 line[i] = {}
  39.                 local p1 = string.find(l.."",";")
  40.                 local d = string.sub(l,0,p1-1)
  41.                 line[i][1] = tonumber(d)
  42.                 print("Delay: "..d)
  43.                 l = string.sub(l,p1+1)
  44.                 local j = 2
  45.                 p1 = string.find(l.."",";")
  46.                 while p1 ~= nil do
  47.                     line[i][j] = {}
  48.                     local th = string.sub(l,0,p1-1)
  49.                     local p2 = string.find(th.."",",")
  50.                     t = tonumber(string.sub(th,0,p2-1))
  51.                     line[i][j][1] = t
  52.                     h = tonumber(string.sub(th,p2+1))
  53.                     line[i][j][2] = h              
  54.                     print("Ton: "..t.." Hoehe: "..h)
  55.                     l = string.sub(l,p1+1)
  56.                     j = j+1
  57.                     p1 = string.find(l.."",";")
  58.                 end
  59.                 i = i+1
  60.                 l = m.readLine()
  61.             end
  62.             m.close()
  63.             print("reading finished...")
  64.             sleep(.5)
  65.             return true
  66.         else
  67.             print("wrong format.")
  68.             return false
  69.         end
  70.     else
  71.         print("file not found.")
  72.         return false
  73.     end
  74. end
  75.  
  76. function parseNote(iNote, iInstrument)
  77.   local bExtra = false
  78.   local sSide = ""
  79.   if iNote >= 16 then bExtra = true end
  80.   if not bExtra then
  81.     if iInstrument == 1 then sSide = "bottom" end
  82.     if iInstrument == 2 then sSide = "back" end
  83.     if iInstrument >= 3 then sSide = "right" end
  84.     iColor = 2 ^ iNote
  85.   else
  86.     if iInstrument == 1 then sSide = "top" end
  87.     if iInstrument == 2 then sSide = "left" end
  88.     if iInstrument >= 3 then sSide = "right" end
  89.     iColor = 2 ^ (iNote - 16)
  90.   end
  91.   return iColor, sSide
  92. end
  93.  
  94. function setNoteState(iNote, iInstrument, bState)
  95.   iC, sS = parseNote(iNote, iInstrument)
  96.   if not bState then iC = -iC end
  97.   activeColors[sS] = activeColors[sS] + iC
  98.   rs.setBundledOutput(sS, activeColors[sS])
  99. end
  100.  
  101. if readFile(name) then
  102.     Background(Bcol)
  103.     JoJa(xMax/2-7,1)
  104.     term.setTextColor(colors.white)
  105.     term.setCursorPos(3,yMax)
  106.     term.write("in cooperation with eisenhower8")
  107.     term.setTextColor(colors.red)
  108.     term.setCursorPos(3,3)
  109.     term.write("MF")
  110.     term.setTextColor(colors.white)
  111.     term.write("-Player")
  112.     term.setCursorPos(3,5)
  113.     term.write("Gerade wird abgespielt: "..name)
  114.    
  115.     for i = 1,#line do
  116.         d = line[i][1]
  117.         for j = 2,#line[i] do
  118.             setNoteState(line[i][j][1], line[i][j][2], true)
  119.         end
  120.         sleep(d/2)
  121.         for j = 2,#line[i] do
  122.             setNoteState(line[i][j][1], line[i][j][2], false)
  123.         end
  124.         sleep(d/2)
  125.     end
  126. else
  127.     sleep(.5)
  128. end
Advertisement
Add Comment
Please, Sign In to add comment