Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions piano.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/usr/bin/python
#or /your/python/path

done = False

#Importing the libraries
import subprocess
import curses

#Set up Curses
lin = curses.initscr() #Initialize window
curses.cbreak() #Turn off buffering of chars, allows to be read without pressing enter

#Be friendly
lin.addstr("Welcome to the linux beep piano! (Coded in Python!)\n")
lin.addstr("Press keys a-k for whole steps, keys w-u for half steps, and q to exit.\n")

#Infinite loop! (kinda)
while done == False:
#Get that character
x = lin.getch()
#Check that character
if(x == ord('a')):
#Using subprocess to call beep from command line
subprocess.call("beep -f 261.63", shell=True) #C4
elif(x == ord('w')):
subprocess.call("beep -f 277.18", shell=True) #Db4
elif(x == ord('s')):
subprocess.call("beep -f 293.66", shell=True) #D4
elif(x == ord('e')):
subprocess.call("beep -f 311.13", shell=True) #Eb4
elif(x == ord('d')):
subprocess.call("beep -f 329.63", shell=True) #E4
elif(x == ord('f')):
subprocess.call("beep -f 349.23", shell=True) #F4
elif(x == ord('t')):
subprocess.call("beep -f 369.99", shell=True) #Gb4
elif(x == ord('g')):
subprocess.call("beep -f 392.00", shell=True) #G4
elif(x == ord('y')):
subprocess.call("beep -f 415.30", shell=True) #Ab4
elif(x == ord('h')):
subprocess.call("beep -f 440.00", shell=True) #A4
elif(x == ord('u')):
subprocess.call("beep -f 466.16", shell=True) #Bb4
elif(x == ord('j')):
subprocess.call("beep -f 493.88", shell=True) #B4
elif(x == ord('k')):
subprocess.call("beep -f 523.25", shell=True) #C5
elif(x == ord('q')):
done = True
elif(x == -1):
# if eq -1, means end of file from stdin, so exit.
done = True

#Call commands to properly exit curses and return terminal to original state
curses.nocbreak()
lin.keypad(0)
curses.echo()
curses.endwin()

58 changes: 0 additions & 58 deletions piano.sh

This file was deleted.