diff options
| author | Tim Redfern <tim@eclectronics.org> | 2013-11-18 14:40:41 +0000 |
|---|---|---|
| committer | Tim Redfern <tim@eclectronics.org> | 2013-11-18 14:40:41 +0000 |
| commit | a36735b4585521218268da5fed2214ba239b4c2a (patch) | |
| tree | 77f951acb62d61c88b0b01d4bcb34367e44abc91 /lyricstimer/timelyrics | |
| parent | 6c5ba0ff0a4301b932c70aee6b4c87b2092d8bff (diff) | |
simple lyrics script
Diffstat (limited to 'lyricstimer/timelyrics')
| -rwxr-xr-x | lyricstimer/timelyrics | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/lyricstimer/timelyrics b/lyricstimer/timelyrics new file mode 100755 index 0000000..2d6e071 --- /dev/null +++ b/lyricstimer/timelyrics @@ -0,0 +1,60 @@ +#!/usr/bin/python + +from pyxhook import HookManager +from time import time +import termios, sys +import atexit + +if len(sys.argv)<2: + print "usage: timelyrics audio_filename" + exit() + +import pygame +pygame.mixer.init() +pygame.mixer.music.load(sys.argv[1]) +pygame.mixer.music.play() + +for arg in sys.argv: + print arg + + +def enable_echo(fd, enabled): + (iflag, oflag, cflag, lflag, ispeed, ospeed, cc) \ + = termios.tcgetattr(fd) + if enabled: + lflag |= termios.ECHO + else: + lflag &= ~termios.ECHO + new_attr = [iflag, oflag, cflag, lflag, ispeed, ospeed, cc] + termios.tcsetattr(fd, termios.TCSANOW, new_attr) + +atexit.register(enable_echo, sys.stdin.fileno(), True) + +enable_echo( sys.stdin.fileno(),False) + +start=0.0 +down=0.0 +state="up" +count=0 + +def handle_up (event): + global start,down,state,count + if count>0: + print "[",down,",",time()-(start+down),"]" + state="up" + count+=1 + +def handle_down (event): + global start,down,state + if state=="up": + down=time()-start + state="down" + + +hm = HookManager() +hm.HookKeyboard() +hm.KeyUp = handle_up +hm.KeyDown = handle_down +start=time() +print "started:",start +hm.start()
\ No newline at end of file |
