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

@ -288,4 +288,4 @@ class chatBuffer(baseBuffer):
def send_chat_to_user(self, *args, **kwargs): def send_chat_to_user(self, *args, **kwargs):
text = self.tab.text.GetValue() text = self.tab.text.GetValue()
if text == "": return 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)

View File

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

View File

@ -7,4 +7,11 @@ reverse_timelines = boolean(default=False)
[buffers] [buffers]
count_for_audio_buffers = integer(default=100) count_for_audio_buffers = integer(default=100)
count_for_wall_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 vkSessionHandler
import logging import logging
import utils import utils
import sound
from config_utils import Configuration, ConfigurationResetException from config_utils import Configuration, ConfigurationResetException
log = logging.getLogger("session") log = logging.getLogger("session")
@ -184,6 +185,7 @@ class vkSession(object):
# try: # try:
log.debug("Creating config file %s" % (file_,)) log.debug("Creating config file %s" % (file_,))
self.settings = Configuration(paths.config_path(file_), paths.app_path("session.defaults")) self.settings = Configuration(paths.config_path(file_), paths.app_path("session.defaults"))
self.soundplayer = sound.soundSystem(self.settings["sound"])
# except: # except:
# log.exception("The session configuration has failed.") # 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()