Handle missing sources gracefully.

pull/3/head
Jonathan Moore Liles 2008-05-20 19:46:02 -05:00
parent 7e72339ea9
commit fc6ffee22e
6 changed files with 93 additions and 25 deletions

View File

@ -17,18 +17,19 @@
/* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
/*******************************************************************************/
/* FIXME: need locking for when disk thread and peak reader are
* interested in the same source? */
#include "Audio_File.H"
#include "Audio_File_SF.H"
#include "Audio_File_Dummy.H"
#include "debug.h"
std::map <std::string, Audio_File*> Audio_File::_open_files;
Audio_File::~Audio_File ( )
{
_open_files[ std::string( _filename ) ] = NULL;
if ( _filename )
free( _filename );
}
void
@ -58,15 +59,16 @@ Audio_File::from_file ( const char * filename )
// TODO: other formats
DWARNING( "creating dummy source for \"%s\"", filename );
/* FIXME: wrong place for this? */
if ( ( a = Audio_File_Dummy::from_file( filename ) ) )
goto done;
return NULL;
done:
/* a->_peaks = new Peaks; */
/* a->_peaks->clip( a ); */
/* a->_peaks->open(); */
_open_files[ std::string( filename ) ] = a;
return a;
@ -78,21 +80,26 @@ Audio_File::read_peaks( float fpp, nframes_t start, nframes_t end, int *peaks, P
{
// Peaks pk;
*peaks = 0;
*channels = 0;
*pbuf = NULL;
if ( dummy() )
{
*peaks = (end - start) / fpp;
*channels = 0;
*pbuf = NULL;
// pk.clip( this );
return false;
}
else
{
*peaks = 0;
*channels = 0;
*pbuf = NULL;
/* /\* only open peaks (and potentially generate) when first requested *\/ */
/* if ( ! _peaks.open() ) */
/* return false; */
*peaks = _peaks.fill_buffer( fpp, start, end );
*peaks = _peaks.fill_buffer( fpp, start, end );
*channels = this->channels();
*channels = this->channels();
*pbuf = _peaks.peakbuf();
*pbuf = _peaks.peakbuf();
return true;
return true;
}
}

View File

@ -50,7 +50,7 @@ protected:
unsigned long id;
};
const char *_filename;
char *_filename;
volatile nframes_t _length; /* length of file in samples */
nframes_t _samplerate; /* sample rate */
int _channels;
@ -79,6 +79,8 @@ public:
virtual ~Audio_File ( );
virtual bool dummy ( void ) const { return false; }
static void all_supported_formats ( std::list <const char *> &formats );
static Audio_File *from_file ( const char *filename );

View File

@ -0,0 +1,53 @@
/*******************************************************************************/
/* Copyright (C) 2008 Jonathan Moore Liles */
/* */
/* This program is free software; you can redistribute it and/or modify it */
/* under the terms of the GNU General Public License as published by the */
/* Free Software Foundation; either version 2 of the License, or (at your */
/* option) any later version. */
/* */
/* This program is distributed in the hope that it will be useful, but WITHOUT */
/* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for */
/* more details. */
/* */
/* You should have received a copy of the GNU General Public License along */
/* with This program; see the file COPYING. If not,write to the Free Software */
/* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
/*******************************************************************************/
#pragma once
#include "Audio_File.H"
class Audio_File_Dummy : public Audio_File
{
Audio_File_Dummy ( )
{
}
public:
/* static const Audio_File::format_desc supported_formats[]; */
static Audio_File_Dummy *from_file ( const char *filename )
{
Audio_File_Dummy *d = new Audio_File_Dummy;
d->_filename = strdup( filename );
return d;
}
bool dummy ( void ) const { return true; }
~Audio_File_Dummy ( )
{
}
bool open ( void ) { return true; }
void close ( void ) { }
void seek ( nframes_t ) { }
nframes_t read ( sample_t *, int, nframes_t len ) { return len; }
nframes_t read ( sample_t *, int, nframes_t start, nframes_t end ) { return end - start; }
nframes_t write ( sample_t *, nframes_t nframes ) { return nframes; }
};

View File

@ -58,10 +58,7 @@ Audio_File_SF::from_file ( const char *filename )
memset( &si, 0, sizeof( si ) );
if ( ! ( in = sf_open( filename, SFM_READ, &si ) ) )
{
printf( "couldn't open file\n" );
return NULL;
}
/* if ( si.samplerate != timeline->sample_rate() ) */
/* { */

View File

@ -17,6 +17,8 @@
/* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
/*******************************************************************************/
#pragma once
#include "Audio_File.H"
#include <sndfile.h>

View File

@ -636,7 +636,14 @@ Audio_Region::draw ( void )
/* fl_line( rx, Y, rx, Y + H ); */
/* fl_line( rx + rw - 1, Y, rx + rw - 1, Y + H ); */
draw_label( _clip->name(), align() );
if ( _clip->dummy() )
{
char pat[256];
snprintf( pat, sizeof( pat ), "Missing Source!: %s", _clip->name() );
draw_label( pat, align() );
}
else
draw_label( _clip->name(), align() );
/* if ( current() ) */
/* { */