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

2012-11-11 Thread Raymond Yau
> >
> > 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.)
> >
>
> Good catch. I got myself thinking that I could generalize the solution a
> little bit but it seems that we can't figure out which port belongs
> where just from pa_card_port_info.
>
> >
> > I think profiles should be "plugged in" if any port is available.
> >
>
i have doubt about it

the profile is not available when the jack available state of the port is
NO but all profiles have passed the open pcm test.

this mean that some port does not have jack detect capability (e.g. some
nvidia hdmi , spdif,  all pci sound cards and onboard ac97 sound card, )
___
pulseaudio-discuss mailing list
pulseaudio-discuss@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss


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

2012-11-11 Thread poljarinho
On Fri, Nov 09, 2012 at 08:17:02PM +0200, Tanu Kaskinen wrote:
> 
> 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.)
> 

Good catch. I got myself thinking that I could generalize the solution a
little bit but it seems that we can't figure out which port belongs
where just from pa_card_port_info.

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

For what its worth I agree with Tanu here.

I'll send a v2 of the patch next week.
___
pulseaudio-discuss mailing list
pulseaudio-discuss@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss


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

2012-11-10 Thread Tanu Kaskinen
On Sat, 2012-11-10 at 22:54 +0100, David Henningsson wrote:
> On 11/09/2012 08:26 PM, Tanu Kaskinen wrote:
> > On Fri, 2012-11-09 at 19:29 +0100, David Henningsson wrote:
> >> On 11/09/2012 07:17 PM, Tanu Kaskinen wrote:
> >>> On Thu, 2012-11-08 at 23:38 +0100, poljar (Damir Jelić) wrote:
>  +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.
> >>
> >> The reason I did it for profiles in the first place, were just to make
> >> the user get a hint about which one of the four HDMIs to select on the
> >> configuration tab, and there is just one port per profile in that scenario.
> >>
> >> I also think that if one port is available and another is not, we
> >> shouldn't say that the entire profile is "plugged in". It really only
> >> makes sense to write something when all of the ports have the same
> >> value. I e, the current code is correct IMO.
> >
> > What about laptop speakers that are always available (let's ignore the
> > fact that it looks like the analog-output-speaker port never reports
> > itself as "available", only "unknown" or "unavailable")? If headphones
> > are not plugged in, I think the output:analog-stereo profile is still
> > very much available ("plugged in" is not the best phrase in this case).
> >
> > I think the distinction between "all ports available" and "some ports
> > available" is confusing to the user,
> 
> I don't think that is confusing, and...

Ok.

> > and it would be better to drop that
> > distinction altogether. I would actually prefer not using any status
> > specifier for profiles, except if all ports are unavailable, in which
> > case I think "unplugged" is fine to signal to the user that this profile
> > is pretty useless.
> 
> ...I think that this last proposal would be more confusing as it treats 
> the states of "plugged in" and "unplugged" differently.

Well, I guess the problem is that profiles don't actually have "plugged
in" vs. "unplugged" state. Only individual inputs and outputs do. I can
see the usefulness for telling the user when we know for sure that a
profile is useless. I see less usefulness in telling when we know that
all ports of a profile are available, since I believe in most cases
profiles will be only partially connected, despite being still useful,
and displaying some profiles as "plugged in" undermines the user's
confidence in the fine profiles that don't have any specifier.

But if I'm not convincing anyone here, I'm certainly not blocking on
this issue.

-- 
Tanu

___
pulseaudio-discuss mailing list
pulseaudio-discuss@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss


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

2012-11-10 Thread Raymond Yau
>
> +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.
>>>
>>>
>>> The reason I did it for profiles in the first place, were just to make
>>> the user get a hint about which one of the four HDMIs to select on the
>>> configuration tab, and there is just one port per profile in that
scenario.
>>>
>>> I also think that if one port is available and another is not, we
>>> shouldn't say that the entire profile is "plugged in". It really only
>>> makes sense to write something when all of the ports have the same
>>> value. I e, the current code is correct IMO.
>>
>>
>> What about laptop speakers that are always available (let's ignore the
>> fact that it looks like the analog-output-speaker port never reports
>> itself as "available", only "unknown" or "unavailable")? If headphones
>> are not plugged in, I think the output:analog-stereo profile is still
>> very much available ("plugged in" is not the best phrase in this case).
>>
>> I think the distinction between "all ports available" and "some ports
>> available" is confusing to the user,
>
>
> I don't think that is confusing, and...
>
>
>> and it would be better to drop that
>> distinction altogether. I would actually prefer not using any status
>> specifier for profiles, except if all ports are unavailable, in which
>> case I think "unplugged" is fine to signal to the user that this profile
>> is pretty useless.
>
>
> ...I think that this last proposal would be more confusing as it treats
the states of "plugged in" and "unplugged" differently.
>

the name of the module-switch-on-available-port is already confusing when
the logic is switch away from unavailable port

after the implementaton of spdif phantom port, the active port is
automatically switched to iec958 from the rear analog jack of desktop
___
pulseaudio-discuss mailing list
pulseaudio-discuss@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss


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

2012-11-10 Thread David Henningsson

On 11/09/2012 08:26 PM, Tanu Kaskinen wrote:

On Fri, 2012-11-09 at 19:29 +0100, David Henningsson wrote:

On 11/09/2012 07:17 PM, Tanu Kaskinen wrote:

On Thu, 2012-11-08 at 23:38 +0100, poljar (Damir Jelić) wrote:

+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.


The reason I did it for profiles in the first place, were just to make
the user get a hint about which one of the four HDMIs to select on the
configuration tab, and there is just one port per profile in that scenario.

I also think that if one port is available and another is not, we
shouldn't say that the entire profile is "plugged in". It really only
makes sense to write something when all of the ports have the same
value. I e, the current code is correct IMO.


What about laptop speakers that are always available (let's ignore the
fact that it looks like the analog-output-speaker port never reports
itself as "available", only "unknown" or "unavailable")? If headphones
are not plugged in, I think the output:analog-stereo profile is still
very much available ("plugged in" is not the best phrase in this case).

I think the distinction between "all ports available" and "some ports
available" is confusing to the user,


I don't think that is confusing, and...


and it would be better to drop that
distinction altogether. I would actually prefer not using any status
specifier for profiles, except if all ports are unavailable, in which
case I think "unplugged" is fine to signal to the user that this profile
is pretty useless.


...I think that this last proposal would be more confusing as it treats 
the states of "plugged in" and "unplugged" differently.



--
David Henningsson, Canonical Ltd.
https://launchpad.net/~diwic
___
pulseaudio-discuss mailing list
pulseaudio-discuss@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss


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

2012-11-09 Thread Raymond Yau
> > >> +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.
> >
> > The reason I did it for profiles in the first place, were just to make
> > the user get a hint about which one of the four HDMIs to select on the
> > configuration tab, and there is just one port per profile in that
scenario.
> >
> > I also think that if one port is available and another is not, we
> > shouldn't say that the entire profile is "plugged in". It really only
> > makes sense to write something when all of the ports have the same
> > value. I e, the current code is correct IMO.
>
> What about laptop speakers that are always available (let's ignore the
> fact that it looks like the analog-output-speaker port never reports
> itself as "available", only "unknown" or "unavailable")? If headphones
> are not plugged in, I think the output:analog-stereo profile is still
> very much available ("plugged in" is not the best phrase in this case).

this is confusing when the speaker are always plugged into the rear panel
jack for most desktop user but pulseaudio just report the state is unknown
___
pulseaudio-discuss mailing list
pulseaudio-discuss@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss


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

2012-11-09 Thread Tanu Kaskinen
On Fri, 2012-11-09 at 19:29 +0100, David Henningsson wrote:
> On 11/09/2012 07:17 PM, Tanu Kaskinen wrote:
> > On Thu, 2012-11-08 at 23:38 +0100, poljar (Damir Jelić) wrote:
> >> +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.
> 
> The reason I did it for profiles in the first place, were just to make 
> the user get a hint about which one of the four HDMIs to select on the 
> configuration tab, and there is just one port per profile in that scenario.
> 
> I also think that if one port is available and another is not, we 
> shouldn't say that the entire profile is "plugged in". It really only 
> makes sense to write something when all of the ports have the same 
> value. I e, the current code is correct IMO.

What about laptop speakers that are always available (let's ignore the
fact that it looks like the analog-output-speaker port never reports
itself as "available", only "unknown" or "unavailable")? If headphones
are not plugged in, I think the output:analog-stereo profile is still
very much available ("plugged in" is not the best phrase in this case).

I think the distinction between "all ports available" and "some ports
available" is confusing to the user, and it would be better to drop that
distinction altogether. I would actually prefer not using any status
specifier for profiles, except if all ports are unavailable, in which
case I think "unplugged" is fine to signal to the user that this profile
is pretty useless.

-- 
Tanu

___
pulseaudio-discuss mailing list
pulseaudio-discuss@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss


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

2012-11-09 Thread David Henningsson

On 11/09/2012 07:17 PM, Tanu Kaskinen wrote:

On Thu, 2012-11-08 at 23:38 +0100, poljar (Damir Jelić) wrote:

+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.


The reason I did it for profiles in the first place, were just to make 
the user get a hint about which one of the four HDMIs to select on the 
configuration tab, and there is just one port per profile in that scenario.


I also think that if one port is available and another is not, we 
shouldn't say that the entire profile is "plugged in". It really only 
makes sense to write something when all of the ports have the same 
value. I e, the current code is correct IMO.



--
David Henningsson, Canonical Ltd.
https://launchpad.net/~diwic
___
pulseaudio-discuss mailing list
pulseaudio-discuss@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss


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

2012-11-09 Thread Tanu Kaskinen
On Thu, 2012-11-08 at 23:38 +0100, poljar (Damir Jelić) wrote:
> From: "poljar (Damir Jelić)" 
> 
> 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 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 
> &ports) {
>  std::map::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(p.name, desc));
> +else if ((typeid(*w) == typeid(SourceWidget)) && (p.direction == 
> PA_DIRECTION_INPUT))
> +
> w->ports.push_back(std::pair(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::iterator i = 
> profile_priorities.begin(); i != profile_priorities.end(); ++i)
> -
> w->profiles.push_back(std::pair(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::iterator profileIt = 
> profile_priorities.begin(); profileIt != profile_priorities.end(); 
> ++profileIt) {
> +bool hasYes = false, hasNo = false, hasOther = false;
> +std::map::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

___
pulseaudio-discuss mailing list
pulseaudio-discuss@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss


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

2012-11-09 Thread poljarinho
>iec958-stereo-output: Digital Output (S/PDIF) (priority 0, available:
>unknown)
>properties:
> 
>is there any simple way to find out the  cause of no sound problem of
>spdif of ad1989b on ubuntu 12.10 ? driver (No hda jack detect kcontrol)
>or pa 's spdif port priority
> 
>[2]https://bugs.launchpad.net/ubuntu/+source/alsa-driver/+bug/1076224
> 
>active profile: 
>sinks:
>alsa_output.pci-_00_1b.0.iec958-stereo/#6: Built-in Audio Digital
>Stereo (IEC958)
>sources:
>alsa_input.pci-_00_1b.0.analog-stereo/#1: Built-in Audio Analog
>Stereo
>alsa_output.pci-_00_1b.0.iec958-stereo.monitor/#8: Monitor of
>Built-in Audio Digital Stereo (IEC958)
>ports:
>analog-output: Analog Output (priority 9900, available: unknown)
>properties:
>analog-output-headphones: Headphones (priority 9000, available:
>unknown)
>properties:
>analog-input-microphone-front: Front Microphone (priority 8500,
>available: unknown)
>properties:
>analog-input-microphone: Microphone (priority 8700, available: unknown)
>properties:
>analog-input-linein: Line In (priority 8100, available: unknown)
>properties:
>iec958-stereo-input: iec958-stereo-input (priority 0, available:
>unknown)
>properties:
>iec958-stereo-output: Digital Output (S/PDIF) (priority 0, available:
>unknown)
>properties:

I'm sorry I don't know anything about this specific card. This patch
anyways only prints out the information thats already present within the
PA daemon.

Please start a new thread and provide some logs (e.g. the output of
pactl) maybe someone else on the list has any clue about this.
___
pulseaudio-discuss mailing list
pulseaudio-discuss@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss


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

2012-11-09 Thread Raymond Yau
2012-11-9 下午6:18 於  寫道:
>
> On Fri, Nov 09, 2012 at 11:03:14AM +0800, Raymond Yau wrote:
> >>
> >> 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).
> >
> >but the port has three state: yes, no and unknown
>
> Yes thats true, if we don't know the state of the port we don't print
> out anything.
> >
> >> A profile is also available/unavailable if all ports which have
that
> >> profile is available/unavailable.
> >
> >for surround 5.1, does it meant that pulseaudio have to check the
> >availability of the green, black and orange
> >
> >many professional sound card does not support jack detection since it
> >produce noise during the detection
> >
> >spdif jack does not has any jack detection
> >
>
> We check all the ports that belong to a certain profile. So yes if we
> have a surround profile we check all the surround ports for their state.

iec958-stereo-output: Digital Output (S/PDIF) (priority 0, available:
unknown)
properties:

is there any simple way to find out the  cause of no sound problem of spdif
of ad1989b on ubuntu 12.10 ? driver (No hda jack detect kcontrol) or pa 's
spdif port priority

https://bugs.launchpad.net/ubuntu/+source/alsa-driver/+bug/1076224

 active profile: 
sinks:
alsa_output.pci-_00_1b.0.iec958-stereo/#6: Built-in Audio Digital
Stereo (IEC958)
sources:
alsa_input.pci-_00_1b.0.analog-stereo/#1: Built-in Audio Analog Stereo
alsa_output.pci-_00_1b.0.iec958-stereo.monitor/#8: Monitor of Built-in
Audio Digital Stereo (IEC958)
ports:
analog-output: Analog Output (priority 9900, available: unknown)
properties:

analog-output-headphones: Headphones (priority 9000, available: unknown)
properties:

analog-input-microphone-front: Front Microphone (priority 8500, available:
unknown)
properties:

analog-input-microphone: Microphone (priority 8700, available: unknown)
properties:

analog-input-linein: Line In (priority 8100, available: unknown)
properties:

iec958-stereo-input: iec958-stereo-input (priority 0, available: unknown)
properties:

iec958-stereo-output: Digital Output (S/PDIF) (priority 0, available:
unknown)
properties:
___
pulseaudio-discuss mailing list
pulseaudio-discuss@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss


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

2012-11-09 Thread poljarinho
On Fri, Nov 09, 2012 at 11:03:14AM +0800, Raymond Yau wrote:
>>
>> 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).
> 
>but the port has three state: yes, no and unknown

Yes thats true, if we don't know the state of the port we don't print
out anything.
> 
>> A profile is also available/unavailable if all ports which have that
>> profile is available/unavailable.
> 
>for surround 5.1, does it meant that pulseaudio have to check the
>availability of the green, black and orange
> 
>many professional sound card does not support jack detection since it
>produce noise during the detection
> 
>spdif jack does not has any jack detection
> 

We check all the ports that belong to a certain profile. So yes if we
have a surround profile we check all the surround ports for their state.
___
pulseaudio-discuss mailing list
pulseaudio-discuss@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss


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

2012-11-08 Thread Raymond Yau
>
> 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).

but the port has three state: yes, no and unknown

> A profile is also available/unavailable if all ports which have that
> profile is available/unavailable.

for surround 5.1, does it meant that pulseaudio have to check the
availability of the green, black and orange

many professional sound card does not support jack detection since it
produce noise during the detection

spdif jack does not has any jack detection

>
> 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 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 &ports) {
>  std::map::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(
p.name, desc));
> +else if ((typeid(*w) == typeid(SourceWidget)) && (p.direction ==
PA_DIRECTION_INPUT))
> +w->ports.push_back(std::pair(
p.name, desc));
> +}
> +
>  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::iterator i =
profile_priorities.begin(); i != profile_priorities.end(); ++i)
> -
 w->profiles.push_back(std::pair(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::iterator profileIt =
profile_priorities.begin(); profileIt != profile_priorities.end();
++profileIt) {
> +bool hasYes = false, hasNo = false, hasOther = false;
> +std::map::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)";
> +
> +
 w->profiles.push_back(std::pair(profileIt->name,
desc));
> +}
> +
> +w->activeProfile = info.active_profile ? info.active_profile->name :
"";
> +
>  /* Because the port info for sinks and sources is discontinued we
need
>   * to update the port info for them here. */
>
> @@ -399,10 +445,6 @@ bool MainWindow::updateSink(const pa_sink_info
&info) {
>  port_priorities.insert(*info.ports[i]);
>  }
>
> -w->ports.clear();
> -for (std::set::iterator i =
port_priorities.begin(); i != port_priorities.end(); ++i)
> -
 w->ports.push_back(std::pair(i->name,
i->description));
> -
>  w->activePort = 

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

2012-11-08 Thread Damir Jelić
From: "poljar (Damir Jelić)" 

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 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 
&ports) {
 std::map::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(p.name, 
desc));
+else if ((typeid(*w) == typeid(SourceWidget)) && (p.direction == 
PA_DIRECTION_INPUT))
+w->ports.push_back(std::pair(p.name, 
desc));
+}
+
 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::iterator i = 
profile_priorities.begin(); i != profile_priorities.end(); ++i)
-w->profiles.push_back(std::pair(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::iterator profileIt = 
profile_priorities.begin(); profileIt != profile_priorities.end(); ++profileIt) 
{
+bool hasYes = false, hasNo = false, hasOther = false;
+std::map::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)";
+
+
w->profiles.push_back(std::pair(profileIt->name, 
desc));
+}
+
+w->activeProfile = info.active_profile ? info.active_profile->name : "";
+
 /* Because the port info for sinks and sources is discontinued we need
  * to update the port info for them here. */
 
@@ -399,10 +445,6 @@ bool MainWindow::updateSink(const pa_sink_info &info) {
 port_priorities.insert(*info.ports[i]);
 }
 
-w->ports.clear();
-for (std::set::iterator i = port_priorities.begin(); i 
!= port_priorities.end(); ++i)
-w->ports.push_back(std::pair(i->name, 
i->description));
-
 w->activePort = info.active_port ? info.active_port->name : "";
 
 cw = cardWidgets.find(info.card);
@@ -554,10 +596,6 @@ void MainWindow::updateSource(const pa_source_info &info) {
 port_priorities.insert(*info.ports[i]);
 }
 
-w->ports.clear();
-for (std::set::iterator i = port_priorities.begin(); 
i != port_priorities.end(); ++i)
-w->ports.push_back(std::pair(i->name, 
i->description));
-
 w->activePort = info.active_port ? info.active_port->name