Xmms-Perl

 view release on metacpan or  search on metacpan

lib/Xmms.pm  view on Meta::CPAN

    eval {
	require Audio::CD;
    };
}

sub shell {
    $term = Term::ReadLine->new(__PACKAGE__);
    init();
    boot();

    my $attr = $term->Attribs;
    $attr->{completion_function} = \&cpl;
    $readline::rl_completer_word_break_characters = 
      $readline::rl_basic_word_break_characters = "\\\t\n' \"`\@><=;|&{(";

    init_keybindings();
    $sc->run if $sc;

    my $rcfile = "$ENV{HOME}/.xmms/.perlrc";
    if (-e $rcfile) {
	Xmms::Cmd->history("<$rcfile");
    }   

    while (1) {
	$Signal = 0;
	run_cmd($term->readline("xmms> "));
    }
}

sub version {
    print "xmms shell -- remote control v$Xmms::VERSION\n";

    printf "ReadLine support..........%s\n", 
    $term->ReadLine ne "Term::ReadLine::Stub" ? "enabled" :
      "available (install Bundle::Xmms)";

    print "MPEG::MP3Info support.....", ($INC{'MPEG/MP3Info.pm'} ?
      "enabled" : "available"), "\n";

    print "Audio::CD support.........", ($INC{'Audio/CD.pm'} ?
      "enabled" : "available"), "\n";

    print "Term::ANSIColor support...", ($INC{'Term/ANSIColor.pm'} ?
	"enabled" : "available"), "\n";
}

sub boot {
    version();

    my $op = $config->read(xmms => 'output_plugin');
    if ($op =~ /disk_writer/) {
	print <<EOF;
*************************************************************
* WARNING:
* Your xmms Output Plugin is set to disk_writer,
* which is probably not what you want.
* I\'ll pop up a the preferences window for you to change...
*************************************************************
EOF
        sleep 1;
	$remote->show_prefs_box;
    }
}

#the default C-c binding hosed my tty
sub readline::F_Xmms_interrupt {
    readline::F_UnixLineDiscard();
    Xmms::Cmd->quit if $Signal++;
}

sub readline::F_Xmms_volume_up {
    Xmms::Cmd::volume(undef, '+');
}

sub readline::F_Xmms_volume_down {
    Xmms::Cmd::volume(undef, '-');
}

#remote time slider doesnt work so well
#sub readline::F_Xmms_time_up {
#    Xmms::Cmd::time(undef, '+');
#}

#sub readline::F_Xmms_time_down {
#    Xmms::Cmd::time(undef, '-');
#}

my %keybindings = (
    'M-=' => 'next',
    'M--' => 'prev',
    'M-.' => 'stop',
    'M-/' => 'play',
    'M-,' => 'pause',
    'M-~' => 'shuffle',
    'M-`' => 'history',
    'M-@' => 'repeat',
    'M-\\\\' => 'jtime',
    'M-m' => 'mtime',
    'M-c' => 'crop',
    'C-c' => 'interrupt',
    'M-e' => 'eject',
    qq/"\e[A"/  => 'volume_up',
    qq/"\e[B"/  => 'volume_down',
    qq/"\e[[A"/ => 'volume_up',
    qq/"\e[[B"/ => 'volume_down',
#    qq/"\e[C"/,  'time_up',
#    qq/"\e[D"/,  'time_down',
#    qq/"\e[[C"/,  'time_up',
#    qq/"\e[[D"/,  'time_down',
);

my %window_bindings = (
    'M-w' => 'main',
    'M-l' => 'pl',
    'M-q' => 'eq',
    'M-a' => 'all',
);

sub init_keybindings {
    my @code;
    return unless readline::->can('rl_bind');

lib/Xmms.pm  view on Meta::CPAN

    #M-`
    unless ($_[0]) {
	my $line = $readline::rl_History[-1];
	Xmms::run_cmd($line);
	return;
    }

    if ($is_cpl) {
	if ($args =~ /^\d+$/) {
	    return grep /^$args/, (1..$#history);
	}
	elsif($args =~ s/^([<>])//) {
	    return Xmms::filecomplete($args, \&Xmms::historysel);
	}
	else {
	    return grep /^$args/, reverse @history;
	}
    }
    
    unless ($args) {
	for (my $i = 0; $i < @history; $i++) {
	    printf "%d\t$history[$i]\n", $i+1;
	}
	return;
    }

    if (my $meth = Xmms::History->can($args)) {
	return $meth->();
    }

    my $line;
    if ($args =~ /^\d+$/) {
	$line = $history[$args-1];
    }
    elsif ($args =~ s/^<//) {
	my $fh = Symbol::gensym();
	$args = Xmms::guesspath($args);
	open $fh, $args or die "open $args: $!";
	while (<$fh>) {
	    next if /^#/;
	    next if /^history/;
	    print unless s/^\@// or /^\+/;
	    chomp;
	    Xmms::run_cmd($_);
	}
	close $fh;
	Xmms::historysel(Xmms::dirname($args)) unless $args =~ /\.perlrc$/;
    }
    elsif ($args =~ s/^>//) {
	my $fh = Xmms::open_careful($args);
	print $fh join "\n", grep { !/^history/ } @history, "";
	close $fh;
    }
    else {
	$line = $args;
    }

    Xmms::run_cmd($line);
}

my @windows = qw(main pl eq prefs all);
sub Xmms::WindowCmds { \@windows }
my %windows = map { $_,1 } @windows;

sub Xmms::Usage::window {
    my $opts = join '|', @windows;

    print Xmms::highlight(Error => 
			    "usage: window [$opts] [hide|show]\n");
}

my %window_state = (
    'main' => 0, 'pl' => 0, 'eq' => 0, 'all' => 0,
);

sub window ($$$) {
    my($self, $args) = @_;
    my($win, $val) = split /\s+/, $args;

    if ($is_cpl) {
	if ($win and $windows{$win}) {
	    return grep /^$val/, qw(show hide);
	}
	else {
	    return grep /^$win/, @windows;
	}
	return $args;
    }

    $val ||= $window_state{$win} ? 'hide' : 'show';

    unless ($win && $val) {
	Xmms::Usage->window;
	return;
    }

    my $meth = "${win}_win_toggle";
    $window_state{$win} = $val eq 'show';

    if ($remote->can($meth)) {
	$remote->$meth($window_state{$win});
    }
    else {
	Xmms::Usage->window;
    }
}

my @BalanceCmds = sort grep { Xmms::Balance->can($_) } keys %Xmms::Balance::;
sub Xmms::BalanceCmds { \@BalanceCmds }

sub Xmms::Usage::balance {
    my $opts = join '|', @BalanceCmds;

    print Xmms::highlight(Error => 
			    "usage: balance [$opts] [value]\n");
}

{
    package Xmms::Balance;

    sub center {



( run in 1.829 second using v1.01-cache-2.11-cpan-8f98c5d2c55 )