file_lock = Lock("file")
+ channel_id = 0
+
for mapped_key in config['keys']:
key = mapping.find_by_unicode(mapped_key)
if key is None:
if argument == 'file':
filename = action[action_name]['file']
if filename not in seen_files:
- seen_files[filename] = MusicFile(filename, file_lock)
+ seen_files[filename] = MusicFile(filename, file_lock, channel_id)
+ channel_id = channel_id + 1
action_args['music'] = seen_files[filename]
key.set_description(config['key_properties'][key_property]['description'])
if 'color' in config['key_properties'][key_property]:
key.set_color(config['key_properties'][key_property]['color'])
+
+ # Return the number of channels reserved
+ return channel_id + 1
)
def set_description(self, description):
- self.description = [str(desc) for desc in description]
+ for desc in description:
+ if desc is None:
+ self.description.append("")
+ else:
+ self.description.append(str(desc))
def set_color(self, color):
self.custom_color = tuple(color)
import pygame
class MusicFile:
- def __init__(self, filename, lock):
+ def __init__(self, filename, lock, channel_id):
self.filename = filename
- self.channel = None
+ self.channel_id = channel_id
self.raw_data = None
self.sound = None
lock.release()
def is_playing(self):
- return self.channel is not None and self.channel.get_busy()
+ return self.channel().get_busy()
def play(self, fade_in = 0, volume = 100, start_at = 0):
self.set_volume(volume)
else:
self.sound = pygame.mixer.Sound(self.raw_data)
- self.channel = self.sound.play(fade_ms = fade_in * 1000)
+ self.channel().play(self.sound, fade_ms = fade_in * 1000)
def pause(self):
- if self.channel is not None:
- self.channel.pause()
+ self.channel().pause()
def stop(self, fade_out = 0):
- self.channel = None
if fade_out > 0:
- self.sound.fadeout(fade_out * 1000)
+ self.channel().fadeout(fade_out * 1000)
else:
- self.sound.stop()
+ self.channel().stop()
def set_volume(self, value):
if value < 0:
def wait_end(self):
pass
+
+ def channel(self):
+ return pygame.mixer.Channel(self.channel_id)
draw_lock = helpers.Lock("draw")
mapping = helpers.Mapping(screen, draw_lock)
-helpers.parse_config(mapping)
+channel_number = helpers.parse_config(mapping)
+pygame.mixer.set_num_channels(channel_number)
mapping.draw()