EditMgr.c++ 5.77 KB
/*****************************************************************************
 *  File:  EditMgr.c 
 *
 *  Editor Manager
 *
 ****************************************************************************/
#include <stdio.h>

#include "Editor.h"
#include "EditMgr.h"

#include "AssetMgr.h"
#include "Mgrs.h"

static char* editorNames[] = { "Reverb\nEditor",
                               "Bank\nEditor",
                               "Instrument\nEditor",
                               "Sound\nEditor",
                               "Keymap\nEditor",
                               "Enveloper\nEditor",
                               "Wavetable\nEditor" };
                         
static void reverb_activate(Widget w, XtPointer client_data, XtPointer call_data);    
static void bank_activate(Widget w, XtPointer client_data, XtPointer call_data);
static void inst_activate(Widget w, XtPointer client_data, XtPointer call_data);
static void sound_activate(Widget w, XtPointer client_data, XtPointer call_data);
static void keymap_activate(Widget w, XtPointer client_data, XtPointer call_data);
static void envlp_activate(Widget w, XtPointer client_data, XtPointer call_data);
static void wavet_activate(Widget w, XtPointer client_data, XtPointer call_data);


EditMgr::EditMgr(int argc, char **argv)
{
    int             i;
    XmString        xms;
    Widget          rowColWidget;
    Widget          buttonWidget;
    XtCallbackProc  theCBProcs[XtNumber(editorNames)];


    reverbEditor = 0;
    bankEditor = 0;
    instEditor = 0;
    soundEditor = 0;
    keymapEditor = 0;
    envlpEditor = 0;
    wavetEditor = 0;
    
    theCBProcs[0] = reverb_activate;
    theCBProcs[1] = bank_activate;
    theCBProcs[2] = inst_activate;
    theCBProcs[3] = sound_activate;
    theCBProcs[4] = keymap_activate;
    theCBProcs[5] = envlp_activate;
    theCBProcs[6] = wavet_activate;

    this->main_widget = XtAppInitialize(&this->appCxt, "AudioEditor", NULL, 0, 
                                        &argc,argv, NULL, NULL, 0);

    rowColWidget = XtVaCreateManagedWidget("EMRowCol", xmRowColumnWidgetClass, this->main_widget,
                                           XmNorientation, XmVERTICAL,
                                           XmNisAligned, TRUE,
                                           XmNentryAlignment, XmALIGNMENT_CENTER,
                                           XmNpacking, XmPACK_COLUMN,
                                           NULL);

    for( i = 0; i < XtNumber(editorNames); i++)
    {
        xms = XmStringCreateLtoR(editorNames[i], XmSTRING_DEFAULT_CHARSET);
        buttonWidget =  XtVaCreateManagedWidget("Button", 
                                  xmPushButtonWidgetClass, rowColWidget,
                                  XmNlabelString,   xms,
                                  NULL);
        XmStringFree(xms);
        XtAddCallback(buttonWidget, XmNactivateCallback, theCBProcs[i], (XtPointer)this);
    }

    XtRealizeWidget(main_widget);
}

void EditMgr::startApp(void)
{
    XtAppMainLoop(this->appCxt);
}

void EditMgr::removeReverb(void)
{
    if(reverbEditor)
    {
	delete reverbEditor;
	reverbEditor = 0;
    }
}

void EditMgr::removeBank(void)
{
    if(bankEditor)
    {
	delete bankEditor;
	bankEditor = 0;
    }
}

void EditMgr::removeInst(void)
{
    if(instEditor)
    {
	delete instEditor;
	instEditor = 0;
    }
}

void EditMgr::removeSound(void)
{
    if(soundEditor)
    {
	delete soundEditor;
	soundEditor = 0;
    }
}

void EditMgr::removeKeymap(void)
{
    if(keymapEditor)
    {
	delete keymapEditor;
	keymapEditor = 0;
    }
}

void EditMgr::removeEnvlp(void)
{
    if(envlpEditor)
    {
	delete envlpEditor;
	envlpEditor = 0;
    }
}

void EditMgr::removeWavet(void)
{
    if(wavetEditor)
    {
	delete wavetEditor;
	wavetEditor = 0;
    }
}

/*******************************************************************************
 *
 *    Callback functions for the editor buttons
 *
 ******************************************************************************/
static void reverb_activate(Widget w, XtPointer client_data, XtPointer call_data)
{
    EditMgr *theEditMgr = (EditMgr*) client_data;

    if(!theEditMgr->reverbEditor)
        theEditMgr->reverbEditor = new ReverbEditor((void*)theEditMgr,XtDisplay(w));
    else
        theEditMgr->reverbEditor->RaiseWindow();
}

static void bank_activate(Widget w, XtPointer client_data, XtPointer call_data)
{
    EditMgr *theEditMgr = (EditMgr*) client_data;

    if(!theEditMgr->bankEditor)
        theEditMgr->bankEditor = new BankEditor((void*)theEditMgr,XtDisplay(w));
    else
        theEditMgr->bankEditor->RaiseWindow();
}

AEBank *tmpBank;

static void inst_activate(Widget w, XtPointer client_data, XtPointer call_data)
{
    EditMgr    *theEditMgr = (EditMgr*) client_data;
    
    if(!theEditMgr->instEditor)
	theEditMgr->instEditor = new InstEditor((void*)theEditMgr,XtDisplay(w));
    else
	theEditMgr->instEditor->RaiseWindow();

}

static void sound_activate(Widget w, XtPointer client_data, XtPointer call_data)
{
    EditMgr *theEditMgr = (EditMgr*) client_data;

//    if(!theEditMgr->soundEditor)
//      theEditMgr->soundEditor = new Editor(XtDisplay(w));

}

static void keymap_activate(Widget w, XtPointer client_data, XtPointer call_data)
{
    EditMgr *theEditMgr = (EditMgr*) client_data;

//     if(!theEditMgr->keymapEditor)
//      theEditMgr->keymapEditor = new Editor(XtDisplay(w));

}

static void envlp_activate(Widget w, XtPointer client_data, XtPointer call_data)
{
    EditMgr *theEditMgr = (EditMgr*) client_data;

//     if(!theEditMgr->envlpEditor)
//      theEditMgr->envlpEditor = new Editor(XtDisplay(w));

}

static void wavet_activate(Widget w, XtPointer client_data, XtPointer call_data)
{
    EditMgr *theEditMgr = (EditMgr*) client_data;

//     if(!theEditMgr->wavetEditor)
//      theEditMgr->wavetEditor = new Editor(XtDisplay(w));

}