Advertisement
Darking560

Touch Piano ironnoteblock

Mar 14th, 2013
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.35 KB | None | 0 0
  1. local MonitorSide = "back"
  2. local side1 = "right" -- the side that has only the 9 noteblocks attached
  3. local side2 = "front" -- The side that has the remaining 16 noteblocks attached
  4. local song = {};waittime = 0;recor = false;overlaystat=false
  5.  
  6. function drawGUI()
  7.     term.redirect(peripheral.wrap(MonitorSide))
  8.     paintutils.drawImage(paintutils.loadImage("PianoSprite"),1,1)
  9.     paintutils.drawImage(paintutils.loadImage("Record") ,2,9)
  10.     term.setCursorPos(8,11)
  11.     write("REC")
  12.    
  13.     paintutils.drawImage(paintutils.loadImage("Play") ,12,9)
  14.     term.setCursorPos(17,11)
  15.     write("PLAY")
  16.    
  17.     paintutils.drawImage(paintutils.loadImage("Overlay") ,58,9)
  18.     term.setCursorPos(63,11)
  19.     write("OVERLAY")
  20.    
  21.     term.restore()
  22. end
  23.  
  24. function play(note)
  25.     --colors = {1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768}
  26.     --if note <= 8 then redstone.setBundledOutput(side1,colors[note+1]);sleep(0.1);redstone.setBundledOutput(side1,0) end
  27.     --if note >= 9 then redstone.setBundledOutput(side2,colors[note-8]);sleep(0.1);redstone.setBundledOutput(side2,0) end --Avec cable RedPower
  28.  
  29.     playnote(0,note) --Avec Iron Note Block
  30.  
  31.     if recor == true then  
  32.         table.insert(song,os.clock()-waittime)
  33.         table.insert(song,note)
  34.         waittime = os.clock()
  35.     end
  36. end
  37.  
  38. function playback()
  39.     term.redirect(peripheral.wrap(MonitorSide))
  40.     paintutils.drawImage(paintutils.loadImage("Play2") ,12,9)
  41.     term.setCursorPos(17,11)
  42.     write("PLAY")
  43.     for i,v in ipairs(song) do
  44.         if i % 2 == 0 then
  45.             play(v)
  46.         else
  47.             sleep(v-.1)
  48.         end
  49.     end
  50.     sleep(0.5)
  51.     paintutils.drawImage(paintutils.loadImage("Play") ,12,9)
  52.     term.setCursorPos(17,11)
  53.     write("PLAY")
  54.     term.restore()
  55. end
  56.  
  57. function writec(str,x,y)
  58.     term.setCursorPos(x,y)
  59.     write(str)
  60. end
  61.  
  62. drawGUI()
  63.  
  64. while true do                        -- This section tracks where on the screen the player clicks and what to do depending on where it clicks, takes alot of space
  65.     event,side,x,y = os.pullEvent()  -- mainly because the notes on the piano arent plain quads so i had to define ech shape
  66.     if event == "monitor_touch" then
  67.         if (x == 3 or x == 4 or x == 5) and y <= 4 then play(0) end -- Note 0/24
  68.         if ((x == 5 or x == 7) and y >= 5 and y <= 7) or (x == 6 and y <= 7) then play(1) end -- Note 1/24
  69.         if (x == 7 or x == 8 or x == 9) and y <= 4 then play(2) end -- Note 2/24
  70.         if ((x == 9 or x == 11) and y >= 5 and y <= 7) or (x == 10 and y <= 7) then play(3) end -- Note 3/24    -- Normal White note
  71.         if (x == 11 or x == 12 or x == 13) and y <= 4 then play(4) end -- Note 4/24                             -- Black Note
  72.         if (x == 13 and y >= 5 and y <= 7) or ((x == 14 or x == 15) and y <= 7) then play(5) end -- Note 5/24   -- Backwards L Shape
  73.         if ((x == 17 or x == 18) and y <= 7) or (x == 19 and y >= 5 and y <= 7) then play(6) end -- Note 6/24   -- L Shape
  74.         if (x == 19 or x == 20 or x == 21) and y <= 4 then play(7) end -- Note 7/24
  75.         if ((x == 21 or x == 23) and y >= 5 and y <= 7) or (x == 22 and y <= 7) then play(8) end -- Note 8/24
  76.         if (x == 23 or x == 24 or x == 25) and y <= 4 then play(9) end -- Note 9/24
  77.         if (x == 25 and y >= 5 and y <= 7) or ((x == 26 or x == 27) and y <= 7) then play(10) end -- Note 10/24
  78.         if ((x == 29 or x == 30) and y <= 7) or (x == 31 and y >= 5 and y <= 7) then play(11) end -- Note 11/24
  79.         if (x == 31 or x == 32 or x == 33) and y <= 4 then play(12) end -- Note 12/24
  80.         if ((x == 33 or x == 35) and y >= 5 and y <= 7) or (x == 34 and y <= 7) then play(13) end -- Note 13/24
  81.         if (x == 35 or x == 36 or x == 37) and y <= 4 then play(14) end -- Note 14/24
  82.         if ((x == 37 or x == 39) and y >= 5 and y <= 7) or (x == 38 and y <= 7) then play(15) end -- Note 15/24
  83.         if (x == 39 or x == 40 or x == 41) and y <= 4 then play(16) end -- Note 16/24
  84.         if (x == 41 and y >= 5 and y <= 7) or ((x == 42 or x == 43) and y <= 7) then play(17) end -- Note 17/24
  85.         if ((x == 45 or x == 46) and y <= 7) or (x == 47 and y >= 5 and y <= 7) then play(18) end -- Note 18/24
  86.         if (x == 47 or x == 48 or x == 49) and y <= 4 then play(19) end -- Note 19/24
  87.         if ((x == 49 or x == 51) and y >= 5 and y <= 7) or (x == 50 and y <= 7) then play(20) end -- Note 20/24
  88.         if (x == 51 or x == 52 or x == 53) and y <= 4 then play(21) end -- Note 21/24
  89.         if (x == 53 and y >= 5 and y <= 7) or ((x == 54 or x == 55) and y <= 7) then play(22) end -- Note 22/24
  90.         if ((x == 57 or x == 58) and y <= 7) or (x == 59 and y >= 5 and y <= 7) then play(23) end -- Note 23/24
  91.         if (x == 59 or x == 60 or x == 61) and y <= 4 then play(24) end -- Note 24/24
  92.         if (x <= 11 and x >=3) and (y <=12 and y >= 10) and recor == true then
  93.             recor = false
  94.             term.redirect(peripheral.wrap(MonitorSide))
  95.             paintutils.drawImage(paintutils.loadImage("Record") ,2,9)
  96.             term.setCursorPos(8,11)
  97.             write("REC")
  98.             term.restore()
  99.         elseif (x <= 11 and x >=3) and (y <=12 and y >= 10) and recor == false then
  100.             recor = true
  101.             term.redirect(peripheral.wrap(MonitorSide))
  102.             paintutils.drawImage(paintutils.loadImage("Record2") ,2,9)
  103.             term.setCursorPos(8,11)
  104.             write("REC")
  105.             term.restore()
  106.             song = {};waittime = os.clock()
  107.         end
  108.         if (x <= 21 and x >=13) and (y <=12 and y >= 10) and song ~= {} and recor == false then playback() end
  109.         if (x >=59 and x <= 70) and (y <=12 and y >= 10) and overlaystat == false then
  110.             term.redirect(peripheral.wrap(MonitorSide))
  111.             paintutils.drawImage(paintutils.loadImage("Overlay2") ,58,9)
  112.             term.setCursorPos(63,11)
  113.             term.setTextColor(1)
  114.             write("OVERLAY")
  115.             overlaystat = true
  116.             term.setBackgroundColor(32768)
  117.             writec("F#",4,3);writec("G#",8,3);writec("A#",12,3);writec("C#",20,3);writec("D#",24,3);writec("F#",32,3);writec("G#",36,3);writec("A#",40,3);writec("C#",48,3);writec("D#",52,3);writec("F#",60,3) -- OVERLAY for black keys
  118.             term.setBackgroundColor(1)
  119.             term.setTextColor(32768)
  120.             writec("G",6,6)
  121.             writec("A",10,6)
  122.             writec("B",14,6)
  123.             writec("C",18,6)
  124.             writec("D",22,6)
  125.             writec("E",26,6)
  126.             writec("F",30,6)
  127.             writec("G",34,6)
  128.             writec("A",38,6)
  129.             writec("B",42,6)
  130.             writec("C",46,6)
  131.             writec("D",50,6)
  132.             writec("E",54,6)
  133.             writec("F",58,6)
  134.             term.setTextColor(1)
  135.             term.restore()
  136.         elseif (x >=59 and x <= 70) and (y <=12 and y >= 10) and overlaystat == true then
  137.             drawGUI()
  138.             term.redirect(peripheral.wrap(MonitorSide))
  139.             paintutils.drawImage(paintutils.loadImage("Overlay") ,58,9)
  140.             term.setCursorPos(63,11)
  141.             write("OVERLAY")
  142.             term.restore()
  143.             overlaystat = false
  144.         end
  145.     end
  146. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement