AeBankEditor.c++ 2.91 KB
#include <assert.h>
#include <Xm/Xm.h>
#include "Matrix.h"

#include "GList.h"
#include "AeBankEditor.h"
#include "AeBankWindow.h"
#include "AeAssetBase.h"
#include "AeAssetBin.h"
#include "AeAssetBinUI.h"
#include "AeAssetUI.h"
#include "AeFieldUI.h"
#include "AeBinView.h"


AeBankEditor::AeBankEditor (void) : AeBinEditor ()
{
    fBank = NULL;
    fWindow = NULL;
}


AeBankEditor::~AeBankEditor (void)
{
    if (fWindow)
	delete fWindow;
}


void
AeBankEditor::SetBankAsset (AeBankAsset * bank)
{
    assert (bank);		// must be non-NULL

    fBank = bank;

    // create and init the UI objects for this editor
    createBinUIs ();
    initBinUIs ();
    createAssetUIs ();
    initChildBinUIs ();

    // default to editing the first bin in the list
    fBinUI = (*fBinUIList)[0];

    // now that we have data, create a window to display it
    // note that we create the window with a constant title and 
    // then set it to the bank's name.  this avoids a bug that
    // occurs if the bank's name has a '.' in it which causes
    // the resources based on the instance name to get messed up.
    fWindow  = new AeBankWindow("Bank Editor", this);
    fWindow->show();
    fWindow->setTitle (fBank->GetName ());

    fView = fWindow->GetView ();
    fView->TabSetLabels ();		// update the view's bin labels
}


void
AeBankEditor::createAssetUIs (void)
{
    createAssetUI (fBank);
    createAssetUIsRecurse (fBank->GetChildList ());
}


void
AeBankEditor::createAssetUIsRecurse (GList<AeAsset *> * assetList)
{
    AeAssetBinUI *	binUI = NULL;
    AeAssetUI *		assetUI;
    AeAsset *		asset;
    int			i;

    assetList->Start (i);

    while (assetList->Next (i, asset))
    {
	if (createAssetUI (asset) == NULL)
	    break;

	createRefAssetUIs (asset);

	if (asset->CanContain ())
	    createAssetUIsRecurse (((AeContainerAsset *)asset)->GetChildList ());
    }
}


//
// This routine takes care of creating assetUIs for any
// assets that are referenced by another asset.
//
// Note we don't have to create an UIs for loop or
// book assets since they are displayed as part of a
// wave's ui.
//
void
AeBankEditor::createRefAssetUIs (AeAsset * asset)
{
    AeAsset *		refAsset;

    switch (asset->GetType ())
    {
	case kBankType:
	    if (refAsset = (AeAsset *)((AeBankAsset *)asset)->GetPercussion ())
	    {
		createAssetUI (refAsset);
		createAssetUIsRecurse (((AeContainerAsset *)refAsset)->GetChildList ());
	    }
	break;
	    
	case kSoundType:
	    if (refAsset = (AeAsset *)((AeSoundAsset *)asset)->GetEnvelope ())
		createAssetUI (refAsset);

	    if (refAsset = (AeAsset *)((AeSoundAsset *)asset)->GetKeymap ())
		createAssetUI (refAsset);

	    if (refAsset = (AeAsset *)((AeSoundAsset *)asset)->GetWave ())
		createAssetUI (refAsset);
	break;
    }
}


Boolean
AeBankEditor::binHasUI (AeAssetBin * bin)
{
    switch (bin->GetType ())
    {
	case kBankFileType:
	case kLoopType:
	case kADPCMBookType:
	    return False;
    }

    return True;
}