AeWaveAsset.c++ 5.63 KB
/*****************************************************************************
 *  File:  AeWaveAsset.c++
 *
 *  Implementation of AeWaveAsset class
 ****************************************************************************/
#include <assert.h>
#include <stdlib.h>
#include <Vk/VkApp.h>

#include "AeWaveFile.h"
#include "AeAsset.h"
#include "GList.h"
#include "waveIcon.xbm"


////////////////////////////////////////
//
//	Abstract Wave Asset Class
//
////////////////////////////////////////

Pixmap AeWaveAsset::fIcon = NULL;


AeWaveAsset::AeWaveAsset (AeWaveFile * file,
			  TAssetType waveType)
    : AeAsset (file->GetFileName (), kWaveType)
{
    fFile = file;
    fWaveType = waveType;

    fSampleFrames = 0;
    fSampleRate = 0.0;
    fSampleSize = 0;
    fNDataBytes = 0;
    fSmplXRef = NULL;

    if (!fIcon)
    {
	fIcon = XCreateBitmapFromData (theApplication->display (),
				       DefaultRootWindow (theApplication->display ()),
				       (char *)waveIcon_bits,
				       waveIcon_width,
				       waveIcon_height);
    }
}

AeWaveAsset::AeWaveAsset (const char * name,
			  TAssetType waveType)
    : AeAsset (name, kWaveType)
{
    fFile = NULL;
    fWaveType = waveType;
    
    fSampleFrames = 0;
    fSampleRate = 0.0;
    fSampleSize = 0;
    fNDataBytes = 0;
    fSmplXRef = NULL;
}


AeWaveAsset::~AeWaveAsset (void)
{
    if (fFile)
	delete fFile;

    if (fParentList)
    {
	AeAsset *	parent;
	int		i;

	// nullify any references to this asset
	fParentList->Start (i, kReverse);
	while (fParentList->Prev (i, parent))
	{
	    if (((AeSoundAsset *)parent)->GetWave () == this)
		((AeSoundAsset *)parent)->SetWave (NULL);	
	}
    }
}


void
AeWaveAsset::GetClassName (char * name)
{
    strcpy (name, "wave");
}

char *
AeWaveAsset::GetSampleData (void)
{
    char *	buffer = NULL;
    long	nbytes;
    AeErr	err;

    assert (fFile);

    if (fFile)
    {
	err = fFile->ReadSampleData (buffer, nbytes);
	assert (!err);
    }

    return buffer;
}


Boolean
AeWaveAsset::IsParent (AeAsset * parent)
{
    assert (parent);
    return (((AeSoundAsset *)parent)->GetWave () == this);
}


void
AeWaveAsset::SetLoop (AeLoopAsset * loop)
{
    assert (False);	// pure virtual function called
}

AeLoopAsset *
AeWaveAsset::GetLoop (void)
{
    assert (False);	// pure virtual function called
    return NULL;
}

int
AeWaveAsset::GetWaveTypeProc (AeAsset * asset)
{
    assert (asset != NULL);
    return (int)((AeWaveAsset *)asset)->GetWaveType ();
}

char *
AeWaveAsset::GetDirProc (AeAsset * asset)
{
    assert (asset != NULL);
    AeWaveFile * file = ((AeWaveAsset *)asset)->GetFile ();

    if (file)
	return (char *)file->GetDirName ();

    return "--";
}


float
AeWaveAsset::GetSampleRateProc (AeAsset * asset)
{
    assert (asset != NULL);
    return ((AeWaveAsset *)asset)->GetSampleRate ();
}

int
AeWaveAsset::GetSampleSizeProc (AeAsset * asset)
{
    assert (asset != NULL);
    return ((AeWaveAsset *)asset)->GetSampleSize ();
}

int
AeWaveAsset::GetSampleFramesProc (AeAsset * asset)
{
    assert (asset != NULL);
    return ((AeWaveAsset *)asset)->GetSampleFrames ();
}

int
AeWaveAsset::GetLoopStartProc (AeAsset * asset)
{
    assert (asset != NULL);
    AeLoopAsset * loop = ((AeWaveAsset *)asset)->GetLoop ();

    if (loop)
	return loop->GetStart ();

    return 0;
}

int
AeWaveAsset::GetLoopEndProc (AeAsset * asset)
{
    assert (asset != NULL);
    AeLoopAsset * loop = ((AeWaveAsset *)asset)->GetLoop ();

    if (loop)
	return loop->GetEnd ();

    return 0;
}

int
AeWaveAsset::GetLoopCountProc (AeAsset * asset)
{
    assert (asset != NULL);
    AeLoopAsset * loop = ((AeWaveAsset *)asset)->GetLoop ();

    if (loop)
	return loop->GetCount ();

    return 0;
}


void
AeWaveAsset::SetLoopStartProc (AeAsset * asset, int start)
{
    assert (asset != NULL);
    AeLoopAsset * loop = ((AeWaveAsset *)asset)->GetLoop ();

    assert (loop != NULL);
    loop->SetStart (start);
}

void
AeWaveAsset::SetLoopEndProc (AeAsset * asset, int end)
{
    assert (asset != NULL);
    AeLoopAsset * loop = ((AeWaveAsset *)asset)->GetLoop ();

    assert (loop != NULL);
    loop->SetEnd (end);
}

void
AeWaveAsset::SetLoopCountProc (AeAsset * asset, int count)
{
    assert (asset != NULL);
    AeLoopAsset * loop = ((AeWaveAsset *)asset)->GetLoop ();

    assert (loop != NULL);
    loop->SetCount (count);
}




////////////////////////////////////////
//
//	Concrete Wave Asset Classes
//
////////////////////////////////////////

AeRaw16WaveAsset::AeRaw16WaveAsset (AeWaveFile * file)
    : AeWaveAsset (file, kRaw16WaveType)
{
    fLoop = NULL;
}

AeRaw16WaveAsset::AeRaw16WaveAsset (const char * name)
    : AeWaveAsset (name, kRaw16WaveType)
{
    fLoop = NULL;
}

AeRaw16WaveAsset::~AeRaw16WaveAsset (void)
{
    if (fLoop)
        fLoop->RemoveParent (this);
}

void
AeRaw16WaveAsset::SetLoop (AeLoopAsset * loop)
{
    if (fLoop)
	fLoop->RemoveParent (this);

    fLoop = loop;

    if (fLoop)
	fLoop->AppendParent (this);
}



AeADPCMWaveAsset::AeADPCMWaveAsset (AeWaveFile * file)
    : AeWaveAsset (file, kADPCMWaveType)
{
    fLoop = NULL;
    fBook = NULL;
}

AeADPCMWaveAsset::AeADPCMWaveAsset (const char * name)
    : AeWaveAsset (name, kADPCMWaveType)
{
    fLoop = NULL;
    fBook = NULL;
}

AeADPCMWaveAsset::~AeADPCMWaveAsset (void)
{
    if (fLoop)
        fLoop->RemoveParent (this);

    if (fBook)
        fBook->RemoveParent (this);
}

void
AeADPCMWaveAsset::SetLoop (AeLoopAsset * loop)
{
    if (fLoop)
	fLoop->RemoveParent (this);

    fLoop = (AeADPCMLoopAsset *)loop;

    if (fLoop)
	fLoop->AppendParent (this);
}

void
AeADPCMWaveAsset::SetBook (AeADPCMBookAsset * book)
{
    if (fBook)
	fBook->RemoveParent (this);

    fBook = book;

    if (fBook)
	fBook->AppendParent (this);
}