PDA

View Full Version : Writing screensavers



mwphoto
2005-06-02, 06:03
Hi,

I've run into a problem writing a screensaver/plugin. Since I might be using
the wrong approach entirely I'll explain what I want first:

I would like to write some code that executes if a number button is pressed
while a track is playing.

Initially I thought I'd write a standard plugin, however the downside of
this is that if the squeezebox is not in the particular mode defined by my
plugin it stops working. Ie if I navigate away from my plugin in the menu
other modes take over and the number keys no longer do what I want.

Then I thought I'd write a screensaver, however in Default.map all number
keys may to 'done'. I could change this but I'm not sure of the impact on
other screensavers. ie if another screensaver was activated and received a
'screensaver0' function (or whatever) would it ignore it? treat it as done?
I'm not sure.

Is there a better place to intercept the button pressing?

I'd be interested in any comments on any of the above.

Thanks

Malcolm

mwphoto
2005-06-03, 04:19
Following on, I've now written a screensaver that's does what I want, but I
have a bug.

I use the lines function to display what I need, and I can tell this
function is called every second or so while the screensaver is active.
Unfortunately although the return value of the lines function is changing
the SB2 doesn't update until I press a key to make it leave screensaver mode
and return.

This means the display is right every time I enter screensaver mode, but it
never updates. Is there a function I have to call to make the display
update? it seems returning different values for the lines function is not
enough.

Thanks

Malcolm

Triode
2005-06-03, 04:28
Is there a function I have to call to make the display
> update? it seems returning different values for the lines function is not
> enough.

Set the following:
$client->param('modeUpdateInterval', 1);

Usually when you set $client->lines to be your lines function.

This should cause your lines function to be called once per second [change the 1 to be called at a different rate]

Adrian

mherger
2005-06-03, 04:30
> Following on, I've now written a screensaver that's does what I want,
> but I have a bug.

It's not a bug, it's a feature ;-)

> This means the display is right every time I enter screensaver mode, but
> it
> never updates. Is there a function I have to call to make the display
> update?

Add the following line to your screensaver mode:

# setting this param will call client->update() frequently
$client->param('modeUpdateInterval', 1);

--

Michael

-----------------------------------------------------------
Help translate SlimServer by using the
StringEditor Plugin (http://www.herger.net/slim/)

mwphoto
2005-06-03, 05:22
Thanks,

I'll try as soon as I can (SB2 in use by other family members right now).
However I have a suspicion that this is not it. If I put a debug message in
the lines function I can see it being called every second or so already.
I'll report back when I've been able to do a proper test.

Malcolm

> -----Original Message-----
> From: developers-bounces (AT) lists (DOT) slimdevices.com
> [mailto:developers-bounces (AT) lists (DOT) slimdevices.com]On Behalf Of Michael
> Herger
> Sent: 03 June 2005 12:31
> To: Slim Devices Developers
> Subject: Re: [Developers] Writing screensavers
>
>
> > Following on, I've now written a screensaver that's does what I want,
> > but I have a bug.
>
> It's not a bug, it's a feature ;-)
>
> > This means the display is right every time I enter screensaver
> mode, but
> > it
> > never updates. Is there a function I have to call to make the display
> > update?
>
> Add the following line to your screensaver mode:
>
> # setting this param will call client->update() frequently
> $client->param('modeUpdateInterval', 1);
>
> --
>
> Michael
>
> -----------------------------------------------------------
> Help translate SlimServer by using the
> StringEditor Plugin (http://www.herger.net/slim/)
>
>

mherger
2005-06-03, 05:30
> I'll try as soon as I can (SB2 in use by other family members right now).
> However I have a suspicion that this is not it. If I put a debug message
> in
> the lines function I can see it being called every second or so already.
> I'll report back when I've been able to do a proper test.

You can trust in Adrian - he's the guy who's written all that stuff. And
it's working perfectly well with my screensaver.

--

Michael

-----------------------------------------------------------
Help translate SlimServer by using the
StringEditor Plugin (http://www.herger.net/slim/)

mwphoto
2005-06-03, 06:31
Ok the problem persists . . .

Here's the relevant functions

The screensaver init calls

Slim::Buttons::Common::addSaver(
'SCREENSAVER.rateMe',
getScreensaverFunctions(),
\&setScreensaverMode,
\&leaveScreensaverMode,
string('PLUGIN_RATEME')
);

And the registered functions are:

sub setScreensaverMode {
my $client = shift;
$client->param('modeUpdateInterval', 1);
$client->lines(\&lines);
}

sub leaveScreensaverMode {
my $client = shift;
}

sub lines {
my $client = shift;
my $displayLine = $client->currentSongLines()->{line2};
print "Displaying $displayLine\n";
return ("RATABLE",$displayLine);
}

When I run this I get the following behaviour:

When the track starts I see the lines function called every second or so,
the displayLine is as expected (it's the song). At this stage the
screensaver is not running.

When the screensaver kicks in the SB2 also shows the song (this is the
correct behaviour)

As the song transitions to the next track the log shows the lines function
is returning the new track details. However the SB2 display continues to
show the old track details (incorrect behaviour).

If I do something to come out of screensaver mode it will be correct again
when it returns to screensaver mode.

I'm using 6.03 server code and firmware 11 in my SB2.

Any thoughts?

Malcolm

> -----Original Message-----
> From: developers-bounces (AT) lists (DOT) slimdevices.com
> [mailto:developers-bounces (AT) lists (DOT) slimdevices.com]On Behalf Of Michael
> Herger
> Sent: 03 June 2005 13:30
> To: Slim Devices Developers
> Subject: Re: [Developers] Writing screensavers
>
>
> > I'll try as soon as I can (SB2 in use by other family members
> right now).
> > However I have a suspicion that this is not it. If I put a
> debug message
> > in
> > the lines function I can see it being called every second or so already.
> > I'll report back when I've been able to do a proper test.
>
> You can trust in Adrian - he's the guy who's written all that stuff. And
> it's working perfectly well with my screensaver.
>
> --
>
> Michael
>
> -----------------------------------------------------------
> Help translate SlimServer by using the
> StringEditor Plugin (http://www.herger.net/slim/)
>
>

Triode
2005-06-03, 07:01
> Ok the problem persists . . .
>

Malcolm,

Could you put a backtrace in the lines function. It may be called by update or scrollBottom in the 6.0 code. On SB2, it's only
update that will display anything if the text does not need to scroll. (So we need to check update is calling it, scrollBottom is
not useful...)

If you were to use 6.1 trunk it gets rid of scrollBottom and should give a different result.

[backtrace = Slim::Utils::Misc::bt()]

Robert Moser
2005-06-03, 07:39
Malcolm Wotton wrote:
> Then I thought I'd write a screensaver, however in Default.map all number
> keys may to 'done'. I could change this but I'm not sure of the impact on
> other screensavers. ie if another screensaver was activated and received a
> 'screensaver0' function (or whatever) would it ignore it? treat it as done?
> I'm not sure.

If you change the 'done' in the [screensaver] mode to a function name
that didn't exist either in common.pm or in the other screensaver modes
it would end up being ignored.

> Is there a better place to intercept the button pressing?

Yes, you can set up the default mapping for your plugin by providing a
defaultMap() function. Then that mapping will take precedence over the
[screensaver] mapping, for those buttons which you care about. In your
case, you only want to override the number buttons so your defaultMap
would look something like this:

sub defaultMap {
return { '0' => 'rate_0',
'1' => 'rate_1',
'2' => 'rate_2',
'3' => 'rate_3',
'4' => 'rate_4',
'5' => 'rate_5',
'6' => 'rate_6',
'7' => 'rate_7',
'8' => 'rate_8',
'9' => 'rate_9'};
}

mwphoto
2005-06-03, 09:27
Thanks for taking a look,

The update backtrace appears only once:

2005-06-03 17:22:14.6595 Backtrace:

frame 0: Plugins::RateMe::lines (/PerlApp/Slim/Display/Display.pm line
120)
frame 1: Slim::Display::Display::curLines
(/PerlApp/Slim/Player/SqueezeboxG.pm line 147)
frame 2: Slim::Player::SqueezeboxG::update
(/PerlApp/Slim/Buttons/ScreenSaver.pm line 113)
frame 3: Slim::Buttons::ScreenSaver::screenSaver
(/PerlApp/Slim/Utils/Timers.pm line 62)
frame 4: Slim::Utils::Timers::checkTimers (slimserver.pl line 624)
frame 5: main::idle (slimserver.pl line 562)
frame 6: main::main (slimserver.pl line 61)
frame 7: PerlSvc::Interactive (perlsvc line 1208)
frame 8: PerlSvc::_interactive (slimserver.pl line 0)
frame 9: (eval) (slimserver.pl line 0)

Displaying Platform End - Manfred Mann's Earth Band - Angel Station

After that I get regular backtrace reports as follows:

2005-06-03 17:11:30.9082 Backtrace:

frame 0: Plugins::RateMe::lines (/PerlApp/Slim/Player/SqueezeboxG.pm line
622)
frame 1: Slim::Player::SqueezeboxG::scrollUpdate
(/PerlApp/Slim/Utils/Timers.pm line 62)
frame 2: Slim::Utils::Timers::checkTimers (slimserver.pl line 624)
frame 3: main::idle (slimserver.pl line 562)
frame 4: main::main (slimserver.pl line 61)
frame 5: PerlSvc::Interactive (perlsvc line 1208)
frame 6: PerlSvc::_interactive (slimserver.pl line 0)
frame 7: (eval) (slimserver.pl line 0)

Displaying Platform End - Manfred Mann's Earth Band - Angel Station

Each of these is identical.

Does that help the diagnosis?

Malcolm



> -----Original Message-----
> From: developers-bounces (AT) lists (DOT) slimdevices.com
> [mailto:developers-bounces (AT) lists (DOT) slimdevices.com]On Behalf Of Triode
> Sent: 03 June 2005 15:01
> To: Slim Devices Developers
> Subject: Re: [Developers] Writing screensavers
>
>
> > Ok the problem persists . . .
> >
>
> Malcolm,
>
> Could you put a backtrace in the lines function. It may be
> called by update or scrollBottom in the 6.0 code. On SB2, it's only
> update that will display anything if the text does not need to
> scroll. (So we need to check update is calling it, scrollBottom is
> not useful...)
>
> If you were to use 6.1 trunk it gets rid of scrollBottom and
> should give a different result.
>
> [backtrace = Slim::Utils::Misc::bt()]
>
>

mwphoto
2005-06-03, 09:38
Thanks for the hint,

I've set up the function - does it need to be registered anywhere or is it
called automatically? I haven't registered it, and it doesn't seem to work.
So I'm hopinh I need to register it :)

Malcolm

> -----Original Message-----
> From: developers-bounces (AT) lists (DOT) slimdevices.com
> [mailto:developers-bounces (AT) lists (DOT) slimdevices.com]On Behalf Of Robert
> Moser
> Sent: 03 June 2005 15:40
> To: Slim Devices Developers
> Subject: Re: [Developers] Writing screensavers
>
>
> Malcolm Wotton wrote:
> > Then I thought I'd write a screensaver, however in Default.map
> all number
> > keys may to 'done'. I could change this but I'm not sure of the
> impact on
> > other screensavers. ie if another screensaver was activated and
> received a
> > 'screensaver0' function (or whatever) would it ignore it? treat
> it as done?
> > I'm not sure.
>
> If you change the 'done' in the [screensaver] mode to a function name
> that didn't exist either in common.pm or in the other screensaver modes
> it would end up being ignored.
>
> > Is there a better place to intercept the button pressing?
>
> Yes, you can set up the default mapping for your plugin by providing a
> defaultMap() function. Then that mapping will take precedence over the
> [screensaver] mapping, for those buttons which you care about. In your
> case, you only want to override the number buttons so your defaultMap
> would look something like this:
>
> sub defaultMap {
> return { '0' => 'rate_0',
> '1' => 'rate_1',
> '2' => 'rate_2',
> '3' => 'rate_3',
> '4' => 'rate_4',
> '5' => 'rate_5',
> '6' => 'rate_6',
> '7' => 'rate_7',
> '8' => 'rate_8',
> '9' => 'rate_9'};
> }
>
>
>
>

mwphoto
2005-06-03, 09:48
Apologies, I just discovered that the default map is registered
automatically. However it doesn't seem to work . . .

Here's a trace with --d_ir

C:\Software\SlimServer\server>perl slimserver.pl --d_ir
2005-06-03 17:42:53.3437 irfile entry: Slim_Devices_Remote.ir
2005-06-03 17:42:53.3442 irfile entry: jvc_dvd.ir
2005-06-03 17:42:53.3444 opening IR file
C:\Software\SlimServer\server\IR\jvc_dv
d.ir
2005-06-03 17:42:53.3468 opening IR file
C:\Software\SlimServer\server\IR\Slim_D
evices_Remote.ir
2005-06-03 17:42:53.3490 key mapping file entry: Default.map
2005-06-03 17:42:53.3495 opening map file
C:\Software\SlimServer\server\IR\Defau
lt.map
2005-06-03 17:42:56.3251 Registering defaultMap for 'Picks'
2005-06-03 17:42:56.3368 Registering defaultMap for 'Picks'
2005-06-03 17:42:56.3596 Registering defaultMap for 'Picks'
2005-06-03 17:42:56.3690 Registering defaultMap for 'Picks'
2005-06-03 17:42:56.3763 Registering defaultMap for 'Picks'
2005-06-03 17:42:56.5962 Registering defaultMap for 'Picks'
2005-06-03 17:42:56.6035 Registering defaultMap for 'Picks'
2005-06-03 17:42:56.6039 Registering defaultMap for 'RateMe'
2005-06-03 17:42:56.6493 Registering defaultMap for 'Picks'
2005-06-03 17:42:56.6497 Registering defaultMap for 'RateMe'
2005-06-03 17:42:56.6576 Registering defaultMap for 'Picks'
2005-06-03 17:42:56.6580 Registering defaultMap for 'RateMe'
2005-06-03 17:42:56.6663 Registering defaultMap for 'Picks'
2005-06-03 17:42:56.6667 Registering defaultMap for 'RateMe'
2005-06-03 17:42:56.6756 Registering defaultMap for 'Picks'
2005-06-03 17:42:56.6760 Registering defaultMap for 'RateMe'
2005-06-03 17:42:56.6852 Registering defaultMap for 'Picks'
2005-06-03 17:42:56.6856 Registering defaultMap for 'RateMe'
2005-06-03 17:42:56.6858 Registering defaultMap for 'SavePlaylist'
2005-06-03 17:42:56.7149 Registering defaultMap for 'Picks'
2005-06-03 17:42:56.7153 Registering defaultMap for 'RateMe'
2005-06-03 17:42:56.7155 Registering defaultMap for 'SavePlaylist'
2005-06-03 17:42:56.7970 Registering defaultMap for 'Picks'
2005-06-03 17:42:56.7976 Registering defaultMap for 'RateMe'
2005-06-03 17:42:56.7978 Registering defaultMap for 'SavePlaylist'
2005-06-03 17:42:56.8281 Registering defaultMap for 'Picks'
2005-06-03 17:42:56.8286 Registering defaultMap for 'RateMe'
2005-06-03 17:42:56.8288 Registering defaultMap for 'SavePlaylist'
2005-06-03 17:42:56.8502 Registering defaultMap for 'Picks'
2005-06-03 17:42:56.8506 Registering defaultMap for 'RateMe'
2005-06-03 17:42:56.8508 Registering defaultMap for 'SavePlaylist'
2005-06-03 17:42:56.8888 Registering defaultMap for 'Picks'
2005-06-03 17:42:56.8893 Registering defaultMap for 'RateMe'
2005-06-03 17:42:56.8895 Registering defaultMap for 'SavePlaylist'
2005-06-03 17:43:58.2538 7689f00f 258236.406 1117817038.25382
2005-06-03 17:43:58.2551 irfile entry: Slim_Devices_Remote.ir
2005-06-03 17:43:58.2555 irfile entry: jvc_dvd.ir
2005-06-03 17:43:58.2560 found button 1 for 7689f00f
2005-06-03 17:43:58.2563 found function done for button 1 in mode class
screensa
ver from map C:\Software\SlimServer\server\IR\Default.map
2005-06-03 17:43:58.2566 irCode = [done] timer = [258236.406] timediff =
[258236
..406] last = []
2005-06-03 17:43:58.2568 irCode: done, 00:04:20:05:ac:47
2005-06-03 17:43:58.2576 irCode not defined: done
2005-06-03 17:43:58.2579 trying to execute button: done
2005-06-03 17:43:58.2583 executing button: done
2005-06-03 17:43:58.3596 7689f00f 258236.512 1117817038.35963
2005-06-03 17:43:58.3606 irfile entry: Slim_Devices_Remote.ir
2005-06-03 17:43:58.3610 irfile entry: jvc_dvd.ir
2005-06-03 17:43:58.3613 found button 1 for 7689f00f
2005-06-03 17:43:58.3616 irCode not defined: 1.repeat
2005-06-03 17:43:58.3618 irCode = [] timer = [258236.512] timediff =
[0.10599999
9999767] last = [done]
2005-06-03 17:43:58.4687 7689f00f 258236.621 1117817038.46872
2005-06-03 17:43:58.4697 irfile entry: Slim_Devices_Remote.ir
2005-06-03 17:43:58.4700 irfile entry: jvc_dvd.ir
2005-06-03 17:43:58.4704 found button 1 for 7689f00f
2005-06-03 17:43:58.4707 irCode not defined: 1.repeat
2005-06-03 17:43:58.4709 irCode = [] timer = [258236.621] timediff =
[0.10900000
0025844] last = [done]
2005-06-03 17:43:58.7839 irfile entry: Slim_Devices_Remote.ir
2005-06-03 17:43:58.7843 irfile entry: jvc_dvd.ir
2005-06-03 17:43:58.7847 found button 1 for 7689f00f
2005-06-03 17:43:58.7850 irCode not defined: 1.single
Terminating on signal SIGINT(2)

C:\Software\SlimServer\server>


I added the lines reporting the registration of the defaultMap, otherwise
nothing has changed. . . . It seems that the defaultMap isn't used even
though it got registered. I'll see if I can trace further and work out what
happened, but if you have any ideas that may help initially I'd be grateful.

Thanks

Malcolm

Malcolm


> -----Original Message-----
> From: developers-bounces (AT) lists (DOT) slimdevices.com
> [mailto:developers-bounces (AT) lists (DOT) slimdevices.com]On Behalf Of Robert
> Moser
> Sent: 03 June 2005 15:40
> To: Slim Devices Developers
> Subject: Re: [Developers] Writing screensavers
>
>
> Malcolm Wotton wrote:
> > Then I thought I'd write a screensaver, however in Default.map
> all number
> > keys may to 'done'. I could change this but I'm not sure of the
> impact on
> > other screensavers. ie if another screensaver was activated and
> received a
> > 'screensaver0' function (or whatever) would it ignore it? treat
> it as done?
> > I'm not sure.
>
> If you change the 'done' in the [screensaver] mode to a function name
> that didn't exist either in common.pm or in the other screensaver modes
> it would end up being ignored.
>
> > Is there a better place to intercept the button pressing?
>
> Yes, you can set up the default mapping for your plugin by providing a
> defaultMap() function. Then that mapping will take precedence over the
> [screensaver] mapping, for those buttons which you care about. In your
> case, you only want to override the number buttons so your defaultMap
> would look something like this:
>
> sub defaultMap {
> return { '0' => 'rate_0',
> '1' => 'rate_1',
> '2' => 'rate_2',
> '3' => 'rate_3',
> '4' => 'rate_4',
> '5' => 'rate_5',
> '6' => 'rate_6',
> '7' => 'rate_7',
> '8' => 'rate_8',
> '9' => 'rate_9'};
> }
>
>
>
>

Robert Moser
2005-06-03, 09:54
Malcolm Wotton wrote:
> Thanks for the hint,
>
> I've set up the function - does it need to be registered anywhere or is it
> called automatically? I haven't registered it, and it doesn't seem to work.
> So I'm hopinh I need to register it :)
>
> Malcolm

My mistake, I assumed that the $plugins{$plugin}{'mode'} would be set to
SCREENSAVER.rateMe when the plugin was added, but it isn't, it is
PLUGIN.rateMe instead. So, you'll have to be a little trickier in your
defaultMap, as follows:

sub defaultMap {
my $defaultMap = { '0' => 'rate_0',
'1' => 'rate_1',
'2' => 'rate_2',
'3' => 'rate_3',
'4' => 'rate_4',
'5' => 'rate_5',
'6' => 'rate_6',
'7' => 'rate_7',
'8' => 'rate_8',
'9' => 'rate_9'};
Slim::Hardware::IR::addModeDefaultMapping (
'SCREENSAVER.rateMe', $defaultMap);
return $defaultMap;
}

This ensures that both the SCREENSAVER.rateMe and the PLUGIN.rateMe
modes have the number buttons defined.

Triode
2005-06-03, 09:59
Ah - Your text is scrolling (scrollUpdate calling your lines) - i.e. is longer than one screen.
With 6.0, this is a known limitation of the scrolling code. The now playing modes interrupt scrolling by with
Slim::Music::Info::setCurrentTitleChangeCallback so that a title change can kill animation.

If you are willing to use 6.1 instead, this contains new display code which doesn't suffer this problem.

Otherwise if you want to stick with 6.0, you probably want to cache line2, test if it has changed from last time and do
$client->killAnimation() to kill off scrolling if so.

Adrian

> frame 0: Plugins::RateMe::lines (/PerlApp/Slim/Display/Display.pm line
> 120)
> frame 1: Slim::Display::Display::curLines
> (/PerlApp/Slim/Player/SqueezeboxG.pm line 147)
> frame 2: Slim::Player::SqueezeboxG::update
> (/PerlApp/Slim/Buttons/ScreenSaver.pm line 113)
> frame 3: Slim::Buttons::ScreenSaver::screenSaver
> (/PerlApp/Slim/Utils/Timers.pm line 62)
> frame 4: Slim::Utils::Timers::checkTimers (slimserver.pl line 624)
> frame 5: main::idle (slimserver.pl line 562)
> frame 6: main::main (slimserver.pl line 61)
> frame 7: PerlSvc::Interactive (perlsvc line 1208)
> frame 8: PerlSvc::_interactive (slimserver.pl line 0)
> frame 9: (eval) (slimserver.pl line 0)

Dan Sully
2005-06-03, 10:01
* Malcolm Wotton shaped the electrons to say...

>I'm coming to the conclusion that I need to be playing on the 6.1 trunk
>rather than the 6.03 release. Is it possible to get CVS access so I can keep
>in step with the latest code without downloading the 15Mb per day of
>packaged perl scripts? I can only find references to the nightly build code
>not the anything about CVS access.
>
>NB I don't need update access, I just want to be able to sync with the
>nightly build on a periodic basis without having to download zipfiles all
>the time.

http://www.slimdevices.com/dev_resources.html#subversion

-D
--
You know, for kids.