home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 2 / goldfish_vol2_cd1.bin / files / misc / sci / gfft / source / wbdialog.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-06  |  46.8 KB  |  1,688 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:        wbdialog.c
  13.  * Purpose:     workbench GUI dialog
  14.  * Author:      Charles Peterson (CPP)
  15.  * History:     19-Nov-1993 CPP; Created.
  16.  *              4-Aug-94 CPP (1.04); Filenames may contain spaces
  17.  *              5-Aug-94 CPP (1.05); Make append apply to name shown
  18.  *              5-Aug-94 CPP (1.10); Minor interface improvements
  19.  * Comments:    Workbench GUI.  Amiga Dependent!
  20.  *              We must exit from here on all fatal errors!
  21.  *              (Note: might have been started from CLI.  In that case,
  22.  *               don't expect to find any workbench message or icons.
  23.  *               Read and write files and options might already have been
  24.  *               selected through CLI arguments or commands.)
  25.  */
  26.  
  27. #ifdef AMIGA  /* This module is AMIGA dependent */
  28.  
  29. #include <stdio.h>     /* sprintf() */
  30. #include <string.h>
  31.  
  32. /*
  33.  * Amiga includes
  34.  */
  35. #include <exec/types.h>
  36. #include <workbench/workbench.h>
  37. #include <intuition/intuition.h>
  38. #include <clib/intuition_protos.h>
  39. #include <clib/exec_protos.h>
  40. #include <dos.h> /* chkabort() */
  41.  
  42. /*
  43.  * GFFT includes
  44.  */
  45. #include "gfft.h"
  46. #include "settings.h"  /* for testing */
  47. #include "wbench.h"
  48. #include "format.h"
  49.  
  50. /*
  51.  * special global variables defined here
  52.  */
  53. struct Window *dialog_window_p = NULL;
  54. struct Gadget *message_gadgetp;
  55.  
  56. /*
  57.  * Semi-global variables
  58.  */
  59. extern LONG num_files;
  60. extern LONG file_index;
  61. extern double LoopTimeElapsed;
  62.  
  63.  
  64. /*
  65.  * Strings from messages[.c|.h]
  66.  */
  67. extern const char NameAuthor[];
  68. extern const char VersionData[];
  69. extern const char Copyright[];
  70. extern char *Please_Select_Read_File_S;
  71. extern char *Set_Parameters_Then_Ok_S;
  72. extern char *Attempting_to_Perform_FFT_S;
  73. extern char *Set_Sampling_Rate_S;
  74. extern char *Verify_Sampling_Rate_S;
  75. extern char *Dialog_Window_Title;
  76.  
  77. /*
  78.  * From wbtools
  79.  */
  80. extern BOOLEAN Old_Intuition;
  81. extern short Screen_Font_Height;
  82.  
  83. /*
  84.  * From Amiga Hardware Reference Manual
  85.  */
  86. #define RAW_HELP_KEY 0x5f
  87.  
  88. /*
  89.  * Window definitions
  90.  */
  91. #define FONT_SIZE 8
  92.  
  93. #define SCREEN_WIDTH 640
  94. #define SCREEN_HEIGHT 200
  95. #define MAX_TEXT_COLS 75
  96. #define WINDOW_LEFT 0         /* Same as right edge */
  97. #define WINDOW_TOP 0          /* Allow for WB title & click area above */
  98. #define WINDOW_BOTTOM (FONT_SIZE * 5)  /* Allow for small console below */
  99.  
  100. #define SELECT_READ_FILE 1
  101. #define SELECT_PARAMETERS 2
  102. #define PERFORMING_FFT 3
  103. #define REMEMBER_MESSAGE 4
  104. #define SET_RATE 5
  105. #define VERIFY_RATE 6
  106.  
  107. /*
  108.  * Static variables for this file
  109.  */
  110. static struct Gadget *octave_2_gadgetp, *octave_3_gadgetp;
  111. static struct Gadget *octave_4_gadgetp, *octave_5_gadgetp;
  112. static struct Gadget *octave_6_gadgetp, *octave_7_gadgetp;
  113. static struct Gadget *octave_low_gadgetp, *octave_hi_gadgetp;
  114. static struct Gadget *ok_gadgetp, *CLI_gadgetp, *next_gadgetp;
  115. static struct Gadget *copyright_gadgetp, *select_read_gadgetp;
  116. static struct Gadget *read_file_gadgetp, *con_read_gadgetp;
  117. static struct Gadget *one_shot_gadgetp, *repeat_only_gadgetp;
  118. static struct Gadget *channel_gadgetp, *rate_gadgetp, *bins_gadgetp;
  119. static struct Gadget *bins_max_gadgetp, *overlap_gadgetp, *pad_gadgetp;
  120. static struct Gadget *interleave_gadgetp, *no_interleave_gadgetp;
  121. static struct Gadget *rectangle_gadgetp, *welch_gadgetp, *parzen_gadgetp;
  122. static struct Gadget *b_h_74db_gadgetp, *triangle_gadgetp;
  123. static struct Gadget *b_h_92db_gadgetp;
  124. static struct Gadget *hamming_gadgetp, *combine_plots_gadgetp;
  125. static struct Gadget *hann_gadgetp, *pink_gadgetp, *def_write_gadgetp;
  126. static struct Gadget *write_file_gadgetp, *cancel_write_gadgetp;
  127. static struct Gadget *low_f_gadgetp, *high_f_gadgetp, *time_segs_gadgetp;
  128. static struct Gadget *plot_gadgetp, *log_x_gadgetp, *log_y_gadgetp;
  129. static struct Gadget *amplitude_gadgetp, *power_gadgetp, *db_gadgetp;
  130. static struct Gadget *mean_gadgetp, *smoothing_gadgetp, *help_gadgetp;
  131. static struct Gadget *no_smoothing_gadgetp, *sq_smoothing_gadgetp;
  132. static struct Gadget *re_plot_gadgetp, *re_output_gadgetp;
  133. static struct Gadget *time3d_gadgetp, *cut_plots_gadgetp;
  134. static struct Gadget *append_gadgetp, *cal_gadgetp;
  135. static struct Gadget *spectrum_select_gadgetp;
  136.  
  137. APTR *last_address = NULL;
  138.  
  139. #define DONT_KNOW -1
  140. static ULONG bins_used = DONT_KNOW;
  141. static wb_append_on = FALSE;
  142.  
  143. /*
  144.  * local functions
  145.  */
  146. static void message__set (int message_number);
  147. static void octave_buttons__set (void);
  148. static void fdep_buttons__enable (void);
  149. static void window_buttons__set (void);
  150. static void read_parameters__set (void);
  151. static void rate_gadget__update (void);
  152. static void amplitude__set (void);
  153. static void bins_gadget__update (BOOLEAN force_update);
  154. static void bins_string__set (char *buffer);
  155. static void high_f_gadget__update (void);
  156. static void low_f_gadget__update (void);
  157. static void do_help (struct Gadget *gadgetp);
  158. static char *wb_set_append (char *arguments);
  159. static char *wb_no_set_append (char *arguments);
  160.  
  161. int workbench_dialog (void)
  162. {
  163.     struct NewWindow dialog_window;
  164.  
  165.     int next_action = WORKBENCH_MODE;
  166.     struct IntuiMessage *message;
  167.     APTR *address = NULL;
  168.     ULONG class = NULL;
  169.     UWORD qualifier = NULL;
  170.     UWORD code = NULL;
  171.     APTR next_address = NULL;
  172.     ULONG next_class = NULL;
  173.     UWORD next_code = NULL;
  174.     UWORD next_qualifier = NULL;
  175.     BOOLEAN last_plot;
  176.     char channel_string[20];
  177.     char rate_string[32];
  178.     char bins_string[20];
  179.     char low_f_string[32];
  180.     char high_f_string[32];
  181.     char smoothing_string[20];
  182.     char copyright_string[132];
  183.     int copyright_indent;
  184.     int copyright_delta;
  185.     int last_command_mode = CommandMode;
  186.     APTR string_gadget_being_set = NULL;
  187.     double s_rate = (Rate == AUTO_RATE) ? FileRate : Rate;
  188.  
  189.     CommandMode = WORKBENCH_MODE;
  190.     last_plot = Plot;
  191.     Plot = ANY_PLOT;
  192.  
  193.     open_libraries ();
  194.  
  195.     if (dialog_window_p == NULL)
  196.     {
  197.     /*
  198.      * Define the Gadgets
  199.      */
  200.  
  201.     gadget__begin (NULL);  /* Ensure requester mode off */
  202.  
  203.     /* Top Row */
  204.  
  205.     strcpy (copyright_string, NameAuthor);
  206.     strcat (copyright_string, VersionData);
  207.     strcat (copyright_string, " "); /* One space */
  208.     strcat (copyright_string, Copyright);
  209.     copyright_delta = MAX_TEXT_COLS - strlen (copyright_string);
  210.     if (1 & copyright_delta)
  211.     {
  212.         strcpy (copyright_string, NameAuthor);
  213.         strcat (copyright_string, VersionData);
  214.         strcat (copyright_string, "  "); /* Two spaces */
  215.         strcat (copyright_string, Copyright);
  216.     }
  217.     copyright_delta = MAX_TEXT_COLS - strlen (copyright_string);
  218.     copyright_indent = copyright_delta / 2;
  219.     copyright_gadgetp = text_button__new (copyright_string,
  220.                           copyright_indent, 0);
  221.     copyright_gadgetp->UserData = "Workbench Copyright";
  222.  
  223.     /* Second Row */
  224.  
  225.     help_gadgetp = text_button__new ("Help", 0, 1);
  226.     help_gadgetp->UserData = "Workbench Help";
  227.  
  228.     read_file_gadgetp = string_gadget__new ("Sample File:", ReadName,
  229.                         MAX_PATH, 49, 6, 1);
  230.     read_file_gadgetp->UserData = "Workbench Sample-File";
  231.  
  232.     select_read_gadgetp = text_button__new ("Select", 57, 1);
  233.     select_read_gadgetp->UserData = "Workbench Sample-Select";
  234.  
  235.     con_read_gadgetp = text_button__new ("con:", 65, 1);
  236.     con_read_gadgetp->UserData = "Workbench Sample-Con:";
  237.  
  238.     next_gadgetp = text_button__new ("Next", 71, 1);
  239.     next_gadgetp->UserData = "Workbench Next";
  240.     if (num_files <= 0 ||
  241.         num_files <= file_index + 1)
  242.     {
  243.         next_gadgetp->Flags |= GADGDISABLED;
  244.     }
  245.  
  246.  
  247.  
  248.     /* Third Row */
  249.  
  250.     octave_low_gadgetp = radio_button__new ("Low Oct", 0, 2);
  251.     octave_2_gadgetp = radio_button__new ("2", 9, 2);
  252.     octave_3_gadgetp = radio_button__new ("3", 12, 2);
  253.     octave_4_gadgetp = radio_button__new ("4", 15, 2);
  254.     octave_5_gadgetp = radio_button__new ("5", 18, 2);
  255.     octave_6_gadgetp = radio_button__new ("6", 21, 2);
  256.     octave_7_gadgetp = radio_button__new ("7", 24, 2);
  257.     octave_hi_gadgetp = radio_button__new ("Hi", 27, 2);
  258.     octave_buttons__set ();
  259.  
  260.     octave_low_gadgetp->UserData = "Workbench Octave-Low";
  261.     octave_2_gadgetp->UserData = "Workbench Octave-2";
  262.     octave_3_gadgetp->UserData = "Workbench Octave-3";
  263.     octave_4_gadgetp->UserData = "Workbench Octave-4";
  264.     octave_5_gadgetp->UserData = "Workbench Octave-5";
  265.     octave_6_gadgetp->UserData = "Workbench Octave-6";
  266.     octave_7_gadgetp->UserData = "Workbench Octave-7";
  267.     octave_hi_gadgetp->UserData = "Workbench Octave-Hi";
  268.  
  269.     one_shot_gadgetp = radio_button__new ("One-Shot Only", 32, 2);
  270.     one_shot_gadgetp->UserData = "Workbench One-Shot-Only";
  271.     if (OneShotOnly) one_shot_gadgetp->Flags |= SELECTED;
  272.  
  273.     repeat_only_gadgetp = radio_button__new ("Repeat Only", 48, 2);
  274.     repeat_only_gadgetp->UserData = "Workbench Repeat-Only";
  275.     if (RepeatOnly) repeat_only_gadgetp->Flags |= SELECTED;
  276.  
  277.     sprintf (channel_string,"%d",Channel);
  278.     channel_gadgetp = string_gadget__new ("Channel:", channel_string,
  279.                           3, 14, 61, 2);
  280.     channel_gadgetp->UserData = "Workbench Channel";
  281.  
  282.     /* Fourth Row */
  283.  
  284.     
  285.     if (s_rate != AUTO_RATE && s_rate != INVALID_RATE)
  286.     {
  287.         sprintf (rate_string, "%g", s_rate);
  288.     }
  289.     else
  290.     {
  291.         rate_string[0] = '\0';
  292.     }
  293.     rate_gadgetp = string_gadget__new ("S Rate:", rate_string,
  294.                        30, 20, 0, 3);
  295.     rate_gadgetp->UserData = "Workbench Rate";
  296.  
  297.     bins_string__set (bins_string);
  298.     bins_gadgetp = string_gadget__new ("Bins:", bins_string,
  299.                        12, 16, 22, 3);
  300.     bins_gadgetp->UserData = "Workbench Bins";
  301.  
  302.     bins_max_gadgetp = radio_button__new ("MAX", 40, 3);
  303.     bins_max_gadgetp->UserData = "Workbench Bins-Max";
  304.     if (NumberBins == MAX_BINS) radio_button__in (bins_max_gadgetp, 
  305.                               dialog_window_p);
  306.  
  307.     overlap_gadgetp = radio_button__new ("Overlap", 46, 3);
  308.     overlap_gadgetp->UserData = "Workbench Overlap";
  309.     if (Overlap) overlap_gadgetp->Flags |= SELECTED;
  310.  
  311. /*    pad_gadgetp = radio_button__new ("Pad", 56, 3); */
  312. /*    pad_gadgetp->UserData = "Workbench Pad";        */
  313. /*    if (Pad) pad_gadgetp->Flags |= SELECTED;        */
  314.  
  315.     cal_gadgetp = text_button__new ("Cal & Mag", 56, 3);
  316.     cal_gadgetp->UserData = "Workbench Cal-&-Mag";
  317.  
  318.     time3d_gadgetp = text_button__new ("3D-Time", 68, 3);
  319.     time3d_gadgetp->UserData = "Workbench 3D-Time";
  320.  
  321.  
  322.     /* Fifth Row */
  323.  
  324.     rectangle_gadgetp = radio_button__new ("Window:   Rectangle", 0, 4);
  325.     triangle_gadgetp = radio_button__new ("Triangle", 21, 4);
  326.     parzen_gadgetp = radio_button__new ("Parzen", 31, 4);
  327.     welch_gadgetp = radio_button__new ("Welch", 39, 4);
  328.     hann_gadgetp = radio_button__new ("Hann", 46, 4);
  329.     hamming_gadgetp = radio_button__new ("Hamming", 52, 4);
  330.     b_h_74db_gadgetp = radio_button__new ("B-H 74dB", 61, 4);
  331.     b_h_92db_gadgetp = radio_button__new ("92dB", 71, 4);
  332.     window_buttons__set ();
  333.  
  334.     rectangle_gadgetp->UserData = "Workbench Rectangle";
  335.     triangle_gadgetp->UserData = "Workbench Triangle";
  336.     parzen_gadgetp->UserData = "Workbench Parzen";
  337.     welch_gadgetp->UserData = "Workbench Welch";
  338.     hann_gadgetp->UserData = "Workbench Hann";
  339.     hamming_gadgetp->UserData = "Workbench Hamming";
  340.     b_h_74db_gadgetp->UserData = "Workbench 74dB-Blackman-Harris";
  341.     b_h_92db_gadgetp->UserData = "Workbench 92dB-Blackman-Harris";
  342.  
  343.  
  344.     /* Sixth Row */
  345.  
  346.  
  347.     if (LowFrequency != LOWEST_FREQUENCY)
  348.     {
  349.         sprintf (low_f_string, "%g", LowFrequency);
  350.     }
  351.     else
  352.     {
  353.         low_f_string[0] = '\0';
  354.     }
  355.     low_f_gadgetp = string_gadget__new ("Low Freq:", low_f_string,
  356.                         30, 22, 0, 5);
  357.     low_f_gadgetp->UserData = "Workbench Low-Frequency";
  358.  
  359.     if (HighFrequency != DBL_MAX)
  360.     {
  361.         sprintf (high_f_string, "%g", HighFrequency);
  362.     }
  363.     else
  364.     {
  365.         if (s_rate != AUTO_RATE && s_rate != INVALID_RATE)
  366.         {
  367.         sprintf (high_f_string, "%g", s_rate / 2);
  368.         }
  369.         else
  370.         {
  371.         high_f_string[0] = '\0';
  372.         }
  373.     }
  374.     high_f_gadgetp = string_gadget__new ("High Freq:", high_f_string,
  375.                          30, 23, 25, 5);
  376.     high_f_gadgetp->UserData = "Workbench High-Frequency";
  377.  
  378.     no_smoothing_gadgetp = radio_button__new ("NO", 73, 5);
  379.     no_smoothing_gadgetp->UserData = "Workbench Smoothing-No";
  380.  
  381.     if (SmoothingSegments != INVALID_SMOOTHING &&
  382.         SmoothingSegments != NO_SMOOTHING)
  383.     {
  384.         sprintf (smoothing_string, "%ld", SmoothingSegments);
  385.     }
  386.     else 
  387.     {
  388.         smoothing_string[0] = '\0';
  389.         if (SmoothingSegments != INVALID_SMOOTHING)
  390.         {
  391.         radio_button__in (no_smoothing_gadgetp, dialog_window_p);
  392.         }
  393.     }
  394.     smoothing_gadgetp = string_gadget__new ("Smooth:", smoothing_string,
  395.                         12, 17, 50, 5);
  396.     smoothing_gadgetp->UserData = "Workbench Smoothing";
  397.  
  398.     sq_smoothing_gadgetp = radio_button__new ("Sq", 69, 5);
  399.     sq_smoothing_gadgetp->UserData = "workbench Smoothing-Squared";
  400.     if (SquaredSmoothing) sq_smoothing_gadgetp->Flags |= SELECTED;
  401.  
  402.  
  403.     /* Seventh Row */
  404.  
  405.     plot_gadgetp = radio_button__new ("Plot", 0, 6);
  406.     plot_gadgetp->UserData = "Workbench Plot";
  407.     if (Plot != NO_PLOT) plot_gadgetp->Flags |= SELECTED;
  408.  
  409.     combine_plots_gadgetp = radio_button__new ("&", 6, 6);
  410.     combine_plots_gadgetp->UserData = "Workbench Plot-Combine";
  411.     if (CombinePlots) combine_plots_gadgetp->Flags |= SELECTED;
  412.  
  413.     cut_plots_gadgetp = text_button__new ("X", 9, 6);
  414.     cut_plots_gadgetp->UserData = "Workbench Plot-Cut";
  415.  
  416.     if (is_temp_file (WriteName))
  417.     {
  418.         write_file_gadgetp = string_gadget__new ("Spectrm File:", 
  419.                              NullString, MAX_PATH, 
  420.                              42, 12, 6);
  421.     }
  422.     else
  423.     {
  424.         write_file_gadgetp = string_gadget__new ("Spectrm File:", 
  425.                              WriteName, MAX_PATH, 
  426.                              42, 12, 6);
  427.     }
  428.     write_file_gadgetp->UserData = "Workbench Spectrum-File";
  429.  
  430.     spectrum_select_gadgetp = text_button__new ("S", 56, 6);
  431.     spectrum_select_gadgetp->UserData = 
  432.       "Workbench Spectrum-File-Select";
  433.  
  434.     append_gadgetp = radio_button__new ("Open", 59, 6);
  435.         append_gadgetp->UserData = "Workbench Spectrum-File-Open";
  436.  
  437.     cancel_write_gadgetp = text_button__new ("Can", 65, 6);
  438.     cancel_write_gadgetp->UserData = "Workbench Spectrum-File-Cancel";
  439.  
  440.     def_write_gadgetp = text_button__new ("*.fft", 70, 6);
  441.     def_write_gadgetp->UserData = "Workbench *.fft";
  442.  
  443.  
  444.     /* Eighth Row */
  445.  
  446.     CLI_gadgetp = text_button__new ("CLI", 0, 7);
  447.     CLI_gadgetp->UserData = "Workbench CLI";
  448.  
  449.     pink_gadgetp = radio_button__new ("Pink", 6, 7);
  450.     pink_gadgetp->UserData = "Workbench Pink";
  451.     if (Pink) pink_gadgetp->Flags |= SELECTED;
  452.  
  453.     amplitude_gadgetp = radio_button__new ("Ampl", 13, 7);
  454.     amplitude_gadgetp->UserData = "Workbench Amplitude";
  455.  
  456.     power_gadgetp = radio_button__new ("Power", 19, 7);
  457.     power_gadgetp->UserData = "Workbench Power";
  458.     amplitude__set ();
  459.  
  460.     mean_gadgetp = radio_button__new ("Mean", 27, 7);
  461.     mean_gadgetp->UserData = "Workbench Mean";
  462.     if (Mean) mean_gadgetp->Flags |= SELECTED;
  463.  
  464.     db_gadgetp = radio_button__new ("dB", 34, 7);
  465.     db_gadgetp->UserData = "Workbench dB";
  466.     if (Db) db_gadgetp->Flags |= SELECTED;
  467.  
  468.     log_x_gadgetp = radio_button__new ("LogX", 39, 7);
  469.     log_x_gadgetp->UserData = "Workbench Logx";
  470.  
  471.     log_y_gadgetp = radio_button__new ("LogY", 46, 7);
  472.     log_y_gadgetp->UserData = "Workbench Logy";
  473.  
  474.     re_plot_gadgetp = text_button__new ("RePlot", 53, 7);
  475.     re_plot_gadgetp->UserData = "Workbench RePlot";
  476.  
  477.     re_output_gadgetp = text_button__new ("ReOutput", 62, 7);
  478.     re_output_gadgetp->UserData = "Workbench ReOutput";
  479.  
  480.     ok_gadgetp = text_button__new ("OK", 73, 7);
  481.     ok_gadgetp->UserData = "Workbench OK";
  482.  
  483.  
  484.     /* Ninth Row */
  485.     /* IMPORTANT!  LAST GADGET MUST APPEAR IN WINDOW INITIALIZATION */
  486.  
  487.     message_gadgetp = message_gadget__new (75, 0, 8);
  488.     message_gadgetp->UserData = "Workbench Message";
  489.  
  490.     /*
  491.      * Define the Window
  492.      */
  493.     dialog_window.LeftEdge = WINDOW_LEFT;
  494.     dialog_window.TopEdge = WINDOW_TOP;
  495.     dialog_window.Width = SCREEN_WIDTH - (2 * WINDOW_LEFT);
  496.     dialog_window.Height = SCREEN_HEIGHT - WINDOW_TOP - WINDOW_BOTTOM
  497.       + Screen_Font_Height - 8;
  498.     dialog_window.DetailPen = 0;
  499.     dialog_window.BlockPen = 1;
  500.     dialog_window.Title = Dialog_Window_Title;
  501.     dialog_window.Flags = SMART_REFRESH | ACTIVATE | WINDOWCLOSE | 
  502.       WINDOWDRAG | WINDOWDEPTH | NOCAREREFRESH;
  503.     dialog_window.IDCMPFlags = IDCMP_CLOSEWINDOW | IDCMP_GADGETUP |
  504.       IDCMP_GADGETDOWN | IDCMP_RAWKEY;
  505.     if (Old_Intuition)
  506.     {
  507.         dialog_window.Type = WBENCHSCREEN;
  508.     }
  509.     else
  510.     {
  511.         dialog_window.Type = PUBLICSCREEN;  /* It's the latest thing */
  512.     }
  513.     dialog_window.FirstGadget = message_gadgetp;
  514.     dialog_window.Screen = NULL;
  515.     dialog_window.BitMap = NULL;
  516.     dialog_window.MinWidth = 0;
  517.     dialog_window.MinHeight = 0;
  518.     dialog_window.MaxWidth = 0;
  519.     dialog_window.MaxHeight = 0;
  520.     
  521.     /* Try to open the window.  Like the call to OpenLibrary(), if
  522.      * the OpenWindow call is successful, it returns a pointer to
  523.      * the structure for your new window.  If the OpenWindow() call
  524.      * fails, it returns a zero.
  525.      */
  526.     
  527.     if ((dialog_window_p = (struct Window *) OpenWindow 
  528.          (&dialog_window)) == NULL )
  529.     {
  530.         gabort (EXIT_FAILURE);
  531.     }
  532.     }
  533.     if (ReadName && strlen(ReadName))
  534.     {
  535.     read_parameters__set ();
  536.     message__set (SELECT_PARAMETERS);
  537.     }
  538.     else
  539.     {
  540.     message__set (SELECT_READ_FILE);
  541.     }
  542.  
  543. /* Handle events */
  544.  
  545.     while (TRUE)
  546.     {
  547.     chkabort ();
  548.     Wait (1 << dialog_window_p->UserPort->mp_SigBit);
  549.     while (message = (struct IntuiMessage *) GetMsg 
  550.            (dialog_window_p->UserPort))
  551.     {
  552.         class = message->Class;
  553.         address = message->IAddress;
  554.         qualifier = message->Qualifier;
  555.         code = message->Code;
  556.         ReplyMsg ((struct Message *) message);
  557.     /*
  558.      * IDCMP_CLOSEWINDOW doesn't have an IAddress
  559.          * so must be handled here.
  560.          */
  561.         if (class == IDCMP_CLOSEWINDOW) goto closewindow;
  562.         /*
  563.          * Finish unfinished string
  564.          */
  565.  
  566.         if (string_gadget_being_set &&
  567.         string_gadget_being_set != address && !
  568.         (string_gadget_being_set == read_file_gadgetp &&
  569.          (address == (APTR) select_read_gadgetp) ||
  570.          (address == (APTR) con_read_gadgetp)))
  571.         {
  572.         next_address = address;
  573.         next_class = class;
  574.         next_qualifier = qualifier;
  575.         next_code = code;
  576.  
  577.         address = string_gadget_being_set;
  578.         class = IDCMP_GADGETUP;
  579.         qualifier = NULL;
  580.         code = NULL;
  581.         }
  582.         string_gadget_being_set = NULL;
  583.  
  584.         while (address)
  585.         {
  586.         CATCH_ERROR;
  587.         /*
  588.              * Here begins massive compound if statement
  589.              */
  590.         if (class == IDCMP_RAWKEY)
  591.         {
  592.             /* Test for HELP key on keyboard...
  593.                  * At present, I'm not happy with the way this works.
  594.          * If a string gadget is activated, there is no response.
  595.                  * So, I'm leaving it as undocumented, maybe it will
  596.                  *   help someone anyway.  Meanwhile there is a help
  597.                  *   button which does the same thing.
  598.                  */
  599.             if (code == RAW_HELP_KEY)
  600.             {
  601.             workbench_help_requester ();
  602.             }
  603.         } /* end if class == IDCMP_RAWKEY */
  604.  
  605.         else if (qualifier & IEQUALIFIER_CONTROL)
  606.         {
  607.                 /*
  608.                  * CTRL and any gadget select gives help on that gadget
  609.          */
  610.             do_help ((struct Gadget *) address);
  611.         }
  612.         /*
  613.              * Check for string GADGETDOWN
  614.          */
  615.         else if (class == IDCMP_GADGETDOWN && 
  616.              ((struct Gadget *) address)->GadgetType &
  617.              GTYP_STRGADGET)
  618.         {
  619.             string_gadget_being_set = address;
  620.         }
  621.         else if (address == (APTR) help_gadgetp)
  622.         {
  623.             workbench_help_requester ();
  624.         }
  625.         else if (address == (APTR) ok_gadgetp)
  626.         {
  627.             ULONG check_frames = FileFrames;
  628.             message__set (PERFORMING_FFT);
  629.             CATCH_ERROR
  630.             {
  631.             ok (NullString);
  632.             loop_time_message_done (LoopTimeElapsed);
  633.             }
  634.             ON_ERROR
  635.             {
  636.             message__set (REMEMBER_MESSAGE);
  637.             }
  638.             END_CATCH_ERROR;
  639.  
  640.             if (check_frames != FileFrames)
  641.             {  /* A file scan has occurred */
  642.             bins_gadget__update (FALSE);
  643.             }
  644.         }
  645.         else if (address == (APTR) CLI_gadgetp)
  646.         {
  647.             next_action = INTERACTIVE_MODE;
  648.             goto closewindow;
  649.         }
  650.         else if (address == (APTR) copyright_gadgetp)
  651.         {
  652.             copyright_requester ();
  653.         }
  654.         else if (address == (APTR) cal_gadgetp)
  655.         {
  656.             calibration_requester ();
  657.         }
  658.         else if (address == (APTR) time3d_gadgetp)
  659.         {
  660.             time3d_requester ();
  661.             bins_gadget__update (FALSE);
  662.         }
  663.         else if (address == (APTR) rectangle_gadgetp)
  664.         {
  665.             set_rectangle (NullString);
  666.             window_buttons__set ();
  667.         }
  668.         else if (address == (APTR) triangle_gadgetp)
  669.         {
  670.             set_triangle (NullString);
  671.             window_buttons__set ();
  672.         }
  673.         else if (address == (APTR) parzen_gadgetp)
  674.         {
  675.             set_parzen (NullString);
  676.             window_buttons__set ();
  677.         }
  678.         else if (address == (APTR) welch_gadgetp)
  679.         {
  680.             set_welch (NullString);
  681.             window_buttons__set ();
  682.         }
  683.         else if (address == (APTR) hann_gadgetp)
  684.         {
  685.             set_hann (NullString);
  686.             window_buttons__set ();
  687.         }
  688.         else if (address == (APTR) hamming_gadgetp)
  689.         {
  690.             set_hamming (NullString);
  691.             window_buttons__set ();
  692.         }
  693.         else if (address == (APTR) b_h_74db_gadgetp)
  694.         {
  695.             set_blackman_harris_74db (NullString);
  696.             window_buttons__set ();
  697.         }
  698.         else if (address == (APTR) b_h_92db_gadgetp)
  699.         {
  700.             set_blackman_harris_92db (NullString);
  701.             window_buttons__set ();
  702.         }
  703.         else if (address == (APTR) one_shot_gadgetp)
  704.         {
  705.             if (one_shot_gadgetp->Flags & SELECTED)
  706.             {
  707.             set_no_one_shot_only (NullString);
  708.             radio_button__out (one_shot_gadgetp,
  709.                        dialog_window_p);
  710.             }
  711.             else
  712.             {
  713.             set_one_shot_only (NullString);
  714.             radio_button__in (one_shot_gadgetp,
  715.                       dialog_window_p);
  716.             radio_button__out (repeat_only_gadgetp,
  717.                        dialog_window_p);
  718.             }
  719.             bins_gadget__update (FALSE);
  720.         }
  721.         else if (address == (APTR) repeat_only_gadgetp)
  722.         {
  723.             if (repeat_only_gadgetp->Flags & SELECTED)
  724.             {
  725.             set_no_repeat_only (NullString);
  726.             radio_button__out (repeat_only_gadgetp,
  727.                        dialog_window_p);
  728.             }
  729.             else
  730.             {
  731.             set_repeat_only (NullString);
  732.             radio_button__in (repeat_only_gadgetp,
  733.                       dialog_window_p);
  734.             radio_button__out (one_shot_gadgetp,
  735.                        dialog_window_p);
  736.             }
  737.             bins_gadget__update (FALSE);
  738.         }
  739. /*        else if (address == (APTR) pad_gadgetp) */
  740. /*        { */
  741. /*            radio_button__toggle (pad_gadgetp, set_pad,  */
  742. /*                       set_no_pad, */
  743. /*                       dialog_window_p); */
  744. /*            bins_gadget__update (FALSE); */
  745. /*        } */
  746.         else if (address == (APTR) channel_gadgetp)
  747.         {
  748.             char *buffer = string_gadget__apply 
  749.               (channel_gadgetp, set_channel);
  750.             if (!strlen (buffer))
  751.             {
  752.             sprintf (buffer, "%d", Channel);
  753.             refresh_gadget (channel_gadgetp,
  754.                     dialog_window_p);
  755.             }
  756.         }
  757.         else if (address == (APTR) rate_gadgetp)
  758.         {
  759.             char *buffer = string_gadget__apply 
  760.               (rate_gadgetp, set_rate);
  761.             if (!strlen (buffer))
  762.             {
  763.             rate_gadget__update ();
  764.             }
  765.             high_f_gadget__update ();
  766.             message__set (SELECT_PARAMETERS);
  767.         }
  768.         else if (address == (APTR) bins_max_gadgetp)
  769.         {
  770.             set_bins (NullString);
  771.             radio_button__in (bins_max_gadgetp,
  772.                       dialog_window_p);
  773.             bins_gadget__update (TRUE);  /* Force */
  774.         }
  775.         else if (address == (APTR) bins_gadgetp)
  776.         {
  777.             char *buffer = string_gadget__apply 
  778.               (bins_gadgetp, set_bins);
  779.             if (strlen (buffer))
  780.             {
  781.             radio_button__out (bins_max_gadgetp,
  782.                        dialog_window_p);
  783.             }
  784.             else
  785.             {
  786.             radio_button__in (bins_max_gadgetp,
  787.                       dialog_window_p);
  788.             }
  789.             
  790.             bins_gadget__update (TRUE);  /* Force */
  791.         }
  792.         else if (address == (APTR) no_smoothing_gadgetp)
  793.         {
  794.             struct StringInfo *string_infop = 
  795.               smoothing_gadgetp->SpecialInfo;
  796.             char *buffer = string_infop->Buffer;
  797.             buffer[0] = '\0';
  798.             refresh_gadget (smoothing_gadgetp,
  799.                     dialog_window_p);
  800.             radio_button__in (no_smoothing_gadgetp,
  801.                       dialog_window_p);
  802.             set_smoothing_segments (NullString);
  803.         }
  804.         else if (address == (APTR) smoothing_gadgetp)
  805.         {
  806.             char *buffer = string_gadget__apply 
  807.               (smoothing_gadgetp, set_smoothing_segments);
  808.             if (strlen (buffer))
  809.             {
  810.             radio_button__out (no_smoothing_gadgetp,
  811.                        dialog_window_p);
  812.             }
  813.             else
  814.             {
  815.             radio_button__in (no_smoothing_gadgetp,
  816.                       dialog_window_p);
  817.             }
  818.             
  819.         }
  820.         else if (address == (APTR) sq_smoothing_gadgetp)
  821.         {
  822.             radio_button__toggle (sq_smoothing_gadgetp,
  823.                        set_squared_smoothing, 
  824.                        set_no_squared_smoothing,
  825.                        dialog_window_p);
  826.         }
  827.         else if (address == (APTR) octave_low_gadgetp)
  828.         {
  829.             Octave = 1;
  830.             octave_buttons__set ();
  831.             bins_gadget__update (FALSE);
  832.         }
  833.         else if (address == (APTR) octave_2_gadgetp)
  834.         {
  835.             Octave = 2;
  836.             octave_buttons__set ();
  837.             bins_gadget__update (FALSE);
  838.         }
  839.         else if (address == (APTR) octave_3_gadgetp)
  840.         {
  841.             Octave = 3;
  842.             octave_buttons__set ();
  843.             bins_gadget__update (FALSE);
  844.         }
  845.         else if (address == (APTR) octave_4_gadgetp)
  846.         {
  847.             Octave = 4;
  848.             octave_buttons__set ();
  849.             bins_gadget__update (FALSE);
  850.         }
  851.         else if (address == (APTR) octave_5_gadgetp)
  852.         {
  853.             Octave = 5;
  854.             octave_buttons__set ();
  855.             bins_gadget__update (FALSE);
  856.         }
  857.         else if (address == (APTR) octave_6_gadgetp)
  858.         {
  859.             Octave = 6;
  860.             octave_buttons__set ();
  861.             bins_gadget__update (FALSE);
  862.         }
  863.         else if (address == (APTR) octave_7_gadgetp)
  864.         {
  865.             Octave = 7;
  866.             octave_buttons__set ();
  867.             bins_gadget__update (FALSE);
  868.         }
  869.         else if (address == (APTR) octave_hi_gadgetp)
  870.         {
  871.             Octave = 0;
  872.             octave_buttons__set ();
  873.             bins_gadget__update (FALSE);
  874.         }
  875.         else if (address == (APTR) next_gadgetp)
  876.         {
  877.             next_action = NEXT_FILE;
  878.             goto closewindow;
  879.         }
  880.         else if (address == (APTR) select_read_gadgetp)
  881.         {
  882.             char *read_file = file_requestor 
  883.               ("Select Sample File");
  884.             if (read_file)
  885.             {
  886.             string_gadget__reset (read_file_gadgetp, read_file,
  887.                           dialog_window_p);
  888.             name_string_gadget__apply (read_file_gadgetp,
  889.                            set_read);
  890.             read_parameters__set ();
  891.             }
  892.             else
  893.             {
  894.             message__set (SELECT_READ_FILE);
  895.             }
  896.             gfree (read_file);
  897.         }
  898.         else if (address == (APTR) con_read_gadgetp)
  899.         {
  900.             set_read ("con:");
  901.             string_gadget__reset (read_file_gadgetp, "con:",
  902.                       dialog_window_p);
  903.             read_parameters__set ();
  904.         }
  905.         else if (address == (APTR) read_file_gadgetp)
  906.         {
  907.             CATCH_ERROR
  908.             {
  909.             name_string_gadget__apply (read_file_gadgetp, 
  910.                           set_read);
  911.             read_parameters__set ();
  912.             }
  913.             ON_ERROR
  914.             {
  915.             message__set (SELECT_READ_FILE);
  916.             }
  917.             END_CATCH_ERROR;
  918.         }
  919.         else if (address == (APTR) low_f_gadgetp)
  920.         {
  921.             char *buffer = string_gadget__apply 
  922.               (low_f_gadgetp, set_low_frequency);
  923.             if (!strlen (buffer))
  924.             {
  925.             low_f_gadget__update ();
  926.             }
  927.         }
  928.         else if (address == (APTR) high_f_gadgetp)
  929.         {
  930.             char *buffer = string_gadget__apply 
  931.               (high_f_gadgetp, set_high_frequency);
  932.             if (!strlen (buffer))
  933.             {
  934.             high_f_gadget__update ();
  935.             }
  936.         }
  937.         else if (address == (APTR) write_file_gadgetp)
  938.         {
  939.             if (wb_append_on)
  940.             {
  941.             name_string_gadget__apply (write_file_gadgetp,
  942.                            set_append);
  943.             }
  944.             else
  945.             {
  946.             name_string_gadget__apply (write_file_gadgetp,
  947.                            set_write);
  948.             }
  949.         }
  950.         else if (address == (APTR) spectrum_select_gadgetp)
  951.         {
  952.             char *spectrum_file = file_requestor
  953.               ("Select Spectrum File");
  954.             if (spectrum_file)
  955.             {
  956.             /* default now to append mode; usually helps */
  957.             radio_button__in (append_gadgetp, dialog_window_p);
  958.             wb_set_append (NullString);
  959.             string_gadget__reset (write_file_gadgetp, 
  960.                           spectrum_file,
  961.                           dialog_window_p);
  962.             if (wb_append_on)
  963.             {
  964.                 name_string_gadget__apply (write_file_gadgetp,
  965.                                set_append);
  966.             }
  967.             else
  968.             {
  969.                 name_string_gadget__apply (write_file_gadgetp,
  970.                                set_write);
  971.             }
  972.             }
  973.         }
  974.         else if (address == (APTR) append_gadgetp)
  975.         {
  976.             radio_button__toggle (append_gadgetp,
  977.                        wb_set_append, wb_no_set_append,
  978.                        dialog_window_p);
  979.         }
  980.         else if (address == (APTR) cancel_write_gadgetp)
  981.         {
  982.             string_gadget__reset (write_file_gadgetp,
  983.                       NullString, dialog_window_p);
  984.             if (wb_append_on)
  985.             {
  986.             set_append (NullString);
  987.             }
  988.             else
  989.             {
  990.             set_write (NullString);
  991.             }
  992.         }
  993.         else if (address == (APTR) def_write_gadgetp)
  994.         {
  995.             struct StringInfo *string_infop = 
  996.               write_file_gadgetp->SpecialInfo;
  997.             char *buffer = string_infop->Buffer;
  998.             if (ReadName)
  999.             {
  1000.             strcpy (buffer, ReadName);
  1001.             strcat (buffer, ".fft");
  1002.             }
  1003.             else
  1004.             {
  1005.             strcpy (buffer, ".fft");
  1006.             }
  1007.             string_infop->NumChars = strlen (buffer);
  1008.             if (wb_append_on)
  1009.             {
  1010.             name_string_gadget__apply (write_file_gadgetp,
  1011.                            set_append);
  1012.             }
  1013.             else
  1014.             {
  1015.             name_string_gadget__apply (write_file_gadgetp,
  1016.                            set_write);
  1017.             }
  1018.             refresh_gadget (write_file_gadgetp, 
  1019.                     dialog_window_p);
  1020.         }
  1021.         else if (address == (APTR) amplitude_gadgetp)
  1022.         {
  1023.             set_amplitude (NullString);
  1024.             amplitude__set ();
  1025.         }
  1026.         else if (address == (APTR) power_gadgetp)
  1027.         {
  1028.             set_power (NullString);
  1029.             amplitude__set ();
  1030.         }
  1031.         else if (address == (APTR) overlap_gadgetp)
  1032.         {
  1033.             radio_button__toggle (overlap_gadgetp,
  1034.                        set_overlap, set_no_overlap,
  1035.                        dialog_window_p);
  1036.         }
  1037.         else if (address == (APTR) db_gadgetp)
  1038.         {
  1039.             radio_button__toggle (db_gadgetp, 
  1040.                        set_db, set_no_db,
  1041.                        dialog_window_p);
  1042.         }
  1043.         else if (address == (APTR) pink_gadgetp)
  1044.         {
  1045.             radio_button__toggle (pink_gadgetp, set_pink, 
  1046.                        set_no_pink,
  1047.                        dialog_window_p);
  1048.         }
  1049.         else if (address == (APTR) mean_gadgetp)
  1050.         {
  1051.             radio_button__toggle (mean_gadgetp, set_mean, 
  1052.                        set_sum, 
  1053.                        dialog_window_p);
  1054.         }
  1055.         else if (address == (APTR) plot_gadgetp)
  1056.         {
  1057.             radio_button__toggle (plot_gadgetp, set_plot, 
  1058.                        set_no_plot,
  1059.                        dialog_window_p);
  1060.             last_plot = Plot;
  1061.         }
  1062.         else if (address == (APTR) combine_plots_gadgetp)
  1063.         {
  1064.             radio_button__toggle (combine_plots_gadgetp,
  1065.                        set_combine_plots,
  1066.                        set_no_combine_plots,
  1067.                        dialog_window_p);
  1068.         }
  1069.         else if (address == (APTR) cut_plots_gadgetp)
  1070.         {
  1071.             cut_combined_plot (NullString);
  1072.         }
  1073.         else if (address == (APTR) re_output_gadgetp)
  1074.         {
  1075.             re_output (NullString);
  1076.         }
  1077.         else if (address == (APTR) re_plot_gadgetp)
  1078.         {
  1079.             re_plot (NullString);
  1080.         }
  1081.         else if (address == (APTR) log_x_gadgetp)
  1082.         {
  1083.             radio_button__toggle (log_x_gadgetp, set_logx, 
  1084.                        set_no_logx,
  1085.                        dialog_window_p);
  1086.         }
  1087.         else if (address == (APTR) log_y_gadgetp)
  1088.         {
  1089.             radio_button__toggle (log_y_gadgetp, set_logy,
  1090.                        set_no_logy,
  1091.                        dialog_window_p);
  1092.         } /* end massive compound if*/
  1093.         END_CATCH_ERROR;
  1094.  
  1095.         last_address = address;
  1096.         address = next_address;
  1097.         class = next_class;
  1098.         qualifier = next_qualifier;
  1099.         code = next_code;
  1100.  
  1101.         next_address = NULL;
  1102.         next_class = NULL;
  1103.         next_qualifier = NULL;
  1104.         next_code = NULL;
  1105.  
  1106.         } /* end while (address) */
  1107.     } /* end while (message...) */
  1108.     } /* end while (TRUE) */
  1109.  
  1110. closewindow:    
  1111.     CloseWindow (dialog_window_p);
  1112.     dialog_window_p = NULL;
  1113.     if (class == IDCMP_CLOSEWINDOW)
  1114.     {
  1115.     quit (NullString);  /* it all ends here, no matter where started */
  1116.     }
  1117.     CommandMode = last_command_mode;
  1118.     Plot = last_plot;  /* reset previous default, unless changed */
  1119.     return next_action;
  1120. }
  1121.  
  1122. static void amplitude__set (void)
  1123. {
  1124.     if (Amplitude)
  1125.     {
  1126.     radio_button__in (amplitude_gadgetp, dialog_window_p);
  1127.     radio_button__out (power_gadgetp, dialog_window_p);
  1128.     }
  1129.     else
  1130.     {
  1131.     radio_button__in (power_gadgetp, dialog_window_p);
  1132.     radio_button__out (amplitude_gadgetp, dialog_window_p);
  1133.     }
  1134. }
  1135.  
  1136.  
  1137. static void window_buttons__set ()
  1138. {
  1139.     switch (WindowType)
  1140.     {
  1141.     case RECTANGLE_WINDOW:
  1142.     radio_button__in (rectangle_gadgetp, dialog_window_p);
  1143.     radio_button__out (triangle_gadgetp, dialog_window_p);
  1144.     radio_button__out (parzen_gadgetp, dialog_window_p);
  1145.     radio_button__out (welch_gadgetp, dialog_window_p);
  1146.     radio_button__out (hann_gadgetp, dialog_window_p);
  1147.     radio_button__out (hamming_gadgetp, dialog_window_p);
  1148.     radio_button__out (b_h_74db_gadgetp, dialog_window_p);
  1149.     radio_button__out (b_h_92db_gadgetp, dialog_window_p);
  1150.     break;
  1151.     case TRIANGLE_WINDOW:
  1152.     radio_button__out (rectangle_gadgetp, dialog_window_p);
  1153.     radio_button__in (triangle_gadgetp, dialog_window_p);
  1154.     radio_button__out (parzen_gadgetp, dialog_window_p);
  1155.     radio_button__out (welch_gadgetp, dialog_window_p);
  1156.     radio_button__out (hann_gadgetp, dialog_window_p);
  1157.     radio_button__out (hamming_gadgetp, dialog_window_p);
  1158.     radio_button__out (b_h_74db_gadgetp, dialog_window_p);
  1159.     radio_button__out (b_h_92db_gadgetp, dialog_window_p);
  1160.     break;
  1161.     case PARZEN_WINDOW:
  1162.     radio_button__out (rectangle_gadgetp, dialog_window_p);
  1163.     radio_button__out (triangle_gadgetp, dialog_window_p);
  1164.     radio_button__in (parzen_gadgetp, dialog_window_p);
  1165.     radio_button__out (welch_gadgetp, dialog_window_p);
  1166.     radio_button__out (hann_gadgetp, dialog_window_p);
  1167.     radio_button__out (hamming_gadgetp, dialog_window_p);
  1168.     radio_button__out (b_h_74db_gadgetp, dialog_window_p);
  1169.     radio_button__out (b_h_92db_gadgetp, dialog_window_p);
  1170.     break;
  1171.     case WELCH_WINDOW:
  1172.     radio_button__out (rectangle_gadgetp, dialog_window_p);
  1173.     radio_button__out (triangle_gadgetp, dialog_window_p);
  1174.     radio_button__out (parzen_gadgetp, dialog_window_p);
  1175.     radio_button__in (welch_gadgetp, dialog_window_p);
  1176.     radio_button__out (hann_gadgetp, dialog_window_p);
  1177.     radio_button__out (hamming_gadgetp, dialog_window_p);
  1178.     radio_button__out (b_h_74db_gadgetp, dialog_window_p);
  1179.     radio_button__out (b_h_92db_gadgetp, dialog_window_p);
  1180.     break;
  1181.     case HANN_WINDOW:
  1182.     radio_button__out (rectangle_gadgetp, dialog_window_p);
  1183.     radio_button__out (triangle_gadgetp, dialog_window_p);
  1184.     radio_button__out (parzen_gadgetp, dialog_window_p);
  1185.     radio_button__out (welch_gadgetp, dialog_window_p);
  1186.     radio_button__in (hann_gadgetp, dialog_window_p);
  1187.     radio_button__out (hamming_gadgetp, dialog_window_p);
  1188.     radio_button__out (b_h_74db_gadgetp, dialog_window_p);
  1189.     radio_button__out (b_h_92db_gadgetp, dialog_window_p);
  1190.     break;
  1191.     case HAMMING_WINDOW:
  1192.     radio_button__out (rectangle_gadgetp, dialog_window_p);
  1193.     radio_button__out (triangle_gadgetp, dialog_window_p);
  1194.     radio_button__out (parzen_gadgetp, dialog_window_p);
  1195.     radio_button__out (welch_gadgetp, dialog_window_p);
  1196.     radio_button__out (hann_gadgetp, dialog_window_p);
  1197.     radio_button__in (hamming_gadgetp, dialog_window_p);
  1198.     radio_button__out (b_h_74db_gadgetp, dialog_window_p);
  1199.     radio_button__out (b_h_92db_gadgetp, dialog_window_p);
  1200.     break;
  1201.     case BLACKMAN_HARRIS_74DB_WINDOW:
  1202.     radio_button__out (rectangle_gadgetp, dialog_window_p);
  1203.     radio_button__out (triangle_gadgetp, dialog_window_p);
  1204.     radio_button__out (parzen_gadgetp, dialog_window_p);
  1205.     radio_button__out (welch_gadgetp, dialog_window_p);
  1206.     radio_button__out (hann_gadgetp, dialog_window_p);
  1207.     radio_button__out (hamming_gadgetp, dialog_window_p);
  1208.     radio_button__in (b_h_74db_gadgetp, dialog_window_p);
  1209.     radio_button__out (b_h_92db_gadgetp, dialog_window_p);
  1210.     break;
  1211.     case BLACKMAN_HARRIS_92DB_WINDOW:
  1212.     radio_button__out (rectangle_gadgetp, dialog_window_p);
  1213.     radio_button__out (triangle_gadgetp, dialog_window_p);
  1214.     radio_button__out (parzen_gadgetp, dialog_window_p);
  1215.     radio_button__out (welch_gadgetp, dialog_window_p);
  1216.     radio_button__out (hann_gadgetp, dialog_window_p);
  1217.     radio_button__out (hamming_gadgetp, dialog_window_p);
  1218.     radio_button__out (b_h_74db_gadgetp, dialog_window_p);
  1219.     radio_button__in (b_h_92db_gadgetp, dialog_window_p);
  1220.     break;
  1221.     }
  1222. }
  1223.  
  1224. static void fdep_buttons__enable (void)
  1225. {
  1226.     BOOLEAN changed_value = FALSE;
  1227.     BOOLEAN no_one_shot_frames = TRUE;
  1228.     BOOLEAN no_repeat_frames = TRUE;
  1229.  
  1230.     if (!ReadPtr) return;
  1231.  
  1232.     switch (FileOctaves)
  1233.     {
  1234.     case 7:
  1235.     gadget__enable (octave_7_gadgetp, dialog_window_p);
  1236.     case 6:
  1237.     gadget__enable (octave_6_gadgetp, dialog_window_p);
  1238.     case 5:
  1239.     gadget__enable (octave_5_gadgetp, dialog_window_p);
  1240.     case 4:
  1241.     gadget__enable (octave_4_gadgetp, dialog_window_p);
  1242.     case 3:
  1243.     gadget__enable (octave_3_gadgetp, dialog_window_p);
  1244.     case 2:
  1245.     gadget__enable (octave_2_gadgetp, dialog_window_p);
  1246.     }
  1247.  
  1248.     switch (FileOctaves)
  1249.     {
  1250.     case 1:
  1251.     gadget__disable (octave_2_gadgetp, dialog_window_p);
  1252.     case 2:
  1253.     gadget__disable (octave_3_gadgetp, dialog_window_p);
  1254.     case 3:
  1255.     gadget__disable (octave_4_gadgetp, dialog_window_p);
  1256.     case 4:
  1257.     gadget__disable (octave_5_gadgetp, dialog_window_p);
  1258.     case 5:
  1259.     gadget__disable (octave_6_gadgetp, dialog_window_p);
  1260.     case 6:
  1261.     gadget__disable (octave_7_gadgetp, dialog_window_p);
  1262.     }
  1263.  
  1264.     if (FileChannels > 1)
  1265.     {
  1266.     gadget__enable  (channel_gadgetp, dialog_window_p);
  1267.     }
  1268.     else
  1269.     {
  1270.     if (Channel > 1)
  1271.     {
  1272.         set_channel (NullString);
  1273.         string_gadget__reset (channel_gadgetp, "1", dialog_window_p);
  1274.         changed_value = TRUE;
  1275.     }
  1276.     gadget__disable (channel_gadgetp, dialog_window_p);
  1277.     }
  1278.  
  1279.     if (FileFormat == ID_8SVX)
  1280.     {
  1281.     if (FileOneShotHiFrames)
  1282.     {
  1283.         gadget__enable (one_shot_gadgetp, dialog_window_p);
  1284.         no_one_shot_frames = FALSE;
  1285.     }
  1286.     if (FileRepeatHiFrames)
  1287.     {
  1288.         gadget__enable (repeat_only_gadgetp, dialog_window_p);
  1289.         no_repeat_frames = FALSE;
  1290.     }
  1291.     }
  1292.     if (no_one_shot_frames)
  1293.     {
  1294.     if (OneShotOnly)
  1295.     {
  1296.         set_no_one_shot_only (NullString);
  1297.         radio_button__out (one_shot_gadgetp, dialog_window_p);
  1298.         changed_value = TRUE;
  1299.     }
  1300.     gadget__disable (one_shot_gadgetp, dialog_window_p);
  1301.     }
  1302.     if (no_repeat_frames)
  1303.     {
  1304.     if (RepeatOnly)
  1305.     {
  1306.         set_no_repeat_only (NullString);
  1307.         radio_button__out (repeat_only_gadgetp, dialog_window_p);
  1308.         changed_value = TRUE;
  1309.     }
  1310.     gadget__disable (repeat_only_gadgetp, dialog_window_p);
  1311.     }
  1312.  
  1313.     if (changed_value)
  1314.     {
  1315.     error_message (CHANGED_FORMAT_DEP_VALUE);
  1316.     }
  1317. }
  1318.  
  1319.  
  1320. static void octave_buttons__set (void)
  1321. {
  1322.     switch (Octave)
  1323.     {
  1324.     case 0:
  1325.     radio_button__in (octave_hi_gadgetp, dialog_window_p);
  1326.     radio_button__out (octave_low_gadgetp, dialog_window_p);
  1327.     radio_button__out (octave_2_gadgetp, dialog_window_p);
  1328.     radio_button__out (octave_3_gadgetp, dialog_window_p);
  1329.     radio_button__out (octave_4_gadgetp, dialog_window_p);
  1330.     radio_button__out (octave_5_gadgetp, dialog_window_p);
  1331.     radio_button__out (octave_6_gadgetp, dialog_window_p);
  1332.     radio_button__out (octave_7_gadgetp, dialog_window_p);
  1333.     break;
  1334.     case 1:
  1335.     radio_button__out (octave_hi_gadgetp, dialog_window_p);
  1336.     radio_button__in (octave_low_gadgetp, dialog_window_p);
  1337.     radio_button__out (octave_2_gadgetp, dialog_window_p);
  1338.     radio_button__out (octave_3_gadgetp, dialog_window_p);
  1339.     radio_button__out (octave_4_gadgetp, dialog_window_p);
  1340.     radio_button__out (octave_5_gadgetp, dialog_window_p);
  1341.     radio_button__out (octave_6_gadgetp, dialog_window_p);
  1342.     radio_button__out (octave_7_gadgetp, dialog_window_p);
  1343.     break;
  1344.     case 2:
  1345.     radio_button__out (octave_hi_gadgetp, dialog_window_p);
  1346.     radio_button__out (octave_low_gadgetp, dialog_window_p);
  1347.     radio_button__in (octave_2_gadgetp, dialog_window_p);
  1348.     radio_button__out (octave_3_gadgetp, dialog_window_p);
  1349.     radio_button__out (octave_4_gadgetp, dialog_window_p);
  1350.     radio_button__out (octave_5_gadgetp, dialog_window_p);
  1351.     radio_button__out (octave_6_gadgetp, dialog_window_p);
  1352.     radio_button__out (octave_7_gadgetp, dialog_window_p);
  1353.     break;
  1354.     case 3:
  1355.     radio_button__out (octave_hi_gadgetp, dialog_window_p);
  1356.     radio_button__out (octave_low_gadgetp, dialog_window_p);
  1357.     radio_button__out (octave_2_gadgetp, dialog_window_p);
  1358.     radio_button__in (octave_3_gadgetp, dialog_window_p);
  1359.     radio_button__out (octave_4_gadgetp, dialog_window_p);
  1360.     radio_button__out (octave_5_gadgetp, dialog_window_p);
  1361.     radio_button__out (octave_6_gadgetp, dialog_window_p);
  1362.     radio_button__out (octave_7_gadgetp, dialog_window_p);
  1363.     break;
  1364.     case 4:
  1365.     radio_button__out (octave_hi_gadgetp, dialog_window_p);
  1366.     radio_button__out (octave_low_gadgetp, dialog_window_p);
  1367.     radio_button__out (octave_2_gadgetp, dialog_window_p);
  1368.     radio_button__out (octave_3_gadgetp, dialog_window_p);
  1369.     radio_button__in (octave_4_gadgetp, dialog_window_p);
  1370.     radio_button__out (octave_5_gadgetp, dialog_window_p);
  1371.     radio_button__out (octave_6_gadgetp, dialog_window_p);
  1372.     radio_button__out (octave_7_gadgetp, dialog_window_p);
  1373.     break;
  1374.     case 5:
  1375.     radio_button__out (octave_hi_gadgetp, dialog_window_p);
  1376.     radio_button__out (octave_low_gadgetp, dialog_window_p);
  1377.     radio_button__out (octave_2_gadgetp, dialog_window_p);
  1378.     radio_button__out (octave_3_gadgetp, dialog_window_p);
  1379.     radio_button__out (octave_4_gadgetp, dialog_window_p);
  1380.     radio_button__in (octave_5_gadgetp, dialog_window_p);
  1381.     radio_button__out (octave_6_gadgetp, dialog_window_p);
  1382.     radio_button__out (octave_7_gadgetp, dialog_window_p);
  1383.     break;
  1384.     case 6:
  1385.     radio_button__out (octave_hi_gadgetp, dialog_window_p);
  1386.     radio_button__out (octave_low_gadgetp, dialog_window_p);
  1387.     radio_button__out (octave_2_gadgetp, dialog_window_p);
  1388.     radio_button__out (octave_3_gadgetp, dialog_window_p);
  1389.     radio_button__out (octave_4_gadgetp, dialog_window_p);
  1390.     radio_button__out (octave_5_gadgetp, dialog_window_p);
  1391.     radio_button__in (octave_6_gadgetp, dialog_window_p);
  1392.     radio_button__out (octave_7_gadgetp, dialog_window_p);
  1393.     break;
  1394.     case 7:
  1395.     radio_button__out (octave_hi_gadgetp, dialog_window_p);
  1396.     radio_button__out (octave_low_gadgetp, dialog_window_p);
  1397.     radio_button__out (octave_2_gadgetp, dialog_window_p);
  1398.     radio_button__out (octave_3_gadgetp, dialog_window_p);
  1399.     radio_button__out (octave_4_gadgetp, dialog_window_p);
  1400.     radio_button__out (octave_5_gadgetp, dialog_window_p);
  1401.     radio_button__out (octave_6_gadgetp, dialog_window_p);
  1402.     radio_button__in (octave_7_gadgetp, dialog_window_p);
  1403.     break;
  1404.     }
  1405. }
  1406.  
  1407. static void read_parameters__set (void)
  1408. {
  1409.     if (!ReadName || ReadName == NullString) return;
  1410.     fdep_buttons__enable ();
  1411.     rate_gadget__update ();
  1412.     bins_gadget__update (FALSE);
  1413. /*    low_f_gadget__update (); now included in bins_gadget__update... */
  1414.     high_f_gadget__update ();
  1415.     if (FileFormat != UNFORMATTED)
  1416.     {
  1417.     message__set (SELECT_PARAMETERS);
  1418.     }
  1419.     else if (Rate == AUTO_RATE)
  1420.     {
  1421.     message__set (SET_RATE);
  1422.     }
  1423.     else
  1424.     {
  1425.     message__set (VERIFY_RATE);
  1426.     }
  1427. }
  1428.  
  1429. static void rate_gadget__update (void)
  1430. {
  1431.     double rate;
  1432.     struct StringInfo *string_infop = 
  1433.       rate_gadgetp->SpecialInfo;
  1434.     char *buffer = string_infop->Buffer;
  1435.  
  1436.     rate = (Rate == AUTO_RATE) ? FileRate : Rate;
  1437.     if (rate != AUTO_RATE)
  1438.     {
  1439.         sprintf (buffer,"%g",rate);
  1440.     }
  1441.     else
  1442.     {
  1443.     buffer[0] = '\0';
  1444.     }
  1445.     refresh_gadget (rate_gadgetp, dialog_window_p);
  1446. }
  1447.  
  1448.  
  1449. static void high_f_gadget__update (void)
  1450. {
  1451.     double rate;
  1452.     struct StringInfo *string_infop = 
  1453.       high_f_gadgetp->SpecialInfo;
  1454.     char *buffer = string_infop->Buffer;
  1455.  
  1456.     if (HighFrequency == DBL_MAX)
  1457.     {
  1458.         rate = (Rate == AUTO_RATE) ? FileRate : Rate;
  1459.     if (rate != AUTO_RATE)
  1460.     {
  1461.         sprintf (buffer, "%g", rate / (2 * Interleave));
  1462.         refresh_gadget (high_f_gadgetp, dialog_window_p);
  1463.     }
  1464.     }
  1465. }
  1466.  
  1467. static void low_f_gadget__update (void)
  1468. {
  1469.     double rate;
  1470.     struct StringInfo *string_infop = 
  1471.       low_f_gadgetp->SpecialInfo;
  1472.     char *buffer = string_infop->Buffer;
  1473.     BOOLEAN reset = FALSE;
  1474.  
  1475.     if (LowFrequency == LOWEST_FREQUENCY)
  1476.     {
  1477.         rate = (Rate == AUTO_RATE) ? FileRate : Rate;
  1478.     if (rate != AUTO_RATE)
  1479.     {
  1480.  
  1481. /*
  1482.  * Ahah, a beautiful divide by zero handling
  1483.  * if TRAP_TEST defined, just enter 0 into Bins gadget
  1484.  * Unfortunately, ffp math forces a trap on divide by zero, and
  1485.  * this cannot be intercepted without writing assembly code.  Damn.
  1486.  */
  1487.  
  1488. /* #define TRAP_TEST */
  1489.  
  1490. #ifdef TRAP_TEST
  1491.         if (bins_used != DONT_KNOW)  /* May divide by 0 */
  1492. #else
  1493.         if (bins_used != DONT_KNOW && bins_used > 0) /* Safe */
  1494. #endif
  1495.  
  1496.         {
  1497.         double low_f = rate / (2.0 * bins_used * Interleave);
  1498.         sprintf (buffer, "%g", low_f);
  1499.         reset = TRUE;
  1500.         }
  1501.     }
  1502.     if (!reset)
  1503.     {
  1504.         buffer[0] = '\0';
  1505.     }
  1506.     refresh_gadget (low_f_gadgetp, dialog_window_p);
  1507.     }
  1508. }
  1509.  
  1510. static void bins_gadget__update (BOOLEAN force_update)
  1511. {
  1512.     struct StringInfo *string_infop;
  1513.     char *buffer;
  1514.  
  1515.     if (NumberBins == MAX_BINS || force_update)
  1516.     {
  1517.     string_infop = bins_gadgetp->SpecialInfo;
  1518.     buffer = string_infop->Buffer;
  1519.     bins_string__set (buffer);
  1520.     refresh_gadget (bins_gadgetp, dialog_window_p);
  1521.     }
  1522.     low_f_gadget__update ();
  1523. }
  1524.  
  1525. static void bins_string__set (char *buffer)
  1526. {
  1527.     BOOLEAN done = FALSE;
  1528.  
  1529.     if (NumberBins != MAX_BINS)
  1530.     {
  1531.     bins_used = NumberBins;
  1532.     sprintf (buffer, "%ld", NumberBins);
  1533.     done = TRUE;
  1534.     }
  1535.     else if (ReadPtr != NULL && ReadPtr != stdin)
  1536.     {
  1537.         BOOLEAN save_quiet = Quiet;
  1538.     Quiet = TRUE;
  1539.  
  1540.     bins_used = DONT_KNOW;
  1541.     CATCH_ERROR;
  1542.     bins_used = do_ok (FALSE);
  1543.     sprintf (buffer, "%ld", bins_used);
  1544.     done = TRUE;
  1545.     END_CATCH_ERROR;
  1546.  
  1547.     Quiet = save_quiet;
  1548.     }
  1549.     if (!done) buffer[0] = '\0';
  1550. }
  1551.  
  1552.  
  1553. static void message__set (int message_number)
  1554. {
  1555.     static int remember_message = SELECT_PARAMETERS;
  1556.  
  1557.     switch (message_number)
  1558.     {
  1559.     case SELECT_READ_FILE:
  1560.     message_gadget__write (message_gadgetp,
  1561.                    Please_Select_Read_File_S,
  1562.                    dialog_window_p);
  1563.     ActivateGadget (read_file_gadgetp, dialog_window_p, NULL);
  1564.     remember_message = SELECT_READ_FILE;
  1565.     break;
  1566.     case SELECT_PARAMETERS:
  1567.     message_gadget__write (message_gadgetp,
  1568.                    Set_Parameters_Then_Ok_S,
  1569.                    dialog_window_p);
  1570.     remember_message = SELECT_PARAMETERS;
  1571.     break;
  1572.     case PERFORMING_FFT:
  1573.     message_gadget__write (message_gadgetp,
  1574.                    Attempting_to_Perform_FFT_S,
  1575.                    dialog_window_p);
  1576.     break;
  1577.     case SET_RATE:
  1578.     message_gadget__write (message_gadgetp,
  1579.                    Set_Sampling_Rate_S,
  1580.                    dialog_window_p);
  1581.     remember_message = SET_RATE;
  1582.     ActivateGadget (rate_gadgetp, dialog_window_p, NULL);
  1583.     break;
  1584.     case VERIFY_RATE:
  1585.     message_gadget__write (message_gadgetp,
  1586.                    Verify_Sampling_Rate_S,
  1587.                    dialog_window_p);
  1588.     ActivateGadget (rate_gadgetp, dialog_window_p, NULL);
  1589.     remember_message = VERIFY_RATE;
  1590.     break;
  1591.     case REMEMBER_MESSAGE:
  1592.     message__set (remember_message);
  1593.     break;
  1594.     }
  1595. }
  1596.  
  1597. static void do_help (struct Gadget *gadgetp)
  1598. {
  1599.     if (gadgetp->UserData)
  1600.     {
  1601.     help_message ( (char *) gadgetp->UserData);
  1602.     }
  1603.     else
  1604.     {
  1605.     error_message (HELP_MESSAGE_UNAVAILABLE);
  1606.     }
  1607. }
  1608.  
  1609. static char *wb_set_append (char *arguments)
  1610. {
  1611.     wb_append_on = TRUE;
  1612.     name_string_gadget__apply (write_file_gadgetp, set_append);
  1613.     return arguments;
  1614. }
  1615.  
  1616. static char *wb_no_set_append (char *arguments)
  1617. {
  1618.     wb_append_on = FALSE;
  1619.     if (last_address != (APTR) spectrum_select_gadgetp)
  1620.     {
  1621.     string_gadget__reset (write_file_gadgetp, NullString,
  1622.                   dialog_window_p);
  1623.     }
  1624.     name_string_gadget__apply (write_file_gadgetp, set_write);
  1625.     return arguments;
  1626. }
  1627.  
  1628.  
  1629.  
  1630.  
  1631.  
  1632.  
  1633.  
  1634. /*
  1635.  * Obsolete Gadgets (not enough room; deemed less important)
  1636.  */
  1637. #if FALSE
  1638.     char ileave_string[20];
  1639.  
  1640.     no_interleave_gadgetp = radio_button__new ("NO", 73, 3);
  1641.     if (Interleave > 1 && Interleave != INVALID_INTERLEAVE)
  1642.     {
  1643.         sprintf (ileave_string, "%ld", Interleave);
  1644.     }
  1645.     else
  1646.     {
  1647.         ileave_string[0] = '\0';
  1648.         if (Interleave != INVALID_INTERLEAVE)
  1649.         {
  1650.         radio_button__in (no_interleave_gadgetp, dialog_window_p);
  1651.         }
  1652.     }
  1653.     interleave_gadgetp = string_gadget__new ("Interleave:", 
  1654.                          ileave_string,
  1655.                          12, 20, 51, 3);
  1656.  
  1657.             else if (address == (APTR) no_interleave_gadgetp)
  1658.             {
  1659.                 struct StringInfo *string_infop = 
  1660.                   interleave_gadgetp->SpecialInfo;
  1661.                 char *buffer = string_infop->Buffer;
  1662.                 buffer[0] = '\0';
  1663.                 refresh_gadget (interleave_gadgetp,
  1664.                         dialog_window_p);
  1665.                 radio_button__in (no_interleave_gadgetp, 
  1666.                           dialog_window_p);
  1667.                 set_no_interleave (NullString);
  1668.                 bins_gadget__update (FALSE);
  1669.             }
  1670.             else if (address == (APTR) interleave_gadgetp)
  1671.             {
  1672.                 CATCH_ERROR
  1673.                 {
  1674.                 string_gadget__apply (interleave_gadgetp,
  1675.                               set_interleave);
  1676.                 }
  1677.                 END_CATCH_ERROR;
  1678.                 radio_button__out (no_interleave_gadgetp,
  1679.                            dialog_window_p);
  1680.                 bins_gadget__update (FALSE);
  1681.             }
  1682.  
  1683. #endif /* obsolete section */
  1684.  
  1685.  
  1686. #endif  /* ifdef AMIGA */
  1687.  
  1688.