home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Da Capo
/
da_capo_vol1.bin
/
programs
/
amiga
/
midi
/
synth_librarian
/
sources
/
synthlib
/
synthlib.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-08-23
|
18KB
|
768 lines
/**************************************************************/
/* $VER: SynthLib.c Revison 1.1 */
/* This file is part of Synth Librarian v1.1 */
/* ©1993-1994 Jean-Alexis MONTIGNIES */
/* This file must not be distributed modified or separatly */
/* without my written permission */
/* See Synth_Librarian.guide for more details */
/**************************************************************/
/* Synth librarian main part */
#define __USE_SYSBASE
#include <exec/types.h>
#include <proto/exec.h>
#include <proto/gadtools.h>
#include <proto/intuition.h>
#include <proto/utility.h>
#include <libraries/gadtools.h>
#include <graphics/gfx.h>
#include <exec/ports.h>
#include <graphics/gfxbase.h>
#include <intuition/intuition.h>
#include <intuition/gadgetclass.h>
#include <intuition/classes.h>
#include <intuition/classusr.h>
#include <dos/dos.h>
#include <dos/dosextens.h>
#include <dos/dostags.h>
#include <proto/dos.h>
#include <libraries/locale.h>
#include <proto/locale.h>
#include <string.h>
#include <stdio.h>
#define CATCOMP_NUMBERS
#define CATCOMP_BLOCK
#include "SynthLibLoc.h"
#include "SynthLib.h"
#include "SynthLibInt.h"
#define GT_STRING(G) (((struct StringInfo *)(((struct Gadget *)(G)) -> SpecialInfo)) -> Buffer)
#define MAIN_FLAGS_CANTEND MAIN_FLAGS_COMTASK
STRPTR VersionString="$VER: Synth Librarian v1.0 ©1993-1994 Jean-Alexis MONTIGNIES";
struct DriverData *DD;
BPTR DSeg;
struct DriverData *(*DInit)(ULONG (*GetData)(ULONG));
struct DriverData *InitDriver (ULONG (*GetData)(ULONG));
struct LocaleInfo MLi;
struct MsgPort *MainPort=NULL,*ComTaskPort;
struct Process *TaskCom;
struct LibMessage *AMess,MyMess;
struct List DumpList={(struct Node*)&DumpList.lh_Tail,
0,(struct Node*)&DumpList.lh_Head,0,0};
typedef char String[256];
String Messages[2];
struct EasyStruct AboutES = {
sizeof (struct EasyStruct),
0,
NULL,
NULL,
NULL
};
ULONG Flags;
BOOL MainMessUsed;
BYTE MessageDisplayed;
ULONG SelectedNumber;
struct DumpNode *SelectedDump;
ULONG SelectedRequest;
struct Node *SelectedRequestNode;
STRPTR GetString(struct LocaleInfo *li, LONG stringNum,char *CatCompBlock);
void main(void);
int InitAll(void);
void CloseAll(void);
void EndComTask(void);
int SendMainMsg(UBYTE Code,APTR Data);
void StartComTask(void);
void HandleCom( void );
void AvailablesGadgets( void );
void NewMessage(char *Str,UBYTE Code);
void SelectDump(ULONG Number);
void SelectRequest(ULONG Number);
void AknowledgeMessage( void );
void AddDumpToList(struct DumpNode *Node);
void DropDump(struct DumpNode *ANode);
void LoadDriver(STRPTR Name);
ULONG GetData(ULONG Number);
BOOL CloseDriver(void);
BPTR GetDriverSeg(void);
void CheckForUnknowns(struct DumpNode *Node);
STRPTR GetString(struct LocaleInfo *li, LONG stringNum,char *CatCompBlock)
{
LONG *l;
UWORD *w;
STRPTR builtIn;
l = (LONG *)CatCompBlock;
while (*l != stringNum)
{
w = (UWORD *)((ULONG)l + 4);
l = (LONG *)((ULONG)l + (ULONG)*w + 6);
}
builtIn = (STRPTR)((ULONG)l + 6);
if (LocaleBase)
return(GetCatalogStr(li->li_Catalog,stringNum,builtIn));
return(builtIn);
}
int InitAll()
{int ReturnCode=0;
if (LocaleBase=MLi.li_LocaleBase=OpenLibrary("locale.library",0L))
MLi.li_Catalog=OpenCatalog(NULL,"SynthLib/SynthLib.catalog",OC_BuiltInLanguage,"english",TAG_DONE);
if (!(GfxBase=(struct GfxBase *)OpenLibrary("graphics.library",0L)))
ReturnCode=MG_INIT_GRAPHICS;
if (!ReturnCode)
if (!(IntuitionBase=(struct IntuitionBase *)OpenLibrary("intuition.library",37L)))
ReturnCode=MG_INIT_INTUITION;
if (!ReturnCode)
if (!(GadToolsBase=OpenLibrary("gadtools.library",0L)))
ReturnCode=MG_INIT_GADTOOLS;
if (!ReturnCode)
if (!(UtilityBase=OpenLibrary("utility.library",0L)))
ReturnCode=MG_INIT_UTILITY;
if (!ReturnCode)
if (FileOpInit())
ReturnCode=MG_INIT_ASL;
if (!ReturnCode)
if (SetupScreen())
ReturnCode=MG_INIT_SCREEN;
if (!ReturnCode)
if (OpenLibWindow())
ReturnCode=MG_INIT_WINDOW;
else
{
MessageDisplayed=-1;
SelectedNumber=~0;
SelectedDump=NULL;
SelectedRequest=~0;
SelectedRequestNode=0;
}
if (!ReturnCode)
if (!(MainPort=CreatePort(0,0)))
ReturnCode=MG_INIT_PORT;
else
{
MyMess.LMess.mn_ReplyPort=MainPort;
MainMessUsed=FALSE;
}
Flags=0;
return(ReturnCode);
}
void CloseAll()
{
if (DD)
{GT_SetGadgetAttrs(LibGadgets[GD_TypeList],LibWnd,NULL,GTLV_Labels,NULL,TAG_DONE);
DD->Close();
#ifndef DEBUG_SL
UnLoadSeg(DSeg);
#endif
}
LibNew();
CloseLibWindow();
CloseDownScreen();
FileOpClose();
if (UtilityBase)
CloseLibrary(UtilityBase);
if (GadToolsBase)
CloseLibrary(GadToolsBase);
if (IntuitionBase)
CloseLibrary((struct Library *)IntuitionBase);
if (GfxBase)
CloseLibrary((struct Library *)GfxBase);
if (MainPort)
DeletePort(MainPort);
if (MLi.li_LocaleBase)
{
CloseCatalog(MLi.li_Catalog);
CloseLibrary(MLi.li_LocaleBase);
}
}
void NewMessage(char *Str,UBYTE Code)
{if (Str && (Code>=0) && (Code<=1))
{stccpy(Messages[Code],Str,255);
if (MessageDisplayed<=Code)
{MessageDisplayed=Code;
GT_SetGadgetAttrs(LibGadgets[GD_Info],LibWnd,NULL,GTTX_Text,Messages[Code],TAG_DONE);
}
}
}
void AknowledgeMessage()
{if (MessageDisplayed>=1)
{MessageDisplayed--;
GT_SetGadgetAttrs(LibGadgets[GD_Info],LibWnd,NULL,GTTX_Text,Messages[MessageDisplayed],TAG_DONE);
}
}
int LibCloseWindow(void)
{Flags|=MAIN_FLAGS_END;
EndComTask();
return(0);
}
int DataNodesClicked()
{SelectDump(LibMsg.Code);
return(0);
}
int NodeNameClicked()
{if (SelectedNumber!=~0)
{GT_SetGadgetAttrs(LibGadgets[GD_DataNodes],LibWnd,NULL,GTLV_Labels,~0,TAG_DONE);
stccpy(SelectedDump->Name,GT_STRING(LibMsg.IAddress),32);
SelectedDump->Flags&= ~NODE_FLAGS_UNNAMED;
GT_SetGadgetAttrs(LibGadgets[GD_DataNodes],LibWnd,NULL,GTLV_Labels,&DumpList,TAG_DONE);
SelectDump(~0);
}
return(0);
}
int AboutLib()
{AboutES.es_TextFormat=GetString(&MLi,MG_INFO_ABOUT,MainCatBlock);
AboutES.es_GadgetFormat=GetString(&MLi,MG_INFO_OK,MainCatBlock);
EasyRequest( LibWnd, &AboutES, NULL );
return(0);
}
int AboutDriver(void)
{if (DD && DD->About)
{AboutES.es_TextFormat=DD->About();
AboutES.es_GadgetFormat=GetString(&MLi,MG_INFO_OK,MainCatBlock);
EasyRequest( LibWnd, &AboutES, NULL );
}
return(0);
}
int RemoveLib()
{if (SelectedDump)
{struct DumpNode *RNode;
RNode=SelectedDump;
SelectDump(~0);
GT_SetGadgetAttrs(LibGadgets[GD_DataNodes],LibWnd,NULL,GTLV_Labels,~0,TAG_DONE);
DropDump(RNode);
GT_SetGadgetAttrs(LibGadgets[GD_DataNodes],LibWnd,NULL,GTLV_Labels,&DumpList,TAG_DONE);
}
return(0);
}
int SENDClicked()
{if ((SelectedNumber!=~0) && (Flags && MAIN_FLAGS_COMTASK))
if(!SendMainMsg(MSGCODE_SEND,(APTR)SelectedDump))
{
SelectedDump->Flags|=NODE_FLAGS_BUSY;
Flags|=MAIN_FLAGS_SEND;
AvailablesGadgets();
}
return(0);
}
int AbortClicked()
{if (Flags && MAIN_FLAGS_COMTASK) SendMainMsg(MSGCODE_ABORT,0);
return(0);
}
int TypeListClicked()
{SelectRequest(LibMsg.Code);
return(0);
}
int RequestClicked()
{if ((SelectedRequest!=~0) && (Flags & MAIN_FLAGS_COMTASK))
if(!SendMainMsg(MSGCODE_REQUEST,(APTR)SelectedRequestNode))
{
Flags|=MAIN_FLAGS_REQUEST;
AvailablesGadgets();
}
return(0);
}
void DropDump(struct DumpNode *ANode)
{if (!(ANode->Flags & NODE_FLAGS_BUSY))
{
Remove((struct Node *)ANode);
FreeMem(ANode->Dump,ANode->DumpLength);
if (ANode->Data)
FreeMem(ANode->Data,ANode->DataLength);
FreeMem(ANode,sizeof(struct DumpNode));
}
else
NewMessage(GetString(&MLi,MG_ERROR_INUSE,MainCatBlock),1);
}
int LibNew()
{struct DumpNode *Node1,*Node2;
SelectDump(~0);
GT_SetGadgetAttrs(LibGadgets[GD_DataNodes],LibWnd,NULL,GTLV_Labels,~0,TAG_DONE);
Node1=(struct DumpNode *)DumpList.lh_Head;
while (Node2=(stru