Exemplo n.º 1
0
    def run(self):
        logger.debug("AudioOutputLoop started")
        self._isRunning = True
        while self._isRunning:
            startTime = clock()
            self._lock.acquire(True)

            # do cool stuff here
            if self.numFrames + self._bufferSize > self.totalFrames:
                self._isRunning = False
            else:
                startFrame = self.numFrames
                endFrame = startFrame + self._bufferSize * 2
                bytesOut = bytes(self.allsamples[startFrame:endFrame])
                sound = pygame.mixer.Sound(self.allsamples[startFrame:endFrame])
                self._channel.play(sound)
                self.numFrames += self._bufferSize * 2

            stopTime = clock()
            timeInBlockInSec = (stopTime - startTime)
            sleepTime = self._maxTimePerBlockInSec - timeInBlockInSec
            if sleepTime < 0:
                logger.warn("Audio dropout!")
            else:
                logger.info("CPU: %f", 100 * timeInBlockInSec / self._maxTimePerBlockInSec)
                sleep(sleepTime)
            self._lock.release()
Exemplo n.º 2
0
 def rescan(self):
     self.devices = {}
     logger.info("Audio device rescan started")
     devices = pygame.mixer.get_devices()
     logger.debug("Found %d devices", len(devices))
     for device in devices:
         (name, numInputs, numOutputs) = device
         scannedDevice = AudioDevice(name, numInputs, numOutputs)
         self.devices[name] = scannedDevice
         logger.debug("%s", scannedDevice)
Exemplo n.º 3
0
    def _printVideoInfo(self, videoInfo):
        resolutionWidth = str(videoInfo.current_w)
        resolutionHeight = str(videoInfo.current_h)
        logger.debug("Current resolution: " + resolutionWidth + "x" + resolutionHeight)
        videoInfoAttributes = {'hw': 'Hardware acceleration',
                               'wm': 'Windowed display',
                               'bitsize': 'Display depth',
        }

        for key in videoInfoAttributes.keys():
            logger.debug(videoInfoAttributes[key] + ": " + str(getattr(videoInfo, key)))
Exemplo n.º 4
0
    def rescan(self):
        self.devices = []
        numDevices = pygame.midi.get_count()
        logger.debug("MIDI device rescan started, found %d devices", numDevices)
        for i in range(0, numDevices):
            (interface, name, input, output, opened) = pygame.midi.get_device_info(i)
            deviceName = name.decode("utf-8")

            if input:
                device = MidiInput(i, deviceName, opened)
            else:
                device = MidiOutput(i, deviceName, opened)

            logger.debug("Device %d: %s", i, device)
            self.devices.append(device)
Exemplo n.º 5
0
 def process(self, midiEvent:"MidiEvent", delegate):
     mappingKey = midiEvent.getMappingKey()
     try:
         if mappingKey in self.mappingTable:
             mapping = self.mappingTable[mappingKey]
             if mapping.isButton() and not midiEvent.data2:
                 return
             handlerFunction = getattr(delegate, "on" + mapping.value)
             handlerFunction()
         else:
             raise UnhandledMidiError(midiEvent)
     except AttributeError:
         logger.error("Delegate does not handle MIDI command")
     except UnhandledMidiError as error:
         logger.debug("Unhandled midi event: " + str(error.midiEvent))
Exemplo n.º 6
0
    def run(self):
        # Initialize is done here so as not to block the main thread
        self.devices = MidiDeviceList()
        self.devices.openAll()

        logger.debug("MidiEventLoop started")
        self._isRunning = True

        while self._isRunning:
            self._lock.acquire(True)
            for device in self.devices.openedInputs():
                while device.poll():
                    self._parseEvent(device.readEvents())
            self._lock.release()
            sleep(self._pollInterval)

        pygame.midi.quit()
Exemplo n.º 7
0
    def onKeyDown(self, delegate, key, modifiers = None):
        #logger.debug("Got key: " + str(key) + ", mods: " + str(modifiers))
        try:
            if key in ModifierKeys:
                return
            if modifiers not in ModifierHashes:
                raise UnhandledModifierError(key, modifiers)
            keyHash = ModifierHashes[modifiers]

            if key in keyHash:
                self.handlerFunction = getattr(delegate, "on" + keyHash[key])
                self.handlerFunction()
                self.timer = Timer(0.5, self.repeatKey)
                self.timer.start()
            else:
                raise UnhandledKeyError(key, modifiers)
        except AttributeError:
            logger.error("Error handling key command")
            logger.error(traceback.format_exc().strip())
        except UnhandledKeyError as error:
            logger.debug("Unhandled command: " + error.printKey())
        except UnhandledModifierError as error:
            logger.debug("Unhandled modifier: " + error.printKey())
Exemplo n.º 8
0
 def minimize(self):
     logger.debug("Minimizing")
     pygame.display.iconify()