diff --git a/src/controller/buffers.py b/src/controller/buffers.py index 1d5f750..1f06427 100644 --- a/src/controller/buffers.py +++ b/src/controller/buffers.py @@ -288,4 +288,4 @@ class chatBuffer(baseBuffer): def send_chat_to_user(self, *args, **kwargs): text = self.tab.text.GetValue() if text == "": return - response = self.session.vk.client.messages.send(user_id=self.kwargs["user_id"], message=text) + response = self.session.vk.client.messages.send(user_id=self.kwargs["user_id"], message=text) \ No newline at end of file diff --git a/src/controller/player.py b/src/controller/player.py index bbf1897..03066e2 100644 --- a/src/controller/player.py +++ b/src/controller/player.py @@ -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 diff --git a/src/session.defaults b/src/session.defaults index f3a7b71..6b0daae 100644 --- a/src/session.defaults +++ b/src/session.defaults @@ -7,4 +7,11 @@ reverse_timelines = boolean(default=False) [buffers] count_for_audio_buffers = integer(default=100) -count_for_wall_buffers = integer(default=100) \ No newline at end of file +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") \ No newline at end of file diff --git a/src/sessionmanager/session.py b/src/sessionmanager/session.py index b69992d..03b6491 100644 --- a/src/sessionmanager/session.py +++ b/src/sessionmanager/session.py @@ -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.") diff --git a/src/sound.py b/src/sound.py new file mode 100644 index 0000000..4a4b2aa --- /dev/null +++ b/src/sound.py @@ -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()