summaryrefslogtreecommitdiff
path: root/lyricstimer/timelyrics
blob: 2d6e0711dd9d8cfa5d9cfdd59aa093aefb649812 (plain)
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
#!/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()