Browse Source

Reference count Audio_Files.

tags/non-daw-v1.1.0
Jonathan Moore Liles 17 years ago
parent
commit
ffaa7bff61
3 changed files with 36 additions and 2 deletions
  1. +3
    -1
      Timeline/Audio_Region.C
  2. +28
    -1
      Timeline/Engine/Audio_File.C
  3. +5
    -0
      Timeline/Engine/Audio_File.H

+ 3
- 1
Timeline/Audio_Region.C View File

@@ -134,7 +134,7 @@ Audio_Region::Audio_Region ( const Audio_Region & rhs ) : Sequence_Region( rhs )
{
// *((Sequence_Region*)this) = (Sequence_Region &)rhs;

_clip = rhs._clip;
_clip = rhs._clip->duplicate();
_scale = rhs._scale;

_fade_in = rhs._fade_in;
@@ -192,6 +192,8 @@ Audio_Region::Audio_Region ( Audio_File *c, Sequence *t, nframes_t o )
Audio_Region::~Audio_Region ( )
{
log_destroy();

_clip->release();
}



+ 28
- 1
Timeline/Engine/Audio_File.C View File

@@ -29,7 +29,10 @@ std::map <std::string, Audio_File*> Audio_File::_open_files;

Audio_File::~Audio_File ( )
{
DMESSAGE( "Freeing Audio_File object for \"%s\"", _filename );

_open_files[ std::string( _filename ) ] = NULL;

if ( _filename )
free( _filename );
}
@@ -80,7 +83,7 @@ Audio_File::filename ( void ) const
return realname( _filename );
}

/** attmpet to open any supported filetype */
/** attempt to open any supported filetype */
Audio_File *
Audio_File::from_file ( const char * filename )
{
@@ -88,7 +91,11 @@ Audio_File::from_file ( const char * filename )
Audio_File *a;

if ( ( a = _open_files[ std::string( filename ) ] ) )
{
++a->_refs;

return a;
}

if ( ( a = Audio_File_SF::from_file( filename ) ) )
goto done;
@@ -105,11 +112,31 @@ Audio_File::from_file ( const char * filename )

done:

ASSERT( ! _open_files[ std::string( filename ) ], "Programming errror" );

_open_files[ std::string( filename ) ] = a;

a->_refs = 1;

return a;
}

Audio_File *
Audio_File::duplicate ( void )
{
++_refs;
return this;
}

/** release the resources assoicated with this audio file if no other
* references to it exist */
void
Audio_File::release ( void )
{
if ( --_refs == 0 )
delete this;
}


bool
Audio_File::read_peaks( float fpp, nframes_t start, nframes_t end, int *peaks, Peak **pbuf, int *channels )


+ 5
- 0
Timeline/Engine/Audio_File.H View File

@@ -34,6 +34,8 @@ class Peak_Writer;

class Audio_File : protected Mutex
{
int _refs;

static std::map <std::string, Audio_File*> _open_files;

/* not permitted */
@@ -67,6 +69,7 @@ public:
_filename = NULL;
_samplerate = 0;
_length = _channels = 0;
_refs = 0;
}

virtual ~Audio_File ( );
@@ -77,6 +80,8 @@ public:

static Audio_File *from_file ( const char *filename );

void release ( void );
Audio_File *duplicate ( void );

Peaks const * peaks ( ) { return &_peaks; }
const char *filename ( void ) const;


Loading…
Cancel
Save