-
Notifications
You must be signed in to change notification settings - Fork 0
/
dae.another-copy
executable file
·827 lines (716 loc) · 21.8 KB
/
dae.another-copy
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
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
#!/usr/bin/python
#Released under GNU General Public License version 3, see the file COPYING for details.
#Change the value of the following two lines if your sound device is not /dev/dsp
soundin="alsa"
soundout="alsa"
from pyeca import *
import commands, sys, time, os
e = ECA_CONTROL_INTERFACE(0)
def do_command(cmdstring):
e.command(cmdstring)
returned_error=e.last_error()
if returned_error:
print "an error occured while doing "+cmdstring+" the error was: "+returned_error
print "remember you should have a backup in "+infile+"~"
print "exiting"
exit()
return
if len(sys.argv) == 1:
print "no file given, using unknown.wav"
do_command("cs-add chain1")
do_command("cs-set-audio-format 16,2,44100")
do_command("c-add chain1")
do_command("ai-add rtnull")
do_command("ao-add unknown.wav")
do_command("cs-set-length 1")
do_command("cs-connect chain1")
do_command("run")
do_command("cs-disconnect chain1")
do_command("cs-remove chain1")
infile = "unknown.wav"
else:
infile = sys.argv.pop(1)
if not (os.path.isfile(infile)):
do_command("cs-add chain1")
do_command("cs-set-audio-format 16,2,44100")
do_command("c-add chain1")
do_command("ai-add rtnull")
do_command("ao-add "+infile)
do_command("cs-set-length 1")
do_command("cs-connect chain1")
do_command("run")
do_command("cs-disconnect chain1")
do_command("cs-remove chain1")
print infile+" is new and contains one second silense."
print "please wait while we make a backup of "+infile
backedup=commands.getstatusoutput("cp "+infile+" "+infile+"~")
if backedup[0]==0:
print "backup complete"
else:
print "backup of "+infile+" failled, reason: "+backedup[1]
print "warning: proceding without a backup"
buttons={"f1": "stop", "f2": "play", "f3": "fast rewind", "f4": "fast forward", "f5": "begin block", "f6": "end block", "f7": "play block", "f8": "write block", "f9": "remove block", "f10": "record", "shift_f10": "denoised recording", "ctrl_f10": "wireless recording", "f11": "insert from file", "f12": "go to end", "J": "go to last track mark", "l": "toggle half speed", "p": "wrote position", "S": "split tracks"}
bs=False
be=False
forwarding=False
denoise=False
rewinding=False
halfspeed=False
key=""
active_controls=['f1','f2','shift_f10','ctrl_f10','q','l']
global block_controls_active
block_controls_active=True
def deactivate_block_controls():
active_controls.remove('f5')
active_controls.remove('f6')
active_controls.remove('f7')
active_controls.remove('f8')
active_controls.remove('f9')
active_controls.remove('f10')
active_controls.remove('shift_f10')
active_controls.remove('ctrl_f10')
active_controls.remove('f11')
global block_controls_active
block_controls_active=False
def reactivate_block_controls():
active_controls.append('f5')
active_controls.append('f6')
active_controls.append('f7')
active_controls.append('f8')
active_controls.append('f9')
active_controls.append('f10')
active_controls.append('shift_f10')
active_controls.append('ctrl_f10')
active_controls.append('f11')
active_controls.append('l')
global block_controls_active
block_controls_active=True
def currentpos():
do_command("get-position")
result=e.last_float()
return result
def init_write_position():
global poslines, prevpos, lastline
if os.path.isfile(infile+".pos"):
pf=open(infile+".pos", "r")
poslines=pf.readlines()
pf.close()
lastline=poslines[len(poslines)-1]
last_written=lastline.split(' ')
prevpos=float(last_written[0])+float(last_written[1])
else:
prevpos=0
poslines=[]
return
def write_position():
global poslines, prevpos, lastline
if currentpos() <= prevpos:
result="next track must follow previous track, no position written"
return result
tracklen=currentpos()-prevpos
addline=str(prevpos)+" "+str(tracklen)+chr(10)
pf=open(infile+".pos", "a")
pf.write(addline)
pf.close()
poslines.append(addline)
lastline=poslines[len(poslines)-1]
last_written=lastline.split(' ')
prevpos=float(last_written[0])+float(last_written[1])
return str(prevpos)
def movearound(direction):
#The code for rewinding in this function is currently not used as it is buggy.
global forwarding,rewinding,oldpos,was_playing
if not (rewinding or forwarding):
oldpos=currentpos()
do_command("engine-status")
if e.last_string()=="running":
was_playing=True
else:
was_playing=False
do_command("stop")
d=direction
if d=='r':
if rewinding==False:
do_command("cs-disconnect chain1")
do_command("cs-remove chain1")
do_command("cs-add chain1")
do_command("c-add chain1")
do_command("c-select chain1")
do_command("ai-add reverse,"+infile)
do_command("ao-add "+soundout)
do_command("cs-option -ei:400")
do_command("cs-connect chain1")
do_command("setpos "+str(oldpos))
do_command("start")
rewinding=True
return
else:
rewinding=False
do_command("stop")
do_command("cs-clear")
rewindpos=currentpos()
do_command("cs-disconnect chain1")
do_command("cs-remove chain1")
do_command("cs-add chain1")
do_command("c-add chain1")
do_command("c-select chain1")
do_command("ai-add "+infile)
do_command("ao-add "+soundout)
do_command("cs-connect chain1")
rewound=rewindpos-oldpos
do_command("setpos "+str(oldpos-rewound))
if was_playing:
do_command("start")
return
else:
if forwarding==False:
do_command("cs-option -ei:400")
forwarding=True
else:
if was_playing == False:
do_command("engine-status")
do_command("stop")
do_command("engine-status")
while e.last_string() == "running":
do_command("stop")
do_command("engine-status")
do_command("c-clear")
waitfortask
forwarding=False
return
if (not block_controls_active) and d=='r' and currentpos() <= bs:
#we are trying to rewind past block start when playinng block
do_command("setpos "+str(bs))
if (not block_controls_active) and d=='f' and currentpos() >= be:
#we are trying to forward past block end when playing block
do_command("setpos "+str(be))
do_command("start")
return
def go_slow():
global halfspeed, was_playing
do_command("engine-status")
if e.last_string()=="running":
was_playing=True
else:
was_playing=False
if halfspeed==False:
do_command("cs-option -ei:70")
halfspeed=True
else:
if was_playing == False:
do_command("engine-status")
do_command("stop")
do_command("engine-status")
while e.last_string() == "running":
do_command("stop")
do_command("engine-status")
do_command("c-clear")
waitfortask
halfspeed=False
return
return
def blocktime():
if bs == be:
print "no block"
result=False
return result
if type(bs) !=type(0.0):
print "No beginning of block marked"
result=False
return result
if type(be) != type(0.0):
print "No end of block marked"
result=False
return result
if bs > be:
print "start later than end"
result=False
return result
result=be-bs
return result
def playagain(vanaf):
do_command("cs-add default -i:infile -o alsa")
do_command("cs-connect default")
do_command("setpos "+str(vanaf))
do_command("start")
def playblock():
if blocktime() == False:
return
do_command("cs-get-length")
mainlength=e.last_float()
mainpos=keepme
do_command("stop")
do_command("setpos "+str(bs))
do_command("cs-set-length "+str(be))
if blocktime() < 10:
do_command("run")
else:
do_command("start")
user_control()
do_command("cs-set-length "+str(mainlength))
do_command("setpos "+str(mainpos))
print blocktime()
def write_block():
if blocktime() == False:
return
do_command("cs-get-length")
mainlength=e.last_float()
mainpos=keepme
do_command("stop")
do_command("cs-disconnect chain1")
do_command("cs-remove chain1")
outblock=raw_input("write block as? ")
if os.path.isfile(outblock):
os.remove(outblock)
do_command("cs-add chain1")
do_command("c-add chain1")
set_chain_format()
do_command("ai-add "+infile)
do_command("ao-add "+outblock)
do_command("cop-select chain1")
do_command("cs-connect chain1")
do_command("ai-select "+infile)
do_command("ai-setpos "+str(bs))
# do_command("setpos "+str(bs))
print "block start "+str(bs)
do_command("cs-set-length "+str(be-bs))
do_command("run")
do_command("cs-disconnect chain1")
do_command("cs-remove chain1")
do_command("cs-add chain1")
do_command("c-add chain1")
do_command("ai-add "+infile)
do_command("ao-add "+soundout)
do_command("cop-select chain1")
do_command("cs-connect chain1")
do_command("cs-set-length "+str(mainlength))
do_command("setpos "+str(mainpos))
print "wrote "+outblock+" ",blocktime()," seconds"
return
def split_tracks():
if len(poslines)==0:
print "no tracks marked for splitting"
return
do_command("cs-get-length")
mainlength=e.last_float()
mainpos=keepme
do_command("stop")
do_command("cs-disconnect chain1")
do_command("cs-remove chain1")
trackno_length=len(str(len(poslines)))
track_prefix="track_"
trackno=0
while trackno < len(poslines):
tracknumber=str(trackno+1)
while len(tracknumber) < trackno_length:
tracknumber='0'+tracknumber
outblock=track_prefix+tracknumber+".wav"
if os.path.isfile(outblock):
os.remove(outblock)
do_command("cs-add chain1")
do_command("c-add chain1")
set_chain_format()
do_command("ai-add "+infile)
do_command("ao-add "+outblock)
do_command("cop-select chain1")
do_command("cs-connect chain1")
do_command("ai-select "+infile)
track=poslines[trackno].split(' ')
trackstart=track[0]
tracklength=track[1]
do_command("ai-setpos "+trackstart)
print "writing "+outblock
do_command("cs-set-length "+tracklength)
do_command("run")
do_command("cs-disconnect chain1")
do_command("cs-remove chain1")
trackno=trackno+1
do_command("cs-add chain1")
do_command("c-add chain1")
do_command("ai-add "+infile)
do_command("ao-add "+soundout)
do_command("cop-select chain1")
do_command("cs-connect chain1")
do_command("cs-set-length "+str(mainlength))
do_command("setpos "+str(mainpos))
print "wrote "+str(len(poslines))+" tracks"
return
def set_chain_format():
do_command("cs-option -f:"+bits+","+channels+","+srate)
def remove_block():
if blocktime() == False:
return
do_command("cs-get-length")
global bs,be
mainlength=e.last_float()-blocktime()
mainpos=keepme
if mainpos > bs and mainpos < be:
mainpos=bs
do_command("stop")
do_command("cs-disconnect chain1")
do_command("cs-remove chain1")
do_command("cs-add chain1")
set_chain_format()
# do_command("c-add chain1")
do_command("ai-add "+infile)
do_command("ao-add "+infile)
do_command("ai-select "+infile)
do_command("ai-setpos "+str(be))
do_command("ao-select "+infile)
do_command("ao-setpos "+str(bs))
do_command("cs-connect chain1")
do_command("start")
waitfortask()
do_command("cs-disconnect chain1")
do_command("cs-remove chain1")
base_infile=os.path.basename(infile)
dir_infile=os.path.dirname(infile)
if dir_infile=="":
dir_infile=os.path.curdir
tempfile=dir_infile+"/tmp_"+base_infile
os.rename(infile, tempfile)
do_command("cs-add chain1")
set_chain_format()
# do_command("c-add chain1")
do_command("ai-add "+tempfile)
do_command("ao-add "+infile)
do_command("ao-select "+infile)
# do_command("cop-select chain1")
do_command("cs-connect chain1")
do_command("cs-set-length "+str(mainlength))
do_command("start")
waitfortask()
do_command("cs-disconnect chain1")
do_command("cs-remove chain1")
os.unlink(tempfile)
do_command("cs-add chain1")
set_chain_format()
# do_command("c-add chain1")
do_command("ai-add "+infile)
do_command("ao-add "+soundout)
do_command("cs-connect chain1")
if mainpos >= be:
do_command("setpos "+str(mainpos - blocktime()))
else:
do_command("setpos "+str(mainpos))
print "removed ",blocktime()," second block now "+str(mainlength)
bs=0
be=0
return
def range_check(start_end):
global bs, be, block_controls_active
if start_end=="start" and (not block_controls_active) and currentpos()<bs:
do_command("setpos "+str(bs))
print "trying to rewind past block start"
return
if start_end=="start" and currentpos()<0:
do_command("setpos 0")
return
if start_end=="end" and (not block_controls_active) and currentpos() > be:
do_command("setpos "+str(be))
return
do_command("cs-get-length")
file_length=e.last_float()
if start_end=="end" and currentpos() > file_length:
do_command("setpos "+str(file_length))
return
return
def waitfortask():
time.sleep(0.25)
do_command("engine-status")
while e.last_string() == "running":
do_command("engine-status")
def record_realtime():
do_command("stop")
global keepme, buttons, denoise
mainpos=keepme
buttons["f2"]="recording"
do_command("cs-disconnect chain1")
do_command("cs-remove chain1")
if os.system("test -f realtime.wav") == 0:
os.unlink("realtime.wav")
do_command("cs-add chain1")
do_command("c-add chain1")
set_chain_format()
do_command("ai-add "+soundin)
do_command("ao-add realtime.wav")
do_command("cs-connect chain1")
deactivate_block_controls()
user_control()
reactivate_block_controls()
buttons["f2"]="play"
do_command("cs-disconnect chain1")
do_command("cs-remove chain1")
if denoise:
os.rename("realtime.wav", "with_noise.wav")
print "denoising, please wait"
denoised=commands.getstatusoutput("sox with_noise.wav realtime.wav vol 0.5 speexdsp -denoise 90 norm")
if denoised[0] !=0:
print "Problem denoising, reason: "+denoised[1]
os.rename("with_noise.wav", "realtime.wav")
insert_file("realtime.wav", mainpos)
return
def add_file():
global keepme
mainpos=keepme
do_command("stop")
if os.system("which pickafile 2> /dev/null > /dev/null") == 0:
rc=os.system("pickafile")
if rc > 0:
return
else:
newfile=commands.getoutput("cat $HOME/.kies/.`getterm`file")
else:
newfile=raw_input("filename to insert? ")
do_command("cs-disconnect chain1")
do_command("cs-remove chain1")
insert_file(newfile, mainpos)
return
def record_wifi():
global keepme
mainpos=keepme
do_command("stop")
wifi=os.system('bash kies_wifi_microphone')
if wifi != 0:
print "wireless recording failed"
return
newfile="realtime.wav"
do_command("cs-disconnect chain1")
do_command("cs-remove chain1")
insert_file(newfile, mainpos)
return
def sameformat(checkfile):
do_command("cs-add checkchain")
do_command("cs-select checkchain")
do_command("c-add check")
do_command("c-select check")
do_command("ai-add "+checkfile)
do_command("ao-add null")
do_command("cs-connect checkchain")
do_command("engine-launch")
do_command("ai-select "+checkfile)
do_command("ai-get-format")
newformat=e.last_string()
do_command("cs-disconnect checkchain")
do_command("cs-remove checkchain")
if newformat==masterformat:
print "formats are the same"
result=True
return result
print checkfile+" is "+newformat
result=False
return result
def insert_file(newfile, plek):
do_command("cs-add chain1")
do_command("c-add chain1")
do_command("ai-add "+newfile)
do_command("ao-add null")
do_command("cs-connect chain1")
do_command("ai-select "+newfile)
do_command("ai-get-length "+newfile)
runfor=e.last_float()
do_command("cs-disconnect chain1")
do_command("cs-remove chain1")
format_native=sameformat(newfile)
do_command("cs-add chain1")
do_command("c-add chain1")
set_chain_format()
do_command("ai-add "+infile)
do_command("ao-add tmp_l.wav")
do_command("cs-select chain1")
do_command("cs-connect chain1")
waitfortask()
do_command("cs-set-length "+str(plek))
waitfortask()
do_command("ai-select "+infile)
waitfortask()
do_command("ai-setpos 0")
waitfortask()
do_command("start")
waitfortask()
print "written left side up to: ",currentpos()
do_command("cs-disconnect chain1")
waitfortask()
do_command("cs-remove chain1")
waitfortask()
do_command("cs-add chain1")
do_command("c-add chain1")
set_chain_format()
if format_native:
do_command("ai-add "+newfile)
else:
do_command("ai-add resample-hq,auto,"+newfile)
waitfortask()
do_command("ao-add tmp_l.wav")
do_command("cs-connect chain1")
waitfortask()
do_command("ao-select tmp_l.wav")
do_command("ao-setpos "+str(plek))
waitfortask()
do_command("cs-set-length "+str(runfor))
waitfortask()
print "inserting "+newfile+" which is ",runfor," seconds long"
do_command("start")
do_command("engine-status")
while e.last_string() == "not started":
do_command("engine-status")
waitfortask()
newpos=plek+currentpos()
print "starting at "+str(plek)+" inserted up to "+str(newpos)
do_command("cs-disconnect chain1")
waitfortask()
do_command("cs-remove chain1")
waitfortask()
do_command("cs-add chain1")
do_command("c-add chain1")
set_chain_format()
do_command("ai-add "+infile)
do_command("ao-add tmp_l.wav")
do_command("cs-connect chain1")
waitfortask()
do_command("ai-select "+infile)
do_command("ai-setpos "+str(plek))
waitfortask()
do_command("ao-select tmp_l.wav")
do_command("ao-setpos "+str(newpos))
waitfortask()
do_command("engine-status")
while e.last_string() != "not started":
do_command("engine-status")
do_command("start")
waitfortask()
print "Finished inserting "+newfile
do_command("cs-disconnect chain1")
waitfortask()
do_command("engine-status")
do_command("cs-remove chain1")
waitfortask()
os.unlink(infile)
os.rename("tmp_l.wav", infile)
do_command("cs-add chain1")
do_command("c-add chain1")
set_chain_format()
do_command("ai-add "+infile)
do_command("ao-add "+soundout)
do_command("cs-connect chain1")
waitfortask()
do_command("cs-setpos "+str(plek))
do_command("start")
return
def user_control():
key='f2'
global buttons, bs,be,keepme,block_controls_active, denoise
while key != 'q':
keepme = currentpos()
if key == 'f1':
print buttons[key]
do_command("stop")
if key == 'f2':
print buttons[key]
do_command("start")
if key == 'f3':
print buttons[key]
do_command("rewind 60")
range_check("start")
if key == 'f4':
print buttons[key]
do_command("forward 60")
range_check("end")
if key == 'f5':
bs=currentpos()
print 'begin block at ',bs
if key == 'f6':
be=currentpos()
print 'end block at ',be
if key == 'f7':
deactivate_block_controls()
playblock()
print buttons[key]
reactivate_block_controls()
if key == 'f8':
print buttons[key]
write_block()
if key == 'f9':
print buttons[key]
remove_block()
if key == 'f10':
print buttons[key]
denoise=False
record_realtime()
if key == 'ctrl_f10':
print buttons[key]
denoise=False
record_wifi()
if key == 'shift_f10':
print buttons[key]
denoise=True
record_realtime()
if key == 'f11':
print buttons[key]
add_file()
if key == 'f12':
do_command("cs-get-length")
einde=e.last_float()
do_command("setpos "+str(einde))
print 'go to end at ',einde
if key == 'home':
do_command("setpos 0.0")
if not block_controls_active:
do_command("setpos "+str(bs))
print 'go to start'
if key == 'left':
do_command("rewind 5")
range_check("start")
print 'rewind'
if key == 'right':
movearound("f")
print 'forward'
if key == 'w':
print 'now at: ',currentpos()
if key == 'j':
jump=raw_input("jump to?")
do_command("cs-get-length")
einde=e.last_float()
if float(jump) >= einde:
print 'jump value past end of file, going to end at ',einde
jump=einde
do_command("setpos "+str(jump))
if key == 'J':
jump=prevpos
do_command("setpos "+str(jump))
print buttons[key]+" : "+str(currentpos())
if key == 'l':
print buttons[key]
go_slow()
if key=="p":
print buttons[key]+": "+write_position()+" track "+str(len(poslines))
if key=="S":
print buttons[key]
split_tracks()
key=commands.getoutput("catchkey")
if key not in active_controls:
print key,' inactive here'
key = ''
#Main program starts here.
do_command("cs-add chain1")
do_command("c-add chain1")
do_command("ai-add "+infile)
do_command("ao-add "+soundout)
do_command("cs-connect chain1")
do_command("ai-select "+infile)
do_command("start")
keepme = currentpos()
do_command("ai-get-format")
masterformat = e.last_string()
print "file: ",infile,"master format is: ",masterformat," position ",keepme
fm=masterformat.split(',')
bits=fm[0]
channels=fm[1]
srate=fm[2]
#print "bits: ",bits,"channels: ",channels,"samples: ",srate
init_write_position()
key='f2'
active_controls=['f1','f2','f3','f4','f5','f6','f7','f8','f9','f10','shift_f10','ctrl_f10','f11','f12','left','right','home','j','J','w','q','l','p','S']
user_control()
do_command("cs-disconnect chain1")
print "exiting"