Exemplo n.º 1
0
    def __init__(self, configfile, spool=SoundPool()):

        # load configuration file
        with open(configfile, "r") as f:
            data = f.read()
        root = XmlEt.fromstring(data).find("Ambient")

        # set the name of the ambient
        self.name = root.get("name")

        LOGGER.logInfo("Ambient '{}'".format(self.name))

        # set the update rate from the volatility
        self.urate = 1.0 / float(root.get("volatility"))
        self.urate = constrain(self.urate, 0.0, 5.0)

        # flag indicating whether ambient is currently running
        self.loaded = False
        self.running = False

        # load sounds and sound configuration
        self.sounds = list()
        self.spool = spool
        for soundcfg in root.findall("Sound"):
            sfile = soundcfg.get("file")
            base = float(soundcfg.get("base"))
            drift = float(soundcfg.get("drift"))

            self.sounds.append((sfile, base, drift))

            LOGGER.logInfo("'{}': [{}] +/- ({})".format(sfile, base, drift))
Exemplo n.º 2
0
    def switch(self, ambient_id):
        if self.ambient != None:
            self.ambient.stop()

        # switch to new ambient
        self.ambient = self.ambients[ambient_id]

        LOGGER.logInfo("Switched to ambient '{}'".format(
            self.ambient.getName()))
Exemplo n.º 3
0
    def stop(self):
        if not self.loaded:
            return

        LOGGER.logInfo("'{}' stop".format(self.name))

        for sound in self.sounds:
            sound.stop()

        # indicate stop
        self.running = False
Exemplo n.º 4
0
    def start(self):
        if not self.loaded:
            self.__load()

        LOGGER.logInfo("'{}' start".format(self.name))

        for sound in self.sounds:
            sound.play()

        # indicate start
        self.running = True
        self.__update()