@@ -45,10 +45,6 @@ class PA_MAINLOOP(Structure):
45
45
pass
46
46
47
47
48
- class PA_STREAM (Structure ):
49
- pass
50
-
51
-
52
48
class PA_MAINLOOP_API (Structure ):
53
49
pass
54
50
@@ -61,10 +57,6 @@ class PA_OPERATION(Structure):
61
57
pass
62
58
63
59
64
- class PA_IO_EVENT (Structure ):
65
- pass
66
-
67
-
68
60
class PA_SAMPLE_SPEC (Structure ):
69
61
_fields_ = [
70
62
("format" , c_int ),
@@ -157,8 +149,6 @@ class PA_SOURCE_OUTPUT_INFO(Structure):
157
149
("corked" , c_int ),
158
150
("volume" , PA_CVOLUME ),
159
151
("mute" , c_int ),
160
- ('has_volume' , c_int ),
161
- ('volume_writable' , c_int ),
162
152
]
163
153
164
154
@@ -220,6 +210,7 @@ class PA_CARD_INFO(Structure):
220
210
('proplist' , POINTER (c_int )),
221
211
]
222
212
213
+
223
214
class PA_SERVER_INFO (Structure ):
224
215
_fields_ = [
225
216
('user_name' , c_char_p ),
@@ -269,10 +260,6 @@ PA_SOURCE_INFO_CB_T = CFUNCTYPE(c_int,
269
260
c_int ,
270
261
c_void_p )
271
262
272
- PA_CONTEXT_DRAIN_CB_T = CFUNCTYPE (c_void_p ,
273
- POINTER (PA_CONTEXT ),
274
- c_void_p )
275
-
276
263
PA_CONTEXT_SUCCESS_CB_T = CFUNCTYPE (c_void_p ,
277
264
POINTER (PA_CONTEXT ),
278
265
c_int ,
@@ -288,9 +275,6 @@ PA_SERVER_INFO_CB_T = CFUNCTYPE(None,
288
275
POINTER (PA_CONTEXT ),
289
276
POINTER (PA_SERVER_INFO ),
290
277
c_void_p )
291
- pa_strerror = p .pa_strerror
292
- pa_strerror .restype = c_char_p
293
- pa_strerror .argtypes = [c_int ]
294
278
295
279
pa_mainloop_new = p .pa_mainloop_new
296
280
pa_mainloop_new .restype = POINTER (PA_MAINLOOP )
@@ -308,14 +292,6 @@ pa_mainloop_iterate = p.pa_mainloop_iterate
308
292
pa_mainloop_iterate .restype = c_int
309
293
pa_mainloop_iterate .argtypes = [POINTER (PA_MAINLOOP ), c_int , POINTER (c_int )]
310
294
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
-
319
295
pa_mainloop_free = p .pa_mainloop_free
320
296
pa_mainloop_free .restype = c_int
321
297
pa_mainloop_free .argtypes = [POINTER (PA_MAINLOOP )]
@@ -357,14 +333,6 @@ pa_context_get_state = p.pa_context_get_state
357
333
pa_context_get_state .restype = c_int
358
334
pa_context_get_state .argtypes = [POINTER (PA_CONTEXT )]
359
335
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
-
368
336
pa_context_disconnect = p .pa_context_disconnect
369
337
pa_context_disconnect .restype = c_int
370
338
pa_context_disconnect .argtypes = [POINTER (PA_CONTEXT )]
@@ -511,15 +479,6 @@ pa_context_set_source_output_mute.argtypes = [
511
479
c_void_p
512
480
]
513
481
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
-
523
482
pa_context_get_source_info_by_index = p .pa_context_get_source_info_by_index
524
483
pa_context_get_source_info_by_index .restype = POINTER (c_int )
525
484
pa_context_get_source_info_by_index .argtypes = [
@@ -603,19 +562,6 @@ pa_context_get_client_info_list.argtypes = [
603
562
c_void_p
604
563
]
605
564
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
-
619
565
pa_context_get_card_info_by_index = p .pa_context_get_card_info_by_index
620
566
pa_context_get_card_info_by_index .restype = POINTER (PA_OPERATION )
621
567
pa_context_get_card_info_by_index .argtypes = [
@@ -633,16 +579,6 @@ pa_context_get_card_info_list.argtypes = [
633
579
c_void_p
634
580
]
635
581
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
-
646
582
pa_context_get_server_info = p .pa_context_get_server_info
647
583
pa_context_get_server_info .restype = POINTER (PA_OPERATION )
648
584
pa_context_get_server_info .argtypes = [
@@ -655,6 +591,7 @@ pa_context_get_server_info.argtypes = [
655
591
#########################################################################################
656
592
# v lib
657
593
594
+
658
595
class PulsePort ():
659
596
660
597
def __init__ (self , pa_port ):
@@ -665,6 +602,7 @@ class PulsePort():
665
602
def debug (self ):
666
603
pprint (vars (self ))
667
604
605
+
668
606
class PulseServer ():
669
607
670
608
def __init__ (self , pa_server ):
@@ -709,23 +647,21 @@ class PulseClient():
709
647
710
648
class Pulse ():
711
649
712
- def __init__ (self , client_name = None ):
650
+ def __init__ (self , client_name = 'libpulse' ):
713
651
self .ret = None
714
- self .context = None
715
652
self .operation = None
716
653
self .connected = False
717
654
self .action_done = False
718
655
self .data = []
719
- self .client_name = ( client_name or 'libpulse' ) .encode ()
656
+ self .client_name = client_name .encode ()
720
657
721
658
self .pa_signal_cb = PA_SIGNAL_CB_T (self .signal_cb )
722
659
self .pa_state_cb = PA_STATE_CB_T (self .state_cb )
723
660
724
661
self .mainloop = pa_mainloop_new ()
725
662
self .mainloop_api = pa_mainloop_get_api (self .mainloop )
726
663
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"
729
665
730
666
pa_signal_new (2 , self .pa_signal_cb , None )
731
667
pa_signal_new (15 , self .pa_signal_cb , None )
@@ -960,8 +896,8 @@ class Pulse():
960
896
def set_default_sink (self , name ):
961
897
CONTEXT = PA_CONTEXT_SUCCESS_CB_T (self .context_success )
962
898
self .operation = pa_context_set_default_sink (self .context ,
963
- name ,
964
- CONTEXT , None )
899
+ name ,
900
+ CONTEXT , None )
965
901
self .iterate ()
966
902
967
903
def set_sink_port (self , index , port ):
@@ -995,8 +931,8 @@ class Pulse():
995
931
def set_default_source (self , name ):
996
932
CONTEXT = PA_CONTEXT_SUCCESS_CB_T (self .context_success )
997
933
self .operation = pa_context_set_default_source (self .context ,
998
- name ,
999
- CONTEXT , None )
934
+ name ,
935
+ CONTEXT , None )
1000
936
self .iterate ()
1001
937
1002
938
def set_source_port (self , index , port ):
@@ -1134,8 +1070,7 @@ class PulseSourceOutputInfo(PulseSource):
1134
1070
if self .client :
1135
1071
return "ID: {}, Name: {}, Mute: {}, {}" .format (
1136
1072
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 )
1139
1074
1140
1075
1141
1076
class PulseVolume ():
@@ -1264,7 +1199,7 @@ class Screen():
1264
1199
self .submenu_show = False
1265
1200
self .submenu = curses .newwin (curses .LINES , 25 , 0 , 0 )
1266
1201
self .helpwin_show = False
1267
- self .helpwin = curses .newwin (12 , 62 , 0 , 0 )
1202
+ self .helpwin = curses .newwin (13 , 62 , 0 , 0 )
1268
1203
try :
1269
1204
self .helpwin .mvwin ((curses .LINES // 2 ) - 6 , (curses .COLS // 2 ) - 31 )
1270
1205
except :
@@ -1326,15 +1261,15 @@ class Screen():
1326
1261
self .info = '{}|{}\n {}|{}\n {}|{}\n ' .format (
1327
1262
"L " , self .red if bar .locked else curses .A_DIM ,
1328
1263
"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 )
1330
1265
1331
1266
def check_resize (self ):
1332
1267
if curses .is_term_resized (curses .LINES , curses .COLS ):
1333
1268
self .screen .erase ()
1334
1269
y , x = self .screen .getmaxyx ()
1335
1270
curses .resizeterm (y , x )
1336
1271
self .submenu .resize (curses .LINES , 25 )
1337
- self .helpwin .resize (12 , 62 )
1272
+ self .helpwin .resize (13 , 62 )
1338
1273
self .helpwin .mvwin ((curses .LINES // 2 ) - 6 , (curses .COLS // 2 ) - 31 )
1339
1274
self .helpwin_show = False
1340
1275
self .screen .refresh ()
@@ -1395,10 +1330,10 @@ class Screen():
1395
1330
if self .action == 'Move' :
1396
1331
if type (self .selected [0 ].pa ) is PulseSinkInputInfo :
1397
1332
pulse .sink_input_move (self .selected [0 ].index ,
1398
- self .data [focus ][0 ].pa .index )
1333
+ self .data [focus ][0 ].pa .index )
1399
1334
elif type (self .selected [0 ].pa ) is PulseSourceOutputInfo :
1400
1335
pulse .source_output_move (self .selected [0 ].index ,
1401
- self .data [focus ][0 ].pa .index )
1336
+ self .data [focus ][0 ].pa .index )
1402
1337
self .change_mode (self .old_mode )
1403
1338
self .focus_line_num = self .modes [4 ][1 ]
1404
1339
self .top_line_num = self .modes [4 ][2 ]
@@ -1506,10 +1441,10 @@ class Screen():
1506
1441
else :
1507
1442
if type (self .selected [0 ].pa ) is PulseSinkInfo :
1508
1443
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 )
1510
1445
elif type (self .selected [0 ].pa ) is PulseSourceInfo :
1511
1446
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 )
1513
1448
self .change_mode_allowed = True
1514
1449
self .submenu_show = False
1515
1450
self .focus_line_num = self .modes [4 ][1 ]
@@ -1691,6 +1626,7 @@ class Screen():
1691
1626
'''h/j/k/l navigation, volume change
1692
1627
arrows navigation, volume change
1693
1628
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%
1694
1630
m mute/unmute
1695
1631
Space lock/unlock channels together
1696
1632
Enter context menu
@@ -1832,8 +1768,7 @@ def main():
1832
1768
vol = streams [index ].volume
1833
1769
arg = arg .strip (':' ).split (':' )
1834
1770
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" )
1837
1772
for i , _ in enumerate (vol .values ):
1838
1773
vol .values [i ] = int (arg [i ])
1839
1774
pulse .set_volume (streams [index ], vol )
@@ -1847,4 +1782,3 @@ def main():
1847
1782
1848
1783
if __name__ == '__main__' :
1849
1784
main ()
1850
-
0 commit comments