-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtestbp.py
215 lines (178 loc) · 5.21 KB
/
testbp.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
print("sss")
import os, random, sys
import vrok
import time
import threading
import numpy
import pyaudio as pa
import mpris_server as ms
import cuesheet as cs
from datetime import datetime
from mpris_server.adapters import MprisAdapter
from mpris_server.events import EventAdapter
from mpris_server.server import Server
from mpris_server.base import PlayState
from gi.repository import GLib as glib
def get_file_list(path):
list = []
for dp, dn, fn in os.walk(path):
for f in fn:
filepath = os.path.join(dp, f)
#print(filepath)
if os.path.isfile(filepath):
if (f.endswith("mp3") or f.endswith("MP3") or f.endswith("flac") or f.endswith('opus') or f.endswith('m4a') or f.endswith('webm')):
list.append(filepath)
return list
#p = pa.PyAudio()
#s = p.open(format=pa.paFloat32, channels=1, rate=48000, output=True)
random.seed(datetime.now())
print("sasss")
r = vrok.Resource()
files = []
cue_sheet = None
cue_file = None
if sys.argv[1].endswith(".cue"):
cue = cs.CueSheet()
cue.setOutputFormat("%file%", "%title%")
cue.setData(open(sys.argv[1], "r").read())
cue.parse()
cue_sheet = []
cue_file = os.path.dirname(sys.argv[1]) + "/" + cue.file
for d in cue.tracks:
cue_sheet.append(int(cs.offsetToTimedelta(d.offset).total_seconds()))
else:
for path in sys.argv:
files.extend(get_file_list(path))
pl = vrok.Player()
fir = vrok.EffectSSEQ()
#out = vrok.DriverAlsa()
out = vrok.DriverPulse()
#outJ = vrok.DriverJBufferOut();
#outPy = vrok.DriverPyOut();
dec = vrok.DecoderFFMPEG.Create()
#def PyOutOnBuffer(ndarray):
# data = ndarray[0].astype(numpy.float32)
#ff.write(data.copy().tobytes())
# s.write(data.tobytes())
#def PyOutOnBufferConfigChange(frames, samplerate, channels):
# global s
# print(frames, samplerate, channels)
# s.close()
# s = p.open(format=pa.paFloat32, channels=1, rate=samplerate, output=True)
#outPy.OnBuffer = PyOutOnBuffer
#outPy.OnBufferConfigChange = PyOutOnBufferConfigChange
#outJ.SetEvents(outPy)
for device in out.GetDeviceInfo():
print(device.name)
#for device in outJ.GetDeviceInfo():
# print(device.name)
out.SetDevice(out.GetDeviceInfo()[0].name)
#def worker(fir):
# meter = fir.GetMeters().__getitem__(0)
# print (meter.GetValue(0))
# while (True):
# time.sleep(0.1)
# #print (meter.GetValue(0))
# print("end")
#th = threading.Thread(target=worker,args=[out])
#th.start()
events = vrok.PlayerEvents()
def QueueNextCueSheet():
r.filename = cue_file
offset = random.choice(cue_sheet)
dec = vrok.DecoderFFMPEG.Create()
print(r.filename)
print(dec.Open(r))
print("00000ss")
dec.SetPositionInSeconds(offset)
pl.SubmitForPlayback(dec)
def QueueNextCueSheetNow():
r.filename = cue_file
offset = random.choice(cue_sheet)
dec = vrok.DecoderFFMPEG.Create()
print(r.filename)
print(dec.Open(r))
print("00000ss")
dec.SetPositionInSeconds(offset)
pl.SubmitForPlaybackNow(dec)
def QueueNext():
r.filename = random.choice(files)
dec = vrok.DecoderFFMPEG.Create()
print(r.filename)
print(dec.Open(r))
print("00000ss")
dec.SetPositionInSeconds(100)
pl.SubmitForPlayback(dec)
def QueueNextNow():
r.filename = random.choice(files)
dec = vrok.DecoderFFMPEG.Create()
print(r.filename)
print(dec.Open(r))
pl.SubmitForPlaybackNow(dec)
def QueueFile(ffile):
r = vrok.Resource()
r.filename = ffile
dec = vrok.DecoderFFMPEG.Create()
print(r.filename)
print(dec.Open(r))
pl.SubmitForPlaybackNow(dec)
if not cue_sheet is None:
events.QueueNext = QueueNextCueSheet
r.filename = cue_file
else:
events.QueueNext = QueueNext
r.filename = random.choice(files)
pl.SetQueueNext(True)
print(r.filename)
compman = vrok.ComponentManager.GetSingleton()
comp = compman.GetComponent("SSEQ:0");
if (comp != None):
print("FIRRRR")
print(dec.Open(r))
outX = out
pl.RegisterSink(outX)
fir.RegisterSource(pl)
fir.RegisterSink(outX)
outX.RegisterSource(fir)
pl.Preallocate()
outX.Preallocate()
fir.Preallocate()
outX.SetVolume(0.0)
pl.SetEvents(events)
t = vrok.ThreadPool(2)
t.RegisterWork(1, pl)
t.RegisterWork(0, fir)
t.RegisterWork(0, outX)
dec.SetPositionInSeconds(100)
pl.SubmitForPlayback(dec)
t.CreateThreads()
# publish and serve
while True:
#mc.iteration(False)
nn = sys.stdin.readline().strip()
if nn == 'q':
t.StopThreads()
break
elif nn == 'pp':
pl.Resume()
elif nn == 'p':
pl.Pause()
elif nn == 'listeq':
for i in range(0, 17):
xx = "Band%02d"%(i)
print(compman.GetProperty("ShibatchSuperEQ:0", xx).Get())
elif len(nn.split())==2 and nn.split()[0] == 'setp':
compman.SetProperty("ShibatchSuperEQ:0", "Preamp", nn.split()[1])
elif len(nn.split())==3 and nn.split()[0] == 'setb':
print("ss")
xx = "Band%02d"%(int(nn.split()[1]))
print(xx)
compman.SetProperty("ShibatchSuperEQ:0", xx, nn.split()[2])
elif nn == '':
if not cue_sheet is None:
QueueNextCueSheetNow()
else:
QueueNextNow()
else:
QueueFile(nn)
t.JoinThreads()