home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 2 / goldfish_vol2_cd1.bin / files / misc / sci / gfft / source / wbcalib.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-07  |  11.5 KB  |  438 lines

  1. /***************************************************************************
  2.  *          Copyright (C) 1994  Charles P. Peterson                  *
  3.  *         4007 Enchanted Sun, San Antonio, Texas 78244-1254             *
  4.  *              Email: Charles_P_Peterson@fcircus.sat.tx.us                *
  5.  *                                                                         *
  6.  *          This is free software with NO WARRANTY.                  *
  7.  *          See gfft.c, or run program itself, for details.              *
  8.  *              Support is available for a fee.                      *
  9.  ***************************************************************************
  10.  *
  11.  * Program:     gfft--General FFT analysis
  12.  * File:        wbcalib.c
  13.  * Purpose:     requester to set calibration & quantization parameters
  14.  * Author:      Charles Peterson (CPP)
  15.  * History:     23-April-1994 CPP; Created.
  16.  *              4-Aug-94 CPP (1.04); Filenames may contain spaces
  17.  *              4-Aug-94 CPP (1.04); Allow full size pathnames here
  18.  *              5-Aug-94 CPP (1.05); Show total calibrations in effect
  19.  *              6-Aug-94 CPP (1.10); Minor interface improvements
  20.  * Comments:    Workbench GUI.  Amiga Dependent!
  21.  */
  22.  
  23. #ifdef AMIGA  /* This module is AMIGA dependent */
  24.  
  25. #include <stdio.h>     /* sprintf() */
  26. #include <string.h>
  27.  
  28. /*
  29.  * Amiga includes
  30.  */
  31. #include <exec/types.h>
  32. #include <workbench/workbench.h>
  33. #include <intuition/intuition.h>
  34. #include <clib/intuition_protos.h>
  35. #include <clib/exec_protos.h>
  36. #include <dos.h> /* chkabort() */
  37.  
  38. /*
  39.  * GFFT includes
  40.  */
  41. #include "gfft.h"
  42. #include "settings.h"  /* for testing */
  43. #include "wbench.h"
  44.  
  45. /*
  46.  * External globals
  47.  */
  48. extern struct Window *dialog_window_p;
  49.  
  50. /*
  51.  * Local statics
  52.  */
  53. static struct Requester *calibration_rp = NULL;
  54.  
  55. static struct Gadget *help_calibration_gadgetp;
  56. static struct Gadget *calibration_gadgetp;
  57. static struct Gadget *db_calibration_gadgetp;
  58. static struct Gadget *select_calibration_gadgetp;
  59. static struct Gadget *select_db_calibration_gadgetp;
  60. static struct Gadget *no_calibration_gadgetp;
  61. static struct Gadget *quantization_gadgetp;
  62. static struct Gadget *low_y_gadgetp;
  63. static struct Gadget *high_y_gadgetp;
  64. static struct Gadget *cancel_quantization_gadgetp;
  65. static struct Gadget *cancel_low_y_gadgetp;
  66. static struct Gadget *cancel_high_y_gadgetp;
  67. static struct Gadget *end_calibration_gadgetp;
  68. static struct Gadget *calibration_message_gadgetp;
  69.  
  70. static char message_string[80];
  71.  
  72. static void cal_proc_message (void);
  73.  
  74. #define MAX_VAL_SIZE 30
  75.  
  76. #if FALSE  /* defeat this for now */
  77. #define ACTIVATE_CAL_CANCEL \
  78.     if (CalibrationList) \
  79.     { \
  80.     gadget__enable (no_calibration_gadgetp, \
  81.              dialog_window_p); \
  82.     } \
  83.     else \
  84.     { \
  85.     gadget__disable (no_calibration_gadgetp, \
  86.              dialog_window_p); \
  87.     }
  88. #else
  89. #define ACTIVATE_CAL_CANCEL
  90. #endif
  91.  
  92. void calibration_requester (void)
  93. {
  94.     struct IntuiMessage *message;
  95.     APTR *address = NULL;
  96.     ULONG class = 0;
  97.     UWORD qualifier = NULL;
  98.     APTR *next_address = NULL;
  99.     ULONG next_class = 0;
  100.     UWORD next_qualifier = NULL;
  101.     APTR string_gadget_being_set = NULL;
  102.     char string[MAX_VAL_SIZE];
  103.  
  104.     if (!calibration_rp)
  105.     {
  106.     gadget__begin (GTYP_REQGADGET);
  107. /*
  108.  * Setup Gadgets
  109.  */
  110.     help_calibration_gadgetp = text_button__new ("Help", 0, 0);
  111.  
  112.     string[0] = '\0';
  113.     calibration_gadgetp = string_gadget__new ("Calibration:",
  114.                         string,
  115.                         MAX_PATH,
  116.                         47, 0, 1);
  117.  
  118.     select_calibration_gadgetp = text_button__new ("S",49,1);
  119.  
  120.     db_calibration_gadgetp = string_gadget__new ("dB Calibration:",
  121.                            string,
  122.                            MAX_PATH,
  123.                            47, 0, 2);
  124.  
  125.     select_db_calibration_gadgetp = text_button__new ("S",49,2);
  126.  
  127.     if (Quantization != MIN_QUANTIZATION)
  128.     {
  129.         sprintf (string, "%g", Quantization);
  130.     }
  131.     quantization_gadgetp = string_gadget__new ("Quantization:",
  132.                            string,
  133.                            MAX_VAL_SIZE,
  134.                            40, 0, 3);
  135.     cancel_quantization_gadgetp = text_button__new ("Cancel", 43, 3);
  136.  
  137.     if (LowY != LOWEST_Y)
  138.     {
  139.         sprintf (string, "%g", LowY);
  140.     }
  141.     low_y_gadgetp = string_gadget__new ("Low Y:",
  142.                            string,
  143.                            MAX_VAL_SIZE,
  144.                            40, 0, 4);
  145.  
  146.     cancel_low_y_gadgetp = text_button__new ("Cancel", 43, 4);
  147.  
  148.     if (HighY != HIGHEST_Y)
  149.     {
  150.         sprintf (string, "%g", HighY);
  151.     }
  152.     high_y_gadgetp = string_gadget__new ("High Y:",
  153.                            string,
  154.                            MAX_VAL_SIZE,
  155.                            40, 0, 5);
  156.  
  157.     cancel_high_y_gadgetp = text_button__new ("Cancel", 43, 5);
  158.  
  159.     calibration_message_gadgetp = message_gadget__new (50, 0, 6);
  160.  
  161.     no_calibration_gadgetp = text_button__new
  162.       ("Cancel All Calibrations", 0, 7);
  163.  
  164.     end_calibration_gadgetp = text_button__new ("...Done", 43, 7);
  165.  
  166.     calibration_rp = requester__new ();
  167.     calibration_rp->ReqGadget = end_calibration_gadgetp;
  168.     calibration_rp->ReqText =  NULL;
  169.  
  170.     } /* Ok, calibration_rp has been created */
  171.     
  172.  
  173.     if (requester__display (calibration_rp, dialog_window_p))
  174.     {
  175.     ACTIVATE_CAL_CANCEL;
  176.     ActivateGadget (calibration_gadgetp,
  177.             dialog_window_p,
  178.             calibration_rp);
  179.     while (TRUE)
  180.     {
  181.         sprintf (message_string, "%d Calibration(s) in effect", 
  182.              calibration_list__count (&CalibrationList));
  183.         message_gadget__write (calibration_message_gadgetp, 
  184.                    message_string, dialog_window_p);
  185.         Wait (1 << dialog_window_p->UserPort->mp_SigBit);
  186.         while (message = (struct IntuiMessage *) GetMsg 
  187.            (dialog_window_p->UserPort))
  188.         {
  189.         class = message->Class;
  190.         qualifier = message->Qualifier;
  191.         address = message->IAddress;
  192.         ReplyMsg ((struct Message *) message);
  193.             /*
  194.          * Finish unfinished string
  195.          */
  196.  
  197.         if (string_gadget_being_set &&
  198.             string_gadget_being_set != address)
  199.         {
  200.             next_address = address;
  201.             next_class = class;
  202.             next_qualifier = qualifier;
  203.             address = string_gadget_being_set;
  204.             class = IDCMP_GADGETUP;
  205.             qualifier = NULL;
  206.         }
  207.         string_gadget_being_set = NULL;
  208.  
  209.         while (address) /* once for previous string, then next */
  210.         {
  211.             CATCH_ERROR
  212.  
  213.             if (qualifier & IEQUALIFIER_CONTROL)
  214.             {
  215.             help_message ("Workbench Calibration Help");
  216.             }
  217.             /*
  218.          * Check for string GADGETDOWN
  219.          */
  220.             else if (class == IDCMP_GADGETDOWN && 
  221.             ((struct Gadget *) address)->GadgetType &
  222.             GTYP_STRGADGET)
  223.             {
  224.             string_gadget_being_set = address;
  225.             }
  226.             else if (address == (APTR) help_calibration_gadgetp)
  227.             {
  228.             help_message ("Workbench Calibration Help");
  229.             }
  230.             else if (address == (APTR) end_calibration_gadgetp)
  231.             {
  232.             requester__remove (calibration_rp, dialog_window_p);
  233.             return;
  234.             }
  235.             else if (address == (APTR) no_calibration_gadgetp)
  236.             {
  237.             if (CalibrationList)
  238.             {
  239.                 set_no_calibrations (NullString);
  240.                 string_gadget__reset (calibration_gadgetp,
  241.                           "\0", dialog_window_p);
  242.                 string_gadget__reset (db_calibration_gadgetp,
  243.                           "\0", dialog_window_p);
  244.                 ACTIVATE_CAL_CANCEL;
  245.             }
  246.             }
  247.             else if (address == (APTR) cancel_quantization_gadgetp)
  248.             {
  249.             set_quantization (NullString);
  250.             string_gadget__reset (quantization_gadgetp,
  251.                           "\0", dialog_window_p);
  252.             }
  253.             else if (address == (APTR) cancel_low_y_gadgetp)
  254.             {
  255.             set_low_y (NullString);
  256.             string_gadget__reset (low_y_gadgetp,
  257.                           "\0", dialog_window_p);
  258.             }
  259.             else if (address == (APTR) cancel_high_y_gadgetp)
  260.             {
  261.             set_high_y (NullString);
  262.             string_gadget__reset (high_y_gadgetp,
  263.                           "\0", dialog_window_p);
  264.             }
  265.             else if (address == (APTR) calibration_gadgetp)
  266.             {
  267.             struct StringInfo *sinfop =
  268.               calibration_gadgetp->SpecialInfo;
  269.             char *buffer = sinfop->Buffer;
  270.             WORD *bpos = &sinfop->BufferPos;
  271.             if (strlen (buffer) && *bpos > 0)
  272.             {
  273.                 cal_proc_message ();
  274.                 name_string_gadget__apply 
  275.                   (calibration_gadgetp, set_calibration);
  276.                 ACTIVATE_CAL_CANCEL;
  277.                 *bpos = 0;
  278.                 refresh_gadget (calibration_gadgetp,
  279.                         dialog_window_p);
  280.             }
  281.             if (!next_address)
  282.             {
  283.                 ActivateGadget (db_calibration_gadgetp,
  284.                         dialog_window_p,
  285.                         calibration_rp);
  286.             }
  287.             }
  288.             else if (address == (APTR) select_calibration_gadgetp)
  289.             {
  290.             char *calibration_file = file_requestor
  291.               ("Select Calibration File");
  292.             if (calibration_file)
  293.             {
  294.                 struct StringInfo *sinfop =
  295.                   calibration_gadgetp->SpecialInfo;
  296.                 WORD *bpos = &sinfop->BufferPos;
  297.  
  298.                 string_gadget__reset (calibration_gadgetp,
  299.                           calibration_file,
  300.                           dialog_window_p);
  301.                 cal_proc_message ();
  302.                 name_string_gadget__apply 
  303.                   (calibration_gadgetp, set_calibration);
  304.  
  305.                 ACTIVATE_CAL_CANCEL;
  306.                 *bpos = 0;
  307.                 refresh_gadget (calibration_gadgetp,
  308.                         dialog_window_p);
  309.             }
  310.             if (!next_address)
  311.             {
  312.                 ActivateGadget (calibration_gadgetp,
  313.                         dialog_window_p,
  314.                         calibration_rp);
  315.             }
  316.             }
  317.             else if (address == (APTR) db_calibration_gadgetp)
  318.             {
  319.             struct StringInfo *sinfop =
  320.               db_calibration_gadgetp->SpecialInfo;
  321.             char *buffer = sinfop->Buffer;
  322.             WORD *bpos = &sinfop->BufferPos;
  323.             if (strlen (buffer) && *bpos > 0)
  324.             {
  325.                 cal_proc_message ();
  326.                 name_string_gadget__apply 
  327.                   (db_calibration_gadgetp, set_db_calibration);
  328.                 ACTIVATE_CAL_CANCEL;
  329.                 *bpos = 0;
  330.                 refresh_gadget (calibration_gadgetp,
  331.                         dialog_window_p);
  332.             }
  333.             if (!next_address)
  334.             {
  335.                 ActivateGadget (quantization_gadgetp,
  336.                         dialog_window_p,
  337.                         calibration_rp);
  338.             }
  339.             }
  340.             else if (address == (APTR) 
  341.                  select_db_calibration_gadgetp)
  342.             {
  343.             char *db_calibration_file = file_requestor
  344.               ("Select dB Calibration File");
  345.             if (db_calibration_file)
  346.             {
  347.                 struct StringInfo *sinfop =
  348.                   db_calibration_gadgetp->SpecialInfo;
  349.                 WORD *bpos = &sinfop->BufferPos;
  350.  
  351.                 string_gadget__reset (db_calibration_gadgetp,
  352.                           db_calibration_file,
  353.                           dialog_window_p);
  354.                 cal_proc_message ();
  355.                 name_string_gadget__apply 
  356.                   (db_calibration_gadgetp, set_db_calibration);
  357.  
  358.                 ACTIVATE_CAL_CANCEL;
  359.                 *bpos = 0;
  360.                 refresh_gadget (db_calibration_gadgetp,
  361.                         dialog_window_p);
  362.             }
  363.             if (!next_address)
  364.             {
  365.                 ActivateGadget (db_calibration_gadgetp,
  366.                         dialog_window_p,
  367.                         calibration_rp);
  368.             }
  369.             }
  370.             else if (address == (APTR) quantization_gadgetp)
  371.             {
  372.             string_gadget__apply (quantization_gadgetp, 
  373.                           set_quantization);
  374.             if (Quantization == MIN_QUANTIZATION)
  375.             {
  376.                 struct StringInfo *sinfop =
  377.                   quantization_gadgetp->SpecialInfo;
  378.                 char *buffer = sinfop->Buffer;
  379.                 buffer[0] = '\0';
  380.                 refresh_gadget (quantization_gadgetp,
  381.                         dialog_window_p);
  382.             }
  383.             if (!next_address)
  384.             {
  385.                 ActivateGadget (low_y_gadgetp,
  386.                         dialog_window_p,
  387.                         calibration_rp);
  388.             }
  389.             }
  390.             else if (address == (APTR) low_y_gadgetp)
  391.             {
  392.             string_gadget__apply (low_y_gadgetp, 
  393.                           set_low_y);
  394.             if (!next_address)
  395.             {
  396.                 ActivateGadget (high_y_gadgetp,
  397.                         dialog_window_p,
  398.                         calibration_rp);
  399.             }
  400.             }
  401.             else if (address == (APTR) high_y_gadgetp)
  402.             {
  403.             string_gadget__apply (high_y_gadgetp, 
  404.                           set_high_y);
  405.             if (!next_address)
  406.             {
  407.                 ActivateGadget (calibration_gadgetp,
  408.                         dialog_window_p,
  409.                         calibration_rp);
  410.             }
  411.             }
  412.             END_CATCH_ERROR;
  413.             address = next_address;
  414.             class = next_class;
  415.             qualifier = next_qualifier;
  416.             next_address = NULL;
  417.             next_class = NULL;
  418.             next_qualifier = NULL;
  419.         } /* while next address */
  420.         }
  421.     }
  422.     }
  423. }
  424.  
  425. static void cal_proc_message (void)
  426. {
  427.     sprintf (message_string, "Processing calibration file...");
  428.     message_gadget__write (calibration_message_gadgetp, 
  429.                message_string, dialog_window_p);
  430. }
  431.  
  432.  
  433. #endif /* end ifdef AMIGA */
  434.  
  435.  
  436.  
  437.  
  438.