HDR

Music System 2.2 Infinity Evolved

HDR
Oct 27th, 2016
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 11.30 KB | None | 0 0
  1. --# Made By HDR - @MartinRefseth #--
  2. --# Version 2.2 #--
  3. --# Thanks to Lyqyd for his Button API http://www.computercraft.info/forums2/index.php?/topic/14784-touchpoint-api/ #--
  4. os.loadAPI("touchpoint")
  5. for a,b in pairs(rs.getSides()) do
  6.   if peripheral.getType(b) == 'monitor' then
  7.    mon = peripheral.wrap(b)
  8.    t = touchpoint.new(b)
  9.    break
  10.   end
  11. end
  12.  
  13. --# Functions
  14. function play()
  15.  peripheral.find("drive", disk.stopAudio)
  16.  peripheral.find( "drive", function( name )
  17.   if disk.hasAudio( name ) and disk.getAudioTitle( name ) == title then
  18.     print("Now Playing"," ",( title) )
  19.     disk.playAudio( name )
  20.   end
  21.  end )
  22. end  
  23.  
  24. function Thir()
  25.    t:flash("13")
  26.    title = "C418 - 13"
  27.    play()
  28. end
  29.  
  30. function Cat()
  31.    t:flash("Cat")
  32.    title = "C418 - cat"
  33.    play()
  34. end
  35.  
  36. function Blocks()
  37.    t:flash("Blocks")
  38.    title = "C418 - blocks"
  39.    play()
  40. end  
  41.  
  42. function Chirp()
  43.    t:flash("Chirp")
  44.    title = "C418 - chirp"
  45.    play()
  46. end  
  47.  
  48. function Far()
  49.    t:flash("Far")
  50.    title = "C418 - far"
  51.    play()
  52. end
  53.  
  54. function Mall()
  55.    t:flash("Mall")
  56.    title = "C418 - mall"
  57.    play()
  58. end
  59.  
  60. function Mellohi()
  61.    t:flash("Mellohi")
  62.    title = "C418 - mellohi"
  63.    play()
  64. end
  65.  
  66. function Stal()
  67.    t:flash("Stal")
  68.    title = "C418 - stal"
  69.    play()
  70. end
  71.  
  72. function Strad()
  73.    t:flash("Strad")
  74.    title = "C418 - strad"
  75.    play()
  76. end
  77.    
  78. function Ward()
  79.    t:flash("Ward")
  80.    title = "C418 - ward"
  81.    play()
  82. end
  83.  
  84. function Elev()
  85.    t:flash("11")
  86.    title = "C418 - 11"
  87.    play()
  88. end
  89.  
  90. function Wait()
  91.    t:flash("Wait")
  92.    title = "C418 - wait"
  93.    play()
  94. end
  95.  
  96. function Question()
  97.    t:flash("???")
  98.    title = "corruption"
  99.    play()
  100. end
  101.  
  102. function GaiaOne()
  103.    t:flash("Gaia 1")
  104.    title = "botania:gaia1"
  105.    play()
  106. end
  107.  
  108. function GaiaTwo()
  109.    t:flash("Gaia 2")
  110.    title = "botania:gaia2"
  111.    play()
  112. end
  113.  
  114. function Roop()
  115.    t:flash("R-Loop")
  116.    title = "portalgun:records.radioloop"
  117.    play()
  118. end
  119.  
  120. function Slive()
  121.    t:flash("S-Alive")
  122.    title = "portalgun:records.stillalive"
  123.    play()
  124. end
  125.  
  126. function WYG()
  127.    t:flash("WYG")
  128.    title = "portalgun:records.wantyougone"
  129.    play()
  130. end
  131.  
  132. function WDR()
  133.    t:flash("Wanderer")
  134.    title = "wanderer"
  135.    play()
  136. end
  137.  
  138. --#Stops All Music
  139. function Stop()
  140.    t:flash("Stop")
  141.    print("Stopping Disk")
  142.    peripheral.find("drive", disk.stopAudio)
  143. end
  144. function Reboot()
  145.    t:flash("Reboot")
  146.    print("Rebooting")
  147.    peripheral.find("drive", disk.stopAudio)
  148.    mon.clear()
  149.    os.reboot()
  150. end
  151.  
  152. -- A list of all possible songs
  153. local Songs = {
  154.     Thir, Cat, Blocks, Chirp, Far, Mall, Mellohi, Stal, Strad, Ward,
  155.     Elev, Wait, Question, GaiaOne, GaiaTwo, Roop, Slive, WYG, Wander
  156. }
  157.  
  158. function Random()
  159.     t:flash("Random")
  160.     peripheral.find("drive", disk.stopAudio)
  161.     local maxSongs = #Songs -- the "#" gets the length of the list
  162.     local randomNumber = math.random( maxSongs )
  163.     Songs[randomNumber]() -- call the choosen song directly out of the list
  164. end
  165.  
  166. --#OverWrites Part Of Touchpoint API#--
  167.     t.draw = function(self)
  168.       local function cT(text)
  169.         x,y = term.getSize()
  170.         x1,y1 = term.getCursorPos()
  171.         term.setCursorPos((math.floor(x/2) - (math.floor(#text/2))), y1)
  172.         term.write(text)
  173.      end
  174.                 local old = term.redirect(self.mon)
  175.                 term.setTextColor(colors.white)
  176.                 term.setBackgroundColor(colors.gray)
  177.                 term.clear()
  178.                 term.setCursorPos(1,1)
  179.                 term.setTextColor(colors.orange)
  180.                 cT("HDR's Music System V2.2")
  181.                 for name, buttonData in pairs(self.buttonList) do
  182.                         if buttonData.active then
  183.                                 term.setBackgroundColor(buttonData.activeColor)
  184.                                 term.setTextColor(buttonData.activeText)
  185.                         else
  186.                                 term.setBackgroundColor(buttonData.inactiveColor)
  187.                                 term.setTextColor(buttonData.inactiveText)
  188.                         end
  189.                         for i = buttonData.yMin, buttonData.yMax do
  190.                                 term.setCursorPos(buttonData.xMin, i)
  191.                                 term.write(buttonData.label[i - buttonData.yMin + 1])
  192.                         end
  193.                 end
  194.                 if old then
  195.                         term.redirect(old)
  196.                 else
  197.                         term.restore()
  198.                 end
  199.         end
  200. add = function(self, name, func, xMin, yMin, xMax, yMax, inactiveColor, activeColor, inactiveText, activeText)
  201.                 local label, name = setupLabel(xMax - xMin + 1, yMin, yMax, name)
  202.                 if self.buttonList[name] then error("button already exists", 2) end
  203.                 local x, y = self.mon.getSize()
  204.                 if xMin < 1 or yMin < 1 or xMax > x or yMax > y then error("button out of bounds", 2) end
  205.                 self.buttonList[name] = {
  206.                         func = func,
  207.                         xMin = xMin,
  208.                         yMin = yMin,
  209.                         xMax = xMax,
  210.                         yMax = yMax,
  211.                         active = false,
  212.                         inactiveColor = inactiveColor or colors.red,
  213.                         activeColor = activeColor or colors.lime,
  214.                         inactiveText = inactiveText or colors.white,
  215.                         activeText = activeText or colors.white,
  216.                         label = label,
  217.                 }
  218.                 for i = xMin, xMax do
  219.                         for j = yMin, yMax do
  220.                                 if self.clickMap[i][j] ~= nil then
  221.                                         --undo changes
  222.                                         for k = xMin, xMax do
  223.                                                 for l = yMin, yMax do
  224.                                                         if self.clickMap[k][l] == name then
  225.                                                                 self.clickMap[k][l] = nil
  226.                                                         end
  227.                                                 end
  228.                                         end
  229.                                         self.buttonList[name] = nil
  230.                                         error("overlapping button", 2)
  231.                                 end
  232.                                 self.clickMap[i][j] = name
  233.                         end
  234.                 end
  235.         end
  236.         remove = function(self, name)
  237.                 if self.buttonList[name] then
  238.                         local button = self.buttonList[name]
  239.                         for i = button.xMin, button.xMax do
  240.                                 for j = button.yMin, button.yMax do
  241.                                         self.clickMap[i][j] = nil
  242.                                 end
  243.                         end
  244.                         self.buttonList[name] = nil
  245.                 end
  246.         end
  247.         run = function(self)
  248.                 while true do
  249.                         self:draw()
  250.                         local event = {self:handleEvents(os.pullEvent(self.side == "term" and "mouse_click" or "monitor_touch"))}
  251.                         if event[1] == "button_click" then
  252.                                 self.buttonList[event[2]].func()
  253.                         end
  254.                 end
  255.         end
  256.         handleEvents = function(self, ...)
  257.                 local event = {...}
  258.                 if #event == 0 then event = {os.pullEvent()} end
  259.                 if (self.side == "term" and event[1] == "mouse_click") or (self.side ~= "term" and event[1] == "monitor_touch" and event[2] == self.side) then
  260.                         local clicked = self.clickMap[event[3]][event[4]]
  261.                         if clicked and self.buttonList[clicked] then
  262.                                 return "button_click", clicked
  263.                         end
  264.                 end
  265.                 return unpack(event)
  266.         end
  267.         toggleButton = function(self, name, noDraw)
  268.                 self.buttonList[name].active = not self.buttonList[name].active
  269.                 if not noDraw then self:draw() end
  270.         end
  271.         flash = function(self, name, duration)
  272.                 self:toggleButton(name)
  273.                 sleep(tonumber(duration) or 0.15)
  274.                 self:toggleButton(name)
  275.         end
  276.         rename = function(self, name, newName)
  277.                 self.buttonList[name].label, newName = setupLabel(self.buttonList[name].xMax - self.buttonList[name].xMin + 1, self.buttonList[name].yMin, self.buttonList[name].yMax, newName)
  278.                 if not self.buttonList[name] then error("no such button", 2) end
  279.                 if name ~= newName then
  280.                         self.buttonList[newName] = self.buttonList[name]
  281.                         self.buttonList[name] = nil
  282.                         for i = self.buttonList[newName].xMin, self.buttonList[newName].xMax do
  283.                                 for j = self.buttonList[newName].yMin, self.buttonList[newName].yMax do
  284.                                         self.clickMap[i][j] = newName
  285.                                 end
  286.                         end
  287.                 end
  288.                 self:draw()
  289.         end      
  290. --# Buttons in the following format "Name-Function-X1-Y1-X2-Y2-ButtonColor1-ButtonColor2-TextColor1-TextColor2"
  291. t:add("13", Thir, 2,3,12,5, colors.cyan, colors.lime, colors.orange, colors.orange)
  292. t:add("Cat", Cat, 14,3,24,5, colors.cyan, colors.lime, colors.orange, colors.orange)
  293. t:add("Blocks", Blocks, 26,3,36,5, colors.cyan, colors.lime, colors.orange, colors.orange)
  294. t:add("Chirp", Chirp, 38,3,48,5, colors.cyan, colors.lime, colors.orange, colors.orange)
  295. t:add("Far", Far, 50,3,60,5, colors.cyan, colors.lime, colors.orange, colors.orange)
  296. t:add("Mall", Mall, 2,7,12,9, colors.cyan, colors.lime, colors.orange, colors.orange)
  297. t:add("Mellohi", Mellohi, 14,7,24,9, colors.cyan, colors.lime, colors.orange, colors.orange)
  298. t:add("Stal", Stal, 26,7,36,9, colors.cyan, colors.lime, colors.orange, colors.orange)
  299. t:add("Strad", Strad, 38,7,48,9, colors.cyan, colors.lime, colors.orange, colors.orange)
  300. t:add("Ward", Ward, 50,7,60,9, colors.cyan, colors.lime, colors.orange, colors.orange)
  301. t:add("11", Elev, 2,11,12,13, colors.cyan, colors.lime, colors.orange, colors.orange)
  302. t:add("Wait", Wait, 14,11,24,13, colors.cyan, colors.lime, colors.orange, colors.orange)
  303. t:add("???", Question, 26,11,36,13, colors.cyan, colors.lime, colors.orange, colors.orange)
  304. t:add("Gaia 1", GaiaOne, 38,11,48,13, colors.cyan, colors.lime, colors.orange, colors.orange)
  305. t:add("Gaia 2", GaiaTwo, 50,11,60,13, colors.cyan, colors.lime, colors.orange, colors.orange)
  306. t:add("R-Loop", Roop, 8,15,18,17, colors.cyan, colors.lime, colors.orange, colors.orange)
  307. t:add("S-Alive", Slive, 20,15,30,17, colors.cyan, colors.lime, colors.orange, colors.orange)
  308. t:add("WYG", WYG, 32,15,42,17, colors.cyan, colors.lime, colors.orange, colors.orange)
  309. t:add("Wanderer", WDR, 44,15,54,17, colors.cyan, colors.lime, colors.orange, colors.orange)
  310. t:add("Stop", Stop, 26,19,36,19, colors.cyan, colors.lime, colors.orange, colors.orange)
  311. t:add("Reboot", Reboot, 38,19,48,19, colors.cyan, colors.lime, colors.orange, colors.orange)
  312. t:add("Random", Random, 14,19,24,19, colors.cyan, colors.lime, colors.orange, colors.orange)
  313. t:run()
Advertisement
Add Comment
Please, Sign In to add comment