[tuxdroid-svn] r5107 - software_suite_v3/smart-core/smart-server/trunk/util/system
Status: Beta
Brought to you by:
ks156
|
From: remi <c2m...@c2...> - 2009-07-14 08:56:12
|
Author: remi
Date: 2009-07-14 10:55:56 +0200 (Tue, 14 Jul 2009)
New Revision: 5107
Modified:
software_suite_v3/smart-core/smart-server/trunk/util/system/Device.py
Log:
* Added functions to retrieve the Tuxdroid sound card names. (independent to the Windows version/language)
Modified: software_suite_v3/smart-core/smart-server/trunk/util/system/Device.py
===================================================================
--- software_suite_v3/smart-core/smart-server/trunk/util/system/Device.py 2009-07-13 14:01:31 UTC (rev 5106)
+++ software_suite_v3/smart-core/smart-server/trunk/util/system/Device.py 2009-07-14 08:55:56 UTC (rev 5107)
@@ -13,32 +13,99 @@
"""
# --------------------------------------------------------------------------
- # Get the sound device of Tux Droid.
+ # Get a sound device by a keyword. Win32.
# --------------------------------------------------------------------------
- def getTuxDroidSoundDevice():
- """Get the sound device of Tux Droid.
- @return: A string.
+ def getSoundDeviceByKeywordWin32(deviceKeyword):
+ """Get a sound device by a keyword.
+ @param deviceKeyword: Device keyword.
+ @return: A tuple (device index, device name)
"""
- if os.name == 'nt':
- import platform
- if int(platform.version().split(".")[0]) >= 6:
- deviceName = "Speakers (TuxDroid-Audio)"
- else:
- deviceName = "TuxDroid-Audio"
+ from ctypes import windll
+ winmm = windll.winmm
+ wvcps = ' ' * 52
+ cardsCount = winmm.waveOutGetNumDevs()
+ firstDevice = ""
+ for i in range(cardsCount):
+ try:
+ if winmm.waveOutGetDevCapsA(i, wvcps,len(wvcps)) == 0:
+ deviceName = wvcps[8:].split("\0")[0]
+ if i == 0:
+ firstDevice = deviceName
+ if wvcps.lower().find(deviceKeyword.lower()) != -1:
+ return i, deviceName
+ except:
+ pass
+ return -1, None
+
+ # --------------------------------------------------------------------------
+ # Get the sound device name of Tux Droid Audio.
+ # --------------------------------------------------------------------------
+ def getSoundDeviceNameTuxdroidAudio():
+ """Get the sound device name of Tux Droid Audio.
+ @return: The device name or None (Win32) if not found.
+ """
+ if os.name == "nt":
+ idx, deviceName = Device.getSoundDeviceByKeywordWin32("tuxdroid-audio")
+ return deviceName
+ else:
+ return "plughw:TuxDroid,0"
+
+ # --------------------------------------------------------------------------
+ # Get the sound device name of Tux Droid TTS.
+ # --------------------------------------------------------------------------
+ def getSoundDeviceNameTuxdroidTts():
+ """Get the sound device name of Tux Droid Tts.
+ @return: The device name or None (Win32) if not found.
+ """
+ if os.name == "nt":
+ idx, deviceName = Device.getSoundDeviceByKeywordWin32("tuxdroid-tts")
+ return deviceName
+ else:
+ return "plughw:TuxDroid,1"
+
+ # --------------------------------------------------------------------------
+ # Get the sound device name of Tux Droid Micro.
+ # --------------------------------------------------------------------------
+ def getSoundDeviceNameTuxdroidMicro():
+ """Get the sound device name of Tux Droid Micro.
+ @return: The device name or None (Win32) if not found.
+ """
+ if os.name == "nt":
from ctypes import windll
winmm = windll.winmm
wvcps = ' ' * 52
- cardsCount = winmm.waveOutGetNumDevs()
+ cardsCount = winmm.waveInGetNumDevs()
for i in range(cardsCount):
try:
- if winmm.waveOutGetDevCapsA(i, wvcps,len(wvcps)) == 0:
- if wvcps[8:].split("\0")[0].find(deviceName) == 0:
- idx = i + 1
- return "dsound:device=%d" % idx
+ if winmm.waveInGetDevCapsA(i, wvcps,len(wvcps)) == 0:
+ deviceName = wvcps[8:].split("\0")[0]
+ if wvcps.lower().find("tuxdroid-audio") != -1:
+ return deviceName
except:
pass
- return "dsound:device=1"
+ return None
else:
+ return "plughw:TuxDroid,0"
+
+ # --------------------------------------------------------------------------
+ # Get the sound device of Tux Droid.
+ # --------------------------------------------------------------------------
+ def getTuxDroidSoundDevice():
+ """Get the sound device of Tux Droid.
+ @return: A string.
+ """
+ if os.name == 'nt':
+ idx, deviceName = Device.getSoundDeviceByKeywordWin32("tuxdroid-audio")
+ if idx == -1:
+ return "dsound:device=1"
+ else:
+ idx += 1
+ return "dsound:device=%d" % idx
+ else:
return "alsa:device=plughw=TuxDroid,0"
+ getSoundDeviceByKeywordWin32 = staticmethod(getSoundDeviceByKeywordWin32)
+ getSoundDeviceNameTuxdroidAudio = staticmethod(getSoundDeviceNameTuxdroidAudio)
+ getSoundDeviceNameTuxdroidTts = staticmethod(getSoundDeviceNameTuxdroidTts)
+ getSoundDeviceNameTuxdroidMicro = staticmethod(getSoundDeviceNameTuxdroidMicro)
getTuxDroidSoundDevice = staticmethod(getTuxDroidSoundDevice)
|