AeN64DriverConfig.c++ 6 KB
//
// This file contains routines for posing a configuration
// dialog for the n64 device.  The user can apply changes
// to the configuration information which should take effect
// immediately
//

#include <stdio.h>
#include <stdlib.h>

#include "AeN64DriverConfig.h"
#include "AeN64Driver.h"
#include "AeConfig.h"


String AeN64ConfigDialog::_defaultResources[] =
{
    "*frameGroupLabel.labelString: Audio Frame Prefs",
    "*outputRateLabel.labelString: output rate:",
    "*frameSizeLabel.labelString: samples per frame:",
    "*maxCommandsLabel.labelString: max commands per frame:",

    "*dmaGroupLabel.labelString: Audio DMA Prefs",
    "*dmaBuffersLabel.labelString: DMA buffers:",
    "*dmaBufferSizeLabel.labelString: DMA buffer size:",
    "*dmaQueueSizeLabel.labelString: max DMA requests:",
    "*dmaFrameLagLabel.labelString: # frames to hold DMA buffers:",

    "*synthGroupLabel.labelString: Synthesizer Prefs",
    "*maxVVoicesLabel.labelString: max virtual voices:",
    "*maxPVoicesLabel.labelString: max physical voices:",
    "*maxUpdatesLabel.labelString: max control updates:",

    "*playerGroupLabel.labelString: MIDI Player Prefs",
    "*maxChannelsLabel.labelString: max channels:",
    "*maxEventsLabel.labelString: max events:",

    NULL
};


AeN64ConfigDialog::AeN64ConfigDialog (AeN64Config * config)
    : VkPrefDialog ("AeN64ConfigDialog")
{
    setTitle ("N64 Audio Configuration");
    fConfig = config;
}


void
AeN64ConfigDialog::GetValues (AeN64Config * config)
{
    char s[8];

    sprintf (s, "%d", config->c.synConfig.outputRate);
    outputRate->setValue (s);

    sprintf (s, "%d", config->c.frameSize);
    frameSize->setValue (s);

    sprintf (s, "%d", config->c.maxCmdListSize);
    maxCommands->setValue (s);

    sprintf (s, "%d", config->c.numDMABuffs);
    dmaBuffers->setValue (s);

    sprintf (s, "%d", config->c.dmaBufSize);
    dmaBufferSize->setValue (s);

    sprintf (s, "%d", config->c.dmaQSize);
    dmaQueueSize->setValue (s);

    sprintf (s, "%d", config->c.frameLag);
    dmaFrameLag->setValue (s);

    sprintf (s, "%d", config->c.synConfig.maxVVoices);
    maxVVoices->setValue (s);

    sprintf (s, "%d", config->c.synConfig.maxPVoices);
    maxPVoices->setValue (s);

    sprintf (s, "%d", config->c.synConfig.maxUpdates);
    maxUpdates->setValue (s);

    sprintf (s, "%d", config->c.seqpConfig.maxChannels);
    maxChannels->setValue (s);

    sprintf (s, "%d", config->c.seqpConfig.maxEvents);
    maxEvents->setValue (s);
}


void
AeN64ConfigDialog::SetValues (AeN64Config * config)
{
    config->c.synConfig.outputRate =	atoi (outputRate->getValue());
    config->c.frameSize = 		atoi (frameSize->getValue());
    config->c.maxCmdListSize = 		atoi (maxCommands->getValue());

    config->c.numDMABuffs = 		atoi (dmaBuffers->getValue());
    config->c.dmaBufSize = 		atoi (dmaBufferSize->getValue());
    config->c.dmaQSize = 		atoi (dmaQueueSize->getValue());
    config->c.frameLag =		atoi (dmaFrameLag->getValue ());

    config->c.synConfig.maxVVoices =	atoi (maxVVoices->getValue());
    config->c.synConfig.maxPVoices =	atoi (maxPVoices->getValue());
    config->c.synConfig.maxUpdates =	atoi (maxUpdates->getValue());

    config->c.seqpConfig.maxChannels =	atoi (maxChannels->getValue());
    config->c.seqpConfig.maxEvents =	atoi (maxEvents->getValue());
    config->c.seqpConfig.maxVoices = 	config->c.synConfig.maxVVoices;
}



Widget AeN64ConfigDialog::createDialog(Widget parent)
{
    setDefaultResources (parent, _defaultResources);

    frameGroup = new VkPrefGroup ("frameGroup");
    outputRate = new VkPrefText ("outputRate");
    frameSize = new VkPrefText ("frameSize");
    maxCommands = new VkPrefText ("maxCommands");
    frameGroup->addItem(outputRate);
    frameGroup->addItem(frameSize);
    frameGroup->addItem(maxCommands);

    sep1 = new VkPrefSeparator("sep1");

    dmaGroup = new VkPrefGroup ("dmaGroup");
    dmaBuffers = new VkPrefText ("dmaBuffers");
    dmaBufferSize = new VkPrefText ("dmaBufferSize");
    dmaQueueSize = new VkPrefText ("dmaQueueSize");
    dmaFrameLag = new VkPrefText ("dmaFrameLag");
    dmaGroup->addItem(dmaBuffers);
    dmaGroup->addItem(dmaBufferSize);
    dmaGroup->addItem(dmaQueueSize);
    dmaGroup->addItem(dmaFrameLag);

    sep2 = new VkPrefSeparator("sep2");

    synthGroup = new VkPrefGroup ("synthGroup");
    maxVVoices = new VkPrefText ("maxVVoices");
    maxPVoices = new VkPrefText ("maxPVoices");
    maxUpdates = new VkPrefText ("maxUpdates");
    synthGroup->addItem(maxVVoices);
    synthGroup->addItem(maxPVoices);
    synthGroup->addItem(maxUpdates);

    sep3 = new VkPrefSeparator("sep3");

    playerGroup = new VkPrefGroup ("playerGroup");
    maxChannels = new VkPrefText ("maxChannels");
    maxEvents = new VkPrefText ("maxEvents");
    playerGroup->addItem(maxChannels);
    playerGroup->addItem(maxEvents);

    prefList = new VkPrefList ("prefList");
    prefList->addItem (frameGroup);
    prefList->addItem (sep1);
    prefList->addItem (dmaGroup);
    prefList->addItem (sep2);
    prefList->addItem (synthGroup);
    prefList->addItem (sep3);
    prefList->addItem (playerGroup);
    setItem (prefList);

    GetValues (fConfig);

    Widget base = VkPrefDialog::createDialog (parent);

    return base;
}

AeN64ConfigDialog::~AeN64ConfigDialog()
{
    // Empty
}

const char* AeN64ConfigDialog::className()
{ 
    return "AeN64ConfigDialog";
}

void
AeN64Driver::PoseConfigure (void)
{
    AeN64ConfigDialog * n64Prefs = new AeN64ConfigDialog (fConfig);

    n64Prefs->addCallback(VkPrefDialog::prefCallback, (VkCallbackObject *)n64Prefs,
			  (VkCallbackMethod)&AeN64ConfigDialog::configCallback,
			  (void *)this);
    n64Prefs->post ();
}

void
AeN64ConfigDialog::configCallback (VkCallbackObject * obj, void * clientData, void * callData)
{
  AeN64ConfigDialog * dialog = (AeN64ConfigDialog *) obj;
  AeN64Driver * driver = (AeN64Driver *) clientData;
  VkDialogManager::VkDialogReason reason = (VkDialogManager::VkDialogReason) callData;

  if (reason == VkDialogManager::APPLY)
  {
      SetValues (driver->GetConfig ());
      driver->ReconfigureAudio ();
  }
}