home *** CD-ROM | disk | FTP | other *** search
/ Enigma Amiga Life 106 / EnigmaAmiga106CD.iso / software / sviluppo / ahisrc / ahi / gui_mui.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-08-29  |  29.4 KB  |  911 lines

  1. /*
  2.      AHI - The AHI preferences program
  3.      Copyright (C) 1996-1999 Martin Blom <martin@blom.org>
  4.      
  5.      This program is free software; you can redistribute it and/or
  6.      modify it under the terms of the GNU General Public License
  7.      as published by the Free Software Foundation; either version 2
  8.      of the License, or (at your option) any later version.
  9.      
  10.      This program is distributed in the hope that it will be useful,
  11.      but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.      GNU General Public License for more details.
  14.      
  15.      You should have received a copy of the GNU General Public License
  16.      along with this program; if not, write to the Free Software
  17.      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  18. */
  19.  
  20. /* $Id: gui_mui.c,v 4.10 1999/08/29 23:43:54 lcs Exp $
  21.  * $Log: gui_mui.c,v $
  22.  * Revision 4.10  1999/08/29 23:43:54  lcs
  23.  * Added support for ahigp_AntiClickTime.
  24.  *
  25.  * Revision 4.9  1999/04/22 19:41:22  lcs
  26.  * Removed SAS/C smakefile.
  27.  * I had the copyright date screwed up: Changed to 1996-1999 (which is only
  28.  * partly correct, but still better than 1997-1999....)
  29.  *
  30.  * Revision 4.8  1999/03/28 22:30:49  lcs
  31.  * AHI is now GPL/LGPL software.
  32.  * Make target bindist work correctly when using a separate build directory.
  33.  * Small first steps towards a WarpOS PPC version.
  34.  *
  35.  * Revision 4.7  1999/01/09 23:14:12  lcs
  36.  * Switched from SAS/C to gcc
  37.  *
  38.  * Revision 4.6  1997/07/15 00:51:28  lcs
  39.  * Fixed some bugs.
  40.  *
  41.  * Revision 4.5  1997/07/11 14:25:49  lcs
  42.  * Small bug fix: Wrong order of set() calls in guinewmode()
  43.  *
  44.  * Revision 4.4  1997/06/24 21:49:31  lcs
  45.  * Fixed an enforcer hit, and a few more potential ones (problem caused by
  46.  * having a 0-level slider (min 0, max -1...).
  47.  *
  48.  * Revision 4.3  1997/05/06 15:15:46  lcs
  49.  * Can now which pages with the keyboard.
  50.  * Fixed a bug in the mode properties code.
  51.  *
  52.  * Revision 4.2  1997/05/04 22:13:29  lcs
  53.  * Keyboard shortcuts and more.
  54.  *
  55.  * Revision 4.1  1997/05/04 05:30:28  lcs
  56.  * First MUI version.
  57.  *
  58.  *
  59.  */
  60.  
  61. #include <config.h>
  62. #include <CompilerSpecific.h>
  63.  
  64. #include <exec/memory.h>
  65. #include <libraries/asl.h>
  66. #include <libraries/gadtools.h>
  67. #include <libraries/mui.h>
  68. #include <proto/exec.h>
  69. #include <proto/dos.h>
  70. #include <proto/intuition.h>
  71. #include <proto/muimaster.h>
  72. #include <proto/utility.h>
  73. #include <math.h>
  74. #include <stdio.h>
  75. #include <string.h>
  76.  
  77. #include "ahi.h"
  78. #include "ahiprefs_Cat.h"
  79. #include "support.h"
  80. #include "gui.h"
  81.  
  82. static void GUINewSettings(void);
  83. static void GUINewUnit(void);
  84. static void GUINewMode(void);
  85.  
  86.  
  87. enum windowIDs {
  88.   WINID_MAIN=1,
  89.   WINID_COUNT
  90. };
  91.  
  92. enum actionIDs {
  93.   ACTID_OPEN=1, ACTID_SAVEAS, ACTID_ABOUT, ACTID_QUIT,
  94.   ACTID_DEFAULT, ACTID_LASTSAVED, ACTID_RESTORE,
  95.   ACTID_ICONS,
  96.   ACTID_HELP, ACTID_GUIDE, ACTID_HELPINDEX,
  97.   ACTID_SAVE, ACTID_USE,
  98.  
  99.   ACTID_TABS, ACTID_PAGE,
  100.  
  101.   ACTID_UNIT, ACTID_MODE, 
  102.   SHOWID_MODE,
  103.  
  104.   ACTID_FREQ, ACTID_CHANNELS, ACTID_OUTVOL, ACTID_MONVOL, ACTID_GAIN,
  105.   ACTID_INPUT, ACTID_OUTPUT,
  106.   SHOWID_FREQ, SHOWID_CHANNELS, SHOWID_OUTVOL, SHOWID_MONVOL, SHOWID_GAIN,
  107.   SHOWID_INPUT, SHOWID_OUTPUT,
  108.  
  109.   ACTID_DEBUG, ACTID_SURROUND, ACTID_ECHO, ACTID_CLIPMV,
  110.   ACTID_CPULIMIT, SHOWID_CPULIMIT,
  111.   ACTID_ACTIME, SHOWID_ACTIME,
  112.   
  113.  
  114.   ACTID_COUNT
  115. };
  116.  
  117. #define Title(t)        { NM_TITLE, t, NULL, 0, 0, NULL }
  118. #define Item(t,s,i)     { NM_ITEM, t, s, 0, 0, (APTR)i }
  119. #define ItemBar         { NM_ITEM, NM_BARLABEL, NULL, 0, 0, NULL }
  120. #define SubItem(t,s,i)  { NM_SUB, t, s, 0, 0, (APTR)i }
  121. #define SubBar          { NM_SUB, NM_BARLABEL, NULL, 0, 0, NULL }
  122. #define EndMenu         { NM_END, NULL, NULL, 0, 0, NULL }
  123. #define ItCk(t,s,i,f)   { NM_ITEM, t, s, f, 0, (APTR)i }
  124.  
  125. struct Library       *MUIMasterBase  = NULL;
  126.  
  127. static struct NewMenu Menus[] = {
  128.   Title( NULL /* Project */ ),
  129.     Item( NULL /* Open... */,             NULL, ACTID_OPEN      ),
  130.     Item( NULL /* Save As... */,          NULL, ACTID_SAVEAS    ),
  131.     ItemBar,
  132.     Item( NULL /* About... */,            NULL, ACTID_ABOUT     ),
  133.     ItemBar,
  134.     Item( NULL /* Quit */,                NULL, ACTID_QUIT      ),
  135.   Title( NULL /* Edit */ ),
  136.     Item( NULL /* Reset To Defaults */,   NULL, ACTID_DEFAULT   ),
  137.     Item( NULL /* Last Saved */,          NULL, ACTID_LASTSAVED ),
  138.     Item( NULL /* Restore */,             NULL, ACTID_RESTORE   ),
  139.   Title( NULL /* Settings */ ),
  140.     ItCk( NULL /* Create Icons? */,       NULL, ACTID_ICONS, CHECKIT|MENUTOGGLE ),
  141.   Title( NULL /* Help */ ),
  142.     ItCk( NULL /* Help... */,             NULL, ACTID_HELP, COMMSEQ),
  143.     ItemBar,
  144.     Item( NULL /* AHI User's guide... */, NULL, ACTID_GUIDE),
  145.     Item( NULL /* Concept Index... */,    NULL, ACTID_HELPINDEX ),
  146.   EndMenu
  147. };
  148.  
  149. static char *PageNames[] =
  150. {
  151.   NULL,  /* Mode settings */
  152.   NULL,  /* Advanced settings */
  153.   NULL
  154. };
  155.  
  156. static char * DebugLabels[] = {
  157.   NULL,  /* None */
  158.   NULL,  /* Low */
  159.   NULL,  /* High */
  160.   NULL,  /* Full */
  161.   NULL
  162. };
  163.  
  164. static char * EchoLabels[] = {
  165.   NULL,  /* Enabled */
  166.   NULL,  /* Fast */
  167.   NULL,  /* Disabled */
  168.   NULL
  169. };
  170.  
  171. static char * SurroundLabels[] = {
  172.   NULL,  /* Enabled */
  173.   NULL,  /* Disabled */
  174.   NULL
  175. };
  176.  
  177. static char * ClipMVLabels[] = {
  178.   NULL,  /* Without clipping */
  179.   NULL,  /* With clipping */
  180.   NULL
  181. };
  182.  
  183. /***** Local function to update the strings above ****************************/
  184.  
  185. static void UpdateStrings(void) {
  186.   char ** strings[] =
  187.   {
  188.     (char**) &msgMenuProject,
  189.     (char**) &msgItemOpen,
  190.     (char**) &msgItemSaveAs,
  191.     (char**) &msgItemAbout,
  192.     (char**) &msgItemQuit,
  193.     (char**) &msgMenuEdit,
  194.     (char**) &msgItemDefaults,
  195.     (char**) &msgItemLastSaved,
  196.     (char**) &msgItemRestore,
  197.     (char**) &msgMenuSettings,
  198.     (char**) &msgItemCreateIcons,
  199.     (char**) &msgMenuHelp,
  200.     (char**) &msgItemHelp,
  201.     (char**) &msgItemUsersGuide,
  202.     (char**) &msgItemConceptIndex
  203.   };
  204.  
  205.   struct NewMenu   *menuptr;
  206.   char           ***stringptr;
  207.   
  208.   menuptr   = (struct NewMenu *) &Menus;
  209.   stringptr = (char ***) &strings;
  210.  
  211.   while(menuptr->nm_Type != NM_END)
  212.   {
  213.     if(menuptr->nm_Label == NULL)
  214.     {
  215.       if(strlen(**stringptr) != 0) {
  216.         menuptr->nm_CommKey = **stringptr;
  217.       }
  218.       menuptr->nm_Label = **stringptr + strlen(**stringptr) + 1;
  219.       stringptr++;
  220.     }
  221.     menuptr++;
  222.   }
  223.  
  224.  
  225.   PageNames[0] = (char *) msgPageMode;
  226.   PageNames[1] = (char *) msgPageAdvanced;
  227.   DebugLabels[0] = (char *) msgDebugNone;
  228.   DebugLabels[1] = (char *) msgDebugLow;
  229.   DebugLabels[2] = (char *) msgDebugHigh;
  230.   DebugLabels[3] = (char *) msgDebugFull;
  231.   EchoLabels[0] = (char *) msgEchoEnabled;
  232.   EchoLabels[1] = (char *) msgEchoFast;
  233.   EchoLabels[2] = (char *) msgEchoDisabled;
  234.   SurroundLabels[0] = (char *) msgSurroundEnabled;
  235.   SurroundLabels[1] = (char *) msgSurroundDisabled;
  236.   ClipMVLabels[0] = (char *) msgMVNoClip;
  237.   ClipMVLabels[1] = (char *) msgMVClip;
  238.  
  239. }
  240.  
  241.  
  242. static Object *MUIWindow,*MUIList,*MUIInfos,*MUIUnit;
  243. static Object *MUIFreq,*MUIChannels,*MUIOutvol,*MUIMonvol,*MUIGain,*MUIInput,*MUIOutput;
  244. static Object *MUILFreq,*MUILChannels,*MUILOutvol,*MUILMonvol,*MUILGain,*MUILInput,*MUILOutput;
  245. static Object *MUIDebug,*MUIEcho,*MUISurround,*MUIClipvol,*MUICpu,*MUIACTime;
  246.  
  247. LONG xget(Object * obj, ULONG attribute)
  248. {
  249.   LONG x = 0;
  250.  
  251.   get(obj, attribute, &x);
  252.   return (x);
  253. }
  254.  
  255. static void GUINewSettings(void)
  256. {
  257.   set(MUIUnit,MUIA_Cycle_Active,state.UnitSelected);
  258.   set(MUIDebug, MUIA_Cycle_Active, globalprefs.ahigp_DebugLevel);
  259.   set(MUIEcho, MUIA_Cycle_Active, (globalprefs.ahigp_DisableEcho ? 2 : 0)|(globalprefs.ahigp_FastEcho    ? 1 : 0));
  260.   set(MUISurround, MUIA_Cycle_Active, globalprefs.ahigp_DisableSurround);
  261.   set(MUIClipvol, MUIA_Cycle_Active, globalprefs.ahigp_ClipMasterVolume);
  262.   set(MUICpu, MUIA_Cycle_Active, (globalprefs.ahigp_MaxCPU * 100 + 32768) >> 16);
  263.   set(MUIACTime, MUIA_Cycle_Active, (globalprefs.ahigp_AntiClickTime * 1000 + 32768) >> 16);
  264.   GUINewUnit();
  265. }
  266.  
  267. static void GUINewUnit(void)
  268. {
  269.   DoMethod(MUIList, MUIM_List_Clear);
  270.   set(MUIList, MUIA_List_Quiet, TRUE);
  271.   DoMethod(MUIList, MUIM_List_Insert, Modes, -1, MUIV_List_Insert_Bottom);
  272.   set(MUIList, MUIA_List_Quiet, FALSE);
  273.   set(MUIList, MUIA_List_Active, state.ModeSelected);
  274.   GUINewMode();
  275. }
  276.  
  277. static void GUINewMode(void)
  278. {
  279.   int Max, Sel;
  280.   char* buffer;
  281.   char* arg1 = getRecord();
  282.   char* arg2 = getAuthor();
  283.   char* arg3 = getCopyright();
  284.   char* arg4 = getDriver();
  285.   char* arg5 = getVersion();
  286.  
  287.   buffer = AllocVec( strlen( arg1 ) +
  288.                      strlen( arg2 ) +
  289.                      strlen( arg3 ) +
  290.                      strlen( arg4 ) +
  291.                      strlen( arg5 ) +
  292.                      128,
  293.                      MEMF_ANY);
  294.  
  295.   if( buffer != NULL )
  296.   {
  297.     sprintf( buffer,"0x%08lx\n%s\n%s\n%s\nDevs:AHI/%s.audio\n%s",
  298.       getAudioMode(),
  299.       arg1,
  300.       arg2,
  301.       arg3,
  302.       arg4,
  303.       arg5 );
  304.  
  305.     set(MUIInfos, MUIA_Text_Contents, (ULONG) buffer);
  306.  
  307.     FreeVec(buffer);
  308.   }
  309.  
  310.   Max = max(state.Frequencies -1, 0);
  311.   Sel = min(Max, state.FreqSelected);
  312.   set(MUIFreq, MUIA_Disabled, Max==0);
  313.   set(MUIFreq, MUIA_Numeric_Max, Max);
  314.   set(MUIFreq, MUIA_Numeric_Value, Sel);
  315.   set(MUILFreq, MUIA_Text_Contents, (ULONG) getFreq());
  316.  
  317.   Max = max(state.Channels, 0);
  318.   Sel = min(Max, state.ChannelsSelected);
  319.   set(MUIChannels, MUIA_Disabled, (Max == 1) || state.ChannelsDisabled);
  320.   set(MUIChannels, MUIA_Numeric_Max, Max);
  321.   set(MUIChannels, MUIA_Numeric_Value, Sel);
  322.   set(MUILChannels, MUIA_Text_Contents, (ULONG) getChannels());
  323.  
  324.   Max = max(state.OutVols -1, 0);
  325.   Sel = min(Max, state.OutVolSelected);
  326.   set(MUIOutvol, MUIA_Disabled, Max==0);
  327.   set(MUIOutvol, MUIA_Numeric_Max, Max);
  328.   set(MUIOutvol, MUIA_Numeric_Value, Sel);
  329.   set(MUILOutvol, MUIA_Text_Contents, (ULONG) getOutVol());
  330.  
  331.   Max = max(state.MonVols -1, 0);
  332.   Sel = min(Max, state.MonVolSelected);
  333.   set(MUIMonvol, MUIA_Disabled, Max==0);
  334.   set(MUIMonvol, MUIA_Numeric_Max, Max);
  335.   set(MUIMonvol, MUIA_Numeric_Value, Sel);
  336.   set(MUILMonvol, MUIA_Text_Contents, (ULONG) getMonVol());
  337.  
  338.   Max = max(state.Gains -1, 0);
  339.   Sel = min(Max, state.GainSelected);
  340.   set(MUIGain, MUIA_Disabled, Max==0);
  341.   set(MUIGain, MUIA_Numeric_Max, Max);
  342.   set(MUIGain, MUIA_Numeric_Value, Sel);
  343.   set(MUILGain, MUIA_Text_Contents, (ULONG) getGain());
  344.  
  345.   Max = max(state.Inputs -1, 0);
  346.   Sel = min(Max, state.InputSelected);
  347.   set(MUIInput, MUIA_Disabled, Max==0);
  348.   set(MUIInput, MUIA_Numeric_Max, Max);
  349.   set(MUIInput, MUIA_Numeric_Value, Sel);
  350.   set(MUILInput, MUIA_Text_Contents, (ULONG) getInput());
  351.  
  352.   Max = max(state.Outputs -1, 0);
  353.   Sel = min(Max, state.OutputSelected);
  354.   set(MUIOutput, MUIA_Disabled, Max==0);
  355.   set(MUIOutput, MUIA_Numeric_Max, Max);
  356.   set(MUIOutput, MUIA_Numeric_Value, Sel);
  357.   set(MUILOutput, MUIA_Text_Contents, (ULONG) getOutput());
  358. }
  359.  
  360. static VOID HOOKCALL
  361. SliderHookFunc( REG( a0, struct Hook *hook ),
  362.                 REG( a2, Object *obj ),
  363.                 REG( a1, ULONG** arg ) )
  364. {
  365.   if(obj == MUIFreq)
  366.   {
  367.     state.FreqSelected = (LONG) (*arg);
  368.     set(MUILFreq,MUIA_Text_Contents, (ULONG) getFreq());
  369.   }
  370.   else if(obj == MUIChannels )
  371.   {
  372.     state.ChannelsSelected = (LONG) (*arg);
  373.     set(MUILChannels,MUIA_Text_Contents, (ULONG) getChannels());
  374.   }
  375.   else if(obj == MUIOutvol )
  376.   {
  377.     state.OutVolSelected = (LONG) (*arg);
  378.     set(MUILOutvol,MUIA_Text_Contents, (ULONG) getOutVol());
  379.   }
  380.   else if(obj == MUIMonvol )
  381.   {
  382.     state.MonVolSelected = (LONG) (*arg);
  383.     set(MUILMonvol,MUIA_Text_Contents, (ULONG) getMonVol());
  384.   }
  385.   else if(obj == MUIGain )
  386.   {
  387.     state.GainSelected = (LONG) (*arg);
  388.     set(MUILGain,MUIA_Text_Contents, (ULONG) getGain());
  389.   }
  390.   else if(obj == MUIInput )
  391.   {
  392.     state.InputSelected = (LONG) (*arg);
  393.     set(MUILInput,MUIA_Text_Contents, (ULONG) getInput());
  394.   }
  395.   else if(obj == MUIOutput )
  396.   {
  397.   state.OutputSelected = (ULONG) (*arg);
  398.   set(MUILOutput,MUIA_Text_Contents, (ULONG) getOutput());
  399.   }
  400. }
  401.  
  402. static struct Hook hookSlider =
  403. {
  404.   { NULL, NULL },
  405.   (HOOKFUNC) SliderHookFunc,
  406.   NULL,
  407.   NULL
  408. };
  409.  
  410. /******************************************************************************
  411. **** Call to open the window **************************************************
  412. ******************************************************************************/
  413.  
  414. static Object *MUIApp,*MUIMenu;
  415.  
  416. static Object* SpecialLabel(STRPTR label)
  417. {
  418.   return(TextObject,
  419.       MUIA_HorizWeight, 75,
  420.       MUIA_Text_Contents, label,
  421.       MUIA_Text_PreParse, "\33l",
  422.     End);
  423. }
  424.  
  425. static Object* SpecialButton(STRPTR label)
  426. {
  427.   Object *button = NULL;
  428.   STRPTR lab;
  429.   
  430.   lab = AllocVec(strlen(label)+1,0);
  431.  
  432.   if( lab != NULL )
  433.   {
  434.     char ctrlchar = 0;
  435.     STRPTR l = lab;
  436.  
  437.     while(*label)
  438.     {
  439.       *l = *label;
  440.       if(*label++ == '_')
  441.       {
  442.         ctrlchar = ToLower(*label);
  443.         *l = *label++;
  444.       }
  445.       l++;
  446.     }
  447.     *l = '\0';
  448.     button = TextObject,
  449.       MUIA_HorizWeight, 0,
  450.       MUIA_Text_Contents, lab,
  451.       MUIA_Text_PreParse, "\33r",
  452.       MUIA_Text_HiChar, ctrlchar,
  453.       MUIA_ControlChar, ctrlchar,
  454.       MUIA_InputMode, MUIV_InputMode_RelVerify,
  455.       MUIA_ShowSelState, FALSE,
  456.     End;
  457.     FreeVec(lab);
  458.   }
  459.   return button;
  460. }
  461.  
  462. static Object* SpecialSlider(LONG min, LONG max, LONG value)
  463. {
  464.   return(SliderObject,
  465.       MUIA_CycleChain, 1,
  466.       MUIA_Slider_Quiet, TRUE,
  467.       MUIA_Numeric_Min, min,
  468.       MUIA_Numeric_Max,max,
  469.       MUIA_Numeric_Value,value,
  470.       MUIA_Numeric_Format, "",
  471.     End);
  472. }
  473.  
  474. BOOL BuildGUI(char *screenname)
  475. {
  476.   Object *MUISave, *MUIUse, *MUICancel;
  477.   Object *page1,*page2;
  478.   Object *MUITFreq,*MUITChannels,*MUITOutvol,*MUITMonvol,*MUITGain,*MUITInput,*MUITOutput,*MUITDebug,*MUITEcho,*MUITSurround,*MUITClipvol,*MUITCpu,*MUITACTime;
  479.  
  480.   UpdateStrings();
  481.  
  482.   MUIMasterBase = (void *)OpenLibrary("muimaster.library", MUIMASTER_VLATEST);
  483.   if(MUIMasterBase == NULL)
  484.   {
  485.     Printf((char *) msgTextNoOpen, (ULONG) "muimaster.library", MUIMASTER_VLATEST);
  486.     Printf("\n");
  487.     return FALSE;
  488.   }
  489.  
  490.   page1 = HGroup,
  491.     Child, VGroup,
  492.       Child, MUIUnit = CycleObject,
  493.         MUIA_CycleChain, 1,
  494.         MUIA_Cycle_Entries, Units,
  495.         MUIA_Cycle_Active, state.UnitSelected,
  496.       End,
  497.       Child, ListviewObject,
  498.         MUIA_CycleChain, 1,
  499.         MUIA_Listview_List, MUIList = ListObject,
  500.           InputListFrame,
  501.           MUIA_List_AutoVisible, TRUE,
  502.         End,
  503.       End,
  504.       Child, HGroup,
  505.         ReadListFrame,
  506.         MUIA_Background, MUII_TextBack,
  507.         Child, TextObject,
  508.           MUIA_Text_Contents, msgProperties,
  509.           MUIA_Text_SetMax, TRUE,
  510.         End,
  511.         Child, MUIInfos = TextObject,
  512.           MUIA_Text_Contents, "\n\n\n\n\n",
  513.           MUIA_Text_SetMin, FALSE,
  514.         End,
  515.       End,
  516.     End,
  517.     Child, BalanceObject,
  518.     End,
  519.     Child, VGroup,
  520.       Child, HVSpace,
  521.       Child, ColGroup(3),
  522.         GroupFrameT(msgOptions),
  523.         Child, MUITFreq = SpecialButton((STRPTR)msgOptFrequency),
  524.         Child, MUIFreq = SpecialSlider(0,max(state.Frequencies-1,0),state.FreqSelected),
  525.         Child, MUILFreq = SpecialLabel(getFreq()),
  526.         Child, MUITChannels = SpecialButton((STRPTR)msgOptChannels),
  527.         Child, MUIChannels = SpecialSlider(1,state.Channels,state.ChannelsSelected),
  528.         Child, MUILChannels = SpecialLabel(getChannels()),
  529.         Child, MUITOutvol = SpecialButton((STRPTR)msgOptVolume),
  530.         Child, MUIOutvol = SpecialSlider(0,max(state.OutVols-1,0),state.OutVolSelected),
  531.         Child, MUILOutvol = SpecialLabel(getOutVol()),
  532.         Child, MUITMonvol = SpecialButton((STRPTR)msgOptMonitor),
  533.         Child, MUIMonvol = SpecialSlider(0,max(state.MonVols-1,1),state.MonVolSelected),
  534.         Child, MUILMonvol = SpecialLabel(getMonVol()),
  535.         Child, MUITGain = SpecialButton((STRPTR)msgOptGain),
  536.         Child, MUIGain = SpecialSlider(0,max(state.Gains-1,0),state.GainSelected),
  537.         Child, MUILGain = SpecialLabel(getGain()),
  538.         Child, MUITInput = SpecialButton((STRPTR)msgOptInput),
  539.         Child, MUIInput = SpecialSlider(0,max(state.Inputs-1,0),state.InputSelected),
  540.         Child, MUILInput = SpecialLabel(getInput()),
  541.         Child, MUITOutput = SpecialButton((STRPTR)msgOptOutput),
  542.         Child, MUIOutput = SpecialSlider(0,max(state.Outputs-1,0),state.OutputSelected),
  543.         Child, MUILOutput = SpecialLabel(getOutput()),
  544.       End,
  545.       Child, HVSpace,
  546.     End,
  547.   End;
  548.  
  549.   page2 = VGroup,
  550.     Child, HVSpace,
  551.     Child, HGroup,
  552.       Child, HVSpace,
  553.       Child, ColGroup(2),
  554.         GroupFrameT(msgGlobalOptions),
  555.         Child, MUITDebug = SpecialButton((STRPTR)msgGlobOptDebugLevel),
  556.         Child, MUIDebug = CycleObject,
  557.           MUIA_CycleChain, 1,
  558.           MUIA_Cycle_Entries, DebugLabels,
  559.           MUIA_Cycle_Active, globalprefs.ahigp_DebugLevel,
  560.         End,
  561.         Child, MUITEcho = SpecialButton((STRPTR)msgGlobOptEcho),
  562.         Child, MUIEcho  = CycleObject,
  563.           MUIA_CycleChain, 1,
  564.           MUIA_Cycle_Entries, EchoLabels,
  565.           MUIA_Cycle_Active, (globalprefs.ahigp_DisableEcho ? 2 : 0) | (globalprefs.ahigp_FastEcho ? 1 : 0),
  566.         End,
  567.         Child, MUITSurround = SpecialButton((STRPTR)msgGlobOptSurround),
  568.         Child, MUISurround = CycleObject,
  569.           MUIA_CycleChain, 1,
  570.           MUIA_Cycle_Entries, SurroundLabels,
  571.           MUIA_Cycle_Active, globalprefs.ahigp_DisableSurround,
  572.         End,
  573.         Child, MUITClipvol = SpecialButton((STRPTR)msgGlobOptMasterVol),
  574.         Child, MUIClipvol = CycleObject,
  575.           MUIA_CycleChain, 1,
  576.           MUIA_Cycle_Entries, ClipMVLabels,
  577.           MUIA_Cycle_Active, globalprefs.ahigp_ClipMasterVolume,
  578.         End,
  579.         Child, MUITCpu = SpecialButton((STRPTR)msgGlobOptCPULimit),
  580.         Child, MUICpu = SliderObject,
  581.           MUIA_CycleChain, 1,
  582.           MUIA_Slider_Horiz, TRUE,
  583.           MUIA_Numeric_Min, 0,
  584.           MUIA_Numeric_Max, 100,
  585.           MUIA_Numeric_Value,(globalprefs.ahigp_MaxCPU * 100 + 32768) / 65536,
  586.           MUIA_Numeric_Format,"%ld%%",
  587.         End,
  588.         Child, MUITACTime = SpecialButton((STRPTR)msgGlobOptACTime),
  589.         Child, MUIACTime = SliderObject,
  590.           MUIA_CycleChain, 1,
  591.           MUIA_Slider_Horiz, TRUE,
  592.           MUIA_Numeric_Min, 0,
  593.           MUIA_Numeric_Max, 100,
  594.           MUIA_Numeric_Value,(globalprefs.ahigp_AntiClickTime * 1000 + 32768) >> 16,
  595.           MUIA_Numeric_Format,"%ld% ms",
  596.         End,
  597.       End,
  598.       Child, HVSpace,
  599.     End,
  600.     Child, HVSpace,
  601.   End;
  602.  
  603.   MUIApp = ApplicationObject,
  604.     MUIA_Application_Title, (char *) msgTextProgramName,
  605.     MUIA_Application_Version, Version,
  606.     MUIA_Application_Copyright, "©1996-1999 Martin Blom",
  607.     MUIA_Application_Author, "Stéphane Barbaray/Martin Blom",
  608.     MUIA_Application_Base, "AHI",
  609.     MUIA_Application_HelpFile, HELPFILE,
  610.     MUIA_Application_Menustrip, MUIMenu = MUI_MakeObject(MUIO_MenustripNM,Menus,0),
  611.     MUIA_Application_SingleTask, TRUE,
  612.     SubWindow, MUIWindow = WindowObject,
  613.       MUIA_Window_Title, (char *) msgTextProgramName,
  614.       MUIA_Window_ID   , MAKE_ID('M','A','I','N'),
  615.       MUIA_HelpNode, "AHI",
  616.       WindowContents, VGroup,
  617.         Child, RegisterGroup(PageNames),
  618.           MUIA_CycleChain, 1,
  619.           Child, page1,
  620.           Child, page2,
  621.         End,
  622.         Child, HGroup,
  623.           Child, MUISave = SimpleButton(msgButtonSave),
  624.           Child, MUIUse = SimpleButton(msgButtonUse),
  625.           Child, MUICancel = SimpleButton(msgButtonCancel),
  626.         End,
  627.       End,
  628.     End,
  629.   End;
  630.   
  631.   if( MUIApp != NULL )
  632.   {
  633.     APTR item = (APTR)DoMethod(MUIMenu,MUIM_FindUData,ACTID_ICONS);
  634.     if(item)
  635.     {
  636.       set(item, MUIA_Menuitem_Checked, SaveIcons);
  637.     }
  638.     DoMethod(MUIWindow, MUIM_MultiSet, MUIA_Text_PreParse,"\033l",MUILFreq,MUILChannels,MUILOutvol,MUILMonvol,MUILGain,MUILInput,MUILOutput,NULL);
  639.     DoMethod(MUIWindow, MUIM_MultiSet, MUIA_CycleChain, 1, MUISave,MUIUse,MUICancel,NULL);
  640.  
  641.     DoMethod(MUITFreq, MUIM_Notify, MUIA_Pressed, TRUE, MUIWindow, 3, MUIM_Set, MUIA_Window_ActiveObject, MUIFreq);
  642.     DoMethod(MUITChannels, MUIM_Notify, MUIA_Pressed, TRUE, MUIWindow, 3, MUIM_Set, MUIA_Window_ActiveObject, MUIChannels);
  643.     DoMethod(MUITOutvol, MUIM_Notify, MUIA_Pressed, TRUE, MUIWindow, 3, MUIM_Set, MUIA_Window_ActiveObject, MUIOutvol);
  644.     DoMethod(MUITMonvol, MUIM_Notify, MUIA_Pressed, TRUE, MUIWindow, 3, MUIM_Set, MUIA_Window_ActiveObject, MUIMonvol);
  645.     DoMethod(MUITGain, MUIM_Notify, MUIA_Pressed, TRUE, MUIWindow, 3, MUIM_Set, MUIA_Window_ActiveObject, MUIGain);
  646.     DoMethod(MUITInput, MUIM_Notify, MUIA_Pressed, TRUE, MUIWindow, 3, MUIM_Set, MUIA_Window_ActiveObject, MUIInput);
  647.     DoMethod(MUITOutput, MUIM_Notify, MUIA_Pressed, TRUE, MUIWindow, 3, MUIM_Set, MUIA_Window_ActiveObject, MUIOutput);
  648.     DoMethod(MUITDebug, MUIM_Notify, MUIA_Pressed, TRUE, MUIWindow, 3, MUIM_Set, MUIA_Window_ActiveObject, MUIDebug);
  649.     DoMethod(MUITEcho, MUIM_Notify, MUIA_Pressed, TRUE, MUIWindow, 3, MUIM_Set, MUIA_Window_ActiveObject, MUIEcho);
  650.     DoMethod(MUITSurround, MUIM_Notify, MUIA_Pressed, TRUE, MUIWindow, 3, MUIM_Set, MUIA_Window_ActiveObject, MUISurround);
  651.     DoMethod(MUITClipvol, MUIM_Notify, MUIA_Pressed, TRUE, MUIWindow, 3, MUIM_Set, MUIA_Window_ActiveObject, MUIClipvol);
  652.     DoMethod(MUITCpu, MUIM_Notify, MUIA_Pressed, TRUE, MUIWindow, 3, MUIM_Set, MUIA_Window_ActiveObject, MUICpu);
  653.     DoMethod(MUITACTime, MUIM_Notify, MUIA_Pressed, TRUE, MUIWindow, 3, MUIM_Set, MUIA_Window_ActiveObject, MUIACTime);
  654.  
  655.     DoMethod(MUIWindow, MUIM_Notify, MUIA_Window_CloseRequest, TRUE, MUIApp, 2, MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit);
  656.     DoMethod(MUISave, MUIM_Notify, MUIA_Pressed, FALSE, MUIApp, 2, MUIM_Application_ReturnID, ACTID_SAVE);
  657.     DoMethod(MUIUse, MUIM_Notify, MUIA_Pressed, FALSE, MUIApp, 2, MUIM_Application_ReturnID, ACTID_USE);
  658.     DoMethod(MUICancel, MUIM_Notify, MUIA_Pressed, FALSE, MUIApp, 2, MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit);
  659.     DoMethod(MUIUnit, MUIM_Notify, MUIA_Cycle_Active, MUIV_EveryTime, MUIApp, 2, MUIM_Application_ReturnID, ACTID_UNIT);
  660.     DoMethod(MUIList, MUIM_Notify, MUIA_List_Active, MUIV_EveryTime, MUIApp, 2, MUIM_Application_ReturnID, ACTID_MODE);
  661.     DoMethod(MUIDebug, MUIM_Notify, MUIA_Cycle_Active, MUIV_EveryTime, MUIApp, 2, MUIM_Application_ReturnID,  ACTID_DEBUG);
  662.     DoMethod(MUISurround, MUIM_Notify, MUIA_Cycle_Active, MUIV_EveryTime, MUIApp, 2, MUIM_Application_ReturnID,  ACTID_SURROUND);
  663.     DoMethod(MUIEcho, MUIM_Notify, MUIA_Cycle_Active, MUIV_EveryTime, MUIApp, 2, MUIM_Application_ReturnID,  ACTID_ECHO);
  664.     DoMethod(MUICpu, MUIM_Notify, MUIA_Numeric_Value, MUIV_EveryTime, MUIApp, 2, MUIM_Application_ReturnID,  ACTID_CPULIMIT);
  665.     DoMethod(MUIClipvol, MUIM_Notify, MUIA_Cycle_Active, MUIV_EveryTime, MUIApp, 2, MUIM_Application_ReturnID,  ACTID_CLIPMV);
  666.     DoMethod(MUIACTime, MUIM_Notify, MUIA_Numeric_Value, MUIV_EveryTime, MUIApp, 2, MUIM_Application_ReturnID,  ACTID_ACTIME);
  667.     DoMethod(MUIFreq, MUIM_Notify, MUIA_Numeric_Value, MUIV_EveryTime, MUIV_Notify_Self, 3, MUIM_CallHook, &hookSlider, MUIV_TriggerValue);
  668.     DoMethod(MUIChannels, MUIM_Notify, MUIA_Numeric_Value, MUIV_EveryTime, MUIV_Notify_Self, 3, MUIM_CallHook, &hookSlider, MUIV_TriggerValue);
  669.     DoMethod(MUIOutvol, MUIM_Notify, MUIA_Numeric_Value, MUIV_EveryTime, MUIV_Notify_Self, 3, MUIM_CallHook, &hookSlider, MUIV_TriggerValue);
  670.     DoMethod(MUIMonvol, MUIM_Notify, MUIA_Numeric_Value, MUIV_EveryTime, MUIV_Notify_Self, 3, MUIM_CallHook, &hookSlider, MUIV_TriggerValue);
  671.     DoMethod(MUIGain, MUIM_Notify, MUIA_Numeric_Value, MUIV_EveryTime, MUIV_Notify_Self, 3, MUIM_CallHook, &hookSlider, MUIV_TriggerValue);
  672.     DoMethod(MUIInput, MUIM_Notify, MUIA_Numeric_Value, MUIV_EveryTime, MUIV_Notify_Self, 3, MUIM_CallHook, &hookSlider, MUIV_TriggerValue);
  673.     DoMethod(MUIOutput, MUIM_Notify, MUIA_Numeric_Value, MUIV_EveryTime, MUIV_Notify_Self, 3, MUIM_CallHook, &hookSlider, MUIV_TriggerValue);
  674.     set(MUIWindow, MUIA_Window_Open, TRUE);
  675.     GUINewUnit();
  676.     return TRUE;
  677.   }
  678.   return FALSE;
  679. }
  680.  
  681. /******************************************************************************
  682. **** Call to close the window *************************************************
  683. ******************************************************************************/
  684.  
  685. void CloseGUI(void)
  686. {
  687.   if (MUIApp)
  688.     MUI_DisposeObject(MUIApp);
  689.   if (MUIMasterBase)
  690.     CloseLibrary(MUIMasterBase);
  691. }
  692.  
  693.  
  694. /******************************************************************************
  695. **** Handles the input events *************************************************
  696. ******************************************************************************/
  697.  
  698. void EventLoop(void)
  699. {
  700.   while (1)
  701.   {
  702.     ULONG sigs = 0UL;
  703.  
  704.     switch(DoMethod(MUIApp, MUIM_Application_NewInput, &sigs))
  705.     {
  706.  
  707.       case MUIV_Application_ReturnID_Quit:
  708.         return;
  709.  
  710.       case ACTID_OPEN:
  711.       {
  712.         struct FileRequester *request;
  713.  
  714.         request = MUI_AllocAslRequestTags(ASL_FileRequest, 
  715.             ASLFR_Window, xget(MUIWindow, MUIA_Window_Window),
  716.             ASLFR_TitleText, msgTextProgramName, 
  717.             ASLFR_RejectIcons, TRUE, 
  718.             ASLFR_InitialDrawer, "SYS:Prefs/Presets",
  719.             TAG_DONE );
  720.         if( request != NULL )
  721.         {
  722.           DoMethod(MUIApp, MUIA_Application_Sleep, TRUE);
  723.           if (MUI_AslRequest(request, NULL))
  724.           {
  725.             char *file;
  726.  
  727.             DoMethod(MUIApp, MUIA_Application_Sleep, FALSE);
  728.             
  729.             file = AllocVec(strlen(request->fr_Drawer)+128,0);
  730.             
  731.             if( file != NULL )
  732.             {
  733.               CopyMem(request->fr_Drawer, file, strlen(request->fr_Drawer)+1);
  734.               AddPart(file, request->fr_File, 128);
  735.               NewSettings(file);
  736.               GUINewSettings();
  737.               FreeVec(file);
  738.             }
  739.           }
  740.           else
  741.           {
  742.             DoMethod(MUIApp, MUIA_Application_Sleep, FALSE);
  743.           }
  744.           MUI_FreeAslRequest(request);
  745.         }
  746.         break;
  747.       }
  748.  
  749.       case ACTID_SAVEAS:
  750.       {
  751.         struct FileRequester *request;
  752.  
  753.         request = MUI_AllocAslRequestTags(ASL_FileRequest,
  754.             ASLFR_Window, xget(MUIWindow, MUIA_Window_Window),
  755.             ASLFR_TitleText, msgTextProgramName,
  756.             ASLFR_RejectIcons, TRUE,
  757.             ASLFR_DoSaveMode, TRUE,
  758.             ASLFR_InitialDrawer, "SYS:Prefs/Presets",
  759.             TAG_DONE);
  760.             
  761.         if(request != NULL )
  762.         {
  763.           DoMethod(MUIApp, MUIA_Application_Sleep, TRUE);
  764.           FillUnit();
  765.           if (MUI_AslRequest(request, NULL))
  766.           {
  767.             char *file;
  768.  
  769.             DoMethod(MUIApp, MUIA_Application_Sleep, FALSE);
  770.             
  771.             file = AllocVec(strlen(request->fr_Drawer)+128,0);
  772.             
  773.             if( file != NULL )
  774.             {
  775.               CopyMem(request->fr_Drawer, file, strlen(request->fr_Drawer)+1);
  776.               AddPart(file, request->fr_File, 128);
  777.               SaveSettings(file, UnitList);
  778.               if(SaveIcons)
  779.               {
  780.                 WriteIcon(file);
  781.               }
  782.               FreeVec(file);
  783.             }
  784.           }
  785.           else
  786.           {
  787.             DoMethod(MUIApp, MUIA_Application_Sleep, FALSE);
  788.           }
  789.           MUI_FreeAslRequest(request);
  790.         }
  791.         break;
  792.       }
  793.  
  794.       case ACTID_ABOUT:
  795.         MUI_Request(MUIApp, MUIWindow, 0, (char *) msgTextProgramName,
  796.             (char*)msgButtonOK, (char*)msgTextCopyright, "\033c",
  797.             (char*)msgTextProgramName, "1996-1999 Stéphane Barbaray/Martin Blom");
  798.         break;
  799.  
  800.       case ACTID_SAVE:
  801.         FillUnit();
  802.         SaveSettings(ENVFILE, UnitList);
  803.         SaveSettings(ENVARCFILE, UnitList);
  804.         return;
  805.  
  806.       case ACTID_USE:
  807.         FillUnit();
  808.         SaveSettings(ENVFILE, UnitList);
  809.         return;
  810.  
  811.       case ACTID_QUIT:
  812.         return;
  813.  
  814.       case ACTID_DEFAULT:
  815.         NewSettings(NULL);
  816.         GUINewSettings();
  817.         break;
  818.  
  819.       case ACTID_LASTSAVED:
  820.         NewSettings(ENVARCFILE);
  821.         GUINewSettings();
  822.         break;
  823.  
  824.       case ACTID_RESTORE:
  825.         NewSettings(args.from);
  826.         GUINewSettings();
  827.         break;
  828.  
  829.       case ACTID_ICONS:
  830.       {
  831.         APTR item = (APTR)DoMethod(MUIMenu,MUIM_FindUData,ACTID_ICONS);
  832.  
  833.         if(item)
  834.         {
  835.           if(xget(item, MUIA_Menuitem_Checked))
  836.           {
  837.             SaveIcons = TRUE;
  838.           }
  839.           else
  840.           {
  841.             SaveIcons = FALSE;
  842.           }
  843.         }
  844.         break;
  845.       }
  846.  
  847.       case ACTID_HELP:
  848.         DoMethod(MUIApp,MUIM_Application_ShowHelp,NULL,NULL,"AHI",0);
  849.         break;
  850.  
  851.       case ACTID_GUIDE:
  852.         DoMethod(MUIApp,MUIM_Application_ShowHelp,NULL,NULL,"MAIN",0);
  853.         break;
  854.  
  855.       case ACTID_HELPINDEX:
  856.         DoMethod(MUIApp,MUIM_Application_ShowHelp,NULL,NULL,"Concept Index",0);
  857.         break;
  858.  
  859.       case ACTID_UNIT:
  860.         FillUnit();
  861.         NewUnit(xget(MUIUnit,MUIA_Cycle_Active));
  862.         GUINewUnit();
  863.         break;
  864.  
  865.       case ACTID_MODE:
  866.         FillUnit();
  867.         NewMode(xget(MUIList, MUIA_List_Active));
  868.         GUINewMode();
  869.         break;
  870.  
  871.       case ACTID_DEBUG:
  872.       case ACTID_SURROUND:
  873.       case ACTID_ECHO:
  874.       case ACTID_CPULIMIT:
  875.       case ACTID_CLIPMV:
  876.       case ACTID_ACTIME:
  877.       {
  878.         ULONG debug = AHI_DEBUG_NONE, surround = FALSE, echo = 0, cpu = 90;
  879.         ULONG clip = FALSE, actime = 0;
  880.  
  881.         get(MUIDebug, MUIA_Cycle_Active, &debug);
  882.         get(MUISurround, MUIA_Cycle_Active, &surround);
  883.         get(MUIEcho, MUIA_Cycle_Active, &echo);
  884.         get(MUIClipvol, MUIA_Cycle_Active, &clip);
  885.         get(MUICpu, MUIA_Numeric_Value, &cpu);
  886.         get(MUIACTime, MUIA_Numeric_Value, &actime);
  887.  
  888.         globalprefs.ahigp_DebugLevel       = debug;
  889.         globalprefs.ahigp_DisableSurround  = surround;
  890.         globalprefs.ahigp_DisableEcho      = (echo == 2);
  891.         globalprefs.ahigp_FastEcho         = (echo == 1);
  892.         globalprefs.ahigp_MaxCPU           = ((cpu << 16) + 100) / 100;
  893.         globalprefs.ahigp_ClipMasterVolume = clip;
  894.         globalprefs.ahigp_AntiClickTime    = ((actime << 16) + 1000) / 1000;
  895.  
  896.         break;
  897.       }
  898.  
  899.       default:
  900.         if (sigs)
  901.         {
  902.           sigs = Wait(sigs | SIGBREAKF_CTRL_C);
  903.           if (sigs & SIGBREAKF_CTRL_C)
  904.           return;
  905.         }
  906.         break;
  907.     }
  908.   }
  909. }
  910.  
  911.