@@ -188,11 +188,22 @@ async def _adjustments_menu(self):
188
188
# Audio
189
189
def _load_audio_menu_entries (self ) -> List [ServiceMenuEntry ]:
190
190
"""Return the audio menu items with label and callback."""
191
- return [
191
+ items = [
192
192
ServiceMenuEntry ("Software Levels" , self ._volume_menu )
193
- # TODO: Add hardware platform volume control
194
193
]
195
194
195
+ self .debug_log ("Looking for platform volumes: %s" , self .machine .hardware_platforms )
196
+ for p , platform in self .machine .hardware_platforms .items ():
197
+ # TODO: Define an AudioInterface base class
198
+ if getattr (platform , "audio_interface" , None ):
199
+ self .debug_log ("Found '%s' platform audio for volume: %s" , p , platform )
200
+ # TODO: find a good way to get a name of a platform
201
+ name = p .title ()
202
+ items .append (ServiceMenuEntry (f"{ name } Levels" , partial (self ._volume_menu , platform )))
203
+ else :
204
+ self .debug_log ("Platform '%s' has no audio to configure volume: %s" , p , platform )
205
+ return items
206
+
196
207
async def _audio_menu (self ):
197
208
await self ._make_menu (self ._load_audio_menu_entries ())
198
209
@@ -453,16 +464,25 @@ def _load_software_sound_menu_entries(self) -> List[ServiceMenuEntry]:
453
464
for track , config in self .machine .config ["sound_system" ]["tracks" ].items ()
454
465
]
455
466
456
- async def _volume_menu (self ):
467
+ async def _volume_menu (self , platform = None ):
457
468
position = 0
469
+ if platform :
470
+ item_configs = platform .audio_interface .amps
471
+ else :
472
+ item_configs = self .machine .config ["sound_system" ]["tracks" ]
458
473
items = [{** config , "name" : track , "label" : config .get ("label" , track ),
459
- "value" : int (( self .machine .variables .get_machine_var (f"{ track } _volume" ) or config ['volume' ]) * 100 )
460
- } for track , config in self . machine . config [ "sound_system" ][ "tracks" ] .items ()]
474
+ "value" : ( self .machine .variables .get_machine_var (f"{ track } _volume" ) or config ['volume' ])
475
+ } for track , config in item_configs .items ()]
461
476
462
477
# do not crash if no items
463
478
if not items : # pragma: no cover
464
479
return
465
480
481
+ # Convert floats to ints for systems that use 0.0-1.0 for volume
482
+ for item in items :
483
+ if isinstance (item ['value' ], float ):
484
+ item ['value' ] = int (item ['value' ] * 100 )
485
+
466
486
self ._update_volume_slide (items , position )
467
487
468
488
while True :
@@ -481,31 +501,38 @@ async def _volume_menu(self):
481
501
self ._update_volume_slide (items , position )
482
502
elif key == 'ENTER' :
483
503
# change setting
484
- await self ._volume_change (items , position )
504
+ await self ._volume_change (items , position , focus_change = "enter" )
485
505
486
506
self .machine .events .post ("service_volume_stop" )
487
507
488
508
489
- def _update_volume_slide (self , items , position , is_change = False ):
509
+ def _update_volume_slide (self , items , position , is_change = False , focus_change = None ):
490
510
config = items [position ]
491
511
event = "service_volume_{}" .format ("edit" if is_change else "start" )
512
+ # The 'focus_change' argument can be used to start/stop sound files playing
513
+ # during the service menu, to test volume.
492
514
self .machine .events .post (event ,
493
515
settings_label = config ["label" ],
494
- value_label = "%d%%" % config ["value" ])
516
+ value_label = config ["value" ],
517
+ track = config ["name" ],
518
+ focus_change = focus_change )
495
519
496
- async def _volume_change (self , items , position ):
497
- self ._update_volume_slide (items , position )
520
+ async def _volume_change (self , items , position , focus_change = None ):
521
+ self ._update_volume_slide (items , position , focus_change = focus_change )
498
522
499
- # Use ints for values to avoid floating-point comparisons
500
- values = [int ((0.05 * i ) * 100 ) for i in range (0 ,21 )]
523
+ if items [position ].get ("levels_list" ):
524
+ values = items [position ]["levels_list" ]
525
+ else :
526
+ # Use ints for values to avoid floating-point comparisons
527
+ values = [int ((0.05 * i ) * 100 ) for i in range (0 ,21 )]
501
528
value_position = values .index (items [position ]["value" ])
502
529
self ._update_volume_slide (items , position , is_change = True )
503
530
504
531
while True :
505
532
key = await self ._get_key ()
506
533
new_value = None
507
534
if key == 'ESC' :
508
- self ._update_volume_slide (items , position )
535
+ self ._update_volume_slide (items , position , focus_change = "exit" )
509
536
break
510
537
if key == 'UP' :
511
538
value_position += 1
0 commit comments