aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--pulse.cc31
-rw-r--r--pulse.h5
2 files changed, 30 insertions, 6 deletions
diff --git a/pulse.cc b/pulse.cc
index 3a248de..f6b633b 100644
--- a/pulse.cc
+++ b/pulse.cc
@@ -151,12 +151,23 @@ Card* PulseClient::GetCard(const uint32_t& index) {
Card* PulseClient::GetCard(const string& name) {
long val;
+ vector<Card> res;
if (xstrtol(name.c_str(), &val) == 0) return GetCard(val);
for (Card& card : cards_) {
- if (card.name_ == name) return &card;
+ if (card.name_.find(name) != string::npos) res.push_back(card);
}
- return nullptr;
+
+ switch (res.size()) {
+ case 0:
+ return nullptr;
+ case 1:
+ break;
+ default:
+ warnx("warning: ambiguous result for '%s', using '%s'",
+ name.c_str(), res[0].name_.c_str());
+ }
+ return &res[0];
}
Card* PulseClient::GetCard(const Device& device) {
@@ -176,12 +187,24 @@ Device* PulseClient::get_device(vector<Device>& devices,
Device* PulseClient::get_device(vector<Device>& devices, const string& name) {
long val;
+ vector<Device> res;
if (xstrtol(name.c_str(), &val) == 0) return get_device(devices, val);
for (Device& device : devices) {
- if (device.name_ == name) return &device;
+ if (device.name_.find(name) != string::npos) res.push_back(device);
}
- return nullptr;
+
+ switch (res.size()) {
+ case 0:
+ return nullptr;
+ case 1:
+ break;
+ default:
+ warnx("warning: ambiguous result for '%s', using '%s'",
+ name.c_str(), res[0].name_.c_str());
+ }
+
+ return &res[0];
}
Device* PulseClient::GetDevice(const uint32_t& index, enum DeviceType type) {
diff --git a/pulse.h b/pulse.h
index a19ce0b..a062975 100644
--- a/pulse.h
+++ b/pulse.h
@@ -24,8 +24,9 @@ enum DeviceType {
struct Profile {
Profile(const pa_card_profile_info& info) :
- name(info.name),
- desc(info.description) {}
+ name(info.name),
+ desc(info.description) {
+ }
string name;
string desc;