Metropoli BBS
VIEWER: wbcalib.c MODE: TEXT (ASCII)
/***************************************************************************
 *		  Copyright (C) 1994  Charles P. Peterson                  *
 *	     4007 Enchanted Sun, San Antonio, Texas 78244-1254             *
 *              Email: Charles_P_Peterson@fcircus.sat.tx.us                *
 *                                                                         *
 *		  This is free software with NO WARRANTY.                  *
 *	      See gfft.c, or run program itself, for details.              *
 *		      Support is available for a fee.                      *
 ***************************************************************************
 *
 * Program:     gfft--General FFT analysis
 * File:        wbcalib.c
 * Purpose:     requester to set calibration & quantization parameters
 * Author:      Charles Peterson (CPP)
 * History:     23-April-1994 CPP; Created.
 *              4-Aug-94 CPP (1.04); Filenames may contain spaces
 *              4-Aug-94 CPP (1.04); Allow full size pathnames here
 *              5-Aug-94 CPP (1.05); Show total calibrations in effect
 *              6-Aug-94 CPP (1.10); Minor interface improvements
 *              14-Dec-94 CPP (1.17); Fix button gadgets for >4 colors
 *              10-Feb-95 CPP (1.37); Use progress requesters
 *
 * Comments:    Workbench GUI.  Amiga Dependent!
 */

#ifdef AMIGA  /* This module is AMIGA dependent */

#include <stdio.h>     /* sprintf() */
#include <string.h>

/*
 * Amiga includes
 */
#include <exec/types.h>
#include <workbench/workbench.h>
#include <intuition/intuition.h>
#include <clib/intuition_protos.h>
#include <clib/exec_protos.h>
#include <dos.h> /* chkabort() */

/*
 * GFFT includes
 */
#include "gfft.h"
#include "settings.h"  /* for testing */
#include "wbench.h"

/*
 * External globals
 */
extern struct Window *dialog_window_p;
extern char *Processing_Calibration_S;

/*
 * Local statics
 */
static char *calibration_filename = NULL;

static struct Requester *calibration_rp = NULL;

static struct Gadget *help_calibration_gadgetp;
static struct Gadget *calibration_gadgetp;
static struct Gadget *db_calibration_gadgetp;
static struct Gadget *select_calibration_gadgetp;
static struct Gadget *select_db_calibration_gadgetp;
static struct Gadget *no_calibration_gadgetp;
static struct Gadget *quantization_gadgetp;
static struct Gadget *low_y_gadgetp;
static struct Gadget *high_y_gadgetp;
static struct Gadget *cancel_quantization_gadgetp;
static struct Gadget *cancel_low_y_gadgetp;
static struct Gadget *cancel_high_y_gadgetp;
static struct Gadget *end_calibration_gadgetp;
static struct Gadget *calibration_message_gadgetp;

static char message_string[80];

static void cal_proc_message (void);

static void cal_prog_begin (struct Gadget *cal_gadgetp, 
		       char *cal_func(char *arg));

static char *cal_prog_get_name (char *cal_filename);


#define MAX_VAL_SIZE 30

#if FALSE  /* defeat this for now */
#define ACTIVATE_CAL_CANCEL \
    if (CalibrationList) \
    { \
	gadget__enable (no_calibration_gadgetp, \
			 dialog_window_p); \
    } \
    else \
    { \
	gadget__disable (no_calibration_gadgetp, \
			 dialog_window_p); \
    }
#else
#define ACTIVATE_CAL_CANCEL
#endif

void calibration_requester (void)
{
    struct IntuiMessage *message;
    APTR *address = NULL;
    ULONG class = 0;
    UWORD qualifier = NULL;
    APTR *next_address = NULL;
    ULONG next_class = 0;
    UWORD next_qualifier = NULL;
    APTR string_gadget_being_set = NULL;
    char string[MAX_VAL_SIZE];

    if (!calibration_rp)
    {
	gadget__begin (GTYP_REQGADGET);
/*
 * Setup Gadgets
 */
	help_calibration_gadgetp = action_button__new ("Help", 0, 0);

	string[0] = '\0';
	calibration_gadgetp = string_gadget__new ("Calibration:",
						string,
						MAX_PATH,
						47, 0, 1);

	select_calibration_gadgetp = action_button__new ("S",49,1);

	db_calibration_gadgetp = string_gadget__new ("dB Calibration:",
						   string,
						   MAX_PATH,
						   47, 0, 2);

	select_db_calibration_gadgetp = action_button__new ("S",49,2);

	if (Quantization != MIN_QUANTIZATION)
	{
	    sprintf (string, "%g", Quantization);
	}
	quantization_gadgetp = string_gadget__new ("Quantization:",
						   string,
						   MAX_VAL_SIZE,
						   40, 0, 3);
	cancel_quantization_gadgetp = action_button__new ("Cancel", 43, 3);

	if (LowY != LOWEST_Y)
	{
	    sprintf (string, "%g", LowY);
	}
	low_y_gadgetp = string_gadget__new ("Low Y:",
						   string,
						   MAX_VAL_SIZE,
						   40, 0, 4);

	cancel_low_y_gadgetp = action_button__new ("Cancel", 43, 4);

	if (HighY != HIGHEST_Y)
	{
	    sprintf (string, "%g", HighY);
	}
	high_y_gadgetp = string_gadget__new ("High Y:",
						   string,
						   MAX_VAL_SIZE,
						   40, 0, 5);

	cancel_high_y_gadgetp = action_button__new ("Cancel", 43, 5);

	calibration_message_gadgetp = message_gadget__new (40, 0, 6);

	no_calibration_gadgetp = action_button__new
	  ("Cancel All Calibrations", 0, 7);

	end_calibration_gadgetp = tall_action_button__new 
	  ("...Done", 43, 7);

	calibration_rp = requester__new ();
	calibration_rp->ReqGadget = end_calibration_gadgetp;
	calibration_rp->ReqText =  NULL;

    } /* Ok, calibration_rp has been created */
    

    if (requester__display (calibration_rp, dialog_window_p))
    {
	ACTIVATE_CAL_CANCEL;
	ActivateGadget (calibration_gadgetp,
			dialog_window_p,
			calibration_rp);
	while (TRUE)
	{
	    sprintf (message_string, "%d Calibration(s) in effect", 
		     calibration_list__count (&CalibrationList));
	    message_gadget__write (calibration_message_gadgetp, 
				   message_string, dialog_window_p);
	    Wait (1 << dialog_window_p->UserPort->mp_SigBit);
	    while (message = (struct IntuiMessage *) GetMsg 
		   (dialog_window_p->UserPort))
	    {
		class = message->Class;
		qualifier = message->Qualifier;
		address = message->IAddress;
		ReplyMsg ((struct Message *) message);
            /*
	     * Finish unfinished string
	     */

		if (string_gadget_being_set &&
		    string_gadget_being_set != address)
		{
		    next_address = address;
		    next_class = class;
		    next_qualifier = qualifier;
		    address = string_gadget_being_set;
		    class = IDCMP_GADGETUP;
		    qualifier = NULL;
		}
		string_gadget_being_set = NULL;

		while (address) /* once for previous string, then next */
		{
		    CATCH_ERROR

		    if (qualifier & IEQUALIFIER_CONTROL)
		    {
			help_message ("Workbench Calibration Help");
		    }
	        /*
		 * Check for string GADGETDOWN
		 */
		    else if (class == IDCMP_GADGETDOWN && 
			((struct Gadget *) address)->GadgetType &
			GTYP_STRGADGET)
		    {
			string_gadget_being_set = address;
		    }
		    else if (address == (APTR) help_calibration_gadgetp)
		    {
			help_message ("Workbench Calibration Help");
		    }
		    else if (address == (APTR) end_calibration_gadgetp)
		    {
			requester__remove (calibration_rp, dialog_window_p);
			return;
		    }
		    else if (address == (APTR) no_calibration_gadgetp)
		    {
			if (CalibrationList)
			{
			    set_no_calibrations (NullString);
			    string_gadget__reset (calibration_gadgetp,
						  "\0", dialog_window_p);
			    string_gadget__reset (db_calibration_gadgetp,
						  "\0", dialog_window_p);
			    ACTIVATE_CAL_CANCEL;
			}
		    }
		    else if (address == (APTR) cancel_quantization_gadgetp)
		    {
			set_quantization (NullString);
			string_gadget__reset (quantization_gadgetp,
					      "\0", dialog_window_p);
		    }
		    else if (address == (APTR) cancel_low_y_gadgetp)
		    {
			set_low_y (NullString);
			string_gadget__reset (low_y_gadgetp,
					      "\0", dialog_window_p);
		    }
		    else if (address == (APTR) cancel_high_y_gadgetp)
		    {
			set_high_y (NullString);
			string_gadget__reset (high_y_gadgetp,
					      "\0", dialog_window_p);
		    }
		    else if (address == (APTR) calibration_gadgetp)
		    {
			struct StringInfo *sinfop =
			  calibration_gadgetp->SpecialInfo;
			char *buffer = sinfop->Buffer;
			WORD *bpos = &sinfop->BufferPos;
			if (strlen (buffer) && *bpos > 0)
			{
			    cal_prog_begin (calibration_gadgetp,
					    set_calibration);
			    ACTIVATE_CAL_CANCEL;
			    *bpos = 0;
			    refresh_gadget (calibration_gadgetp,
					    dialog_window_p);
			}
			if (!next_address)
			{
			    ActivateGadget (db_calibration_gadgetp,
					    dialog_window_p,
					    calibration_rp);
			}
		    }
		    else if (address == (APTR) select_calibration_gadgetp)
		    {
			char *calibration_file = file_requestor
			  ("Select Calibration File");
			if (calibration_file)
			{
			    struct StringInfo *sinfop =
			      calibration_gadgetp->SpecialInfo;
			    WORD *bpos = &sinfop->BufferPos;

			    string_gadget__reset (calibration_gadgetp,
						  calibration_file,
						  dialog_window_p);
			    cal_prog_begin (calibration_gadgetp,
					    set_calibration);

			    ACTIVATE_CAL_CANCEL;
			    *bpos = 0;
			    refresh_gadget (calibration_gadgetp,
					    dialog_window_p);
			}
			if (!next_address)
			{
			    ActivateGadget (calibration_gadgetp,
					    dialog_window_p,
					    calibration_rp);
			}
		    }
		    else if (address == (APTR) db_calibration_gadgetp)
		    {
			struct StringInfo *sinfop =
			  db_calibration_gadgetp->SpecialInfo;
			char *buffer = sinfop->Buffer;
			WORD *bpos = &sinfop->BufferPos;
			if (strlen (buffer) && *bpos > 0)
			{
			    cal_prog_begin (db_calibration_gadgetp,
					    set_db_calibration);
			    ACTIVATE_CAL_CANCEL;
			    *bpos = 0;
			    refresh_gadget (calibration_gadgetp,
					    dialog_window_p);
			}
			if (!next_address)
			{
			    ActivateGadget (quantization_gadgetp,
					    dialog_window_p,
					    calibration_rp);
			}
		    }
		    else if (address == (APTR) 
			     select_db_calibration_gadgetp)
		    {
			char *db_calibration_file = file_requestor
			  ("Select dB Calibration File");
			if (db_calibration_file)
			{
			    struct StringInfo *sinfop =
			      db_calibration_gadgetp->SpecialInfo;
			    WORD *bpos = &sinfop->BufferPos;

			    string_gadget__reset (db_calibration_gadgetp,
						  db_calibration_file,
						  dialog_window_p);
			    cal_prog_begin (db_calibration_gadgetp,
					    set_db_calibration);
			    ACTIVATE_CAL_CANCEL;
			    *bpos = 0;
			    refresh_gadget (db_calibration_gadgetp,
					    dialog_window_p);
			}
			if (!next_address)
			{
			    ActivateGadget (db_calibration_gadgetp,
					    dialog_window_p,
					    calibration_rp);
			}
		    }
		    else if (address == (APTR) quantization_gadgetp)
		    {
			string_gadget__apply (quantization_gadgetp, 
					      set_quantization);
			if (Quantization == MIN_QUANTIZATION)
			{
			    struct StringInfo *sinfop =
			      quantization_gadgetp->SpecialInfo;
			    char *buffer = sinfop->Buffer;
			    buffer[0] = '\0';
			    refresh_gadget (quantization_gadgetp,
					    dialog_window_p);
			}
			if (!next_address)
			{
			    ActivateGadget (low_y_gadgetp,
					    dialog_window_p,
					    calibration_rp);
			}
		    }
		    else if (address == (APTR) low_y_gadgetp)
		    {
			string_gadget__apply (low_y_gadgetp, 
					      set_low_y);
			if (!next_address)
			{
			    ActivateGadget (high_y_gadgetp,
					    dialog_window_p,
					    calibration_rp);
			}
		    }
		    else if (address == (APTR) high_y_gadgetp)
		    {
			string_gadget__apply (high_y_gadgetp, 
					      set_high_y);
			if (!next_address)
			{
			    ActivateGadget (calibration_gadgetp,
					    dialog_window_p,
					    calibration_rp);
			}
		    }
		    END_CATCH_ERROR;
		    address = next_address;
		    class = next_class;
		    qualifier = next_qualifier;
		    next_address = NULL;
		    next_class = NULL;
		    next_qualifier = NULL;
		} /* while next address */
	    }
	}
    }
}

static void cal_proc_message (void)
{
    sprintf (message_string, Processing_Calibration_S);
    message_gadget__write (calibration_message_gadgetp, 
			   message_string, dialog_window_p);
}

static void cal_prog_begin (struct Gadget *cal_gadgetp, 
			    char *cal_func(char *arg))
{
    static struct Requester *cal_progress_rp = NULL;

    cal_proc_message ();

    if (!cal_progress_rp)
      cal_progress_rp = progress_requester__new
      (Processing_Calibration_S, 35);

    name_string_gadget__apply (cal_gadgetp, cal_prog_get_name);

    progress_requester__apply (cal_progress_rp,
			       cal_func,
			       calibration_filename,
			       dialog_window_p);
}    

static char *cal_prog_get_name (char *cal_filename)
{
    calibration_filename = cal_filename;
    return cal_filename;
}



#endif /* end ifdef AMIGA */




[ RETURN TO DIRECTORY ]