Skip to content

Commit 6940ebe

Browse files
author
George
committed
Minor code cleanup
1 parent 195e3c0 commit 6940ebe

File tree

1 file changed

+20
-86
lines changed

1 file changed

+20
-86
lines changed

pulsemixer

+20-86
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,6 @@ class PA_MAINLOOP(Structure):
4545
pass
4646

4747

48-
class PA_STREAM(Structure):
49-
pass
50-
51-
5248
class PA_MAINLOOP_API(Structure):
5349
pass
5450

@@ -61,10 +57,6 @@ class PA_OPERATION(Structure):
6157
pass
6258

6359

64-
class PA_IO_EVENT(Structure):
65-
pass
66-
67-
6860
class PA_SAMPLE_SPEC(Structure):
6961
_fields_ = [
7062
("format", c_int),
@@ -157,8 +149,6 @@ class PA_SOURCE_OUTPUT_INFO(Structure):
157149
("corked", c_int),
158150
("volume", PA_CVOLUME),
159151
("mute", c_int),
160-
('has_volume', c_int),
161-
('volume_writable', c_int),
162152
]
163153

164154

@@ -220,6 +210,7 @@ class PA_CARD_INFO(Structure):
220210
('proplist', POINTER(c_int)),
221211
]
222212

213+
223214
class PA_SERVER_INFO(Structure):
224215
_fields_ = [
225216
('user_name', c_char_p),
@@ -269,10 +260,6 @@ PA_SOURCE_INFO_CB_T = CFUNCTYPE(c_int,
269260
c_int,
270261
c_void_p)
271262

272-
PA_CONTEXT_DRAIN_CB_T = CFUNCTYPE(c_void_p,
273-
POINTER(PA_CONTEXT),
274-
c_void_p)
275-
276263
PA_CONTEXT_SUCCESS_CB_T = CFUNCTYPE(c_void_p,
277264
POINTER(PA_CONTEXT),
278265
c_int,
@@ -288,9 +275,6 @@ PA_SERVER_INFO_CB_T = CFUNCTYPE(None,
288275
POINTER(PA_CONTEXT),
289276
POINTER(PA_SERVER_INFO),
290277
c_void_p)
291-
pa_strerror = p.pa_strerror
292-
pa_strerror.restype = c_char_p
293-
pa_strerror.argtypes = [c_int]
294278

295279
pa_mainloop_new = p.pa_mainloop_new
296280
pa_mainloop_new.restype = POINTER(PA_MAINLOOP)
@@ -308,14 +292,6 @@ pa_mainloop_iterate = p.pa_mainloop_iterate
308292
pa_mainloop_iterate.restype = c_int
309293
pa_mainloop_iterate.argtypes = [POINTER(PA_MAINLOOP), c_int, POINTER(c_int)]
310294

311-
pa_mainloop_quit = p.pa_mainloop_quit
312-
pa_mainloop_quit.restype = c_int
313-
pa_mainloop_quit.argtypes = [POINTER(PA_MAINLOOP), c_int]
314-
315-
pa_mainloop_dispatch = p.pa_mainloop_dispatch
316-
pa_mainloop_dispatch.restype = c_int
317-
pa_mainloop_dispatch.argtypes = [POINTER(PA_MAINLOOP)]
318-
319295
pa_mainloop_free = p.pa_mainloop_free
320296
pa_mainloop_free.restype = c_int
321297
pa_mainloop_free.argtypes = [POINTER(PA_MAINLOOP)]
@@ -357,14 +333,6 @@ pa_context_get_state = p.pa_context_get_state
357333
pa_context_get_state.restype = c_int
358334
pa_context_get_state.argtypes = [POINTER(PA_CONTEXT)]
359335

360-
pa_context_drain = p.pa_context_drain
361-
pa_context_drain.restype = POINTER(PA_OPERATION)
362-
pa_context_drain.argtypes = [
363-
POINTER(PA_CONTEXT),
364-
PA_CONTEXT_DRAIN_CB_T,
365-
c_void_p
366-
]
367-
368336
pa_context_disconnect = p.pa_context_disconnect
369337
pa_context_disconnect.restype = c_int
370338
pa_context_disconnect.argtypes = [POINTER(PA_CONTEXT)]
@@ -511,15 +479,6 @@ pa_context_set_source_output_mute.argtypes = [
511479
c_void_p
512480
]
513481

514-
pa_context_kill_source_output = p.pa_context_kill_source_output
515-
pa_context_kill_source_output.restype = POINTER(c_int)
516-
pa_context_kill_source_output.argtypes = [
517-
POINTER(PA_CONTEXT),
518-
c_uint32,
519-
PA_CONTEXT_SUCCESS_CB_T,
520-
c_void_p
521-
]
522-
523482
pa_context_get_source_info_by_index = p.pa_context_get_source_info_by_index
524483
pa_context_get_source_info_by_index.restype = POINTER(c_int)
525484
pa_context_get_source_info_by_index.argtypes = [
@@ -603,19 +562,6 @@ pa_context_get_client_info_list.argtypes = [
603562
c_void_p
604563
]
605564

606-
pa_context_get_client_info = p.pa_context_get_client_info
607-
pa_context_get_client_info.restype = POINTER(c_int)
608-
pa_context_get_client_info.argtypes = [
609-
POINTER(PA_CONTEXT),
610-
c_uint32,
611-
PA_CLIENT_INFO_CB_T,
612-
c_void_p
613-
]
614-
615-
pa_operation_unref = p.pa_operation_unref
616-
pa_operation_unref.restype = c_int
617-
pa_operation_unref.argtypes = [POINTER(PA_OPERATION)]
618-
619565
pa_context_get_card_info_by_index = p.pa_context_get_card_info_by_index
620566
pa_context_get_card_info_by_index.restype = POINTER(PA_OPERATION)
621567
pa_context_get_card_info_by_index.argtypes = [
@@ -633,16 +579,6 @@ pa_context_get_card_info_list.argtypes = [
633579
c_void_p
634580
]
635581

636-
pa_context_set_card_profile_by_index = p.pa_context_set_card_profile_by_index
637-
pa_context_set_card_profile_by_index.restype = POINTER(PA_OPERATION)
638-
pa_context_set_card_profile_by_index.argtypes = [
639-
POINTER(PA_CONTEXT),
640-
c_uint32,
641-
c_char_p,
642-
PA_CONTEXT_SUCCESS_CB_T,
643-
c_void_p
644-
]
645-
646582
pa_context_get_server_info = p.pa_context_get_server_info
647583
pa_context_get_server_info.restype = POINTER(PA_OPERATION)
648584
pa_context_get_server_info.argtypes = [
@@ -655,6 +591,7 @@ pa_context_get_server_info.argtypes = [
655591
#########################################################################################
656592
# v lib
657593

594+
658595
class PulsePort():
659596

660597
def __init__(self, pa_port):
@@ -665,6 +602,7 @@ class PulsePort():
665602
def debug(self):
666603
pprint(vars(self))
667604

605+
668606
class PulseServer():
669607

670608
def __init__(self, pa_server):
@@ -709,23 +647,21 @@ class PulseClient():
709647

710648
class Pulse():
711649

712-
def __init__(self, client_name=None):
650+
def __init__(self, client_name='libpulse'):
713651
self.ret = None
714-
self.context = None
715652
self.operation = None
716653
self.connected = False
717654
self.action_done = False
718655
self.data = []
719-
self.client_name = (client_name or 'libpulse').encode()
656+
self.client_name = client_name.encode()
720657

721658
self.pa_signal_cb = PA_SIGNAL_CB_T(self.signal_cb)
722659
self.pa_state_cb = PA_STATE_CB_T(self.state_cb)
723660

724661
self.mainloop = pa_mainloop_new()
725662
self.mainloop_api = pa_mainloop_get_api(self.mainloop)
726663

727-
if pa_signal_init(self.mainloop_api) != 0:
728-
raise Exception("pa_signal_init failed")
664+
assert pa_signal_init(self.mainloop_api) == 0, "pa_signal_init failed"
729665

730666
pa_signal_new(2, self.pa_signal_cb, None)
731667
pa_signal_new(15, self.pa_signal_cb, None)
@@ -960,8 +896,8 @@ class Pulse():
960896
def set_default_sink(self, name):
961897
CONTEXT = PA_CONTEXT_SUCCESS_CB_T(self.context_success)
962898
self.operation = pa_context_set_default_sink(self.context,
963-
name,
964-
CONTEXT, None)
899+
name,
900+
CONTEXT, None)
965901
self.iterate()
966902

967903
def set_sink_port(self, index, port):
@@ -995,8 +931,8 @@ class Pulse():
995931
def set_default_source(self, name):
996932
CONTEXT = PA_CONTEXT_SUCCESS_CB_T(self.context_success)
997933
self.operation = pa_context_set_default_source(self.context,
998-
name,
999-
CONTEXT, None)
934+
name,
935+
CONTEXT, None)
1000936
self.iterate()
1001937

1002938
def set_source_port(self, index, port):
@@ -1134,8 +1070,7 @@ class PulseSourceOutputInfo(PulseSource):
11341070
if self.client:
11351071
return "ID: {}, Name: {}, Mute: {}, {}".format(
11361072
self.index, self.client.name.decode(), self.mute, self.volume)
1137-
return "ID: {}, Name: {}, Mute: {}".format(
1138-
self.index, self.name.decode(), self.mute)
1073+
return "ID: {}, Name: {}, Mute: {}".format(self.index, self.name.decode(), self.mute)
11391074

11401075

11411076
class PulseVolume():
@@ -1264,7 +1199,7 @@ class Screen():
12641199
self.submenu_show = False
12651200
self.submenu = curses.newwin(curses.LINES, 25, 0, 0)
12661201
self.helpwin_show = False
1267-
self.helpwin = curses.newwin(12, 62, 0, 0)
1202+
self.helpwin = curses.newwin(13, 62, 0, 0)
12681203
try:
12691204
self.helpwin.mvwin((curses.LINES // 2) - 6, (curses.COLS // 2) - 31)
12701205
except:
@@ -1326,15 +1261,15 @@ class Screen():
13261261
self.info = '{}|{}\n{}|{}\n{}|{}\n'.format(
13271262
"L ", self.red if bar.locked else curses.A_DIM,
13281263
"M ", self.red if bar.muted else curses.A_DIM, name, curses.A_NORMAL)
1329-
self.info += '{:>{}}%|{}'.format(pos, self.cols-len(name)-8, curses.A_BOLD)
1264+
self.info += '{:>{}}%|{}'.format(pos, self.cols - len(name) - 8, curses.A_BOLD)
13301265

13311266
def check_resize(self):
13321267
if curses.is_term_resized(curses.LINES, curses.COLS):
13331268
self.screen.erase()
13341269
y, x = self.screen.getmaxyx()
13351270
curses.resizeterm(y, x)
13361271
self.submenu.resize(curses.LINES, 25)
1337-
self.helpwin.resize(12, 62)
1272+
self.helpwin.resize(13, 62)
13381273
self.helpwin.mvwin((curses.LINES // 2) - 6, (curses.COLS // 2) - 31)
13391274
self.helpwin_show = False
13401275
self.screen.refresh()
@@ -1395,10 +1330,10 @@ class Screen():
13951330
if self.action == 'Move':
13961331
if type(self.selected[0].pa) is PulseSinkInputInfo:
13971332
pulse.sink_input_move(self.selected[0].index,
1398-
self.data[focus][0].pa.index)
1333+
self.data[focus][0].pa.index)
13991334
elif type(self.selected[0].pa) is PulseSourceOutputInfo:
14001335
pulse.source_output_move(self.selected[0].index,
1401-
self.data[focus][0].pa.index)
1336+
self.data[focus][0].pa.index)
14021337
self.change_mode(self.old_mode)
14031338
self.focus_line_num = self.modes[4][1]
14041339
self.top_line_num = self.modes[4][2]
@@ -1506,10 +1441,10 @@ class Screen():
15061441
else:
15071442
if type(self.selected[0].pa) is PulseSinkInfo:
15081443
pulse.set_sink_port(self.selected[0].pa.index,
1509-
self.selected[0].pa.ports[focus].name)
1444+
self.selected[0].pa.ports[focus].name)
15101445
elif type(self.selected[0].pa) is PulseSourceInfo:
15111446
pulse.set_source_port(self.selected[0].pa.index,
1512-
self.selected[0].pa.ports[focus].name)
1447+
self.selected[0].pa.ports[focus].name)
15131448
self.change_mode_allowed = True
15141449
self.submenu_show = False
15151450
self.focus_line_num = self.modes[4][1]
@@ -1691,6 +1626,7 @@ class Screen():
16911626
'''h/j/k/l navigation, volume change
16921627
arrows navigation, volume change
16931628
H/L, Shift+Left/Shift+Right change volume by 10
1629+
1/2/3/4/5/6/7/8/9/0 set volume to 10%-100%
16941630
m mute/unmute
16951631
Space lock/unlock channels together
16961632
Enter context menu
@@ -1832,8 +1768,7 @@ def main():
18321768
vol = streams[index].volume
18331769
arg = arg.strip(':').split(':')
18341770
if len(arg) != len(vol.values):
1835-
sys.exit("ERR: Specified volumes not equal to number of channles"
1836-
" in the stream")
1771+
sys.exit("ERR: Specified volumes not equal to number of channles in the stream")
18371772
for i, _ in enumerate(vol.values):
18381773
vol.values[i] = int(arg[i])
18391774
pulse.set_volume(streams[index], vol)
@@ -1847,4 +1782,3 @@ def main():
18471782

18481783
if __name__ == '__main__':
18491784
main()
1850-

0 commit comments

Comments
 (0)