Hallo,
ich benutze das von stylesuxx bzw. stavox (hier: http://forum.ubuntuusers.de/topic/perl-cpan-mpd/) gepostete Perl Skript um Informationen von mpd über LCDd auf einem 4x20 Display auszugeben.
#!/usr/bin/perl use IO::Socket; use Fcntl; use Audio::MPD; use Text::Wrap; # a MPD (Music Player Daemon) client # http://musicpd.org/ # buZz 2006 # http://lcdproc.spacedout.nl/ # Minor code changes by stavox # vars for customization $LCDHOST = "localhost"; $LCDPORT = "13666"; sub lcd { ($data,$debug) = @_; print $lcdproc $data."\n"; print $data."\n" if ($debug); $res = <$lcdproc>; } sub updatescreen { lcd("widget_set mpdlcd title {MPD $samplerate}"); if ($oldline1 ne $line1) { $oldline1=$line1; lcd("widget_set mpdlcd line1 1 2 ".$screen{wid}." 2 h 1 {$line1}",0); }; if ($oldline2 ne $line2) { $oldline2=$line2; lcd("widget_set mpdlcd line2 1 3 {$line2}",0); }; if ($oldline3 ne $line3) { $oldline3=$line3; lcd("widget_set mpdlcd line3 1 4 {$line3 $bitrate Kbit}",0); }; if ($oldhbar ne $hbar) { $oldhbar=$hbar; lcd("widget_set mpdlcd hbar 2 3 $hbar",0); }; }; $lcdproc = IO::Socket::INET->new( Proto => "tcp", PeerAddr => $LCDHOST, PeerPort => $LCDPORT, ) || die "Cannot connect to LCDd port\n"; $lcdproc->autoflush(1); sleep 1; print $lcdproc "hello\n"; @lcd_specs = split(/ /,<$lcdproc>); $screen{wid} = $lcd_specs[7]; $screen{hgt} = $lcd_specs[9]; $screen{cellwid} = $lcd_specs[11]; $screen{cellhgt} = $lcd_specs[13]; $screen{pixwid} = $screen{wid}*$screen{cellwid}; $screen{pixhgt} = $screen{hgt}*$screen{cellhgt}; fcntl($lcdproc, F_SETFL, O_NONBLOCK); lcd("client_set name {mpdlcd.pl}"); lcd("client_add_key A"); lcd("client_add_key C"); lcd("screen_add mpdlcd"); lcd("screen_set mpdlcd name {mpdlcd}"); lcd("screen_set mpdlcd heartbeat off"); lcd("widget_add mpdlcd title title"); #lcd("widget_set mpdlcd title {mpdlcd}"); lcd("screen_set mpdlcd priority 2"); lcd("widget_add mpdlcd line1 scroller"); lcd("widget_add mpdlcd line2 string"); lcd("widget_add mpdlcd line3 string"); lcd("widget_add mpdlcd line4 string"); lcd("widget_add mpdlcd hbar hbar"); $mpd = Audio::MPD->new('localhost', '6600', ''); $title = $mpd->song->as_string; $oldtitle = $title; $line1 = " ".$title." "; $bitrate = $mpd->status->bitrate; $samplerate = $mpd->status->audio; $Text::Wrap::columns = 21; while(1) { $ignore=0; $keypressed=0; $screenshowing=0; while(defined($input = <$lcdproc>)) { @lines = split(/\n/, $input); foreach $line (@lines) { if ( $line =~ /^success$/ ) { next; } if ( $line =~ /^listen (\w+)/ ) { $screenshowing = $1; } if ( $line =~ /^ignore (\S)/ ) { $ignore = -1; } if ( $line =~ /^key (\w)/ ) { $keypressed = $1; } } } $mpd->status(); $title = $mpd->song->as_string(); if ($keypressed eq "A") { $mpd->next; } if ($keypressed eq "C") { $mpd->pause($toggle); if ($toggle = 1) { $toggle = 0; } else { $toggle = 1; } } if ($title ne $oldtitle) { $oldtitle = $title; $alerttitle = $title; $alertline[1]=""; $alertline[2]=""; $alertline[3]=""; $alertline[4]=""; # $alerttitle =~ s/(.{1,19})(\s)/$1\n/g; $alerttitle = wrap('', '', $title); $templine=0; foreach $line (split /\n/,$alerttitle) { $templine++; $alertline[$templine]=$line; } lcd("widget_del mpdlcd title"); lcd("widget_del mpdlcd line1"); lcd("widget_add mpdlcd line1 string"); lcd("widget_set mpdlcd line1 1 1 {$alertline[1]}"); lcd("widget_set mpdlcd line2 1 2 {$alertline[2]}"); lcd("widget_set mpdlcd line3 1 3 {$alertline[3]}"); lcd("widget_set mpdlcd line4 1 4 {$alertline[4]}"); lcd("widget_set mpdlcd hbar 2 3 0"); sleep 4; lcd("widget_del mpdlcd line1"); lcd("widget_add mpdlcd title title"); lcd("widget_add mpdlcd line1 scroller"); lcd("widget_set mpdlcd title {mpdlcd}"); $line1 = " ".$title." "; $oldline1=""; $oldline2=""; $oldline3=""; $oldline4=""; $oldhbar=0; } $mpd->status(); $time = $mpd->{'time'}; if (defined($time)) { ($cursec, $totsec) = split /:/, $time; } $totsec = $mpd->status->time->seconds_total; $cursec = $mpd->status->time->seconds_sofar; $tottime = sprintf("%d:%02d",int($totsec / 60),$totsec - (60 * int($totsec / 60))); $curtime = sprintf("%d:%02d",int($cursec / 60),$cursec - (60 * int($cursec / 60))); $lefttime = $mpd->status->time->left; $time = $curtime.'/'.$tottime; # $time = $curtime.'/'.$lefttime.'/'.$tottime; $state = $mpd->{'state'}; if ($state eq "play") { $state = ""; } $line3 = $time." ".$state; $hbar = int($cursec/($totsec/90)); $line2 = "[..................]"; if (!$ignore) { updatescreen; sleep 1; } } close ($lcdproc) || die "close: $!"; exit;
Ich würde die Anzeige gerne etwas ändern bzw. eigentlich vereinfachen um mehr Übersicht zu erzielen. In der ersten Zeile sollte der Interpret angezeigt werden, in der zweiten vielleicht Tracknummer und Titel und in der dritten der Albumname. Die vierte Zeile würde ich so lassen, dass die Spielzeit angezeigt wird. Ein extra Bildschirm am Beginn eines Liedes halte ich für Überflüssig. Bisher habe ich allerdings noch keinerlei Ahnung von Perl und wäre sehr dankbar, wenn mir jemand hier etwas helfen würde. ☺