Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Monitor: 5x3 blocks
- programmed in:
- CC:T for Fabric (ComputerCraft: Tweaked) v1.91.2
- Minecraft 1.16.4
- fabric 0.10.8
- ]]
- -- variables
- local instnr = 14
- local notation = true
- local volume = tonumber(1)
- local s = peripheral.find("speaker")
- local instruments = {
- "bass",
- "snare",
- "hat",
- "bell",
- "flute",
- "chime",
- "guitar",
- "xylophone",
- "iron_xylophone",
- "cow_bell",
- "didgeridoo",
- "bit",
- "banjo",
- "pling",
- "harp"
- }
- local instname = {
- "Bass",
- "Snare",
- "Hat",
- "Bell",
- "Flute",
- "Chime",
- "Guitar",
- "Xylophone",
- "Iron Xylophone",
- "Cow Bell",
- "Didgeridoo",
- "Bit",
- "Banjo",
- "Piano",
- "Harp",
- }
- -- basic functions
- function toint(n)
- local s = tostring(n)
- local i, j = s:find('%.')
- if i then
- return tonumber(s:sub(1,i-1))
- else
- return n
- end
- end
- -- draw keyboard keys
- function drawkeys()
- term.setBackgroundColor(colors.lightBlue)
- paintutils.drawFilledBox(3,7,48,17)
- term.setBackgroundColor(colors.white)
- paintutils.drawFilledBox(5,12,46,16)
- term.setBackgroundColor(colors.lightGray)
- paintutils.drawFilledBox(8,12,10,16)
- paintutils.drawFilledBox(14,12,16,16)
- paintutils.drawFilledBox(20,12,22,16)
- paintutils.drawFilledBox(26,12,28,16)
- paintutils.drawFilledBox(32,12,34,16)
- paintutils.drawFilledBox(38,12,40,16)
- paintutils.drawFilledBox(44,12,46,16)
- term.setBackgroundColor(colors.black)
- paintutils.drawFilledBox(4,8,5,11)
- paintutils.drawFilledBox(7,8,8,11)
- paintutils.drawFilledBox(10,8,11,11)
- paintutils.drawFilledBox(16,8,17,11)
- paintutils.drawFilledBox(19,8,20,11)
- paintutils.drawFilledBox(25,8,26,11)
- paintutils.drawFilledBox(28,8,29,11)
- paintutils.drawFilledBox(31,8,32,11)
- paintutils.drawFilledBox(37,8,38,11)
- paintutils.drawFilledBox(40,8,41,11)
- paintutils.drawFilledBox(46,8,47,11)
- end
- -- draw letters on keyboard
- function drawletters()
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- term.setCursorPos(4,9)
- write("0")
- term.setCursorPos(4,11)
- write("F#")
- term.setCursorPos(7,9)
- write("2")
- term.setCursorPos(7,11)
- write("G#")
- term.setCursorPos(10,9)
- write("4")
- term.setCursorPos(10,11)
- write("A#")
- term.setCursorPos(16,9)
- write("7")
- term.setCursorPos(16,11)
- write("C#")
- term.setCursorPos(19,9)
- write("9")
- term.setCursorPos(19,11)
- write("D#")
- term.setCursorPos(25,9)
- write("12")
- term.setCursorPos(25,11)
- write("F#")
- term.setCursorPos(28,9)
- write("14")
- term.setCursorPos(28,11)
- write("G#")
- term.setCursorPos(31,9)
- write("16")
- term.setCursorPos(31,11)
- write("A#")
- term.setCursorPos(37,9)
- write("19")
- term.setCursorPos(37,11)
- write("C#")
- term.setCursorPos(40,9)
- write("21")
- term.setCursorPos(40,11)
- write("D#")
- term.setCursorPos(46,9)
- write("24")
- term.setCursorPos(46,11)
- write("F#")
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.black)
- term.setCursorPos(6,13)
- write("1")
- term.setCursorPos(6,15)
- write("G")
- term.setCursorPos(12,13)
- write("5")
- term.setCursorPos(12,15)
- write("B")
- term.setCursorPos(18,13)
- write("8")
- term.setCursorPos(18,15)
- write("D")
- term.setCursorPos(23,13)
- write("11")
- term.setCursorPos(24,15)
- write("F")
- term.setCursorPos(29,13)
- write("15")
- term.setCursorPos(30,15)
- write("A")
- term.setCursorPos(35,13)
- write("18")
- term.setCursorPos(36,15)
- write("C")
- term.setCursorPos(41,13)
- write("22")
- term.setCursorPos(42,15)
- write("E")
- term.setBackgroundColor(colors.lightGray)
- term.setTextColor(colors.black)
- term.setCursorPos(9,13)
- write("3")
- term.setCursorPos(9,15)
- write("A")
- term.setCursorPos(15,13)
- write("6")
- term.setCursorPos(15,15)
- write("C")
- term.setCursorPos(20,13)
- write("10")
- term.setCursorPos(21,15)
- write("E")
- term.setCursorPos(26,13)
- write("13")
- term.setCursorPos(27,15)
- write("G")
- term.setCursorPos(32,13)
- write("17")
- term.setCursorPos(33,15)
- write("B")
- term.setCursorPos(38,13)
- write("20")
- term.setCursorPos(39,15)
- write("D")
- term.setCursorPos(44,13)
- write("23")
- term.setCursorPos(45,15)
- write("F")
- end
- -- Main Screen Draw Function
- function mainscreen()
- -- draw background
- term.setBackgroundColor(colors.cyan)
- term.clear()
- -- draw keyboard keys
- drawkeys()
- -- draw letters on keyboards
- drawletters()
- -- draw volume
- term.setBackgroundColor(colors.purple)
- term.setTextColor(colors.white)
- paintutils.drawFilledBox(3,2,5,3)
- paintutils.drawFilledBox(15,2,17,3)
- term.setCursorPos(4,3)
- write("-")
- term.setCursorPos(16,3)
- write("+")
- term.setBackgroundColor(colors.cyan)
- term.setCursorPos(7,2)
- write("Volume:")
- term.setCursorPos(9,3)
- write("100")
- -- draw notation
- term.setBackgroundColor(colors.lightBlue)
- term.setTextColor(colors.black)
- paintutils.drawFilledBox(20,2,27,3)
- term.setCursorPos(20,2)
- write("Notation")
- term.setTextColor(colors.green)
- term.setCursorPos(22,3)
- write("ON")
- -- draw close button
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.red)
- term.setCursorPos(50,1)
- write("X")
- -- draw instruments
- term.setBackgroundColor(colors.red)
- term.setTextColor(colors.white)
- paintutils.drawFilledBox(1,17,2,18)
- paintutils.drawFilledBox(49,17,50,18)
- term.setCursorPos(1,18)
- write("<")
- term.setCursorPos(50,18)
- write(">")
- term.setBackgroundColor(colors.cyan)
- term.setCursorPos(13,18)
- write("Instrument: ")
- write(instname[instnr])
- -- draw logo
- term.setBackgroundColor(colors.orange)
- term.setTextColor(colors.black) --start
- paintutils.drawLine(31,1,31,6)
- paintutils.drawPixel(32,1)
- paintutils.drawPixel(32,3)
- paintutils.drawPixel(33,2) --P
- paintutils.drawPixel(35,1)
- paintutils.drawLine(35,3,35,6) --i
- paintutils.drawLine(37,4,37,5)
- paintutils.drawLine(39,3,39,6)
- paintutils.drawPixel(38,3)
- paintutils.drawPixel(38,6) --a
- paintutils.drawLine(41,3,41,6)
- paintutils.drawPixel(42,3)
- paintutils.drawLine(43,4,43,6) --n
- paintutils.drawLine(45,4,45,5)
- paintutils.drawPixel(46,3)
- paintutils.drawPixel(46,6)
- paintutils.drawLine(47,4,47,5) --o
- -- end
- end
- -- main program
- mainscreen()
- -- touch input
- while true do
- local event, par, x, y = os.pullEvent()
- if event == "mouse_click" then
- if y>=8 and y<=11 then
- -- black keys
- if x==4 or x==5 then
- s.playNote(instruments[instnr],volume,0)
- elseif x==7 or x==8 then
- s.playNote(instruments[instnr],volume,2)
- elseif x==10 or x==11 then
- s.playNote(instruments[instnr],volume,4)
- elseif x==16 or x==17 then
- s.playNote(instruments[instnr],volume,7)
- elseif x==19 or x==20 then
- s.playNote(instruments[instnr],volume,9)
- elseif x==25 or x==26 then
- s.playNote(instruments[instnr],volume,12)
- elseif x==28 or x==29 then
- s.playNote(instruments[instnr],volume,14)
- elseif x==31 or x==32 then
- s.playNote(instruments[instnr],volume,16)
- elseif x==37 or x==38 then
- s.playNote(instruments[instnr],volume,19)
- elseif x==40 or x==41 then
- s.playNote(instruments[instnr],volume,21)
- elseif x==46 or x==47 then
- s.playNote(instruments[instnr],volume,24)
- end
- elseif y>=12 and y<=16 then
- -- white keys
- if x>=5 and x<=7 then
- s.playNote(instruments[instnr],volume,1)
- elseif x>=8 and x<=10 then
- s.playNote(instruments[instnr],volume,3)
- elseif x>=11 and x<=13 then
- s.playNote(instruments[instnr],volume,5)
- elseif x>=14 and x<=16 then
- s.playNote(instruments[instnr],volume,6)
- elseif x>=17 and x<=19 then
- s.playNote(instruments[instnr],volume,8)
- elseif x>=20 and x<=22 then
- s.playNote(instruments[instnr],volume,10)
- elseif x>=23 and x<=25 then
- s.playNote(instruments[instnr],volume,11)
- elseif x>=26 and x<=28 then
- s.playNote(instruments[instnr],volume,13)
- elseif x>=29 and x<=31 then
- s.playNote(instruments[instnr],volume,15)
- elseif x>=32 and x<=34 then
- s.playNote(instruments[instnr],volume,17)
- elseif x>=35 and x<=37 then
- s.playNote(instruments[instnr],volume,18)
- elseif x>=38 and x<=40 then
- s.playNote(instruments[instnr],volume,20)
- elseif x>=41 and x<=43 then
- s.playNote(instruments[instnr],volume,22)
- elseif x>=44 and x<=46 then
- s.playNote(instruments[instnr],volume,23)
- end
- elseif y==17 or y==18 then
- if x>=1 and x<=2 then
- if instnr == 1 then
- instnr = 15
- else
- instnr = instnr - 1
- end
- elseif x>=49 and x<=50 then
- if instnr == 15 then
- instnr = 1
- else
- instnr = instnr + 1
- end
- end
- term.setBackgroundColor(colors.cyan)
- term.setTextColor(colors.white)
- term.setCursorPos(25,18)
- write(" ")
- term.setCursorPos(25,18)
- write(instname[instnr])
- elseif y==2 or y==3 then
- local suc = false
- if x>=3 and x<=5 then
- if volume >= 0.2 then
- volume = volume - 0.1
- end
- suc = true
- elseif x>=15 and x<=17 then
- if volume <= 0.9 then
- volume = volume + 0.1
- end
- suc = true
- end
- if suc then
- term.setBackgroundColor(colors.cyan)
- term.setTextColor(colors.white)
- term.setCursorPos(9,3)
- write(" ")
- term.setCursorPos(9,3)
- local vol = toint(volume*100)
- write(vol)
- local vol2 = toint(volume*10)
- s.playNote(instruments[instnr],volume,vol2)
- end
- if x>=20 and x<=27 then
- if notation then
- notation = false
- term.setBackgroundColor(colors.lightBlue)
- term.setTextColor(colors.red)
- term.setCursorPos(22,3)
- write("OFF")
- drawkeys()
- else
- notation = true
- term.setBackgroundColor(colors.lightBlue)
- term.setTextColor(colors.green)
- term.setCursorPos(22,3)
- write("ON ")
- drawletters()
- end
- end
- elseif x==50 and y==1 then
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- term.clear()
- term.setCursorPos(1,1)
- break
- end
- end
- end
Add Comment
Please, Sign In to add comment