Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- print("Welcome to Tesik's music player!")
- sleep(1)
- while true do
- print("Select output side for speaker or end program:")
- r = io.read("*l")
- if r == "end" then
- error("Bye")
- else
- x = peripheral.wrap(r)
- if x == nil then
- print("No speaker found!")
- sleep(1)
- else
- break
- end
- end
- end
- function note(n)
- if n=="E1" or n=="Fb1" then
- return 41.20
- elseif n=="F1" or n=="E#1" then
- return 43.65
- elseif n=="F#1" or n=="Gb1" then
- return 46.25
- elseif n=="G1" then
- return 49.00
- elseif n=="G#1" or n=="Ab1" then
- return 51.91
- elseif n=="A1" then
- return 55.00
- elseif n=="A#1" or n=="Bb1" then
- return 58.27
- elseif n=="B1" or n=="Cb2" then
- return 61.74
- elseif n=="C2" or n=="B#1" then
- return 65.41
- elseif n=="C#2" or n=="Db2" then
- return 69.30
- elseif n=="D2" then
- return 73.42
- elseif n=="D#2" or n=="Eb2" then
- return 77.78
- elseif n=="E2" or n=="Fb2" then
- return 82.41
- elseif n=="F2" or n=="E#2" then
- return 87.31
- elseif n=="F#2" or n=="Gb2" then
- return 92.50
- elseif n=="G2" then
- return 98.00
- elseif n=="G#2" or n=="Ab2" then
- return 103.83
- elseif n=="A2" then
- return 110.00
- elseif n=="A#2" or n=="Bb2" then
- return 116.54
- elseif n=="B2" or n=="Cb2" then
- return 123.47
- elseif n=="C3" or n=="B#2" then
- return 130.81
- elseif n=="C#3" or n=="Db3" then
- return 138.59
- elseif n=="D3" then
- return 146.83
- elseif n=="D#3" or n=="Eb3" then
- return 155.56
- elseif n=="E3" or n=="Fb3" then
- return 164.81
- elseif n=="F3" or n=="E#3" then
- return 174.61
- elseif n=="F#3" or n=="Gb3" then
- return 185.00
- elseif n=="G3" then
- return 196.00
- elseif n=="G#3" or n=="Ab3" then
- return 207.65
- elseif n=="A3" then
- return 220.00
- elseif n=="A#3" or n=="Bb3" then
- return 233.08
- elseif n=="B3" or n=="Cb3" then
- return 246.94
- elseif n=="C4" or n=="B#3" then
- return 261.63
- elseif n=="C#4" or n=="Db4" then
- return 277.18
- elseif n=="D4" then
- return 293.66
- elseif n=="D#4" or n=="Eb4" then
- return 311.13
- elseif n=="E4" or n=="Fb4" then
- return 329.63
- elseif n=="F4" or n=="E#4" then
- return 349.23
- elseif n=="F#4" or n=="Gb4" then
- return 369.99
- elseif n=="G4" then
- return 392.00
- elseif n=="G#4" or n=="Ab4" then
- return 415.30
- elseif n=="A4" then
- return 440.00
- elseif n=="A#4" or n=="Bb4" then
- return 466.16
- elseif n=="B4" or n=="Cb4" then
- return 493.88
- elseif n=="C5" or n=="B#4" then
- return 523.25
- elseif n=="C#5" or n=="Db5" then
- return 554.37
- elseif n=="D5" then
- return 587.33
- elseif n=="D#5" or n=="Eb5" then
- return 622.25
- elseif n=="E5" or n=="Fb5" then
- return 659.25
- elseif n=="F5" or n=="E#5" then
- return 698.46
- elseif n=="F#5" or n=="Gb5" then
- return 739.99
- elseif n=="G5" then
- return 783.99
- elseif n=="G#5" or n=="Ab5" then
- return 830.61
- elseif n=="A5" then
- return 880.00
- elseif n=="A#5" or n=="Bb5" then
- return 932.33
- elseif n=="B5" or n=="Cb5" then
- return 987.77
- elseif n=="C6" or n=="B#5" then
- return 1046.50
- elseif n=="C#6" or n=="Db6" then
- return 1108.73
- elseif n=="D6" then
- return 1174.66
- elseif n=="D#6" or n=="Eb6" then
- return 1244.51
- elseif n=="E6" or n=="Fb6" then
- return 1318.51
- elseif n=="F6" or n=="E#6" then
- return 1396.91
- elseif n=="F#6" or n=="Gb6" then
- return 1479.98
- elseif n=="G6" then
- return 1567.98
- elseif n=="G#6" or n=="Ab6" then
- return 1661.22
- elseif n=="A6" then
- return 1760.00
- elseif n=="A#6" or n=="Bb6" then
- return 1864.66
- elseif n=="B6" or n=="Cb6" then
- return 1975.53
- elseif n=="C7" or n=="B#1" then
- return 2093.00
- elseif n=="C#7" or n=="Db6" then
- return 2217.46
- elseif n=="D7" then
- return 2349.32
- elseif n=="D#7" or n=="Eb7" then
- return 2489.02
- elseif n=="E7" or n=="Fb7" then
- return 2637.02
- elseif n=="F7" or n=="E#7" then
- return 2793.83
- elseif n=="F#7" or n=="Gb7" then
- return 2959.96
- elseif n=="G7" then
- return 3135.96
- elseif n=="G#7" or n=="Ab7" then
- return 3322.44
- elseif n=="A7" then
- return 3520.00
- elseif n=="A#7" or n=="Bb7" then
- return 3729.31
- elseif n=="B7" or n=="Cb7" then
- return 3951.07
- elseif n=="C8" or n=="B#7" then
- return 4186.01
- elseif n=="C#8" or n=="Db8" then
- return 4434.92
- elseif n=="D8" then
- return 4698.63
- elseif n=="D#8" or n=="Eb8" then
- return 4978.03
- elseif n=="E8" or n=="Fb8" then
- return 5274.04
- elseif n=="F8" or n=="E#8" then
- return 5587.65
- elseif n=="F#8" or n=="Gb8" then
- return 5919.91
- elseif n=="G8" then
- return 6271.93
- elseif n=="G#8" or n=="Ab8" then
- return 6644.88
- elseif n=="A8" then
- return 7040.00
- elseif n=="A#8" or n=="Bb8" then
- return 7458.62
- elseif n=="X" then
- return 0
- else
- return nil
- end
- end
- function stop()
- x.stop(1)
- end
- function play(n, t)
- if note(n)==nil then
- elseif note(n)==0 then
- stop()
- sleep(t)
- else
- x.start(1, note(n))
- sleep(t)
- end
- end
- notes = {}
- lengths = {}
- a = 0
- while true do
- a = a + 1
- while true do
- print("Enter a note or end:")
- r = io.read("*l")
- if r == "end" then
- ending = true
- break
- elseif note(r) == nil then
- print("Invalid note")
- sleep(0.5)
- else
- notes[a] = r
- break
- end
- end
- if ending then
- break
- end
- while true do
- print("Enter note length[s]:")
- r =io.read("*l")
- if tonumber(r) == nil then
- print("Invalid number!")
- sleep(0.5)
- else
- lengths[a] = tonumber(r)
- break
- end
- end
- end
- sleep(0.5)
- shell.run("clear")
- ending = false
- b = a
- print("Playing...")
- while true do
- if ending then
- break
- end
- a = 0
- repeat
- a = a + 1
- print(notes[a])
- play(notes[a], lengths[a])
- until a == b
- stop()
- while true do
- print("Repeat? y/n")
- r = io.read("*l")
- if r == "y" then
- break
- elseif r == "n" then
- ending = true
- break
- end
- end
- end
- print("Bye...")
- sleep(1.7)
- shell.run("clear")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement