-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
86 lines (67 loc) · 3.17 KB
/
Copy pathtest.py
File metadata and controls
86 lines (67 loc) · 3.17 KB
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
import os, json, time, struct, pulsectl, math, concurrent.futures
from pulsectl import _pulsectl as c
import asyncio
DEBUG = True
class VirtualDevices:
def __init__(self, f="audiomeeter_session.json"):
self.pulse = pulsectl.Pulse('audiomeeter-core')
self.f = f
self.devices = {}
self._executor = concurrent.futures.ThreadPoolExecutor(max_workers=1)
self.active_bridges = {}
def init(self):
if DEBUG and os.path.exists(self.f):
self._clean()
expected_devices = {
"input_main": ("sink", "audiomeeter-input"),
"input_aux": ("sink", "audiomeeter-aux-input"),
"out_b1": ("source", "audiomeeter-out-b1"),
"out_b2": ("source", "audiomeeter-out-b2"),
}
existing = {}
try:
for key, (dev_type, name) in expected_devices.items():
if dev_type == "sink":
try:
sink = self.pulse.get_sink_by_name(name)
existing[key] = sink.index
except pulsectl.PulseIndexError:
break
else:
try:
source = self.pulse.get_source_by_name(name)
existing[key] = source.index
except pulsectl.PulseIndexError:
break
if len(existing) == len(expected_devices):
self.devices = existing
return self.devices
except Exception as e:
print(f" Core error: {e}")
if os.path.exists(self.f):
self._clean()
print(" [AudioMeeter] Sanal cihaz matrisi enjekte ediliyor...")
self.devices = {
"input_main": self.pulse.module_load('module-null-sink', 'sink_name=audiomeeter-input sink_properties="device.description=AudioMeeter_Input_(Main) audiomeeter.device_type=virtual"'),
"input_aux": self.pulse.module_load('module-null-sink', 'sink_name=audiomeeter-aux-input sink_properties="device.description=AudioMeeter_AUX_Input audiomeeter.device_type=virtual"'),
# "out_b1": self.pulse.module_load('module-virtual-source', 'source_name=audiomeeter-out-b1 source_properties="device.description=AudioMeeter_Out_B1_(Virtual_Mic) audiomeeter.device_type=virtual"'),
# "out_b2": self.pulse.module_load('module-virtual-source', 'source_name=audiomeeter-out-b2 source_properties="device.description=AudioMeeter_Out_B2_(Virtual_Mic) audiomeeter.device_type=virtual"'),
}
json.dump(self.devices, open(self.f, "w"), indent=4)
return self.devices
def _clean(self):
try:
for k, v in json.load(open(self.f)).items():
if not v:
continue
for m in [int(x) for x in str(v).split(",")]:
if m in [x.index for x in self.pulse.module_list()]:
try:
self.pulse.module_unload(m)
except:
pass
os.remove(self.f)
except:
pass
t = VirtualDevices()
t.init()