Audio-RaveMP

 view release on metacpan or  search on metacpan

MANIFEST  view on Meta::CPAN

ravemp.c
ravemp.h
font_8x16.c
RaveMP.xs
RaveMP.pm
Makefile.PL
typemap
examples/ravemp_upload
README
MANIFEST
Server/Makefile.PL
Server/RaveMPServer.pm
Server/RaveMPClient.pm

RaveMP.pm  view on Meta::CPAN

    }
    if ($rmp->remove($number)) {
	print "$filename removed\n";
    }
    else {
	print "failed to remove $filename\n";
    }
    Audio::RaveMP::files_uncache();
}

sub ravemp_upload ($;$) {
    my($self, $arg) = @_;

    my($file, $name) = split /\s+/, $arg;

    my @files = Xmms::filecomplete($file);

    return @files if Xmms::is_cpl();
    $name = "" if @files > 1;

    for $file (@files) {
        my $base = Xmms::basename($file);
        $name = @files > 1 ? $base : $name || $base;

        print "uploading $file to $name...";
        if ($rmp->upload($file, $name)) {
	    print "done\n";
        }
        else {
	    print "failed\n";
        }
    }

    Audio::RaveMP::files_uncache();
}

RaveMP.pm  view on Meta::CPAN

 }

=item show_status

Show status messages:

 $rmp->show_status(1);

 $rmp->show_status(0);

=item upload

Upload a file.  The second argument is the name to upload to, which is 
optional and defaults to the upload name:

 unless ($rmp->upload("we_eat_rhythm.mp3")) {
      print "upload failed\n";
 }

 unless ($rmp->upload("we_eat_rhythm.mp3", "We Eat Rhythm")) {
      print "upload failed\n";
 }

=item remove

Remove a file specified by the give slot number:

 unless ($rmp->remove(8)) {
     print "unable to remove file at slot 8\n";
 }

RaveMP.pm  view on Meta::CPAN

The following commands become available in the shell:

=over 4

=item ravemp_track

List mp3 files in the player:

 xmms> ravemp_track

=item ravemp_upload

Upload files:

 xmms> ravemp_upload /usr/local/mp3/prodigy/what_evil_lurks/*.mp3

=item ravemp_download

Download files specified by slot or filename:

 xmms> ravemp_download rythm_of_life.mp3.mp3 ~/mp3/

=item ravemp_delete

Remove files from the player specified by slot or filename:

RaveMP.xs  view on Meta::CPAN

is_ready(self)
    Audio::RaveMP self

    CODE:
    RETVAL = ravemp_check_idle();

    OUTPUT:
    RETVAL

int
upload(self, fname, dest_name=NULL)
    Audio::RaveMP self
    char *fname
    char *dest_name

    CODE:
    CHECK_RAVEMP;
    RETVAL = ravemp_upload_file(fname, dest_name);

    OUTPUT:
    RETVAL

int
download(self, number, dest=NULL)
    Audio::RaveMP self
    unsigned number
    char *dest

Server/RaveMPServer.pm  view on Meta::CPAN

		  }, 'Audio::RaveMPSlotRemote';
    }
    bless $c, 'Audio::RaveMPSlotsRemote';
}

sub filename {
    my($self, $slot) = @_;
    $self->{rmp}->filename($slot);
}

sub upload {
    my($self, $fname, $dest_name) = @_;
    $self->{rmp}->upload($fname, $dest_name);
}

sub download {
    my($self, $fname, $dest_name) = @_;
    $self->{rmp}->download($fname, $dest_name);
}

sub remove {
    my($self, $number) = @_;
    $self->{rmp}->remove($number);

examples/ravemp_upload  view on Meta::CPAN

#!perl

use ExtUtils::testlib;

#e.g. ravemp_upload /usr/local/mp3/to_upload/*.mp3

use strict;

use Audio::RaveMP ();
use File::Basename qw(basename);

my $rmp = Audio::RaveMP->new;

unless ($rmp->permitted) {
    print "$!\n";
    exit 1;
}

unless ($rmp->is_ready) {
    print "device not ready\n";
    exit 2;
}

$| = 1;
for (@ARGV) {
    print "uploading $_...";
    unless ($rmp->upload($_, basename $_)) {
	print "not ";
    }
    print "ok\n";
}

#my $contents = $rmp->contents(1);
my $contents = $rmp->contents;

for my $slot (@$contents) {
    printf "%d: %s (%s)\n", $slot->number, $slot->filename || '-',

ravemp.c  view on Meta::CPAN

  Upload/download/management utility for the RaveMP portable MP3 player.

  TO DO:

	Improve recovery if block write/read fails - at present a single failure
    seems to cause the retries to fail as well. As there is an internal
    player timeout, a temporary solution is to sleep between retries.

	Test for Device presence on startup (e.g. read/check first page of FAT)

    Add automatic power up (allows upload/download even if device appears to be "off")

	Add "summary" command to display usage, capacity etc

	Make all XP's XPV() inside read/functions

    Tidy up command structure (common routine to send commands)

    Add support for ECP (requires EPP at present)

    Add configuration for port address

    Add support for different memory configurations

    Twiddle for clean compile at max. warnings

 History
 -------

  25-Dec-99 Version 0.0.1:	Initial version by hazeii (of the Snowblind
	Alliance),for basic upload and download testings and exploration of
	player device memory structure.


  30-Dec-99: Version 0.0.2:	Improved timing, made upload and download rather
	more friendly, implemented file deletion. 

  Jan-00: modified for Perl interface by dougm

*/

#include "ravemp.h"
#include "font_8x16.c"

static int read_page(unsigned block,unsigned page,struct page *pp);

ravemp.c  view on Meta::CPAN

		lpt_test(port); /* Test default port */
	    break;

	  case 'u':
	    s = p;
	    while (*s>=' ')
		s++;
	    *s='\0';	/* Trim filename at first control character */

	    if (strlen(p)==0)
		XP("No file specified for upload\n");
	    else
		upload_file(p);
	    break;

	  case 'q':
	  case 'x':
	    return;

	  case '?':
	  case 'h':
	    XP("B <b>      Block Dump\n");
	    XP("D <slot>   Download file from player\n");

ravemp.c  view on Meta::CPAN

		break;
	}
    }
#endif

    free(blkbuff);

    return 1;
}

/************************ upload_file *********************/

/* Upload a file to the device */

int ravemp_upload_file(char *fname, char *dest_name)
{
    int i,j,mp3file,uploadok;
    int block,blk1no,blk2no,prvblk,nxtblk,page;
    unsigned fsize,fblocks,avail,namelen;
    unsigned char *p,*t,*firstblk,*datablk,*filebuff;
    unsigned char fat[TOTAL_BLOCKS];
    FILE *fp;
    struct stat fileinfo;

    uploadok = 0;

    /* Read device FAT */

    if (!load_fat(fat)) {
	RMP_TRACE(fprintf(stderr, "Unable to load allocation table\n"));
	return 0;
    }

    /* Count free blocks and determine header block numbers */

ravemp.c  view on Meta::CPAN


    RMP_TRACE(fprintf(stderr, "File size: %u bytes [%u blocks needed, %u available]\n",fsize,fblocks,avail));

    if (fblocks+2 > avail) {	/* +2 for 2 header blocks */
	RMP_TRACE(fprintf(stderr, "Not enough space available for file\n"));
	return 0;
    }

    mp3file = ((p=strrchr(fname,'.')) != NULL && strcasecmp(p,".mp3")==0);

    /* Open file for upload */

    if ((fp=fopen(fname,"r"))==NULL) {
	RMP_TRACE(fprintf(stderr, "Unable to open file %s\n",fname));
	return 0;
    }

    /* Allocate memory for block buffers */

    if ((firstblk=malloc(MAX_BLOCK_SIZE))==NULL || 
	(datablk=malloc(MAX_BLOCK_SIZE)) == NULL ||

ravemp.c  view on Meta::CPAN

    /* Debug */
#if 0
    XP("MP3 File: %s\n",mp3file?"YES":"NO");
    p = firstblk;
    for (i=0;i<fblocks;i++) {
	printf("Block %u\n",(*p<<8) + *(p+1));
	p+=2;
    }
#endif

    /* Read file data and upload one block at a time */

    p = firstblk+4;	/* Pointer to first data block number */

    prvblk = blk1no;	/* Initialise "previous block" number for tag area */

    memset(datablk,0xff,DATA_SIZE); /* Initialise buffer (so all tag areas are 0xff) */

    for (i=0;i<fblocks;i++) {

	/* Read as much data as will fit into a single block */

ravemp.c  view on Meta::CPAN

    if (!write_block(blk2no,datablk)) {
	RMP_TRACE(fprintf(stderr, "Upload Failure: Unable to update header block [Block %u]\n",blk2no));
	goto uldone;
    }

    if (!store_fat(fat)) {
	RMP_TRACE(fprintf(stderr, "Upload failure: Unable to update directory\n"));
	goto uldone;
    }

    uploadok = 1;

    RMP_TRACE(fprintf(stderr, "File %s (size %u) uploaded.\n",fname,fsize));

    /* Exit path - clean up and return success/failure indication */

 uldone:
    free(filebuff);
    free(datablk);
    free(firstblk);
    fclose(fp);

    return uploadok;

}
/************************ download *************************/

/*

  File download (from player device to file)

  The first block of file holds the block number list

ravemp.h  view on Meta::CPAN

    int number;
    char type;
} ravemp_slot;

/* Prototypes for local functions */

int ravemp_permitted(void);
int ravemp_check_idle(void);
ravemp_slot **ravemp_contents(unsigned listall, int *nslots);
char *ravemp_get_filename(unsigned sblock);
int ravemp_upload_file(char *fname, char *dest_name);
int ravemp_remove_file(unsigned firstblock);
int ravemp_download(unsigned firstblock, char *dest);
void ravemp_set_show_status(int status);

/* #define RAVEMP_DEBUG */
#ifdef RAVEMP_DEBUG
#define RMP_TRACE(a) a
#else
#define RMP_TRACE(a)
#endif



( run in 2.782 seconds using v1.01-cache-2.11-cpan-b16cb0d3907 )