commit - 3dd907310bab777213b20bd814d72faba91e40ae
commit + e9c1a5587b16f1b74d268d56e8adfbba6b117628
blob - 7f589f9d06806f63ad7f6de04135b2b5d75e0331
blob + 660a18a75c6027aeded2941a407da08b4910224a
--- contrib/amused-monitor
+++ contrib/amused-monitor
my $pair_n = 1;
my @songs;
+my $current_song;
my $playlist_cur;
my $playlist_max;
my $time_cur;
chomp;
s,$trim,,;
$tmp[$idx] = $_;
- $cur = $n if m/^>/;
+
+ if (m/^>/) {
+ $cur = $n;
+ $current_song = s/^> //r;
+ }
+
$n++;
$idx = ++$idx % $lines;
open (my $fh, "-|", "amused", "status", "-f",
"status,time:raw,mode:oneline");
- my $status = <$fh>;
- chomp $status;
+
+ <$fh> =~ m/([a-z]+) (.*)/;
+ my ($status, $current_song) = ($1, $2);
+
while (<$fh>) {
chomp;
$pos = s/position //r if m/^position /;
$mode = $_ if m/^repeat/;
}
close($fh);
- return ($status, $pos, $dur, $mode);
+ return ($status, $current_song, $pos, $dur, $mode);
}
sub showtime {
offsets $LINES - 4, 0, $playlist_cur, $playlist_max;
progress $LINES - 3, 0, $time_cur, $time_dur;
- show_status $LINES - 2, 0, $status;
+ show_status $LINES - 2, 0, "$status $current_song";
show_mode $LINES - 1, 0, $mode;
refresh;
($playlist_cur, $playlist_max) = playlist_numbers;
}
-sub getstatus {
- ($status, $time_cur, $time_dur, $mode) = status;
-}
-
sub save {
return unless defined $pfile;
my $fh = shift;
my $l = <$fh>;
die "monitor quit" unless defined($l);
- getstatus;
+
+ $status = "playing" if $l =~ m/^play/;
+ $status = "paused" if $l =~ m/^pause/;
+ $status = "stopped" if $l =~ m/^stop/;
+
+ ($time_cur, $time_dur) = ($1, $2) if $l =~ m/^seek (\d+) (\d+)/;
+
+ $mode = $1 if $l =~ m/^mode (.*)/;
+
getnums if $l =~ m/load|jump|next|prev/;
getsongs if $l =~ m/load|jump|next|prev/;
}
getsongs;
getnums;
-getstatus;
+($status, $current_song, $time_cur, $time_dur, $mode) = status;
render;
-my $tick = 0;
-my $tbefore = clock_gettime(CLOCK_MONOTONIC);
-
while ($run) {
- $poll->poll(0.25);
- my $now = clock_gettime(CLOCK_MONOTONIC);
- my $elapsed = $now - $tbefore;
- if ($elapsed > 1) {
- $tbefore = $now;
- $time_cur += round($elapsed)
- if $status =~ m/^playing/;
- }
-
- getstatus unless $tick++ % 8;
-
+ $poll->poll();
hinput if $poll->events(\*STDIN) & POLLIN;
hevent $monitor if $poll->events($monitor) & POLLIN;