Added soundpacks' possibility

This commit is contained in:
Manuel Cortez 2016-05-24 17:48:22 -05:00
parent cada87275d
commit 2b44c72999
5 changed files with 81 additions and 4 deletions

View File

@ -1,7 +1,6 @@
# -*- coding: utf-8 -*-
import output
import sound_lib
from sound_lib.output import Output
from sound_lib.stream import URLStream
from mysc.repeating_timer import RepeatingTimer
from pubsub import pub
@ -16,7 +15,6 @@ def setup():
class audioPlayer(object):
def __init__(self):
Output()
self.is_playing = False
self.stream = None
self.vol = 100

View File

@ -8,3 +8,10 @@ reverse_timelines = boolean(default=False)
[buffers]
count_for_audio_buffers = integer(default=100)
count_for_wall_buffers = integer(default=100)
[sound]
volume = float(default=1.0)
input_device = string(default="Default")
output_device = string(default="Default")
session_mute = boolean(default=False)
current_soundpack = string(default="default")

View File

@ -6,6 +6,7 @@ import paths
import vkSessionHandler
import logging
import utils
import sound
from config_utils import Configuration, ConfigurationResetException
log = logging.getLogger("session")
@ -184,6 +185,7 @@ class vkSession(object):
# try:
log.debug("Creating config file %s" % (file_,))
self.settings = Configuration(paths.config_path(file_), paths.app_path("session.defaults"))
self.soundplayer = sound.soundSystem(self.settings["sound"])
# except:
# log.exception("The session configuration has failed.")

70
src/sound.py Normal file
View File

@ -0,0 +1,70 @@
# -*- coding: utf-8 -*-
""" Sound utilities for socialized."""
import sys
import os
import logging as original_logger
log = original_logger.getLogger("sound")
import paths
import sound_lib
import output
from mysc.repeating_timer import RepeatingTimer
from mysc.thread_utils import call_threaded
import glob
class soundSystem(object):
def check_soundpack(self):
""" Checks if the folder where live the current soundpack exists."""
self.soundpack_OK = False
if os.path.exists(paths.sound_path(self.config["current_soundpack"])):
self.path = paths.sound_path(self.config["current_soundpack"])
self.soundpack_OK = True
elif os.path.exists(paths.sound_path("default")):
log.error("The soundpack does not exist, using default...")
self.path = paths.sound_path("default")
self.soundpack_OK = True
else:
log.error("The current soundpack could not be found and the default soundpack has been deleted, Socializer will not play sounds.")
self.soundpack_OK = False
def __init__(self, soundConfig):
""" Sound Player."""
self.config = soundConfig
# Set the output and input default devices.
try:
self.output = sound_lib.output.Output()
self.input = sound_lib.input.Input()
except:
pass
# Try to use the selected device from the configuration. It can fail if the machine does not has a mic.
try:
log.debug("Setting input and output devices...")
self.output.set_device(self.output.find_device_by_name(self.config["output_device"]))
self.input.set_device(self.input.find_device_by_name(self.config["input_device"]))
except:
log.error("Error in input or output devices, using defaults...")
self.config["output_device"] = "Default"
self.config["input_device"] = "Default"
self.files = []
self.cleaner = RepeatingTimer(60, self.clear_list)
self.cleaner.start()
self.check_soundpack()
def clear_list(self):
if len(self.files) == 0: return
try:
for i in xrange(0, len(self.files)):
if self.files[i].is_playing == False:
self.files[i].free()
self.files.pop(i)
except IndexError:
pass
def play(self, sound, argument=False):
if self.soundpack_OK == False: return
if self.config["session_mute"] == True: return
sound_object = sound_lib.stream.FileStream(file="%s/%s" % (self.path, sound))
sound_object.volume = float(self.config["volume"])
self.files.append(sound_object)
sound_object.play()