-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpiano.py
61 lines (50 loc) · 1.9 KB
/
piano.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
'''
PyPiano Version 1.0 (C) 2018 apple502j
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
'''
from platform import system as _system
from sys import exit as _exit
if _system() != "Windows":
print("Sorry, This program doesn't work in your OS. Please use Windows!")
_exit()
import winsound
from gpltext import GPL_license
from linereadw import linereadw
from msvcrt import getch
from math import log10
def freq(note):
return 440*(10**(((note-69)/12)*log10(2)))
def yesno(s):
if s.lower()=="yes" or s.lower()=="y" or s=="1" or s.lower()=="true":
return True
else:
return False
keyNote={b"a":59,b"s":60,b"e":61,b"d":62,b"r":63,b"f":64,b"g":65,b"y":66,b"h":67,b"u":68,b"j":69,b"i":70,b"k":71,b"l":72}
def play(k):
if k in keyNote:
winsound.Beep(int(freq(keyNote[k])),500)
print("""
PyPiano Version 1.0 (C) 2018 apple502j
This program comes with ABSOLUTELY NO WARRANTY.
This is free software, and you are welcome to redistribute it
under certain conditions; type 'o' for details.
Use your keyboard to play. Quit? Push 'p'.
Anyway, play with it! Have fun!
""")
while True:
key=getch()
if key == b'o':
linereadw(GPL_license,20)
if key == b'p':
if yesno(input("Do you really want to quit? (Yes/No)>")):
_exit()
play(key)