-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherecorder
executable file
·589 lines (472 loc) · 15 KB
/
erecorder
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
#!/usr/bin/python3
#
#----------------------------------------------------------------
# erecorder
# by Andrus
#
# This is a fairly simple utility which records the timing of keystrokes.
# It is for generating .e files to use with 'easy' (with further editing).
#
# The idea is you play the video and you tap the keypad along with events.
# A skeleton .e file is created with the timing. You need to further edit this file
# at places (mostly) indicated.
#
# With some practice - to be fair, maybe quite a bit of practice - it should be possible
# to quickly produce a perfect stroke stim. I'll admit I'm still practising.
import pdb
from os import environ
environ['PYGAME_HIDE_SUPPORT_PROMPT'] = '1'
import pygame
from pygame.locals import *
import time
import os.path
import argparse
import sys
import time
mintime=0.5 # seconds between events
ignore_mintime=True # use mintime between events
phase=float(0) # start at close to zero
keycaps = {
"1": "warb+",
"2": "warb-",
"3": "ph-",
"4": "bend+",
"5": "bend++",
"6": "ph+",
"7": "vol-",
"8": "vol+",
"9": "ph++",
"_P": "ph--",
"_PLUS": "ph0",
"_MINUS": "ph0",
"_MULTIPLY": " ",
"_ENTER": "vol+",
"_DIVIDE": " ",
"0": "tap"
}
locations = {
"1": (0,150),
"2": (50,150),
"3": (100,150),
"4": (0,100),
"5": (50,100),
"6": (100,100),
"7": (0,50),
"8": (50,50),
"9": (100,50),
"_P": (100,200),
"_PLUS": (150,75),
"_MINUS": (150,0),
"_MULTIPLY": (150,0),
"_ENTER": (150,175),
"_DIVIDE": (100,0),
"0": (0,200)
}
parser = argparse.ArgumentParser(description='Monitor keystroke for estim timing')
parser.add_argument('-n', help = "don't impose minimum time of 0.5s")
parser.add_argument('-f', help = "timing basefile name")
args = parser.parse_args()
filename=args.f+".e"
if (args.n):
ignore_mintime=True
if (os.path.exists(filename)):
print("file %s already exists. Erase it first." % (filename))
sys.exit("exiting...")
#----------------------------------------
def drawKeys(screen,x,y,pushed):
points=[]
pygame.draw.rect(screen,(66,75,66),Rect(x,y,200,250)) #background
points.append((x+0,y+0)) # top left
points.append((x+200,y+0)) # top right
points.append((x+200,y+250)) # bottom right
points.append((x+0,y+250)) # bottom left
points.append((x+0,y+0)) # start
pygame.draw.lines(screen,(0,0,0),False,points,3)
pygame.draw.lines(screen,(0,0,0),False,((x+0,y+50),(x+200,y+50)),3)
pygame.draw.lines(screen,(0,0,0),False,((x+0,y+100),(x+150,y+100)),3)
pygame.draw.lines(screen,(0,0,0),False,((x+0,y+150),(x+200,y+150)),3)
pygame.draw.lines(screen,(0,0,0),False,((x+0,y+200),(x+150,y+200)),3)
pygame.draw.lines(screen,(0,0,0),False,((x+50,y+0),(x+50,y+200)),3)
pygame.draw.lines(screen,(0,0,0),False,((x+100,y+0),(x+100,y+250)),3)
pygame.draw.lines(screen,(0,0,0),False,((x+150,y+0),(x+150,y+250)),3)
for key in locations:
point=locations[key]
label=keycaps[key]
xl=point[0]
yl=point[1]
text = font2.render(label, True, (255, 255, 255), (66, 66, 66))
textRect = text.get_rect()
textRect.centerx = x+xl+25
textRect.centery = y+yl+25
screen.blit(text, textRect)
pygame.display.update()
#----------------------------------------
f=open(args.f+".e","w")
# start the output file with some boiler plate stuff to fill in
f.write('''
# made with erecorder
print "title of file: xxx " # TO DO - FILL ME IN
output xxx.wav # TO DO - FILL ME IN
#---------------------------------------------
# Define your base signals
# These are examples
#
# TO DO - at minumum, adjust end times of waves if you want a
# simple file. If you make the sounds too long and tap too
# often you will drive into clipping.
#
defsound BASEL form:sine freq:900 vol:.7 fadein:.75 fadeout:0.1 length:FILL IN!
defsound BASER form:sine freq:900 vol:.7 fadein:.75 fadeout:0.1 length:FILL IN!
defsound QTAP form:comp freq:600 vol:.2 fadein:.15 fadeout:0.0 length:.55
defsound HTAP form:square freq:610 vol:.3 fadein:.1 length:.25
defsound STRONG form:poly vol:.1 fadein:.25 fadeout:.2 length:1.5
defsound STRONGER form:poly2 vol:.2 fadein:.2 fadeout:.2 langth:3
#---------------------------------------------
# Define what you want to happen at event times...
# These are examples.
#
event0=mix QTAP
event02=noop
event0R=noop
event0R_2=noop
thing=modify BASER phase
event9=modify BASER phase .5 slow
event9R=noop
event6=modify BASER phase .3 slow
event6R=noop
event3=modify BASER phase -.3 slow
event3R=noop
event_P=modify BASER phase -.5 slow
event_P2=noop
event_PR=noop
event_PR_2=noop
event_ENT=modify BASER vol .1
event_ENT_2=modify BASEL vol .1
event_ENTR=modify BASER vol -.1
event_ENTR_2=modify BASEL vol -.1
event_PLUS=modify BASER phase 0
event_PLUSR=noop
event_PLUS_2=noop
event_PLUS2=noop
event_PLUSR_2=noop
event_MINUS=modify BASER phase 0
event_MINUSR=noop
# ----------
# fade up and down
event7=modify BASER fade -.1 2
event72=modify BASEL fade -.1 2
event7R=noop
event7R_2=noop
event8=modify BASER fade .1 2
event82=modify BASEL fade .1 2
event8R=noop
event8R_2=noop
#-------
# some bendvols
event4=modify BASER bendvol +.05 4
event42=modify BASEL bendvol +.05 4
event4R=noop
event4R_2=noop
event5=modify BASER bendvol +.1 4
event52=modify BASEL bendvol +.1 4
event5R=noop
event5R_2=noop
event1=modify BASER warb 4
event12=modify BASER warbtremelo 1
event1R=noop
event1R_2=noop
event2=modify BASER warbstop
event22=noop
event2R=noop
event2R_2=noop
#------------
event3R_2=noop
event5R_2=noop
event6R_2=noop
event9R_2=noop
event32=noop
event52=noop
event62=noop
event92=noop
#
#---------------------------------------------
# Event timings...
# You can also cut-and-paste these to change the
# order in which they are laid down into the tracks.
#
''')
#------------------------------
# Graphics stuff... keeping this simple...
def updatePhase():
global phase
pygame.draw.rect(screen,(66,66,66),Rect(0,200,200,200)) #background
# decide color on meter needle
# you could be seeing this out the corner of your eye
if (phase>=.49):
needleColor=(255,99,255)
elif (phase>=.4):
needleColor=(33,33,200)
elif (phase>=.3):
needleColor=(33,33,160)
elif (phase>=.2):
needleColor=(33,33,120)
elif (phase>=.1):
needleColor=(33,33,99)
elif (phase>=.01):
needleColor=(33,33,66)
elif (phase==0):
needleColor=(33,33,33)
elif (phase<=-.49):
needleColor=(255,255,99)
elif (phase<=-.4):
needleColor=(33,200,33)
elif (phase<=-.3):
needleColor=(33,160,33)
elif (phase<=-.2):
needleColor=(33,120,33)
elif (phase<=-.1):
needleColor=(33,99,33)
elif (phase<=-.01):
needleColor=(33,66,33)
else:
needleColor=(33,33,33)
# print ("%d %d %d" % (needleColor[0],needleColor[1],needleColor[2]))
labelText=font.render("Phase",True,(255,255,255), (66,66,66))
labelRect=labelText.get_rect()
labelRect.centerx=35
labelRect.centery=210
screen.blit(labelText,labelRect)
pygame.draw.rect(screen,(160,160,160),Rect(8,230,56,110)) #border
pygame.draw.rect(screen,(128,128,128),Rect(10,230,50,110)) #background of meter
pygame.draw.rect(screen,needleColor,Rect(11,280+int(-phase*100),48,10)) #needle on meter
phaseText=font.render(str(phase),True,(255,255,0), (66,66,66))
phaseRect=phaseText.get_rect()
phaseRect.centerx=35
phaseRect.centery=350
screen.blit(phaseText,phaseRect)
pygame.display.update()
def updateTime(elapsedst):
pygame.draw.rect(screen,(66,66,66),Rect(0,0,200,200)) #background
labelText=font.render("Time Elapsed (s)",True,(255,255,255), (66,66,66))
labelRect=labelText.get_rect()
labelRect.centerx=100
labelRect.centery=10
screen.blit(labelText,labelRect)
labelText2=font.render(elapsedst,True,(255,255,0), (66,66,66))
labelRect2=labelText2.get_rect()
labelRect2.centerx=100
labelRect2.centery=40
screen.blit(labelText2,labelRect2)
pygame.display.update()
def showEvent(string):
pygame.draw.rect(screen,(33,33,33),Rect(200,0,200,200)) #background
pygame.draw.rect(screen,(66,66,66),Rect(204,4,192,192)) #background
labelText=font.render(string,True,(255,255,255), (66,66,66))
labelRect=labelText.get_rect()
labelRect.centerx=300
labelRect.centery=100
screen.blit(labelText,labelRect)
pygame.display.update()
def display2(str,r,g,b):
text = font.render(str, True, (255, 255, 255), (r, g, b))
textRect = text.get_rect()
textRect.centerx = screen.get_rect().centerx
textRect.centery = screen.get_rect().centery+40
screen.blit(text, textRect)
pygame.display.update()
def display3(x,y,str,r,g,b):
text = font.render(str, True, (255, 255, 255), (r, g, b))
textRect = text.get_rect()
textRect.centerx = screen.get_rect().x
textRect.centery = screen.get_rect().y
def display4(str):
text = font.render(str, True, (255, 255, 255), (255,40,40))
textRect = text.get_rect()
textRect.centerx = screen.get_rect().centerx
textRect.centery = screen.get_rect().centery+40
screen.blit(text, textRect)
pygame.display.update()
#----------------------------------------
def downevent(key,st,elapsed_st): # key press
global lasttime
showEvent("Macro:"+st)
drawKeys(screen,200,210,key)
key_state=1
f.write (("%s " % (elapsed_st))+(command % (st)+"\n"))
f.write (("%s " % (elapsed_st))+(command % (st+"2")+"\n"))
lasttime=time.time()
return
def upevent(key,st,elapsed_st): # key release
global lasttime
showEvent("")
# display2(" ",66,66,66)
key_state=0
f.write (("%s " % (elapsed_st))+(command % (st)+"\n"))
f.write (("%s " % (elapsed_st))+(command % (st+"_2")+"\n"))
lasttime=time.time()
return
def dothing(elapsed_st,amount): # used for mouse wheel phase shift
global lasttime
key_state=0
f.write ("%s $(thing) %s\n" % (elapsed_st,amount))
lasttime=time.time()
return
# set up graphics
pygame.init()
screen = pygame.display.set_mode( (500,500) )
pygame.display.set_caption('Stroke Recorder')
screen.fill((66,66,66))
font = pygame.font.Font(None, 20)
font2 = pygame.font.Font(None, 15)
num = 0
done = False
key_state = 0 # current key status is none down
command="$(event%s)"
pygame.key.set_repeat()
#wait for first key
while not done:
for event in pygame.event.get():
showEvent("HIT A KEY TO START")
if (event.type==pygame.KEYDOWN):
start=time.time()
done=True
showEvent("5")
time.sleep(1)
showEvent("4")
time.sleep(1)
showEvent("3")
time.sleep(1)
showEvent("2")
time.sleep(1)
showEvent("1")
time.sleep(1)
showEvent("GO")
start=time.time()
done=False
updatePhase()
drawKeys(screen,200,210,None)
# main loop
lasttime=start
while not done:
drawKeys(screen,200,210,None)
now=time.time()
difftime=(now-lasttime)
elapsed=(now-start)
elapsed_st="{:.2f}".format(elapsed)
# display( " "+elapsed_st+" " )
updateTime(elapsed_st)
num += 1
for event in pygame.event.get():
if (event.type==pygame.KEYDOWN):
if event.key==K_KP0:
downevent(K_KP0,"0",elapsed_st)
elif event.key==K_KP1:
downevent(K_KP1,"1",elapsed_st)
elif event.key==K_KP2:
downevent(K_KP2,"2",elapsed_st)
elif event.key==K_KP3:
downevent(K_KP3,"3",elapsed_st)
elif event.key==K_KP4:
downevent(K_KP4,"4",elapsed_st)
elif event.key==K_KP5:
downevent(K_KP5,"5",elapsed_st)
elif event.key==K_KP6:
downevent(K_KP6,"6",elapsed_st)
elif event.key==K_KP7:
downevent(K_KP7,"7",elapsed_st)
elif event.key==K_KP8:
downevent(K_KP8,"8",elapsed_st)
elif event.key==K_KP9:
downevent(K_KP9,"9",elapsed_st)
elif event.key==K_KP_PERIOD:
downevent(K_KP_PERIOD,"_P",elapsed_st)
elif event.key==K_KP_PLUS:
downevent(K_KP_PLUS,"_PLUS",elapsed_st)
elif event.key==K_KP_MINUS:
downevent(K_KP_MINUS,"_MINUS",elapsed_st)
elif event.key==K_KP_MULTIPLY:
downevent(K_KP_MULTIPLY,"_MULTIPLY",elapsed_st)
elif event.key==K_KP_ENTER:
downevent(K_KP_ENTER,"_ENTER",elapsed_st)
elif event.key==K_KP_DIVIDE:
downevent(K_KP_DIVIDE,"_DIVIDE",elapsed_st)
elif event.key==K_ESCAPE:
done = True
break
elif event.key==K_q:
done = True
break
elif (event.type==pygame.KEYUP):
if event.key==K_KP0:
upevent(K_KP0,"0R",elapsed_st)
elif event.key==K_KP1:
upevent(K_KP1,"1R",elapsed_st)
elif event.key==K_KP2:
upevent(K_KP2,"2R",elapsed_st)
elif event.key==K_KP3:
upevent(K_KP3,"3R",elapsed_st)
elif event.key==K_KP4:
upevent(K_KP4,"4R",elapsed_st)
elif event.key==K_KP5:
upevent(K_KP5,"5R",elapsed_st)
elif event.key==K_KP6:
upevent(K_KP6,"6R",elapsed_st)
elif event.key==K_KP7:
upevent(K_KP7,"7R",elapsed_st)
elif event.key==K_KP8:
upevent(K_KP8,"8R",elapsed_st)
elif event.key==K_KP9:
upevent(K_KP9,"9R",elapsed_st)
elif event.key==K_KP_PERIOD:
upevent(K_KP_PERIOD,"_PR",elapsed_st)
elif event.key==K_KP_PLUS:
upevent(K_KP_PLUS,"_PLUS",elapsed_st)
elif event.key==K_KP_MINUS:
upevent(K_KP_MINUS,"_MINUS",elapsed_st)
elif event.key==K_KP_MULTIPLY:
upevent(K_KP_MULTIPLY,"_MULTIPLY",elapsed_st)
elif event.key==K_KP_ENTER:
upevent(K_KP_ENTER,"_ENTER",elapsed_st)
elif event.key==K_KP_DIVIDE:
upevent(K_KP_DIVIDE,"_DIVIDE",elapsed_st)
elif event.type==MOUSEBUTTONDOWN:
if (event.button==5): # scroll wheel down
phase-=.05
phase=round(phase,2)
if (phase<-.5):
phase=-.5
dothing(elapsed_st,str(phase))
#print ("phase down: %1.2f" % (phase))
updatePhase()
elif (event.button==4): # scroll wheel up
phase+=.05
phase=round(phase,2)
if (phase>.5):
phase=.5
dothing(elapsed_st,phase)
#print ("phase up: %1.2f" % (phase))
updatePhase()
if (difftime>10):
phase=0
dothing(elapsed_st,str(0)+" slow")
updatePhase()
f.write (("length %s" % (elapsed_st)+"\n"))
f.write('''
#--------------------------------------------------
# TO DO - do whatever you want here.
# This just lays down a basic signal in each channel
# You can add lots of stuff.
#
# If you change start point the other time stamps
# will have to shift!
#
balance left
0 mix BASEL
balance right
0 mix BASER
id3title ""
id3author ""
id3comment ""
''')
f.close()
# end main loop