Advertisement
GravityCube

nMon

Sep 29th, 2018
790
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.78 KB | None | 0 0
  1. --SETUP
  2. local barColor = colors.cyan
  3. local barTitleDefault = "Record Player"
  4. local notesInfoText = "&1Harp&9  &4Snare&9  &5Hat&9  &2Bass&9  &3BaseDrum&9"
  5. --END SETUP
  6.  
  7. os.loadAPI("gcapi")
  8.  
  9. --INTERNAL VARIABLES
  10.  
  11. local barTitle = barTitleDefault
  12. local mon = peripheral.find("monitor")
  13. local max_x, max_y = mon.getSize()
  14.  
  15. local song = {} --
  16.  
  17. --PROGRAMS
  18.  
  19. function updateTitleBar()
  20.     if song["name"] then
  21.         barTitle = barTitleDefault .. " - Playing: " .. song["name"]
  22.     end
  23.    
  24.     mon.setBackgroundColor(barColor)
  25.     for x=1, max_x, 1 do
  26.         mon.setCursorPos(x,1)
  27.         mon.write(" ")
  28.     end
  29.     mon.setCursorPos(gcapi.getCenter(max_x, barTitle), 1)
  30.     mon.write(barTitle)
  31. end
  32.  
  33. function setupMonitor()
  34.     barTitle = barTitleDefault
  35.    
  36.     mon.setBackgroundColor(colors.white)
  37.     mon.clear()
  38.    
  39.     mon.setTextColor(colors.black)
  40.    
  41.     updateTitleBar()
  42.    
  43.     for x=1, max_x, 1 do
  44.         mon.setCursorPos(x,max_y)
  45.         mon.write(" ")
  46.     end
  47.     mon.setCursorPos(gcapi.getCenter(max_x, string.len(notesInfoText)-((#string.split(notesInfoText, "&")-1)*2)), max_y)
  48.     gcapi.customMonitorWrite(mon, notesInfoText)
  49. end
  50.  
  51. function setSong(s)
  52.     song = s
  53. end
  54.  
  55. function printNotes(tick)
  56.     local tarjetX = gcapi.getCenter(max_x)
  57.    
  58.     mon.setBackgroundColor(colors.black)
  59.     for y=2, max_y-1,1 do
  60.         mon.setCursorPos(tarjetX,y)
  61.         mon.write(" ")
  62.     end
  63.     for i=1,#song,1 do
  64.         tickTable = song[i]
  65.         local x = -tick+gcapi.getCenter(max_x)+i
  66.         if x > max_x then
  67.             break
  68.         end
  69.         if (x > 0) and tickTable then
  70.             for instrumentID, notePitchs in pairs(tickTable) do
  71.                 for _,pitchID in pairs(notePitchs) do
  72.                     mon.setBackgroundColor(2^instrumentID)
  73.                     mon.setCursorPos(x,gcapi.getCenter(max_y, 24)+pitchID)
  74.                     mon.write(" ")
  75.                 end
  76.             end
  77.         end
  78.     end
  79. end
  80.  
  81. function updateMonitor(tick)
  82.     setupMonitor()
  83.     printNotes(tick)
  84. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement