Created
April 28, 2013 20:45
-
-
Save flags/5478354 to your computer and use it in GitHub Desktop.
Controls volume of different OSS mixers through controller input.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import subprocess | |
import pygame | |
import time | |
pygame.joystick.init() | |
pygame.display.init() | |
for stick in [pygame.joystick.Joystick(x) for x in range(pygame.joystick.get_count())]: | |
stick.init() | |
MIXERS = {1: {'volume': 25, 'modifier': 0, 'mixer': 'vmix0.pcm10'}, | |
5: {'volume': 25, 'modifier': 0, 'mixer': 'vmix0.pcm9'}} | |
def clip(number, start, end): | |
"""Returns `number`, but makes sure it's in the range of [start..end]""" | |
return max(start, min(number, end)) | |
while 1: | |
for event in pygame.event.get(): | |
if event.type == pygame.QUIT: | |
break | |
if event.type == pygame.JOYAXISMOTION: | |
if event.axis in MIXERS: | |
MIXERS[event.axis]['modifier'] = -event.value | |
for mixer in [mixer for mixer in MIXERS.values() if mixer['modifier']]: | |
mixer['volume'] = clip(mixer['volume']+mixer['modifier'], 0, 25) | |
subprocess.call(['ossmix', mixer['mixer'], str(mixer['volume'])]) | |
time.sleep(0.02) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment