-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathx32recorder.py
845 lines (741 loc) · 33.2 KB
/
x32recorder.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
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
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
#!/usr/bin/env python
# By jajito
# https://github.com/jajito
import sys
import time
import datetime
import subprocess
import os
import os.path
import signal
import random
from subprocess import PIPE, Popen
import rtmidi
from rtmidi.midiutil import open_midiinput, open_midioutput
from subprocess import Popen
from subprocess import PIPE
MIDI_NOTE_REC = 95
MIDI_NOTE_PLAY = 94
MIDI_NOTE_STOP = 93
MIDI_NOTE_REW = 91
MIDI_NOTE_FF = 92
port = 1
lcd_header = [0xF0,0x00,0x00,0x66,0x14,0x12,0x00]
lcd_sysex_end = 0xF7
timetowait = 0.05 #time to wait after sending midi messages
#mediafolder = "/media/USBXFS/" # recording folder
MP3_folder = "/share/MP3"
channels_to_record = 16
test_mode = False
midiout = rtmidi.MidiOut()
midiout.open_port(port)
record_start = datetime.datetime.now()
rec_stop_alert = False
change_mode_alert = False
recording = False
playing_record = False
playing_mp3 = False
play_mode_mp3 = False
#actual_option = 0
playlist_mode = False
random_mode = False
modes = [(0 , "Player"),
(1 , "Setup")]
modes_lenght = len(modes)
mode = modes [0]
print "Mode ", mode
formats =[".w64", ".caf"]
play_formats=(".mp3",".w64",".caf",".wav")
format_num = 0
print "format ", formats[format_num]
play_modes = [( False, False),
( True, False),
( True, True)] # playlist_mode , random_mode
play_mode_number = 1
print play_modes[play_mode_number]
actual_mp3_folder = 0
#channel = channels_to_record
modenew = mode[0]
suffixes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB']
def humansize(nbytes):# for readable results of diskspace
i = 0
while nbytes >= 1024 and i < len(suffixes)-1:
nbytes /= 1024.
i += 1
f = ('%.2f' % nbytes).rstrip('0').rstrip('.')
return '%s %s' % (f, suffixes[i])
def minutestorecord(chann = channels_to_record):
statvfs = os.statvfs(mediafolder)
#print statvfs
diskabailable = statvfs.f_frsize * statvfs.f_bavail
bitesporsegundo = 146227 * chann
segundosavailable = diskabailable / bitesporsegundo
segundoshumansize = str(datetime.timedelta(seconds=segundosavailable))
return segundoshumansize
def diskavailable():
statvfs = os.statvfs(mediafolder)
diskabailable = statvfs.f_frsize * statvfs.f_bavail
return humansize(diskabailable)
def check_X32_ALSA_CARD():
p = subprocess.Popen("cat /proc/asound/cards", shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
result = p.stdout.readlines()
for i in range(len(result)):
result[i] = result[i].strip() # strip out white space
print result[i]
if "XUSB" in result[i]:
print "XUSB is ALSA CARD number :", result[i][0]
X32in = result[i][0]
return X32in
else:
print "X32 not found"
X32in = 0
return X32in
def getCol(col, line):
p1 = line.find(col)
if p1<0 : return ""
p2 = p1 + len(col) + 1
p3 = line.find('"',p2+1)
return line[p2+1:p3]
def mount_not_mounted():
# mount all partition by neoedmund
print "Mounting USBs"
data_stream = Popen(["/bin/lsblk", "-P", "-o", "FSTYPE,UUID,MOUNTPOINT,KNAME"], stdout=PIPE)
data=[]
for line in data_stream.stdout:
#print "line ", line
fstype = getCol("FSTYPE", line)
if fstype=="": continue # no fs
mountpoint = getCol("MOUNTPOINT", line)
if mountpoint!="":continue # already mounted
uuid = getCol("UUID", line)
kname = getCol("KNAME", line)
data.append((kname))
for (kname) in data:
print("mkdir /media/%s" % (kname))
print("mount /dev/%s /media/%s" % (kname, kname))
os.system("sudo mkdir /media/%s" % (kname))
os.system("sudo mount /dev/%s /media/%s" % (kname, kname))
print("sudo chmod 777 /media/%s" % (kname))
os.system("sudo chmod 777 /media/%s" % (kname))
def unmount_mounted():
print "Unmounting USBs"
data_stream = Popen(["/bin/lsblk", "-P", "-o", "FSTYPE,UUID,MOUNTPOINT,KNAME,SIZE"], stdout=PIPE)
data=[]
for line in data_stream.stdout:
#print "line ", line
fstype = getCol("FSTYPE", line)
if fstype=="": continue # no fs
mountpoint = getCol("MOUNTPOINT", line)
if mountpoint!="" and "sd" in mountpoint:#continue # already mounted
#uuid = getCol("UUID", line)
kname = getCol("KNAME", line)
#size = getCol("SIZE", line)
data.append((kname))
for (kname) in data:
print("umount /dev/%s" %(kname))
os.system("umount /dev/%s" %(kname))
def check_mounted():
data_stream = Popen(["/bin/lsblk", "-P", "-o", "FSTYPE,UUID,MOUNTPOINT,KNAME,SIZE"], stdout=PIPE)
data=[]
for line in data_stream.stdout:
#print "line ", line
fstype = getCol("FSTYPE", line)
if fstype=="": continue # no fs
mountpoint = getCol("MOUNTPOINT", line)
if mountpoint!="" and "sd" in mountpoint:#continue # already mounted
uuid = getCol("UUID", line)
kname = getCol("KNAME", line)
size = getCol("SIZE", line)
data.append((kname, fstype, mountpoint, uuid, size))
return data
def strip_clean():
sysex = list(lcd_header)
for i in range(112):
sysex.append((0x00))
sysex.append(lcd_sysex_end)
assert sysex[0] == 0xF0 and sysex[-1] == 0xF7
midiout.send_message(sysex)
time.sleep(timetowait)
def update_dir_old(folder):
print "update dir "
files = os.listdir(folder)
paths = [os.path.join(folder, basename) for basename in files]
paths.sort()
dirs_number = len (paths)
print "Updated dir. Number of files =", dirs_number
print "paths ", paths
return dirs_number, paths
def update_dir(folder):
print "update dir "
result = os.listdir(folder)
paths = [os.path.join(folder, basename) for basename in result]
dirs = []
files = []
for file in paths:
if os.path.isdir(file): dirs.append(file)
if os.path.isfile(file):
if file.endswith(play_formats):
files.append(file)
dirs.sort()
files.sort()
fildir = dirs + files
if folder == mediafolder[:-1]:
print "uptdating mediafolder, invert order"
fildir.sort(reverse=True)
dirs_number = len (fildir)
#print "Updated dir. Number of files =", dirs_number
#print "paths ", fildir
return dirs_number, fildir
def info_file_old(file):
print "info file"
print "File to check ", file
if file[-5] == "." and file[-4] != ".":# is file
length = str(os.popen("soxi -d " + file).readlines())[3:10]
print "is file, file length ", length
return length
else:
print "is folder ", file
print os.listdir(file[1:-1])
files_number = str(len((os.listdir(file[1:-1]))))
print "number of files ", files_number
txt = files_number[0:2] + (3 - len(files_number)) * " " + "File"
print "number of files ", txt
return txt
def info_file(folder):
#print "File to check ", folder
#if file[-5] == "." and file[-4] != ".":# is file
if os.path.isfile(folder): #is file
length = str(os.popen("soxi -d " + "'" +folder+"'").readlines())[3:10]
#print "is file, file length ", length
return length
else:
#print "is folder ", folder
result = os.listdir(folder)
paths = [os.path.join(folder, basename) for basename in result]
dirs = []
files = []
for file in paths:
if os.path.isdir(file): dirs.append(file)
if os.path.isfile(file):
if file.endswith(play_formats):
files.append(file)
fildir = dirs + files
files_number = str(len((fildir)))
#print "number of files ", files_number
txt = files_number[0:2] + (3 - len(files_number)) * " " + "File"
#print "number of files ", txt
return txt
def buttons_out(button, onoff):
#midiout = rtmidi.MidiOut()
#midiout.open_port(port)
midiout.send_message([144, button, onoff])
time.sleep(timetowait)
#midiout.close_port()
#del midiout
def send_lcd_2( actiontxt , trktxt ="", trknmbr="", folder_txt="", filetxt="",trklength=" "): # first line, mode an so
#offset = 56
line_1 = "PLAYER "+ " "+ "Folder:"+ (folder_txt[0:35] + (35 - len(folder_txt))*" ")
line_2 = (actiontxt[0:7] + (7 - len(actiontxt)) * " " + (6-len(trktxt+trknmbr))*" "+ (trktxt+"/"+trknmbr) +
trklength + filetxt[0:35] + (35 - len(filetxt)) * " ")
# ("Selected Channels "[:-len(str(channels_to_record))] + str(channels_to_record)))
text_to_send = line_1+line_2
sysex = list(lcd_header)
for character in text_to_send:
sysex.append(ord(character))
sysex.append(lcd_sysex_end)
#sysex[6]= offset
assert sysex[0] == 0xF0 and sysex[-1] == 0xF7
midiout.send_message(sysex)
time.sleep(timetowait)
def send_lcd_record(rec_time):
global channels_to_record
#text_to_send = "Rec" + str(channels_to_record) + (2 - len(str(channels_to_record))) * " " + "ch" + str(rec_time)
text_to_send = "Rec" + (2 - len(str(channels_to_record))) * " " + str(channels_to_record) + "ch" + str(rec_time)
sysex = list(lcd_header)
for character in text_to_send:
sysex.append(ord(character))
sysex.append(lcd_sysex_end)
# sysex[6]= offset
assert sysex[0] == 0xF0 and sysex[-1] == 0xF7
midiout.send_message(sysex)
time.sleep(timetowait)
def update_records_list(folder):
files = os.listdir(folder)
paths = [os.path.join(folder, basename) for basename in files]
records_number = len (paths)
#print "Updated records list . Number of records =", records_number
return records_number, paths
def txt_to_sysex(text):
sysex = lcd_header
sysex.append(lcd_offset)
for character in text:
sysex.append(ord(character))
sysex.append(lcd_sysex_end)
return sysex
def grabar():
if test_mode == True:
print ("demo mode Recording")
return
#grabadora_status["rec"] = True
global record_start
record_start = datetime.datetime.now()
filename = datetime.datetime.now().strftime("%Y-%m-%d_%H.%M.%S")+formats[format_num]
print ("Recording ", record_start)
grabando = "rec -q --buffer 1048576 -c " + str(channels_to_record) + " -b 24 " + mediafolder + filename
#grabando = "AUDIODEV=hw:XUSB rec -q --buffer 1048576 -c " + str(channels_to_record) + " -b 24 " + mediafolder + filename
print (grabando)
send_lcd_record("0:00:00")
global rec_process
rec_process = subprocess.Popen(grabando, stdout=subprocess.PIPE, shell=True, preexec_fn=os.setsid)
def fingrabar():
if test_mode == True:
print ("demo mode End Recording")
return
#grabadora_status["rec"] = False
print ('Recording Stopped :', (datetime.datetime.now()))
global rec_process
#esto mata el proceso de grabacion
os.killpg(os.getpgid(rec_process.pid), signal.SIGTERM)
print ("REC PROCESS TERMINATE")
grabaend = datetime.datetime.now()
global record_start
send_lcd_record("Stopped")
if record_start == 0:
#print 'no hay nada en record_start'
pass
else:
recordtime = grabaend - record_start
print ('Total Recording time = ', str(recordtime)[:-7])
#lcdimprime('Recorded Time:',str(recordtime)[:-7])
#ready_to_rumble()
def playrecording(file, mp3_to_play):
if mp3_to_play == False:
print "Playing from mediafolder"
reproduciendo = "play -q " + file
elif mp3_to_play == True:
print "Playing MP3"
reproduciendo = "mpg123 -C --no-control " + file
print(reproduciendo)
#print("Playing : ", file)
if test_mode == True:
print ("demo mode Playing")
return
global play_recorded_process
play_recorded_process = subprocess.Popen(reproduciendo, stdout=subprocess.PIPE, shell=True, preexec_fn=os.setsid)
def playing_stop():
if test_mode == True:
print ("demo mode Stop Playing")
return
print ("Playing stopped")
global play_recorded_process
os.killpg(os.getpgid(play_recorded_process.pid), signal.SIGTERM)
print ("Play process terminated")
class MidiInputHandler(object):
def __init__(self, port):
self.port = port
self._wallclock = time.time()
def __call__(self, event, data=None):
message, deltatime = event
self._wallclock += deltatime
note = message[1]
global rec_stop_alert
global change_mode_alert
global recording
global playing_record
global playing_mp3
global play_mode_mp3
global actual_record
global mediafolder
global records_number
global records_list
global channels_to_record
global channel
global actual_mp3_folder
global mp3_folders_list
global mp3_folders_number
global mode
global modes_lenght
global modenew
global actual_dir
global dir_to_explore
global dir_number
global channel_temp
global formats
global format_num
global playlist_mode
global random_mode
global play_modes
global play_mode_number
global initial_dirs
global dir_act
global mp3_to_play
if mode[0] == 0: #FILES
if message == [144, MIDI_NOTE_STOP, 127]: # STOP
buttons_out(MIDI_NOTE_STOP, 127)
if rec_stop_alert == True:
print ("Stop Recording")
buttons_out(MIDI_NOTE_REC, 0)
fingrabar()
records_number, records_list = update_records_list(mediafolder)
actual_record = records_number
rec_stop_alert = False
recording = False
else:
print("Stop multitrak")
playing_record = False
buttons_out(MIDI_NOTE_PLAY, 0)
playing_stop()
if message == [144, MIDI_NOTE_STOP, 0]: # STOP
buttons_out(MIDI_NOTE_STOP, 0)
if message == [144, MIDI_NOTE_PLAY, 0]: # PLAY
#print "selected folder ", actual_dir, dir_to_explore[actual_dir]
if dir_to_explore[actual_dir] == "Setup":
print " Setup selected"
init_setup()
mode = modes[1]
if dir_to_explore[actual_dir] == "(..)": # back to previous folder
#print "dir to explore no ni na ", dir_to_explore
#print "initial dirs ", initial_dirs
if len(dir_to_explore) == 1:
path_act = dir_act
else:
path_act = os.path.dirname(dir_to_explore[actual_dir+1])
#print "actuallll dir" , path_act
if (str(path_act)) in initial_dirs: # initial dir
print "initial dir"
dir_to_explore = initial_dirs
dir_number = len(dir_to_explore)
actual_dir = 0
#print "previous dir number initial dirs ", dir_number, " dir to explore ", dir_to_explore
file_length = info_file((dir_to_explore[actual_dir]))
#send_lcd_2("Selectd", str(actual_dir), str(dir_number-1),
# (dir_to_explore[actual_dir]), " rr ", trklength= file_length)
txt_file = str(os.path.basename(dir_to_explore[actual_dir]))
txt_folder = str(os.path.dirname(dir_to_explore[actual_dir]))
send_lcd_2("Selectd", str(actual_dir), str(dir_number-1), txt_folder,
txt_file, trklength= file_length)
return
else: # no initial dir
print "no initial dir"
path_prev = "/".join(path_act.split("/")[:-1])+"/"
print "previous dir", path_prev
dir_number, dir_to_explore = update_dir(path_prev)
dir_to_explore.insert(0, "(..)")
dir_number = dir_number + 1
txt_file = str(os.path.basename(dir_to_explore[actual_dir]))
if txt_file == "(..)":
txt_folder = str(os.path.dirname(dir_to_explore[actual_dir + 1]))
file_length = "Prev. "
else:
txt_folder = str(os.path.dirname(dir_to_explore[actual_dir]))
file_length = info_file(txt_folder + "/" + txt_file)
send_lcd_2("Selectd", str(actual_dir), str(dir_number - 1), txt_folder,
txt_file, trklength= file_length)
if os.path.isdir (dir_to_explore[actual_dir]) == True: # is folder
dir_act = dir_to_explore[actual_dir]
dir_number , dir_to_explore = update_dir(dir_to_explore[actual_dir])
print "dir act ", dir_act
dir_to_explore.insert(0, "(..)")
dir_number = dir_number + 1
actual_dir = 0
txt_file = str(os.path.basename(dir_to_explore[actual_dir]))
if txt_file == "(..)":
#print "actua dir ", actual_dir
#print "dir to explore ", dir_to_explore
#txt_folder = "holasss"
if len(dir_to_explore)==1:
txt_folder= dir_act
else:
txt_folder = str(os.path.dirname(dir_to_explore[actual_dir + 1]))
file_length = "Prev. "
else:
print "dir to explore no p", dir_to_explore[actual_dir]
txt_folder = str(os.path.dirname(dir_to_explore[actual_dir]))
file_length = info_file(txt_folder + "/" + txt_file)
send_lcd_2("Selectd", str(actual_dir), str(dir_number - 1), txt_folder,
txt_file, trklength= file_length)
playing_record = False
if os.path.isfile (dir_to_explore[actual_dir]) == True: #is file, play file
if playing_record == False:
playing_record = True
buttons_out(MIDI_NOTE_PLAY, 127)
txt_file = str(os.path.basename(dir_to_explore[actual_dir]))
print "txt file", txt_file
if txt_file == "(..)":
txt_folder = str(os.path.dirname(dir_to_explore[actual_dir + 1]))
file_length = "Prev. "
else:
txt_folder = str(os.path.dirname(dir_to_explore[actual_dir]))
file_length = info_file(txt_folder + "/" + txt_file)
send_lcd_2("Playing", str(actual_dir), str(dir_number-1),
txt_folder, txt_file, trklength= file_length)
#print "Playing ", dir_to_explore[actual_dir]
print "playing txt_folder ", txt_folder
#print "madiafolder ", mediafolder[:-1]
mp3_to_play = True
if txt_folder == mediafolder[:-1]:
print "playing recording from mediafolder"
#playlist_mode = False
mp3_to_play = False
if not playlist_mode:
#print "dir to explore ", dir_to_explore
#print "actual dir ", actual_dir
#print "dir to explore len ", len(dir_to_explore)
onlyfiles = dir_to_explore[actual_dir:]
#print "onlyfiles ", onlyfiles
#onlyfiles = dir_to_explore[actual_dir]
# files_to_play = "\"" + onlyfiles +"\""
paths_quotes = ["\"" + p + "\"" for p in onlyfiles]
files_to_play = " ".join([str(i) for i in paths_quotes])
print "files to play ", files_to_play
if playlist_mode:
onlyfiles = [f for f in os.listdir(txt_folder) if os.path.isfile(os.path.join(txt_folder, f))]
#print "onlyfiles ", onlyfiles
paths = [os.path.join(txt_folder, basename) for basename in onlyfiles]
#print paths
paths_quotes = ["\"" + p + "\"" for p in paths]
#paths_quotes = paths
#print "paths_quotes ", paths_quotes
if random_mode:
random.shuffle(paths_quotes)
if not random_mode:
#print "not random mode"
paths_quotes.sort()
#print "paths_quotes ", paths_quotes
#files_to_play = paths_quotes
files_to_play = " ".join([str(i) for i in paths_quotes])
#print "actual dir ",
#print "files to play ", files_to_play
playrecording(files_to_play, mp3_to_play)
else:
print ("Already playing multitrak")
if message == [144, MIDI_NOTE_REW, 127]: # REW
buttons_out(MIDI_NOTE_REW, 127)
print("Previous")
actual_dir = min(max((actual_dir - 1), 0), dir_number)
txt_file = str(os.path.basename(dir_to_explore[actual_dir]))
if txt_file == "(..)":
if len(dir_to_explore) == 1:
txt_folder = dir_act
else:
txt_folder = str(os.path.dirname(dir_to_explore[actual_dir+1]))
file_length = "Prev. "
elif txt_file == "":
txt_file = str(os.path.dirname(dir_to_explore[actual_dir]))
txt_folder = " "
file_length = info_file(txt_file)
#file_length = info_file("'" + txt_folder + "/" + txt_file + "'")
else:
txt_folder = str(os.path.dirname(dir_to_explore[actual_dir]))
file_length= info_file(txt_folder + "/" + txt_file)
send_lcd_2("Select", str(actual_dir), str(dir_number - 1),
txt_folder, txt_file,trklength = file_length)
if message == [144, MIDI_NOTE_REW, 0]:
buttons_out(MIDI_NOTE_REW, 0)
#print "rew release"
if message == [144, MIDI_NOTE_FF, 127]: # FF
buttons_out(MIDI_NOTE_FF, 127)
print("Next")
#print "dir_number", dir_number
actual_dir = min(max((actual_dir + 1), 0), dir_number-1)
txt_file = str(os.path.basename(dir_to_explore[actual_dir]))
if txt_file == "(..)":
#print "dir acrt ", dir_act
if len(dir_to_explore) == 1:
txt_folder = dir_act
else:
txt_folder = str(os.path.dirname(dir_to_explore[actual_dir+1]))
file_length = "Prev. "
elif txt_file == "":
txt_file = str(os.path.dirname(dir_to_explore[actual_dir]))
txt_folder = " "
file_length = info_file(txt_file)
#file_length = info_file("'" + txt_folder + "/" + txt_file + "'")
elif txt_file == "Setup":
#txt_file = "Setupa" #str(os.path.dirname(dir_to_explore[actual_dir]))
txt_folder = "Setup "
file_length = " " #info_file("'" + txt_file + "'")
else:
txt_folder = str(os.path.dirname(dir_to_explore[actual_dir]))
file_length = info_file(txt_folder + "/" + txt_file)
send_lcd_2("Select", str(actual_dir), str(dir_number - 1),
txt_folder, txt_file,trklength= file_length)
if message == [144, MIDI_NOTE_FF, 0]: # FF
buttons_out(MIDI_NOTE_FF,00)
if message == [144, MIDI_NOTE_REC, 127]: # REC
if rec_stop_alert == False:
if recording == False:
recording = True
buttons_out(MIDI_NOTE_REC, 127)
print("Recording")
grabar()
rec_stop_alert = True
else:
print ("Already Recording")
rec_stop_alert = True
else:
print("Rec stop alert ", rec_stop_alert)
if message == [144, MIDI_NOTE_REC, 0]:
rec_stop_alert = False
print("Nada")
if mode[0] == 1: #Setup
if message == [144, MIDI_NOTE_REW, 127]: # REW
print ("Channels -")
channel_temp =min(max((channel_temp - 2) , 2), (32))
print "Channels to record ", channel_temp
send_lcd_setup(playlist_mode, random_mode, channel_temp, formats[format_num], minutestorecord(channel_temp))
#send_lcd_2("Select Channel", str(channel)+" ")
if message == [144, MIDI_NOTE_FF, 127]: # FF
print ("Channels +")
channel_temp = min(max((channel_temp + 2), 2), (32))
print "channel to record", channel_temp
#print "Channels to record ", channels_to_record
send_lcd_setup(playlist_mode, random_mode, channel_temp, formats[format_num], minutestorecord(channel_temp))
#send_lcd_2("Select Channel", (str(channel)+" "))
if message == [144, MIDI_NOTE_PLAY, 127]: # PLAY
# do whatever
print "Cambiar modo"
play_mode_number = play_mode_number + 1
if play_mode_number >= len(play_modes):
play_mode_number = 0
print play_mode_number, "play mode ", play_modes[play_mode_number]
playlist_mode, random_mode = play_modes[play_mode_number]
print playlist_mode, random_mode
send_lcd_setup(playlist_mode, random_mode, channel_temp, formats[format_num], minutestorecord(channel_temp))
#send_lcd_2("Select Channel", (str(channel)+" "))
if message == [144, MIDI_NOTE_REC, 127]: # REC
# do whatever
print "Cambiar FORMAT"
#print "actual " , formats[format_num]
format_num = format_num +1
if format_num >= len(formats):
format_num = 0
send_lcd_setup(playlist_mode, random_mode, channel_temp, formats[format_num], minutestorecord(channel_temp))
#print "nuevo ", formats[format_num]
#format = format
if message == [144, MIDI_NOTE_STOP, 127]: # exit
# do whatever
channels_to_record = channel_temp
print "channels to record out setup ", channels_to_record
print "format ", formats[format_num]
print "play modes ", playlist_mode, random_mode
print "exit setup"
mode = modes[0]
init_player()
#send_lcd_2("Select Channel", (str(channel)+" "))
def send_lcd_setup( playlist_bol , random_bol, chann, format_txt, time_available):
line_1 = "SETUP " + "Plylist"+ "Random " + "Record " + "Channls" + "Time " + "Availab" + "Format "
line_2 = "Exit " + str(playlist_bol) + (7-len(str(playlist_bol)))*" " + str(random_bol) + (7-len(str(random_bol)))*" " + " " + " " + str(chann) +(5-len(str(chann)))*" " + \
time_available + " " + format_txt
text_to_send = line_1+line_2
#print text_to_send
sysex = list(lcd_header)
for character in text_to_send:
sysex.append(ord(character))
sysex.append(lcd_sysex_end)
#sysex[6]= offset
assert sysex[0] == 0xF0 and sysex[-1] == 0xF7
midiout.send_message(sysex)
time.sleep(timetowait)
def init_player():
strip_clean()
all_led_off()
txt_file = str(os.path.basename(dir_to_explore[actual_dir]))
if txt_file == "(..)":
txt_folder = str(os.path.dirname(dir_to_explore[actual_dir + 1]))
else:
txt_folder = str(os.path.dirname(dir_to_explore[actual_dir]))
strip_clean()
send_lcd_2("Select", str(actual_dir), str(dir_number - 1), " ",
txt_folder, txt_file)
def init_setup():
print "init setup from ini setup"
strip_clean()
all_led_on()
global channel_temp
global channels_to_record
global formats
global format_num
channel_temp = channels_to_record
send_lcd_setup(playlist_mode, random_mode, channels_to_record, formats[format_num], minutestorecord())
def all_led_off():
buttons_out(MIDI_NOTE_STOP, 0)
buttons_out(MIDI_NOTE_PLAY, 0)
buttons_out(MIDI_NOTE_REW, 0)
buttons_out(MIDI_NOTE_FF, 0)
buttons_out(MIDI_NOTE_REC, 0)
def all_led_on():
buttons_out(MIDI_NOTE_STOP, 127)
buttons_out(MIDI_NOTE_PLAY, 127)
buttons_out(MIDI_NOTE_REW, 127)
buttons_out(MIDI_NOTE_FF, 127)
buttons_out(MIDI_NOTE_REC, 127)
try:
midiin, port_name = open_midiinput(port)
#midiout, port_name = open_midioutput(port)
except (EOFError, KeyboardInterrupt):
sys.exit()
print("Attaching MIDI input callback handler.")
midiin.set_callback(MidiInputHandler(port_name))
print("Entering main loop. Press Control-C to exit.")
try:
print "init player"
check_X32_ALSA_CARD()
mount_not_mounted()
mounted = check_mounted()
print "mounted ", mounted
mounted_usbs = [x[2] for x in check_mounted()]
print "mounted usbs ", mounted_usbs
if len(mounted_usbs) == 0:
print "No USB found"
send_lcd_2("NO USB ", "detectd", " ", " " , " ", " ")
time.sleep(15)
#comprobar que sea xfs!!!!!
for i in mounted:
print i
if "xfs" in i:
strip_clean()
print "Found XFS disc " , i
mediafolder = str(i[2]) + "/"
mediafolder_size = i[4]
print "Mediafolder ", mediafolder
print "Mediafolder size ", mediafolder_size
send_lcd_2("XFS ", "detectd", "Mediaf", i[0], mediafolder_size, "Size ")
time.sleep(3)
strip_clean()
else:
print "No XFS disk found"
print "Risk of ALSA underuns, please use a SFX formatted USB memory for recording"
send_lcd_2("Alert ", "no XFS ", "detectd", "Risk of", "underrun", " ")
time.sleep(15)
initial_dirs = [ MP3_folder ]
#print "initial_dirs", initial_dirs
initial_dirs = initial_dirs + mounted_usbs + ["Setup"]
print "initial_dirs", initial_dirs
#usbs = check_mounted()
#print "usbs ", usbs
dir_to_explore = initial_dirs
dir_number = len(dir_to_explore)
print "dir number ", dir_number, " dir to explore ", dir_to_explore
actual_dir = 0
print "Time to record available ", minutestorecord()
init_player()
while True:
if recording:
actual_time = datetime.datetime.now()
#print "actual ", actual_time, "record start ", record_start
#print record_start
rec_time = str( actual_time - record_start)[:7]
send_lcd_record(rec_time)
time.sleep(1)
except KeyboardInterrupt:
print('Saliendo')
time.sleep(1)
strip_clean()
all_led_off()
finally:
print("Exit.")
unmount_mounted()
midiin.close_port()
midiout.close_port()
del midiin