#include <exec/types.h>
#include <exec/exec.h>
#include <exec/memory.h>
#include <intuition/intuition.h>
#include <libraries/dos.h>
#include <libraries/dosextens.h>
#include <stdio.h>
#include <midi/midi.h>
#include <functions.h>
#include <fcntl.h>

#define VERSION 33L	/* 1.2 Library Version	*/

extern struct Window	*window;
extern struct IntuiMessage *message;

#define rg0	0
#define rg1	1
#define rg2	2
#define rg3	3
#define rg4	4
#define rg5	5
#define rg6	6
#define rg7	7
#define rg8	8
#define rg9	9
#define rg10	10
#define rg11	11
#define rg12	12
#define rg13	13
#define rg14	14
#define rg15	15
#define rg16	16


SHORT BVs1[] = {
	0,0,
	23,0,
	23,12,
	0,12,
	0,0
};
struct Border BdrR1 = {
	-2,-1,	/* XY origin relative to container TopLeft */
	1,0,JAM1,	/* front pen, back pen and drawmode */
	5,	/* number of XY vectors */
	BVs1,	/* pointer to XY vectors */
	NULL	/* next border in list */
};

struct IntuiText ITextR[] = {{
	1,0,JAM2,	/* front and back text pens, drawmode and fill byte */
	2,2,	/* XY origin relative to container TopLeft */
	NULL,	/* font pointer or NULL for default */
	(UBYTE *)"15",	/* pointer to text */
	NULL	/* next IntuiText structure */
},{
	1,0,JAM2,	/* front and back text pens, drawmode and fill byte */
	2,2,	/* XY origin relative to container TopLeft */
	NULL,	/* font pointer or NULL for default */
	(UBYTE *)"14",	/* pointer to text */
	NULL	/* next IntuiText structure */
},{
	1,0,JAM2,	/* front and back text pens, drawmode and fill byte */
	2,2,	/* XY origin relative to container TopLeft */
	NULL,	/* font pointer or NULL for default */
	(UBYTE *)"13",	/* pointer to text */
	NULL	/* next IntuiText structure */
},{
	1,0,JAM2,	/* front and back text pens, drawmode and fill byte */
	2,2,	/* XY origin relative to container TopLeft */
	NULL,	/* font pointer or NULL for default */
	(UBYTE *)"12",	/* pointer to text */
	NULL	/* next IntuiText structure */
},{
	1,0,JAM2,	/* front and back text pens, drawmode and fill byte */
	2,2,	/* XY origin relative to container TopLeft */
	NULL,	/* font pointer or NULL for default */
	(UBYTE *)"11",	/* pointer to text */
	NULL	/* next IntuiText structure */
},{
	1,0,JAM2,	/* front and back text pens, drawmode and fill byte */
	2,2,	/* XY origin relative to container TopLeft */
	NULL,	/* font pointer or NULL for default */
	(UBYTE *)"10",	/* pointer to text */
	NULL	/* next IntuiText structure */
},{
	1,0,JAM2,	/* front and back text pens, drawmode and fill byte */
	6,2,	/* XY origin relative to container TopLeft */
	NULL,	/* font pointer or NULL for default */
	(UBYTE *)"9",	/* pointer to text */
	NULL	/* next IntuiText structure */
},{
	1,0,JAM2,	/* front and back text pens, drawmode and fill byte */
	6,2,	/* XY origin relative to container TopLeft */
	NULL,	/* font pointer or NULL for default */
	(UBYTE *)"8",	/* pointer to text */
	NULL	/* next IntuiText structure */
},{
	1,0,JAM2,	/* front and back text pens, drawmode and fill byte */
	6,2,	/* XY origin relative to container TopLeft */
	NULL,	/* font pointer or NULL for default */
	(UBYTE *)"7",	/* pointer to text */
	NULL	/* next IntuiText structure */
},{
	1,0,JAM2,	/* front and back text pens, drawmode and fill byte */
	6,2,	/* XY origin relative to container TopLeft */
	NULL,	/* font pointer or NULL for default */
	(UBYTE *)"6",	/* pointer to text */
	NULL	/* next IntuiText structure */
},{
	1,0,JAM2,	/* front and back text pens, drawmode and fill byte */
	6,2,	/* XY origin relative to container TopLeft */
	NULL,	/* font pointer or NULL for default */
	(UBYTE *)"5",	/* pointer to text */
	NULL	/* next IntuiText structure */
},{
	1,0,JAM2,	/* front and back text pens, drawmode and fill byte */
	6,2,	/* XY origin relative to container TopLeft */
	NULL,	/* font pointer or NULL for default */
	(UBYTE *)"4",	/* pointer to text */
	NULL	/* next IntuiText structure */
},{
	1,0,JAM2,	/* front and back text pens, drawmode and fill byte */
	6,2,	/* XY origin relative to container TopLeft */
	NULL,	/* font pointer or NULL for default */
	(UBYTE *)"3",	/* pointer to text */
	NULL	/* next IntuiText structure */
},{
	1,0,JAM2,	/* front and back text pens, drawmode and fill byte */
	6,2,	/* XY origin relative to container TopLeft */
	NULL,	/* font pointer or NULL for default */
	(UBYTE *)"2",	/* pointer to text */
	NULL	/* next IntuiText structure */
},{
	1,0,JAM2,	/* front and back text pens, drawmode and fill byte */
	6,2,	/* XY origin relative to container TopLeft */
	NULL,	/* font pointer or NULL for default */
	(UBYTE *)"1",	/* pointer to text */
	NULL	/* next IntuiText structure */
}};

struct Gadget RGadget[] = {{
	NULL,	/* next gadget */
	188,30,	/* origin XY of hit box relative to window TopLeft */
	20,11,	/* hit box width and height */
	GADGHCOMP,	/* gadget flags */
	RELVERIFY+ENDGADGET,	/* activation flags */
	BOOLGADGET+REQGADGET,	/* gadget type flags */
	(APTR)&BdrR1,	/* gadget border or image to be rendered */
	NULL,	/* alternate imagery for selection */
	&ITextR[0],	/* first IntuiText structure */
	NULL,	/* gadget mutual-exclude long word */
	NULL,	/* SpecialInfo structure */
	rg14,	/* user-definable data */
	NULL	/* pointer to user-definable data */
},{
	&RGadget[0],	/* next gadget */
	160,30,	/* origin XY of hit box relative to window TopLeft */
	20,11,	/* hit box width and height */
	GADGHCOMP,	/* gadget flags */
	RELVERIFY+ENDGADGET,	/* activation flags */
	BOOLGADGET+REQGADGET,	/* gadget type flags */
	(APTR)&BdrR1,	/* gadget border or image to be rendered */
	NULL,	/* alternate imagery for selection */
	&ITextR[1],	/* first IntuiText structure */
	NULL,	/* gadget mutual-exclude long word */
	NULL,	/* SpecialInfo structure */
	rg13,	/* user-definable data */
	NULL	/* pointer to user-definable data */
},{
	&RGadget[1],	/* next gadget */
	132,30,	/* origin XY of hit box relative to window TopLeft */
	20,11,	/* hit box width and height */
	GADGHCOMP,	/* gadget flags */
	RELVERIFY+ENDGADGET,	/* activation flags */
	BOOLGADGET+REQGADGET,	/* gadget type flags */
	(APTR)&BdrR1,	/* gadget border or image to be rendered */
	NULL,	/* alternate imagery for selection */
	&ITextR[2],	/* first IntuiText structure */
	NULL,	/* gadget mutual-exclude long word */
	NULL,	/* SpecialInfo structure */
	rg12,	/* user-definable data */
	NULL	/* pointer to user-definable data */
},{
	&RGadget[2],	/* next gadget */
	104,30,	/* origin XY of hit box relative to window TopLeft */
	20,11,	/* hit box width and height */
	GADGHCOMP,	/* gadget flags */
	RELVERIFY+ENDGADGET,	/* activation flags */
	BOOLGADGET+REQGADGET,	/* gadget type flags */
	(APTR)&BdrR1,	/* gadget border or image to be rendered */
	NULL,	/* alternate imagery for selection */
	&ITextR[3],	/* first IntuiText structure */
	NULL,	/* gadget mutual-exclude long word */
	NULL,	/* SpecialInfo structure */
	rg11,	/* user-definable data */
	NULL	/* pointer to user-definable data */
},{
	&RGadget[3],	/* next gadget */
	76,30,	/* origin XY of hit box relative to window TopLeft */
	20,11,	/* hit box width and height */
	GADGHCOMP,	/* gadget flags */
	RELVERIFY+ENDGADGET,	/* activation flags */
	BOOLGADGET+REQGADGET,	/* gadget type flags */
	(APTR)&BdrR1,	/* gadget border or image to be rendered */
	NULL,	/* alternate imagery for selection */
	&ITextR[4],	/* first IntuiText structure */
	NULL,	/* gadget mutual-exclude long word */
	NULL,	/* SpecialInfo structure */
	rg10,	/* user-definable data */
	NULL	/* pointer to user-definable data */
},{
	&RGadget[4],	/* next gadget */
	48,30,	/* origin XY of hit box relative to window TopLeft */
	20,11,	/* hit box width and height */
	GADGHCOMP,	/* gadget flags */
	RELVERIFY+ENDGADGET,	/* activation flags */
	BOOLGADGET+REQGADGET,	/* gadget type flags */
	(APTR)&BdrR1,	/* gadget border or image to be rendered */
	NULL,	/* alternate imagery for selection */
	&ITextR[5],	/* first IntuiText structure */
	NULL,	/* gadget mutual-exclude long word */
	NULL,	/* SpecialInfo structure */
	rg9,	/* user-definable data */
	NULL	/* pointer to user-definable data */
},{
	&RGadget[5],	/* next gadget */
	20,30,	/* origin XY of hit box relative to window TopLeft */
	20,11,	/* hit box width and height */
	GADGHCOMP,	/* gadget flags */
	RELVERIFY+ENDGADGET,	/* activation flags */
	BOOLGADGET+REQGADGET,	/* gadget type flags */
	(APTR)&BdrR1,	/* gadget border or image to be rendered */
	NULL,	/* alternate imagery for selection */
	&ITextR[6],	/* first IntuiText structure */
	NULL,	/* gadget mutual-exclude long word */
	NULL,	/* SpecialInfo structure */
	rg8,	/* user-definable data */
	NULL	/* pointer to user-definable data */
},{
	&RGadget[6],	/* next gadget */
	216,16,	/* origin XY of hit box relative to window TopLeft */
	20,11,	/* hit box width and height */
	GADGHCOMP,	/* gadget flags */
	RELVERIFY+ENDGADGET,	/* activation flags */
	BOOLGADGET+REQGADGET,	/* gadget type flags */
	(APTR)&BdrR1,	/* gadget border or image to be rendered */
	NULL,	/* alternate imagery for selection */
	&ITextR[7],	/* first IntuiText structure */
	NULL,	/* gadget mutual-exclude long word */
	NULL,	/* SpecialInfo structure */
	rg7,	/* user-definable data */
	NULL	/* pointer to user-definable data */
},{
	&RGadget[7],	/* next gadget */
	188,16,	/* origin XY of hit box relative to window TopLeft */
	20,11,	/* hit box width and height */
	GADGHCOMP,	/* gadget flags */
	RELVERIFY+ENDGADGET,	/* activation flags */
	BOOLGADGET+REQGADGET,	/* gadget type flags */
	(APTR)&BdrR1,	/* gadget border or image to be rendered */
	NULL,	/* alternate imagery for selection */
	&ITextR[8],	/* first IntuiText structure */
	NULL,	/* gadget mutual-exclude long word */
	NULL,	/* SpecialInfo structure */
	rg6,	/* user-definable data */
	NULL	/* pointer to user-definable data */
},{
	&RGadget[8],	/* next gadget */
	160,16,	/* origin XY of hit box relative to window TopLeft */
	20,11,	/* hit box width and height */
	GADGHCOMP,	/* gadget flags */
	RELVERIFY+ENDGADGET,	/* activation flags */
	BOOLGADGET+REQGADGET,	/* gadget type flags */
	(APTR)&BdrR1,	/* gadget border or image to be rendered */
	NULL,	/* alternate imagery for selection */
	&ITextR[9],	/* first IntuiText structure */
	NULL,	/* gadget mutual-exclude long word */
	NULL,	/* SpecialInfo structure */
	rg5,	/* user-definable data */
	NULL	/* pointer to user-definable data */
},{
	&RGadget[9],	/* next gadget */
	132,16,	/* origin XY of hit box relative to window TopLeft */
	20,11,	/* hit box width and height */
	GADGHCOMP,	/* gadget flags */
	RELVERIFY+ENDGADGET,	/* activation flags */
	BOOLGADGET+REQGADGET,	/* gadget type flags */
	(APTR)&BdrR1,	/* gadget border or image to be rendered */
	NULL,	/* alternate imagery for selection */
	&ITextR[10],	/* first IntuiText structure */
	NULL,	/* gadget mutual-exclude long word */
	NULL,	/* SpecialInfo structure */
	rg4,	/* user-definable data */
	NULL	/* pointer to user-definable data */
},{
	&RGadget[10],	/* next gadget */
	104,16,	/* origin XY of hit box relative to window TopLeft */
	20,11,	/* hit box width and height */
	GADGHCOMP,	/* gadget flags */
	RELVERIFY+ENDGADGET,	/* activation flags */
	BOOLGADGET+REQGADGET,	/* gadget type flags */
	(APTR)&BdrR1,	/* gadget border or image to be rendered */
	NULL,	/* alternate imagery for selection */
	&ITextR[11],	/* first IntuiText structure */
	NULL,	/* gadget mutual-exclude long word */
	NULL,	/* SpecialInfo structure */
	rg3,	/* user-definable data */
	NULL	/* pointer to user-definable data */
},{
	&RGadget[11],	/* next gadget */
	76,16,	/* origin XY of hit box relative to window TopLeft */
	20,11,	/* hit box width and height */
	GADGHCOMP,	/* gadget flags */
	RELVERIFY+ENDGADGET,	/* activation flags */
	BOOLGADGET+REQGADGET,	/* gadget type flags */
	(APTR)&BdrR1,	/* gadget border or image to be rendered */
	NULL,	/* alternate imagery for selection */
	&ITextR[12],	/* first IntuiText structure */
	NULL,	/* gadget mutual-exclude long word */
	NULL,	/* SpecialInfo structure */
	rg2,	/* user-definable data */
	NULL	/* pointer to user-definable data */
},{
	&RGadget[12],	/* next gadget */
	48,16,	/* origin XY of hit box relative to window TopLeft */
	20,11,	/* hit box width and height */
	GADGHCOMP,	/* gadget flags */
	RELVERIFY+ENDGADGET,	/* activation flags */
	BOOLGADGET+REQGADGET,	/* gadget type flags */
	(APTR)&BdrR1,	/* gadget border or image to be rendered */
	NULL,	/* alternate imagery for selection */
	&ITextR[13],	/* first IntuiText structure */
	NULL,	/* gadget mutual-exclude long word */
	NULL,	/* SpecialInfo structure */
	rg1,	/* user-definable data */
	NULL	/* pointer to user-definable data */
},{
	&RGadget[13],	/* next gadget */
	20,16,	/* origin XY of hit box relative to window TopLeft */
	20,11,	/* hit box width and height */
	GADGHCOMP,	/* gadget flags */
	RELVERIFY+ENDGADGET,	/* activation flags */
	BOOLGADGET+REQGADGET,	/* gadget type flags */
	(APTR)&BdrR1,	/* gadget border or image to be rendered */
	NULL,	/* alternate imagery for selection */
	&ITextR[14],	/* first IntuiText structure */
	NULL,	/* gadget mutual-exclude long word */
	NULL,	/* SpecialInfo structure */
	rg0,	/* user-definable data */
	NULL	/* pointer to user-definable data */
}};

UBYTE	ttx1[] = "Which Voice Bank?";	/* window title */
UBYTE	ttx2[] = "Which Config Bank?";	/* window title */
struct IntuiText Title = {
	1,0,JAM2,	/* front and back text pens, drawmode and fill byte */
	16,6,	/* XY origin relative to container TopLeft */
	NULL,	/* font pointer or NULL for default */
	ttx1,	/* pointer to text */
	NULL	/* next IntuiText structure */
};

SHORT BRV1[] = {
	0,0,
	258,0,
	258,60,
	0,60,
	0,0
};
struct Border BRs1 = {
	-2,-1,	/* XY origin relative to container TopLeft */
	1,0,JAM1,	/* front pen, back pen and drawmode */
	5,	/* number of XY vectors */
	BRV1,	/* pointer to XY vectors */
	NULL	/* next border in list */
};

struct Requester Rqstr1 = {
	NULL,
	4,11,256,58,
	0,0,
	&RGadget[14],	/* first gadget in gadget list */
	&BRs1,
	&Title,	/* window title */
	NULL,
	0,
	NULL,
	{NULL},
	{NULL},
	NULL,
	{NULL}
};


USHORT	GetReqNum(tdump)
USHORT	tdump;

{

SHORT i;
USHORT returncode;
ULONG class;
struct Gadget *gadget;

if(tdump == 1)
	{
	Title.IText = ttx1;
	for(i=7;i>=0;i--)
		{
		RGadget[i].Flags = GADGHNONE+GADGDISABLED;
		}
	}
else if(tdump == 3)
	{
	Title.IText = ttx1;
	for(i=12;i>=0;i--)
		{
		RGadget[i].Flags = GADGHNONE+GADGDISABLED;
		}
	}
else if(tdump == 2)
	{
	Title.IText = ttx2;
	}


Request(&Rqstr1,window);


while(class!=REQCLEAR)
	{
	if ((message=(struct IntuiMessage *)GetMsg(window->UserPort))==0L)
		{
		Wait(1L<<window->UserPort->mp_SigBit);
		continue;
		}
	message=(struct IntuiMessage *)GetMsg(window->UserPort);

	class  = message->Class;
	gadget = (struct Gadget *) message->IAddress;
	ReplyMsg(message);
	returncode = gadget->GadgetID;
	}

for(i=0;i<=14;i++)
	{
	RGadget[i].Flags = GADGHCOMP;
	}

return(returncode);
}
