AEInst.c++ 3.74 KB
/*****************************************************************************
 *  File:  AEInst.c++ 
 *
 *  AEInst Class Implementations
 *
 ****************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>

#include "Assets.h"
#include "Mgrs.h"

/*****************************************************************************
 *
 *   Initialization Routines
 * 
 ****************************************************************************/

AEInst::AEInst()
{
    soundList = new RefList;
    assert(soundList);
    classType = AL_INST_CLASS;
    volume = AL_VOL_FULL;
    pan = AL_PAN_CENTER;
    priority = AL_DEFAULT_PRIORITY;
    flags = 0;
    tremType = 0;
    tremRate = 0;
    tremDepth = 0;
    tremDelay = 0;
    vibType = 0;
    vibRate = 0;
    vibDepth = 0;
    vibDelay = 0;
    bendRange = 200;

    assert(theU64Dev->AllocHdwr(this,AL_INST_CLASS) == 0);
}

AEInst::~AEInst()
{
    Node    *node, *next;
    AESound *sound;

    node = soundList->head;
    while(node)
    {
        sound = (AESound*)node->data;
        sound->RemoveReference(this);
        next = node->next;
        delete node;
        node = next;
    }
    delete soundList;    
    theU64Dev->DeallocHdwr(this);
    
}

/*****************************************************************************
 *
 *    Asset's Methods
 *
 ****************************************************************************/

void AEInst::AddSound(AESound *sound)
{
    soundList->Append(sound);
    sound->AddReference(this);
}

void AEInst::RemoveSound(AESound *sound)
{
    soundList->RemoveByData(sound);
    sound->RemoveReference(this);
}

void AEInst::SetVol(int v)
{
    volume = v;
}

void AEInst::SetPan(int p)
{
    pan = p;
}

void AEInst::SetPriority(int p)
{
    priority = p;
}

void AEInst::SetFlags(int f)
{
    flags = f;
}

void AEInst::SetBendRange(int b)
{
    bendRange = b;
}

void AEInst::SetTremType(int t)
{
    tremType = t;
}

void AEInst::SetTremRate(int r)
{
    tremRate = r;
}

void AEInst::SetTremDepth(int d)
{
    tremDepth = d;
}

void AEInst::SetTremDelay(int d)
{
    tremDelay = d;
}

void AEInst::SetVibType(int t)
{
    vibType = t;
}

void AEInst::SetVibRate(int r)
{
    vibRate = r;
}

void AEInst::SetVibDepth(int d)
{
    vibDepth = d;
}

void AEInst::SetVibDelay(int d)
{
    vibDelay = d;
}

int AEInst::GetVol(void)
{
    return volume;
}

int AEInst::GetPan(void)
{
    return pan;
}

int AEInst::GetPriority(void)
{
    return priority;
}

int AEInst::GetFlags(void)
{
    return flags;
}

int AEInst::GetBendRange(void)
{
    return bendRange;
}

int AEInst::GetTremType(void)
{
    return tremType;
}

int AEInst::GetTremRate(void)
{
    return tremRate;
}

int AEInst::GetTremDepth(void)
{
    return tremDepth;
}

int AEInst::GetTremDelay(void)
{
    return tremDelay;
}

int AEInst::GetVibType(void)
{
    return vibType;
}

int AEInst::GetVibRate(void)
{
    return vibRate;
}

int AEInst::GetVibDepth(void)
{
    return vibDepth;
}

int AEInst::GetVibDelay(void)
{
    return vibDelay;
}


int AEInst::GetNumSounds(void)
{
    return soundList->count;
}


AssetPair* AEInst::GetSounds(int *numSnds)
{
    int        c = 0;
    AssetPair  *assets;
    Node       *node;
    AESound    *snd;

    if(soundList->count == 0)
        return 0;

    assets = (AssetPair*)malloc(soundList->count * sizeof(AssetPair));
    if(!assets)
    {
        fprintf(stderr,"Failure allocating memory for sound list\n");
        return 0;
    }
    
    node = soundList->head;
    
    while(node)
    {
        snd = (AESound*)node->data;
        assets[c].asset = snd;
        assets[c].name = snd->GetName();
        c++;
        node = node->next;
    }
    
    assert(c == soundList->count);
    *numSnds = c;
    return assets;
    
}