Skip to content

Commit

Permalink
Fix issue #45
Browse files Browse the repository at this point in the history
  • Loading branch information
cdemoulins committed Jan 14, 2022
1 parent 53c296c commit 4636885
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
12 changes: 12 additions & 0 deletions device.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ Device::Device(const pa_source_info* info) {
name = info->name;
description = info->description;
mute = info->mute == 1;
switch(info->state) {
case PA_SOURCE_RUNNING: state = DEVICE_RUNNING; break;
case PA_SOURCE_IDLE: state = DEVICE_IDLE; break;
case PA_SOURCE_SUSPENDED: state = DEVICE_SUSPENDED; break;
default: state = DEVICE_INVALID_STATE;
}
setVolume(&(info->volume));
}

Expand All @@ -37,6 +43,12 @@ Device::Device(const pa_sink_info* info) {
name = info->name;
description = info->description;
mute = info->mute == 1;
switch(info->state) {
case PA_SINK_RUNNING: state = DEVICE_RUNNING; break;
case PA_SINK_IDLE: state = DEVICE_IDLE; break;
case PA_SINK_SUSPENDED: state = DEVICE_SUSPENDED; break;
default: state = DEVICE_INVALID_STATE;
}
setVolume(&(info->volume));
}

Expand Down
8 changes: 8 additions & 0 deletions device.hh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ enum device_type {
};
typedef enum device_type device_type_t;

enum device_state {
DEVICE_INVALID_STATE,
DEVICE_RUNNING,
DEVICE_IDLE,
DEVICE_SUSPENDED
};
typedef enum device_state device_state_t;

/**
* Class to store device (sink or source) related informations
Expand All @@ -42,6 +49,7 @@ public:
device_type_t type;
std::string name;
std::string description;
device_state_t state;
pa_cvolume volume;
pa_volume_t volume_avg;
int volume_percent;
Expand Down
13 changes: 13 additions & 0 deletions pamixer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,17 @@ Device get_selected_device(Pulseaudio& pulse, po::variables_map vm, string sink_
return device;
}

string device_state_to_string(Device device) {
string state;
switch(device.state) {
case DEVICE_RUNNING: state = string("Running"); break;
case DEVICE_IDLE: state = string("Idle"); break;
case DEVICE_SUSPENDED: state = string("Suspended"); break;
default: state = string("Invalid state");
}
return state;
}

pa_volume_t gammaCorrection(pa_volume_t i, double gamma, int delta) {
double j = double(i);
double relRelta = double(delta) / 100.0;
Expand Down Expand Up @@ -210,6 +221,7 @@ int main(int argc, char* argv[])
for (const Device& sink : pulse.get_sinks()) {
cout << sink.index << " \""
<< sink.name << "\" \""
<< device_state_to_string(sink) << "\" \""
<< sink.description << "\"\n";
}
}
Expand All @@ -218,6 +230,7 @@ int main(int argc, char* argv[])
for (const Device& source : pulse.get_sources()) {
cout << source.index << " \""
<< source.name << "\" \""
<< device_state_to_string(source) << "\" \""
<< source.description << "\"\n";
}
}
Expand Down

0 comments on commit 4636885

Please sign in to comment.