home *** CD-ROM | disk | FTP | other *** search
/ Da Capo / da_capo_vol1.bin / programs / amiga / midi / synth_librarian / sources / synthlib / synthlib.c < prev    next >
C/C++ Source or Header  |  1994-08-23  |  18KB  |  768 lines

  1. /**************************************************************/
  2. /* $VER: SynthLib.c Revison 1.1                               */
  3. /* This file is part of Synth Librarian v1.1                  */
  4. /* ©1993-1994 Jean-Alexis MONTIGNIES                          */
  5. /* This file must not be distributed modified or separatly    */
  6. /* without my written permission                              */
  7. /* See Synth_Librarian.guide for more details                 */
  8. /**************************************************************/
  9.  
  10. /* Synth librarian main part */
  11.  
  12. #define __USE_SYSBASE
  13. #include <exec/types.h>
  14. #include <proto/exec.h>
  15. #include <proto/gadtools.h>
  16. #include <proto/intuition.h>
  17. #include <proto/utility.h>
  18. #include <libraries/gadtools.h>
  19. #include <graphics/gfx.h>
  20. #include <exec/ports.h>
  21. #include <graphics/gfxbase.h>
  22. #include <intuition/intuition.h>
  23. #include <intuition/gadgetclass.h>
  24. #include <intuition/classes.h>
  25. #include <intuition/classusr.h>
  26. #include <dos/dos.h>
  27. #include <dos/dosextens.h>
  28. #include <dos/dostags.h>
  29. #include <proto/dos.h>
  30. #include <libraries/locale.h>
  31. #include <proto/locale.h>
  32. #include <string.h>
  33. #include <stdio.h>
  34.  
  35. #define CATCOMP_NUMBERS
  36. #define CATCOMP_BLOCK
  37. #include "SynthLibLoc.h"
  38.  
  39. #include "SynthLib.h"
  40. #include "SynthLibInt.h"
  41.  
  42. #define GT_STRING(G)    (((struct StringInfo *)(((struct Gadget *)(G)) -> SpecialInfo)) -> Buffer)
  43.  
  44. #define MAIN_FLAGS_CANTEND MAIN_FLAGS_COMTASK
  45.  
  46. STRPTR VersionString="$VER: Synth Librarian v1.0  ©1993-1994 Jean-Alexis MONTIGNIES";
  47. struct DriverData *DD;
  48. BPTR DSeg;
  49. struct DriverData *(*DInit)(ULONG (*GetData)(ULONG));
  50. struct DriverData *InitDriver (ULONG (*GetData)(ULONG));
  51.  
  52. struct LocaleInfo MLi;
  53. struct MsgPort *MainPort=NULL,*ComTaskPort;
  54. struct Process *TaskCom;
  55. struct LibMessage *AMess,MyMess;
  56.  
  57. struct List DumpList={(struct Node*)&DumpList.lh_Tail,
  58.                       0,(struct Node*)&DumpList.lh_Head,0,0};
  59.  
  60. typedef char String[256];
  61. String Messages[2];
  62.  
  63. struct EasyStruct AboutES = {
  64.     sizeof (struct EasyStruct),
  65.     0,
  66.     NULL,
  67.     NULL,
  68.     NULL
  69.  };
  70.  
  71. ULONG Flags;
  72. BOOL MainMessUsed;
  73. BYTE MessageDisplayed;
  74. ULONG SelectedNumber;
  75. struct DumpNode *SelectedDump;
  76. ULONG SelectedRequest;
  77. struct Node *SelectedRequestNode;
  78.  
  79. STRPTR GetString(struct LocaleInfo *li, LONG stringNum,char *CatCompBlock);
  80. void main(void);
  81. int InitAll(void);
  82. void CloseAll(void);
  83. void EndComTask(void);
  84. int SendMainMsg(UBYTE Code,APTR Data);
  85. void StartComTask(void);
  86. void HandleCom( void );
  87. void AvailablesGadgets( void );
  88. void NewMessage(char *Str,UBYTE Code);
  89. void SelectDump(ULONG Number);
  90. void SelectRequest(ULONG Number);
  91. void AknowledgeMessage( void );
  92. void AddDumpToList(struct DumpNode *Node);
  93. void DropDump(struct DumpNode *ANode);
  94. void LoadDriver(STRPTR Name);
  95. ULONG GetData(ULONG Number);
  96. BOOL CloseDriver(void);
  97. BPTR GetDriverSeg(void);
  98. void CheckForUnknowns(struct DumpNode *Node);
  99.  
  100. STRPTR GetString(struct LocaleInfo *li, LONG stringNum,char *CatCompBlock)
  101. {
  102. LONG   *l;
  103. UWORD  *w;
  104. STRPTR  builtIn;
  105.  
  106.     l = (LONG *)CatCompBlock;
  107.  
  108.     while (*l != stringNum)
  109.     {
  110.         w = (UWORD *)((ULONG)l + 4);
  111.         l = (LONG *)((ULONG)l + (ULONG)*w + 6);
  112.     }
  113.     builtIn = (STRPTR)((ULONG)l + 6);
  114.  
  115.     if (LocaleBase)
  116.         return(GetCatalogStr(li->li_Catalog,stringNum,builtIn));
  117.  
  118.     return(builtIn);
  119. }
  120.  
  121. int InitAll()
  122.  {int ReturnCode=0;
  123.   if (LocaleBase=MLi.li_LocaleBase=OpenLibrary("locale.library",0L))
  124.     MLi.li_Catalog=OpenCatalog(NULL,"SynthLib/SynthLib.catalog",OC_BuiltInLanguage,"english",TAG_DONE);
  125.  
  126.   if (!(GfxBase=(struct GfxBase *)OpenLibrary("graphics.library",0L)))
  127.     ReturnCode=MG_INIT_GRAPHICS;
  128.  
  129.   if (!ReturnCode)
  130.     if (!(IntuitionBase=(struct IntuitionBase *)OpenLibrary("intuition.library",37L)))
  131.       ReturnCode=MG_INIT_INTUITION;
  132.  
  133.   if (!ReturnCode)
  134.     if (!(GadToolsBase=OpenLibrary("gadtools.library",0L)))
  135.       ReturnCode=MG_INIT_GADTOOLS;
  136.  
  137.   if (!ReturnCode)
  138.     if (!(UtilityBase=OpenLibrary("utility.library",0L)))
  139.       ReturnCode=MG_INIT_UTILITY;
  140.  
  141.   if (!ReturnCode)
  142.     if (FileOpInit())
  143.       ReturnCode=MG_INIT_ASL;
  144.  
  145.   if (!ReturnCode)
  146.     if (SetupScreen())
  147.       ReturnCode=MG_INIT_SCREEN;
  148.  
  149.   if (!ReturnCode)
  150.     if (OpenLibWindow())
  151.       ReturnCode=MG_INIT_WINDOW;
  152.      else
  153.      {
  154.       MessageDisplayed=-1;
  155.       SelectedNumber=~0;
  156.       SelectedDump=NULL;
  157.       SelectedRequest=~0;
  158.       SelectedRequestNode=0;
  159.      }
  160.  
  161.   if (!ReturnCode)
  162.     if (!(MainPort=CreatePort(0,0)))
  163.       ReturnCode=MG_INIT_PORT;
  164.      else
  165.      {
  166.       MyMess.LMess.mn_ReplyPort=MainPort;
  167.       MainMessUsed=FALSE;
  168.      }
  169.  
  170.   Flags=0;
  171.  
  172.   return(ReturnCode);
  173.  }
  174.  
  175. void CloseAll()
  176.  {
  177.   if (DD)
  178.    {GT_SetGadgetAttrs(LibGadgets[GD_TypeList],LibWnd,NULL,GTLV_Labels,NULL,TAG_DONE);
  179.     DD->Close();
  180. #ifndef DEBUG_SL
  181.     UnLoadSeg(DSeg);
  182. #endif
  183.    }
  184.   LibNew();
  185.   CloseLibWindow();
  186.   CloseDownScreen();
  187.  
  188.   FileOpClose();
  189.  
  190.   if (UtilityBase)
  191.     CloseLibrary(UtilityBase);
  192.  
  193.   if (GadToolsBase)
  194.     CloseLibrary(GadToolsBase);
  195.  
  196.   if (IntuitionBase)
  197.     CloseLibrary((struct Library *)IntuitionBase);
  198.  
  199.   if (GfxBase)
  200.     CloseLibrary((struct Library *)GfxBase);
  201.  
  202.   if (MainPort)
  203.     DeletePort(MainPort);
  204.  
  205.   if (MLi.li_LocaleBase)
  206.    {
  207.     CloseCatalog(MLi.li_Catalog);
  208.     CloseLibrary(MLi.li_LocaleBase);
  209.    }
  210.  }
  211.  
  212. void NewMessage(char *Str,UBYTE Code)
  213.  {if (Str && (Code>=0) && (Code<=1))
  214.    {stccpy(Messages[Code],Str,255);
  215.     if (MessageDisplayed<=Code)
  216.      {MessageDisplayed=Code;
  217.       GT_SetGadgetAttrs(LibGadgets[GD_Info],LibWnd,NULL,GTTX_Text,Messages[Code],TAG_DONE);
  218.      }
  219.    }
  220.  }
  221.  
  222. void AknowledgeMessage()
  223.  {if (MessageDisplayed>=1)
  224.    {MessageDisplayed--;
  225.     GT_SetGadgetAttrs(LibGadgets[GD_Info],LibWnd,NULL,GTTX_Text,Messages[MessageDisplayed],TAG_DONE);
  226.    }
  227.  }
  228.  
  229. int LibCloseWindow(void)
  230.  {Flags|=MAIN_FLAGS_END;
  231.   EndComTask();
  232.   return(0);
  233.  }
  234.  
  235. int DataNodesClicked()
  236.  {SelectDump(LibMsg.Code);
  237.   return(0);
  238.  }
  239.  
  240. int NodeNameClicked()
  241.  {if (SelectedNumber!=~0)
  242.    {GT_SetGadgetAttrs(LibGadgets[GD_DataNodes],LibWnd,NULL,GTLV_Labels,~0,TAG_DONE);
  243.     stccpy(SelectedDump->Name,GT_STRING(LibMsg.IAddress),32);
  244.     SelectedDump->Flags&= ~NODE_FLAGS_UNNAMED;
  245.     GT_SetGadgetAttrs(LibGadgets[GD_DataNodes],LibWnd,NULL,GTLV_Labels,&DumpList,TAG_DONE);
  246.     SelectDump(~0);
  247.    }
  248.   return(0);
  249.  }
  250.  
  251. int AboutLib()
  252.  {AboutES.es_TextFormat=GetString(&MLi,MG_INFO_ABOUT,MainCatBlock);
  253.   AboutES.es_GadgetFormat=GetString(&MLi,MG_INFO_OK,MainCatBlock);
  254.   EasyRequest( LibWnd, &AboutES, NULL );
  255.   return(0);
  256.  }
  257.  
  258. int AboutDriver(void)
  259.  {if (DD && DD->About)
  260.    {AboutES.es_TextFormat=DD->About();
  261.     AboutES.es_GadgetFormat=GetString(&MLi,MG_INFO_OK,MainCatBlock);
  262.     EasyRequest( LibWnd, &AboutES, NULL );
  263.    }
  264.   return(0);
  265.  }
  266.  
  267. int RemoveLib()
  268.  {if (SelectedDump)
  269.    {struct DumpNode *RNode;
  270.  
  271.     RNode=SelectedDump;
  272.     SelectDump(~0);
  273.     GT_SetGadgetAttrs(LibGadgets[GD_DataNodes],LibWnd,NULL,GTLV_Labels,~0,TAG_DONE);
  274.     DropDump(RNode);
  275.     GT_SetGadgetAttrs(LibGadgets[GD_DataNodes],LibWnd,NULL,GTLV_Labels,&DumpList,TAG_DONE);
  276.    }
  277.   return(0);
  278.  }
  279.  
  280. int SENDClicked()
  281.  {if ((SelectedNumber!=~0) && (Flags && MAIN_FLAGS_COMTASK))
  282.     if(!SendMainMsg(MSGCODE_SEND,(APTR)SelectedDump))
  283.      {
  284.       SelectedDump->Flags|=NODE_FLAGS_BUSY;
  285.       Flags|=MAIN_FLAGS_SEND;
  286.  
  287.       AvailablesGadgets();
  288.      }
  289.   return(0);
  290.  }
  291.  
  292. int AbortClicked()
  293.  {if (Flags && MAIN_FLAGS_COMTASK) SendMainMsg(MSGCODE_ABORT,0);
  294.   return(0);
  295.  }
  296.  
  297. int TypeListClicked()
  298.  {SelectRequest(LibMsg.Code);
  299.   return(0);
  300.  }
  301.  
  302. int RequestClicked()
  303.  {if ((SelectedRequest!=~0) && (Flags & MAIN_FLAGS_COMTASK))
  304.     if(!SendMainMsg(MSGCODE_REQUEST,(APTR)SelectedRequestNode))
  305.      {
  306.       Flags|=MAIN_FLAGS_REQUEST;
  307.  
  308.       AvailablesGadgets();
  309.      }
  310.   return(0);
  311.  }
  312.  
  313. void DropDump(struct DumpNode *ANode)
  314.  {if (!(ANode->Flags & NODE_FLAGS_BUSY))
  315.    {
  316.     Remove((struct Node *)ANode);
  317.     FreeMem(ANode->Dump,ANode->DumpLength);
  318.     if (ANode->Data)
  319.       FreeMem(ANode->Data,ANode->DataLength);
  320.  
  321.     FreeMem(ANode,sizeof(struct DumpNode));
  322.    }
  323.    else
  324.     NewMessage(GetString(&MLi,MG_ERROR_INUSE,MainCatBlock),1);
  325.  }
  326.  
  327. int LibNew()
  328.  {struct DumpNode *Node1,*Node2;
  329.  
  330.   SelectDump(~0);
  331.  
  332.   GT_SetGadgetAttrs(LibGadgets[GD_DataNodes],LibWnd,NULL,GTLV_Labels,~0,TAG_DONE);
  333.   Node1=(struct DumpNode *)DumpList.lh_Head;
  334.  
  335.   while (Node2=(stru