PDA

View Full Version : Re: Location in code tochangetransitionbehavior(crossfade, etc)



mwphoto
2005-07-17, 14:04
Hi,

Here's my plugin verbatim . . .


----------------PLUGIN BEGINS

package Plugins::PreferenceManager;

use Slim::Player::Playlist;
use Slim::Player::Source;
use Slim::Player::Sync;
use Slim::Utils::Misc;
use Slim::Utils::Timers;
use Slim::Utils::Strings qw (string);
use Slim::Player::Client;
use Slim::Music::Info;

my $PREFM_HOOK = 0;
my $PREFM_PLUGIN_VERSION = "0.1";
my $PREFM_DEBUG=0;


my %controlFunction;
$controlFunction{'add'}='item';
$controlFunction{'append'}='item';
$controlFunction{'play'}='item';
$controlFunction{'load'}='item';
$controlFunction{'insert'}='item';
$controlFunction{'insertlist'}='item';
$controlFunction{'shuffle'}='shuffle';
$controlFunction{'playtracks'}='albumstyle';
$controlFunction{'loadtracks'}='albumstyle';
$controlFunction{'addtracks'}='albumstyle';
$controlFunction{'inserttracks'}='albumstyle';
$controlFunction{'loadalbum'}='albumstyle';
$controlFunction{'playalbum'}='albumstyle';
$controlFunction{'addalbum'}='albumstyle';
$controlFunction{'insertalbum'}='albumstyle';
$controlFunction{'deletealbum'}='albumstyle';
$controlFunction{'shuffle'}='shuffle';

sub initPlugin()
{
hookPM();
}

sub shutdownPlugin()
{
unHookPM();
}

sub getDisplayName()
{
return "PLUGIN_PREFERENCE_MANAGER";
}

sub strings
{
local $/ = undef;
<DATA>;
}

sub hookPM()
{
if ($PREFM_HOOK == 0) {
Plugins::PreferenceManager::pmMsg("PreferenceManager V$PREFM_PLUGIN_VERSION
activated.\n");
Slim::Player::Playlist::setExecuteCommandCallback( \&Plugins::PreferenceMana
ger::commandCallback);
$PREFM_HOOK=1;
}
else {
Plugins::PreferenceManager::pmMsg("PreferenceManager already active");
}
}

sub unHookPM()
{
if ($PREFM_HOOK == 1) {
# Note that CLI just has this as "...(\&commandCallback)";
# I'm not sure if what I've done is correct.
Plugins::PreferenceManager::pmMsg("PreferenceManager
V$PREFM_PLUGIN_VERSION deactivated.\n");
Slim::Player::Playlist::clearExecuteCommandCallbac k(\&Plugins::Prefer
enceManager::commandCallback);
$PREFM_HOOK=0;
}
else {
Plugins::PreferenceManager::pmMsg("PreferenceManager not active\n");
}
}

# A wrapper to allow us to uniformly turn on & off Scrobbler debug messages
sub pmMsg($)
{
# Parameter - Message to be displayed
my $pmMsg = shift;
unless ($pmMsg =~ /\n$/) {
$pmMsg .= "\n";
}
if ($PREFM_DEBUG)
{
msg($pmMsg);
}
}

sub commandCallback {
# These are the two passed parameters
my $client = shift;
my $paramsRef = shift;

# Some commands have no client associated with them, so we ignore them.
return if (!$client);
return unless (@$paramsRef[0] eq 'playlist');
my $paramOne = @$paramsRef[1];
return unless (exists($controlFunction{$paramOne}));
if ($controlFunction{$paramOne} eq 'item') {
pmMsg("Item style");
if (@$paramsRef[2] =~ /\.m3u$/i) {
setPlaylistPrefs($client);
}
else {
setAlbumPrefs($client);
}
}
if ($controlFunction{$paramOne} eq 'albumstyle') {
pmMsg("Album style");
setAlbumPrefs($client);
}
if ($controlFunction{$paramOne} eq 'shuffle') {
pmMsg("Shuffle");
setPlaylistPrefs($client);
}
}

sub setAlbumPrefs {
my $client = shift;
pmMsg("Setting Album Preferences");
Slim::Utils::Prefs::clientSet($client,"transitionDuration",0);
Slim::Utils::Prefs::clientSet($client,"transitionType",0);
}

sub setPlaylistPrefs {
my $client = shift;
pmMsg("Setting Playlist Preferences");
Slim::Utils::Prefs::clientSet($client,"transitionDuration",5);
Slim::Utils::Prefs::clientSet($client,"transitionType",4);
}

1;

__DATA__

PLUGIN_PREFERENCE_MANAGER
EN Preference Manager

----------------PLUGIN ENDS

mherger
2005-07-17, 14:15
Malcolm

> Here's my plugin verbatim . . .

I have no idea what it does... but

> sub strings
> {
> local $/ = undef;
> <DATA>;
> }

Putting the strings in <DATA> is depreciated since v6. It doesn't allow
the user to switch language without restarting slimserver. I know, I'm the
only one doing this :-).

Now I go and try to understand what the plugin actually does.

--

Michael

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

kdf
2005-07-20, 00:52
another note on this plugin, which you will be reminded about when you load the plugin (There is a warning sent out by the code). The following command will be deprecated after 6.1.

Slim::Player::Playlist::setExecuteCommandCallback( \&Plugins::PreferenceManager::commandCallback);

-kdf