PDA

View Full Version : 7.3. Boom Line Out plugin... can I adapt it?



ModelCitizen
2008-10-12, 00:25
Hello,

As the new Line Out options and Line Out plugin has been included with 7.3 nightly now I've upgraded to 7.3... which went very well and all appears to work perfectly well.... including the Line Out stuff, which has added extra functionality to the device and makes headphone listening practical (thank you Slim!).

The Line Out plugin (disabled by default) allows you to add the Line Out options to the top level Boom menu... so any user of my Booms can easily switch between headphones and speakers, without delving into settings/audio.

However, to make it even more obvious for my family and house guests I thought I'd adapt the plugin such that it announced itself on the main Boom menu as Headphones (which I've done by editing strings.txt) and allow only two options, Yes and No. I know almost zero about programming but thought I might be able to achieve this by hacking the code in C:\Program Files\SqueezeCenter\server\Slim\Plugin\LineOut\Plu gin.pm

But it looks to me that I can't, as basically the code I want is somewhere else (maybe Slim::Buttons::Settings::analogOutMenu?) and probably has import I am not aware of (i.e. I am likely to mess up a lot more stuff... and/or install Active Perl to get anything to work).

If anyone reading this is familiar with the architecture of plugins I'd be very appreciative if they could simply say "No, don't go there"... or, "yes, you can do it by hacking only Plugin.pm"

Thanks.

No, I had no idea which was the best forum to post this in.

MC

mherger
2008-10-12, 23:57
> But it looks to me that I can't, as basically the code I want is
> somewhere else (maybe Slim::Buttons::Settings::analogOutMenu?) and
> probably has import I am not aware of (i.e. I am likely to mess up a
> lot more stuff... and/or install Active Perl to get anything to work).

Correct. You might be better off writing your own plugin. The menu code you'd need you'll find in the above module. Just rip out the items you don't want and rename them.

--

Michael

ModelCitizen
2008-10-13, 02:58
Just rip out the items you don't want and rename them.

Thanks for this Michael. I will have a go. Your use of the word "just" did make me laugh though.

MC

ModelCitizen
2008-10-13, 03:50
OK. I'm stuck.

Michael, this is not aimed at you (honestly!), but instead is aimed at anyone who uses headphones on the Boom, might benefit from this plugin and knows anything about programming perl and the SqueezeCentre architecture (I do mean anyhting... as it will be a darn site more than I know!).

I've done the easy bit and now have (by adapting the new Line Out plugin) a plugin that announces itself as Headphones, has the correct description and automatcally adds itself to the top level Boom menu.

Unfortunately the "hard bit" eludes me and the headphones Plugin still gives me the full Line Out options and not just "Yes" (for Headphones on) and "No" for full frequency speaker output only.

I run Windows without Active Perl so my SqueezeCenter is compiled. This is not a good starting point so I have downloaded the *nix installation and upnpacked it so I can rip the code out of one of the files.

In my entirely uninformed world it looks to me that I should be able to rip the analogOutMenu section from squeezecenter\Slim\Buttons\settings.pm (i.e Slim::Buttons::Settings::analogOutMenu), adapt it leaving only two options (ANALOGOUTMODE_HEADPHONE & ANALOGOUTMODE_ALWAYS_ON) which I then rename (somehow) to YES and NO.

Then I replace the reference to the section Slim::Buttons::Settings::analogOutMenu in plugin.pm with the adapted code.

But I can't make sense of the logic of the analogOutMenu section and have got lost.

The code in the plugin.pm which I thought might need replacing is somewhere in this bit (line 39 to 43):



Slim::Buttons::Common::pushModeLeft(
$client,
'INPUT.Choice',
Slim::Buttons::Settings::analogOutMenu()
);



The code I thought I might need to adapt before replacing the code above with it is Slim::Buttons::Settings::analogOutMenu (Line 974 to 1006), i.e:



sub analogOutMenu {
return {
'useMode' => 'INPUT.Choice',
'listRef' => [
{
name => '{ANALOGOUTMODE_HEADPHONE}',
value => 0,
},
{
name => '{ANALOGOUTMODE_SUBOUT}',
value => 1,
},
{
name => '{ANALOGOUTMODE_ALWAYS_ON}',
value => 2,
},
{
name => '{ANALOGOUTMODE_ALWAYS_OFF}',
value => 3,
},
],
'onPlay' => \&setPref,
'onAdd' => \&setPref,
'onRight' => \&setPref,
'header' => '{SETUP_ANALOGOUTMODE}',
'headerAddCount' => 1,
'pref' => "analogOutMode",
'initialValue' => sub { $prefs->client(shift)->get('analogOutMode') },
'condition' => sub {
my $client = shift;
return $client->hasHeadSubOut();
},
};



Any pointers as to whether this is entirely misguided (or not) would be very appreciated. :-(

MC

mherger
2008-10-13, 04:45
> OK. I'm stuck.

Are you trying to create your own plugin or patch the existing?

--

Michael

ModelCitizen
2008-10-13, 05:00
> OK. I'm stuck.
Are you trying to create your own plugin or patch the existing?
Michael
Sorry Michael.

I'm trying to create my own (by ripping yours off!).

I've copied the Line Out plugin, renamed it Headphones, adapted the strings, install.xml and identified name in plugin.pm. The adapted files are now in my SqueezeCenter/Server/Plugins/Headphones folder and the plugin and menu item appears correctly labelled and identified in the web and player uis.

So I do have a working Headphones plugin... but I do not get the preferred "Yes" and "No" choices. It still includes all the Line Out choices. :-(

MC

mherger
2008-10-13, 05:17
> I'm trying to create my own (by ripping yours off!).

Ok, instead of calling Slim::Buttons::Settings::analogOutMenu() you should call your own sub, which does basically the same as Slim::Buttons::Settings::analogOutMenu(), but with only the options you want. Something like



sub analogOutMenu {
return {
'useMode' => 'INPUT.Choice',
'listRef' => [
{
name => '{HEADPHONE_ON}',
value => 2,
},
{
name => '{HEADPHONE_OFF}',
value => 3,
},
],
'onPlay' => \&Slim::Browser::Settings::setPref,
'onAdd' => \&Slim::Browser::Settings::setPref,
'onRight' => \&Slim::Browser::Settings::setPref,
'header' => '{PLUGIN_HEADPHONE}',
'headerAddCount' => 1,
'pref' => "analogOutMode",
'initialValue' => sub { $prefs->client(shift)->get('analogOutMode') },
'condition' => sub {
my $client = shift;
return $client->hasHeadSubOut();
},
};
}

Use at your own risk - this is completely untested code :-). Make sure you're using the correct string tokens.

--

Michael

ModelCitizen
2008-10-13, 05:35
Thanks very much Michael. I'll play around with it..

I have a .net programmer sitting next to me so might drag him in...
:-)

MC

ModelCitizen
2008-10-13, 15:33
I've been attempting to get this working most of this evening but with no joy. My headphones plugin exists where it should on both player and web uis (i.e. announces itself correctly) but as soon as I add Michaels code to plugin.pm and restart SlimCenter the Headphones plugin item disappears from the Boom main menu.

To attempt to work out if the problem was with Michael's (as he states, untested) code I ripped the working analogOutMenu sub section code out of settings.pm and tried that instead (updating the tokens in the three relevant lines as noted by Michael). This failed in exactly the same way.

This leads me to believe that I might be getting something wrong in my replacement process, either replacing the wrong lines(s) in plugin.pm or perhaps getting the wrong amount of those squiggly brackets at the end of the code I am inserting.

Any suggestions from anyone would be appreciated (Michael, I'm sorry I really do not want to bother you).

For my test (using the code from settings.pm) I am replacing *only* line 42 in plugin.pm:


Slim::Buttons::Settings::analogOutMenu()


With this code from settings.pm (note that I've updated the three tokens, i.e &setPref has become &Slim::Browser::Settings::setPref).



sub analogOutMenu {
return {
'useMode' => 'INPUT.Choice',
'listRef' => [
{
name => '{ANALOGOUTMODE_HEADPHONE}',
value => 0,
},
{
name => '{ANALOGOUTMODE_SUBOUT}',
value => 1,
},
{
name => '{ANALOGOUTMODE_ALWAYS_ON}',
value => 2,
},
{
name => '{ANALOGOUTMODE_ALWAYS_OFF}',
value => 3,
},
],
'onPlay' => \&Slim::Browser::Settings::setPref,
'onAdd' => \&Slim::Browser::Settings::setPref,
'onRight' => \&Slim::Browser::Settings::setPref,
'header' => '{SETUP_ANALOGOUTMODE}',
'headerAddCount' => 1,
'pref' => "analogOutMode",
'initialValue' => sub { $prefs->client(shift)->get('analogOutMode') },
'condition' => sub {
my $client = shift;
return $client->hasHeadSubOut();
},
};
}


Can anyone say if I am replacing *exactly* the right line with *exactly* the right bit of code? Any comments at all (even if it's "it'd probably be best if you gave up") would be welcomed.

MC

mherger
2008-10-14, 00:25
What does server.log say? Enable debugging for server.plugins. And then you can always upload your file so we can reproduce your issue. But this would probably better go to the dev forum.

--

Michael

ModelCitizen
2008-10-14, 04:01
server.log does not show anything abnormal and it looks just like my Headphones plugin loaded in exactly the same way as the other third party plugins I use.

I will make a summary and start a thread in the developers forum as suggested.
Thanks Michael.

MC