[pulseaudio-discuss] [PATCH pavucontrol] mainwindow: Show the availability of the ports and profiles.

Tanu Kaskinen tanuk at iki.fi
Fri Nov 9 10:17:02 PST 2012


On Thu, 2012-11-08 at 23:38 +0100, poljar (Damir Jelić) wrote:
> From: "poljar (Damir Jelić)" <poljarinho at gmail.com>
> 
> If we know if a certain port is available/unavailable, we can print
> that out, as a help to the user (and as debugging for ourselves).
> A profile is also available/unavailable if all ports which have that
> profile is available/unavailable.
> 
> Credit goes to David Henningson for the original idea and some of the code.
> ---
>  src/cardwidget.h  |  1 +
>  src/mainwindow.cc | 66 +++++++++++++++++++++++++++++++++++++++++++------------
>  2 files changed, 53 insertions(+), 14 deletions(-)
> 
> diff --git a/src/cardwidget.h b/src/cardwidget.h
> index 7c63681..821aae5 100644
> --- a/src/cardwidget.h
> +++ b/src/cardwidget.h
> @@ -31,6 +31,7 @@ public:
>        int available;
>        int direction;
>        int64_t latency_offset;
> +      std::vector<Glib::ustring> profiles;
>  };
>  
>  class CardWidget : public Gtk::VBox {
> diff --git a/src/mainwindow.cc b/src/mainwindow.cc
> index 1041eab..524d1a7 100644
> --- a/src/mainwindow.cc
> +++ b/src/mainwindow.cc
> @@ -255,6 +255,22 @@ static void set_icon_name_fallback(Gtk::Image *i, const char *name, Gtk::IconSiz
>  static void updatePorts(DeviceWidget *w, std::map<Glib::ustring, PortInfo> &ports) {
>      std::map<Glib::ustring, PortInfo>::iterator it;
>  
> +    w->ports.clear();
> +    for (it = ports.begin(); it != ports.end(); it++) {
> +        PortInfo p = (*it).second;
> +        Glib::ustring desc = p.description;
> +
> +        if (p.available == PA_PORT_AVAILABLE_YES)
> +            desc += " (plugged in)";
> +        else if (p.available == PA_PORT_AVAILABLE_NO)
> +            desc += " (unplugged)";
> +
> +        if ((typeid(*w) == typeid(SinkWidget)) && (p.direction == PA_DIRECTION_OUTPUT))
> +            w->ports.push_back(std::pair<Glib::ustring,Glib::ustring>(p.name, desc));
> +        else if ((typeid(*w) == typeid(SourceWidget)) && (p.direction == PA_DIRECTION_INPUT))
> +            w->ports.push_back(std::pair<Glib::ustring,Glib::ustring>(p.name, desc));
> +    }
> +

The ports variable contains all ports of a card. Here I think you add
all output ports of a card to all sinks of the card and all input ports
to all sources. That's not right, a sink may have only a subset of the
card's output ports assigned to it.

The "plugged in" and "unplugged" strings should probably be
translatable. (Same for the profile code.)

>      it = ports.find(w->activePort);
>  
>      if (it != ports.end()) {
> @@ -295,12 +311,6 @@ void MainWindow::updateCard(const pa_card_info &info) {
>          profile_priorities.insert(info.profiles[i]);
>      }
>  
> -    w->profiles.clear();
> -    for (std::set<pa_card_profile_info>::iterator i = profile_priorities.begin(); i != profile_priorities.end(); ++i)
> -        w->profiles.push_back(std::pair<Glib::ustring,Glib::ustring>(i->name, i->description));
> -
> -    w->activeProfile = info.active_profile ? info.active_profile->name : "";
> -
>      w->ports.clear();
>      for (uint32_t i = 0; i < info.n_ports; ++i) {
>          PortInfo p;
> @@ -311,10 +321,46 @@ void MainWindow::updateCard(const pa_card_info &info) {
>          p.available = info.ports[i]->available;
>          p.direction = info.ports[i]->direction;
>          p.latency_offset = info.ports[i]->latency_offset;
> +        for (uint32_t j = 0; j < info.ports[i]->n_profiles; j++)
> +            p.profiles.push_back(info.ports[i]->profiles[j]->name);
>  
>          w->ports[p.name] = p;
>      }
>  
> +    w->profiles.clear();
> +    for (std::set<pa_card_profile_info>::iterator profileIt = profile_priorities.begin(); profileIt != profile_priorities.end(); ++profileIt) {
> +        bool hasYes = false, hasNo = false, hasOther = false;
> +        std::map<Glib::ustring, PortInfo>::iterator portIt;
> +        Glib::ustring desc = profileIt->description;
> +
> +        for (portIt = w->ports.begin(); portIt != w->ports.end(); portIt++) {
> +            PortInfo port = (*portIt).second;
> +
> +            if (std::find(port.profiles.begin(), port.profiles.end(), profileIt->name) == port.profiles.end())
> +                continue;
> +
> +            switch (port.available) {
> +                case PA_PORT_AVAILABLE_YES:
> +                    hasYes = true;
> +                    break;
> +                case PA_PORT_AVAILABLE_NO:
> +                    hasNo = true;
> +                    break;
> +                default:
> +                    hasOther = true;
> +                    break;
> +            }
> +        }
> +        if (hasNo && !hasYes && !hasOther)
> +            desc += " (unplugged)";
> +        else if (hasYes && !hasNo && !hasOther)
> +            desc += " (plugged in)";

I think profiles should be "plugged in" if any port is available.

-- 
Tanu



More information about the pulseaudio-discuss mailing list