#!/usr/bin/perl -w use FileHandle; use Time::HiRes; # Changes: # 2006-08-04 added arrow if displayed string is too long # 2006-08-11 fork; changed this version for 2x20 VFD # 2006-08-11 improved line breaks and stream name removal # 2006-10-14 fork; changed this version for plain-text output on RS232 system ("stty -F /dev/ttyS1 9600 -ocrnl -onlcr -onlret"); open (SERIAL, ">/dev/ttyS1") || die ("Could not open serial port: $!\n"); autoflush SERIAL 1; $oldstatus = 23; $oldtitle = "Blubb"; while (1) { ($status, $time, $bitrate, $channels, $pos, $len, $title) = GetInfo (); if ($status == 2) { # display nothing if stopped $title = ""; } elsif ($status == 1) { # display "PAUSED" if paused $title = "[ PAUSED ]"; } if (($oldtitle ne $title) or ($oldstatus ne $status)) { print (SERIAL chr(0x0C)); # clear $message = $title; $message = strip ($message); if ($len < 0) { # remove stream name $closing = rindex ($message, ")"); $opening = rindex ($message, "(", $closing - 1); if (($opening > -1) and ($closing > -1)) { $closing_new = $closing; while (1) { $closing_new = rindex ($message, ")", $closing_new - 1); if ($closing_new > $opening) { $opening_new = rindex ($message, "(", $opening - 1); if ($opening_new > -1) { $opening = $opening_new; } else { last; } } else { last; } } substr ($message, $opening, $closing - $opening + 1) = ""; } } $message = strip ($message); print (SERIAL $message); $oldstatus = $status; $oldtitle = $title; } sleep (1); } # return currently playing title from XMMS info file sub GetInfo { my (@info, $line, $title, $status, $pos, $len, $time, $channels, $bitrate); open (DATA, "/tmp/xmms-info") || return (2, "0:00", 128, 2, 0, -1, "Could not open /tmp/xmms-info: $!"); @info = ; close (DATA); $title = ""; $pos = 0; $len = -1; $time = "0:00"; $channels = 2; $bitrate = 128; foreach $line (@info) { chomp ($line); if ($line =~ /^Title: /) { $title = substr ($line, 7); $title =~ s/^Title: //; } elsif ($line =~ /^Status: /) { if ($line =~ /Playing/) { $status = 0; } elsif ($line =~ /Paused/) { $status = 1; } elsif ($line =~ /Stopped/) { $status = 2; } } elsif ($line =~ /^uSecPosition: /) { $pos = substr ($line, 14); } elsif ($line =~ /^uSecTime: /) { $len = substr ($line, 10); } elsif ($line =~ /^Time: /) { $time = substr ($line, 6); } elsif ($line =~ /^Current bitrate: /) { $bitrate = substr ($line, 17) / 1000; } elsif ($line =~ /^Channels: /) { $channels = substr ($line, 10); } } return ($status, $time, $bitrate, $channels, $pos, $len, $title); } # remove trailing \n and leading and trailing spaces sub strip { my ($text) = @_; chomp ($text); while ($text =~ s/^ //) { } while ($text =~ s/ $//) { } return ($text); }