<?sphp $this->text('pagetitle') ?>
 
Home of the Squeezebox™ & Transporter® network music players.

PluginBuilder

From SqueezeboxWiki

Jump to: navigation, search
package Plugins::WaveInput::Plugin;

#
#

use strict;

use vars qw($VERSION);
use File::Spec::Functions qw(catdir);
use FindBin qw($Bin);
use Slim::Utils::Misc;
use Plugins::WaveInput::WAVIN;

$VERSION = "1.00";

my %wavsource; # per-client friendly wavin device name

sub getDisplayName {
    return 'PLUGIN_WAVE_INPUT';
}

sub setMode {
    my $client = shift;
    my $method = shift;
    $::d_plugins && msg("WavIn, in setMode\n");
    if ($method eq 'pop') {
        Slim::Buttons::Common::popMode($client);
        return;
    }
    $client->lines(\&lines);
    $client->update();

}

sub leaveMode {
    my $client = shift;
}

sub play {
    my $client = shift;
    my $wavsource = $wavsource{$client};
    my $name = "Audio Input $wavsource";
    my $wavinurl = "wavin:$wavsource";
    $::d_plugins && msg( "WavIn Playing : $name\n");
    Slim::Music::Info::setTitle($wavinurl, $name);
    Slim::Control::Command::execute($client, ['playlist', 'play', $wavinurl]);
    Slim::Control::Command::execute($client, ['play']);
}

my %functions = (
    'left' => sub {
        my $client = shift;
        Slim::Buttons::Common::popModeRight($client);
    },
    'play' => sub {
        my $client = shift;
        play($client);
    }
);

sub lines {
    my $client = shift;
    my($line1, $line2, $overlay);
    # for now, always use the wave mapper
    $wavsource{$client} = 0;
    my $wavsource = $wavsource{$client};
    my $name = "Audio Input $wavsource";
    $line1 = "Wave Input";
    # get current song and play mode 
    my $playmode = Slim::Player::Source::playmode($client);
    my $stream = Slim::Player::Playlist::song($client);
    if ($stream eq undef) {
        $::d_plugins && msg("WavIn, in lines playmode=$playmode stream=undef\n");
        $line2 = "$name (press PLAY)";
        return($line1, $line2, undef, $overlay);
    } else {
        $::d_plugins && msg("WavIn, in lines playmode=$playmode stream=$stream\n");
    }
    if ($::VERSION ge '6.5') {
        $stream = $stream->path;
    }
    if ($playmode eq 'play' && $stream =~ /^wavin:/) {
        $line2 = "$name playing";
        $overlay = $client->symbols('notesymbol');
    } else {
        $line2 = "$name (press PLAY)";
    }
    return($line1, $line2, undef, $overlay);
}

sub getFunctions() {
    return \%functions;
}

sub addMenu {
    return "PLUGINS";
}

sub initPlugin {
    $::d_plugins && msg("WavIn - initPlugin begin...\n");
    # Check for wavin2cmd - Windows only for now
    if (Slim::Utils::OSDetect::OS() ne "win") {
         $::d_plugins && msg("WavIn - non-Windows OS not yet supported\n");
        return 0;
    }
    my $path = Slim::Utils::Misc::findbin('wavin2cmd');
    if (!$path) {
        $::d_plugins && msg("WavIn - wavin2cmd not found\n"); return 0;
    } $::d_plugins && msg("WavIn - initPlugin ...end\n"); return 1;
}

1;