-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathNotePlayer.py
71 lines (51 loc) · 1.62 KB
/
NotePlayer.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
62
63
64
65
66
67
68
69
70
71
import time
import keyboard
import pygetwindow as gw
import os
from common import load_translations, speak
from common import select_window
import common
_ = load_translations()
numbers = common.numbers
keys = common.keys
current_directory = os.getcwd()
def timer(function = 0):
global salise
global now
if function == 1:
now = time.time()
salise = int((now - int(now)) * 1000)
else:
elapsed_time = time.time() - now
return salise + int(elapsed_time * 1000)
def play_music(notes, sfx):
target = select_window(sfx)
Note_dict = {}
for i in notes:
Note_dict[i[1]] = i[0]
for key,value in Note_dict.items():
for i in range(len(numbers)):
if value == int(numbers[i]):
Note_dict[key] = keys[i]
timer(1)
counter = 0
t1 = time.time()
for key,value in Note_dict.items():
counter += 1
current_time = timer()
while current_time < key: # Wait for correct time
current_time = timer()
time.sleep(0.0005)
keyboard.send(value)
print(f"Time: {key} Key {value.capitalize()}")
if keyboard.is_pressed('"'):
break
if target != None:
if gw.getActiveWindowTitle() != target:
speak("focus lost", sfx)
if not sfx:
print(_("focus_lost"))
break
t2=time.time()
playtime = round(t2-t1, 1)
print(_("playback_duration").replace("*", str(playtime)))