Skip to content

Instantly share code, notes, and snippets.

@acspike
Created October 3, 2010 01:16
Show Gist options
  • Save acspike/608162 to your computer and use it in GitHub Desktop.
Save acspike/608162 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import time, getpass
class FakeStream(object):
def write(self, *args, **kwargs):
pass
def flush(self, *args, **kwargs):
pass
print '''TapTempo
Enter - count a beat
q Enter - quit
'''
count = 0.0
total = 0.0
last = 0.0
while True:
if 'q' in getpass.getpass('', FakeStream()):
break
now = time.time()
if bool(last):
current = 60.0 / (now - last)
count += 1
total += current
print '\b' * 30,
print '%7.2f bpm %7.2f avg bpm' % (current, total / count),
last = now
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment