|
From: Tapio V. <aa...@us...> - 2010-10-26 16:40:36
|
Module: performous
Branch: master
Commit: 1251ab7ba963692a859e6529005aa37fbdb01489
Author: Tapio Vierros <tap...@gm...>
Date: Tue Oct 26 19:20:15 2010 +0300
Convert PortAudio device name to UTF-8.
---
game/libda/portaudio.hpp | 9 ++++++---
game/unicode.cc | 8 +++++++-
game/unicode.hh | 3 ++-
3 files changed, 15 insertions(+), 5 deletions(-)
diff --git a/game/libda/portaudio.hpp b/game/libda/portaudio.hpp
index 6172e69..99d54b3 100644
--- a/game/libda/portaudio.hpp
+++ b/game/libda/portaudio.hpp
@@ -10,6 +10,8 @@
#include <stdexcept>
#include <stdint.h>
+#include "../unicode.hh"
+
#define PORTAUDIO_CHECKED(func, args) portaudio::internal::check(func args, #func)
namespace portaudio {
@@ -32,7 +34,7 @@ namespace portaudio {
}
struct DeviceInfo {
- DeviceInfo(std::string n = "", unsigned i = 0, unsigned o = 0): name(n), in(i), out(o) {}
+ DeviceInfo(std::string n = "", int i = 0, int o = 0): name(n), in(i), out(o) {}
std::string desc() {
std::ostringstream oss;
oss << name << " (";
@@ -42,18 +44,19 @@ namespace portaudio {
return oss.str() + ")";
}
std::string name;
- unsigned int in, out;
+ int in, out;
};
typedef std::vector<DeviceInfo> DeviceInfos;
struct AudioDevices {
+ static int count() { return Pa_GetDeviceCount(); }
/// Constructor gets the PA devices into a vector
AudioDevices() {
for (unsigned i = 0, end = Pa_GetDeviceCount(); i != end; ++i) {
PaDeviceInfo const* info = Pa_GetDeviceInfo(i);
if (!info) devices.push_back(DeviceInfo());
- else devices.push_back(DeviceInfo(info->name, info->maxInputChannels, info->maxOutputChannels));
+ else devices.push_back(DeviceInfo(convertToUTF8(info->name), info->maxInputChannels, info->maxOutputChannels));
}
}
/// Get a printable dump of the devices
diff --git a/game/unicode.cc b/game/unicode.cc
index c2129a5..31d2cf2 100644
--- a/game/unicode.cc
+++ b/game/unicode.cc
@@ -23,7 +23,7 @@ namespace {
}
}
-void convertToUTF8( std::stringstream &_stream, std::string _filename ) {
+void convertToUTF8(std::stringstream &_stream, std::string _filename) {
try {
convert(_stream.str(), "UTF-8", "UTF-8"); // Test if input is UTF-8
} catch(...) {
@@ -38,6 +38,12 @@ void convertToUTF8( std::stringstream &_stream, std::string _filename ) {
}
}
+std::string convertToUTF8(std::string const& str) {
+ std::stringstream ss(str);
+ convertToUTF8(ss, "");
+ return ss.str();
+}
+
std::string unicodeCollate(std::string const& str) {
Glib::ustring ustr = str, ustr2;
if (ustr.substr(0, 4) == "The ") ustr = ustr.substr(4) + "the";
diff --git a/game/unicode.hh b/game/unicode.hh
index a0945ac..95f3784 100644
--- a/game/unicode.hh
+++ b/game/unicode.hh
@@ -3,5 +3,6 @@
#include <iostream>
#include <string>
-void convertToUTF8( std::stringstream &_stream, std::string _filename = std::string() );
+void convertToUTF8(std::stringstream &_stream, std::string _filename = std::string());
+std::string convertToUTF8(std::string const& str);
std::string unicodeCollate(std::string const& str);
|