home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Fred Fish Collection 1.5
/
ffcollection-1-5-1992-11.iso
/
ff_progs
/
sound
/
algorhyt.lha
/
source
/
Gadgets.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-02-21
|
26KB
|
833 lines
/* Gadgets.c
Copyright (c) 1990,1991,1992 by Thomas E. Janzen
All Rights Reserved
THIS SOFTWARE IS FURNISHED FREE OF CHARGE FOR STUDY AND USE AND MAY
BE COPIED ONLY FOR PERSONAL USE OR COMPLETELY AS OFFERED WITH NO
CHANGES FOR FREE DISTRIBUTION. NO TITLE TO AND OWNERSHIP OF THE
SOFTWARE IS HEREBY TRANSFERRED. THOMAS E. JANZEN ASSUMES NO
RESPONSBILITY FOR THE USE OR RELIABILITY OF THIS SOFTWARE.
Thomas E. Janzen
58A School St. Apt. 2-L
Hudson, MA 01749
(508)562-1295
*/
/*
** FACILITY:
**
** AlgoRhythms music improviser on Commodore (TM) Amiga (TM)
** compiled with SAS/C V5.10b
**
** ABSTRACT:
**
** Gadgets.c sets up and interacts with the gadgets and requesters.
**
** AUTHORS: Thomas E. Janzen
**
** CREATION DATE: 26-MAR-1990
**
** MODIFICATION HISTORY:
** DATE NAME DESCRIPTION
12 Aug 90 T Janzen Correct proportions of gadgets and borders.
** 8 DEC 91 T. Janzen conform to SAS/C 5.10b remove extern from functs
** 4 Jan 92 TEJ last changes for 2.0
**--
*/
#include <stdlib.h>
#include <ctype.h>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <intuition/intuition.h>
#include <graphics/text.h>
#include <proto/dos.h>
#include <proto/graphics.h>
#include <proto/exec.h>
#include <proto/mathffp.h>
#include <proto/intuition.h>
#include "Window.h" /* An AlgoRhythms header file for Window.c */
#define STRINGSIZE 80
/* GADGET */
#define GADGETTEXTDOWN (12L) /* vertical pixel positioning down */
#define CLEFT (10L) /* horizontal position for string gadgets*/
#define CTOP ( 6L) /* vertical position for string gadgets */
#define GADGETWIDTH (300L)/* width of string gadgets */
#define GADGETHEIGHT (24L) /* height of string gadgets */
#define LEFTEDGE (-1L) /* position for borders around gadgets */
#define TOPEDGE (-1L) /* position for borders around gadgets */
#define REQUESTERTEXTDOWN (34L) /* position for requester text */
#define REQUESTERWIDTH (304L) /* position for requester text */
#define REQUESTERHEIGHT (47L) /* height for requester text */
/*for last routine*/
#define GADGETWIDE (230L) /* width for channel requester */
#define CHANNELGADGETWIDE (40L)
#define GADGETHIGH (10L) /* height for channel requester */
#define TOP (1L)
#define LEFT (100L)
#define WALKGADGWIDE 61
#define WALKGADGHI 13
/* internal routines for converting pitch names to MIDI numbers,vis versa*/
static char *MIDItoPitchName(int NoteNum, char *PitchName);
static int PitchNametoMIDI(char *PitchName);
extern char *GetGadgetInput (
char Previous[], /* input: Previous value for variable */
char RemindString[], /* Help string */
char PromptString[])
{
auto unsigned int Wait_Signal,
Signal_Recvd;
/* Title string for variable */
register int classb; /* intuition message class */
static char GadgetString[32]; /* string for holding answer */
static struct IntuiText GadgetTxt =
{1, 2, JAM2, -140, 0, &font_choice, NULL, NULL};
static struct StringInfo
StringStuff = {NULL, NULL, 0, STRINGSIZE, 0, 0, 0, 0,
CLEFT, CTOP, NULL, 0, NULL};
SHORT GadgetPairs[] = /* coordinates of border for gadget */
{98, 0, 98, 9, 0,9, 1,10, 99, 10, 99, 1, 98, 0, 0, 0, 0, 9};
struct Border GadgetBorder = /* border structure */
{LEFTEDGE, TOPEDGE, 1, 2, JAM1, 9, NULL, NULL};
static struct Gadget StringBox = {
NULL, 150, 10, 100, 11,
GADGHCOMP, RELVERIFY|STRINGCENTER,
STRGADGET|REQGADGET,
NULL, NULL, NULL, 0L, NULL, 1, NULL};
/*REQUESTER*/
static UBYTE RequestString[32];
static struct IntuiText RequestTxt =
{1, 2, JAM2, 10, 2, &font_choice, RequestString, NULL};
static SHORT RequesterPairs[] =
{251, 0, 251, 24, 0, 24, 1, 25, 252, 25, 252, 1, 251, 0, 0, 0, 0, 24};
static struct Border RequesterBorder =
{0, 0, 1, 0, JAM1, 9, NULL, NULL};
struct Requester AnswerRequest; /* An Intuition structure */
struct IntuiMessage *message; /* An Exec structure */
BOOL Waiton = TRUE;
InitRequester (&AnswerRequest); /* zero out requester */
strcpy (RequestString, RemindString);
strcpy (GadgetString, PromptString);
/* Set up the requester variables */
AnswerRequest.OlderRequest = NULL;
AnswerRequest.LeftEdge = 10; /*position*/
AnswerRequest.TopEdge = 30;
AnswerRequest.Width = 253;
AnswerRequest.Height = 25;
AnswerRequest.RelLeft = 0;
AnswerRequest.RelTop = 0;
AnswerRequest.ReqGadget = &StringBox;
AnswerRequest.ReqBorder = &RequesterBorder;
AnswerRequest.ReqText = &RequestTxt;
AnswerRequest.Flags = 0;
AnswerRequest.BackFill = 3;
AnswerRequest.ReqLayer = NULL;
AnswerRequest.ImageBMap = NULL;
AnswerRequest.RWindow = w;
GadgetTxt.IText = GadgetString;
GadgetBorder.XY = GadgetPairs;
StringStuff.Buffer = Previous;
StringStuff.UndoBuffer = Previous;
StringBox.GadgetRender = (APTR)&GadgetBorder;
StringBox.GadgetText = &GadgetTxt;
StringBox.SpecialInfo = (APTR)&StringStuff;
RequesterBorder.XY = RequesterPairs;
Request (&AnswerRequest, w);
OnGadget (&StringBox, w, &AnswerRequest);
RefreshGadgets (&StringBox, w, &AnswerRequest);
Wait_Signal = 1L << w->UserPort->mp_SigBit;
while (Waiton)
{
Signal_Recvd = Wait (Wait_Signal);
if (!(Signal_Recvd & Wait_Signal))
{
continue;
}
while (message = (struct IntuiMessage *)GetMsg(w->UserPort))
{
if (message != NULL)
{
classb = message->Class;
ReplyMsg ((struct Message *)message);
if (classb == REQSET)
{
Waiton = FALSE;
}
}
}
}
Waiton = TRUE;
ActivateGadget (&StringBox, w, &AnswerRequest);
/* wait for mouse event and completion of string gadget */
while (Waiton)
{
Wait_Signal = 1 << w->UserPort->mp_SigBit;
Signal_Recvd = Wait (Wait_Signal);
if (!(Signal_Recvd & Wait_Signal))
{
continue;
}
while (message = (struct IntuiMessage *)GetMsg(w->UserPort))
{
if (message != NULL)
{
classb = message->Class;
ReplyMsg ((struct Message *)message);
switch (classb)
{
case GADGETUP:
EndRequest (&AnswerRequest, w);
Waiton = FALSE;
break;
default:
break;
}
}
}
}
return Previous; /* return the new value */
}
const char OKString[4] = "OK";
const struct IntuiText OKTxt = {1, 2, JAM2, 14, 1, &font_choice,
OKString, NULL};
const static SHORT OKPairs[] =
{41, 0, 41, 12, 0,12, 1, 13, 42, 13, 42, 1, 41, 0, 0, 0, 0, 12};
struct Border OKBorder = {-1, -1, 1, 0, JAM2, 9, OKPairs, NULL};
struct Gadget OKGadget = {
NULL, /* next gadget */
250, 30, 41, 12, /*left , top, wide, high*/
GADGHCOMP, RELVERIFY|ENDGADGET,
BOOLGADGET|REQGADGET,
(APTR)&OKBorder, NULL, &OKTxt, 0L, NULL, 2, NULL
};
struct PropInfo SliderInfo = { /*Flags*/AUTOKNOB|FREEHORIZ,
0x8000 /*HorizPot %*/, 0x8000 /*VertPot*/,
/*HorizBody*/ 0x100 , /* VertBody*/ 0x0,
0 /*CWidth*/, 0 /*CHeight*/, 0 /*HpotRes*/, 0 /*VPotRes*/,
0 /*LeftBorder*/, 0 /*TopBorder*/
};
const SHORT SliderPairs[] =
{GADGETWIDTH, 0, GADGETWIDTH, GADGETHEIGHT, 0,
GADGETHEIGHT, 1, GADGETHEIGHT + 1,
GADGETWIDTH + 1, GADGETHEIGHT + 1, GADGETWIDTH + 1, 1,
GADGETWIDTH, 0, 0, 0, 0, GADGETHEIGHT};
const struct Border SliderBorder =
{LEFTEDGE, TOPEDGE, 1, 2, JAM1, 9, SliderPairs, NULL};
struct Gadget SliderGadget = {
&OKGadget,
1, 20, GADGETWIDTH, 8, /* left, top, wide, high*/
GADGHCOMP, RELVERIFY|GADGIMMEDIATE,
PROPGADGET|REQGADGET,
(APTR)&SliderBorder, NULL, NULL, 0L,
(APTR)&SliderInfo, 1, NULL};
/*REQUESTER*/
struct IntuiText RemindTxt = {1, 2, JAM2, 5, 33, &font_choice, NULL, NULL};
const UBYTE TitleString[32] = "Phase in Radians";
const struct IntuiText TitleTxt = {1, 2, JAM2,
10 /*left */, 2 /*top*/, &font_choice, TitleString, &RemindTxt};
const char PhaseString[] = "-pi -pi/2 0 pi/2 pi";
struct IntuiText PhaseTxt = {1, 2, JAM2, 1, 11 /*text down*/, &font_choice,
PhaseString, &TitleTxt};
SHORT RequesterPairs[] =
{REQUESTERWIDTH - 2, 0, REQUESTERWIDTH - 2, REQUESTERHEIGHT - 2,
0, REQUESTERHEIGHT - 2, 1, REQUESTERHEIGHT - 1,
REQUESTERWIDTH - 1, REQUESTERHEIGHT - 1, REQUESTERWIDTH - 1, 1,
REQUESTERWIDTH - 2, 0, 0, 0, 0, REQUESTERHEIGHT - 1};
struct Border RequesterBorder = {0, 0, 1, 0, JAM1, 9, NULL, NULL};
extern double GetPhaseInput (double Previous, char TypeString[])
{
auto unsigned int Wait_Signal,
Signal_Recvd;
struct IntuiMessage *message;
double Answer;
USHORT GadgetNum;
struct Gadget *TempPtr;
register int classb;
struct Requester PhaseRequest;
BOOL Waiton = TRUE;
InitRequester(&PhaseRequest); /* zero out requester */
/* build up phase requester */
/* this is a slider gadget for phase from - pi to + pi */
PhaseRequest.OlderRequest = NULL;
PhaseRequest.LeftEdge = 10; /*position*/
PhaseRequest.TopEdge = 30;
PhaseRequest.Width = REQUESTERWIDTH;
PhaseRequest.Height = REQUESTERHEIGHT;
PhaseRequest.RelLeft = 0;
PhaseRequest.RelTop = 0;
PhaseRequest.ReqGadget = &SliderGadget;
PhaseRequest.ReqBorder = &RequesterBorder;
PhaseRequest.ReqText = &PhaseTxt;
PhaseRequest.Flags = 0;
PhaseRequest.BackFill = 3;
PhaseRequest.ReqLayer = NULL;
PhaseRequest.ImageBMap = NULL;
PhaseRequest.RWindow = w;
RequesterBorder.XY = RequesterPairs;
RemindTxt.IText = TypeString;
if (fabs(Previous) > 3.141593)
{
Previous = (Previous / (fabs(Previous)))
* (fabs(Previous) - 3.141593);
}
SliderInfo.HorizPot =
(short)(int)((double)10430 * Previous + (double)0x8000);
Request (&PhaseRequest, w);
OnGadget (&SliderGadget, w, &PhaseRequest);
RefreshGadgets (&SliderGadget, w, &PhaseRequest);
Wait_Signal = 1 << w->UserPort->mp_SigBit;
while (Waiton)
{ /* wait for mouse to move the slider for phase */
/* and for the OK gadget to be hit */
Signal_Recvd = Wait (Wait_Signal);
if (!(Signal_Recvd & Wait_Signal))
{
continue;
}
while (message = (struct IntuiMessage *) GetMsg (w->UserPort))
{
if (message != NULL)
{
classb = message->Class;
TempPtr = (struct Gadget *)message->IAddress;
ReplyMsg((struct Message *)message);
if (classb == GADGETUP)
{
GadgetNum = TempPtr->GadgetID;
}
if (GadgetNum == 2)
{
switch (classb)
{
case GADGETUP:
EndRequest (&PhaseRequest, w);
Waiton = FALSE;
Answer = ((95.9E-6)
* (double)(SliderInfo.HorizPot))
- 3.141593;
break;
default:
break;
}
}
}
}
}
return Answer; /* return new phase */
}
extern int GetStringInput (char Previous[], /* string input for file names */
char RemindString[],
char PromptString[])
{
auto unsigned int Wait_Signal,
Signal_Recvd;
int failure = 0;
USHORT GadgetNum;
struct Gadget *TempPtr;
char OKString[4] = "OK";
struct IntuiText OKTxt = {1, 2, JAM2, 14, 1, &font_choice, NULL, NULL};
static SHORT OKPairs[] =
{41, 0, 41, 12, 0, 12, 1, 13, 42, 13, 42, 1, 41, 0, 0, 0, 0, 12};
struct Border OKBorder = {-1, -1, 1, 0, JAM2, 9, NULL, NULL};
struct Gadget OKGadget = {
NULL, /* next gadget */
250, 31, 41, 12, /*left , top, wide, high*/
GADGHCOMP, RELVERIFY|ENDGADGET,
BOOLGADGET|REQGADGET,
NULL, NULL, NULL, 0L, NULL, 1, NULL};
char QuitString[8] = "Quit";
struct IntuiText QuitTxt = {1, 2, JAM2, 4, 1, &font_choice, NULL, NULL};
struct Gadget QuitGadget = {
NULL, /* next gadget */
190, 31, 41, 12, /*left , top, wide, high*/
GADGHCOMP, RELVERIFY|ENDGADGET,
BOOLGADGET|REQGADGET,
NULL, NULL, NULL, 0L, NULL, 2, NULL};
register int classb;
static char GadgetString[32];
static struct IntuiText GadgetTxt =
{1, 2, JAM2, 10, GADGETTEXTDOWN, &font_choice, NULL, NULL};
static struct StringInfo
StringStuff = {NULL, NULL, 0, STRINGSIZE, 0, 0, 0, 0,
CLEFT, CTOP, NULL, 0, NULL};
static SHORT GadgetPairs[] =
{GADGETWIDTH, 0, GADGETWIDTH, GADGETHEIGHT, 0, GADGETHEIGHT, 1,
GADGETHEIGHT + 1,
GADGETWIDTH + 1, GADGETHEIGHT + 1, GADGETWIDTH + 1, 1,
GADGETWIDTH, 0, 0, 0, 0, GADGETHEIGHT};
static struct Border GadgetBorder =
{LEFTEDGE, TOPEDGE, 1, 2, JAM1, 9, NULL, NULL};
static struct Gadget StringBox = {
NULL, 2, 3, GADGETWIDTH, GADGETHEIGHT,
GADGHCOMP, RELVERIFY|STRINGCENTER,
STRGADGET|REQGADGET,
NULL, NULL, NULL, 0L, NULL, 1, NULL};
/*REQUESTER*/
static UBYTE RequestString[32];
static struct IntuiText RequestTxt =
{1, 2, JAM2, 10, REQUESTERTEXTDOWN,
&font_choice, RequestString, NULL};
static SHORT RequesterPairs[] =
{REQUESTERWIDTH - 2, 0, REQUESTERWIDTH - 2, REQUESTERHEIGHT - 2,
0, REQUESTERHEIGHT - 2, 1, REQUESTERHEIGHT - 1,
REQUESTERWIDTH - 1, REQUESTERHEIGHT - 1, REQUESTERWIDTH - 1, 1,
REQUESTERWIDTH - 2, 0, 0, 0, 0, REQUESTERHEIGHT - 1};
static struct Border RequesterBorder =
{0, 0, 1, 0, JAM1, 9, NULL, NULL};
struct Requester AnswerRequest;
struct IntuiMessage *message;
BOOL Waiton = TRUE;
InitRequester (&AnswerRequest);
OKGadget.NextGadget = &QuitGadget;
OKBorder.XY = OKPairs;
OKGadget.GadgetRender = (APTR)&OKBorder;
OKGadget.GadgetText = &OKTxt;
QuitGadget.GadgetRender = (APTR)&OKBorder;
QuitTxt.IText = QuitString;
QuitGadget.GadgetText = &QuitTxt;
OKTxt.IText = OKString;
StringBox.NextGadget = &OKGadget;
strcpy (RequestString, RemindString);
strcpy (GadgetString, PromptString);
AnswerRequest.OlderRequest = NULL;
AnswerRequest.LeftEdge = 10; /*position*/
AnswerRequest.TopEdge = 30;
AnswerRequest.Width = REQUESTERWIDTH;
AnswerRequest.Height = REQUESTERHEIGHT;
AnswerRequest.RelLeft = 0;
AnswerRequest.RelTop = 0;
AnswerRequest.ReqGadget = &StringBox;
AnswerRequest.ReqBorder = &RequesterBorder;
AnswerRequest.ReqText = &RequestTxt;
AnswerRequest.Flags = 0;
AnswerRequest.BackFill = 3;
AnswerRequest.ReqLayer = NULL;
AnswerRequest.ImageBMap = NULL;
AnswerRequest.RWindow = w;
GadgetTxt.IText = GadgetString;
GadgetBorder.XY = GadgetPairs;
StringStuff.Buffer = Previous;
StringStuff.UndoBuffer = Previous;
StringBox.GadgetRender = (APTR)&GadgetBorder;
StringBox.GadgetText = &GadgetTxt;
StringBox.SpecialInfo = (APTR)&StringStuff;
RequesterBorder.XY = RequesterPairs;
Request (&AnswerRequest, w);
OnGadget (&StringBox, w, &AnswerRequest);
RefreshGadgets (&StringBox, w, &AnswerRequest);
/*
** Libs & Devices p 99, should not do the Activate until you hear
** a ACTIVEWINDOW or REQSET, which you also set in the window IDCMP
*/
ActivateGadget (&StringBox, w, &AnswerRequest);
Wait_Signal = 1L << w->UserPort->mp_SigBit;
while (Waiton)
{
Signal_Recvd = Wait (Wait_Signal);
if (!(Signal_Recvd & Wait_Signal))
{
continue;
}
while (message = (struct IntuiMessage *)GetMsg (w->UserPort))
{
if (message != NULL)
{
classb = message->Class;
TempPtr = (struct Gadget *)message->IAddress;
ReplyMsg ((struct Message *)message);
if (classb == GADGETUP)
{
GadgetNum = TempPtr->GadgetID;
switch (GadgetNum)
{
case 0: /*got string*/
failure = 0;
break;
case 1: /*string OK*/
failure = 0;
break;
case 2: /*quit*/
failure = 1;
break;
default:
break;
}
EndRequest (&AnswerRequest, w);
Waiton = FALSE;
break;
}
}
}
}
return failure;
}
#include "AlgoRhythms.h"
/* Channel parameters: high note, low note, MIDI channel, walking*/
extern int GetChannelStuff (NOTEEVENT *Event, int Number)
{
auto unsigned int Wait_Signal,
Signal_Recvd;
/* TempWalking is int */
/* ->Walking is int*/
/* Gadget.Flags is USHORT*/
int TempHigh, TempLow, TempChannel, TempWalking;
char OKString[4] = "OK"; /* L T txt next*/
struct IntuiText OKTxt = {1, 2, JAM2, 24, 1, &font_choice, NULL, NULL};
static SHORT OKPairs[] =
{61, 0, 61, 12, 0, 12, 1, 13, 62, 13, 62, 1, 61, 0, 0, 0, 0, 12};
struct Border OKBorder = {-1, -1, 1, 0, JAM2, 9, NULL, NULL};
struct Gadget OKGadget = {NULL, /* next gadget */
140, 47, 61, 12, /*left , top, wide, high*/
GADGHCOMP, RELVERIFY|ENDGADGET, BOOLGADGET|REQGADGET,
NULL, NULL, NULL, 0L, NULL, 1, NULL};
char CancelString[8] = "Cancel";
struct IntuiText CancelTxt = {1, 2, JAM2, 4, 1,&font_choice,NULL, NULL};
struct Gadget CancelGadget = {NULL, /* next gadget */
140, 32, 61, 12, /*left , top, wide, high*/
GADGHCOMP, RELVERIFY|ENDGADGET, BOOLGADGET|REQGADGET,
NULL, NULL, NULL, 0L, NULL, 2, NULL};
static UBYTE HighString[16] = "High Note";
static struct IntuiText HighTxt =
{1, 2, JAM2, -80, 0, &font_choice, NULL, NULL};
static char HighBuff[80];
static struct StringInfo HighInfo =
{NULL, NULL, 0, STRINGSIZE, 0, 0, 0, 0,
LEFT, TOP, NULL, 0, NULL};
static USHORT HighPairs[18] =
{CHANNELGADGETWIDE, 0, CHANNELGADGETWIDE, 9,
0, 9, 1, 10, CHANNELGADGETWIDE +1, 10, CHANNELGADGETWIDE + 1, 1,
CHANNELGADGETWIDE, 0, 0, 0, 0, 9};
static struct Border HighBorder =
{LEFTEDGE, TOPEDGE, 1, 2, JAM1, 9, NULL, NULL};
static struct Gadget HighGadg = {NULL, 90, 34, CHANNELGADGETWIDE,
GADGETHIGH, GADGHCOMP, RELVERIFY|STRINGCENTER, STRGADGET|REQGADGET,
NULL, NULL, NULL, 0L, NULL, 3, NULL};
static UBYTE LowString[16] = "Low Note";
static struct IntuiText LowTxt =
{1, 2, JAM2, -80, 0, &font_choice, NULL, NULL};
static char LowBuff[80];
static struct StringInfo LowInfo =
{NULL, NULL, 0, STRINGSIZE, 0, 0, 0, 0, LEFT, TOP, NULL, 0, NULL};
static struct Gadget LowGadg = {NULL, 90, 49,
CHANNELGADGETWIDE, GADGETHIGH,
GADGHCOMP, RELVERIFY|STRINGCENTER, STRGADGET|REQGADGET,
NULL, NULL, NULL, 0L, NULL, 4, NULL};
static UBYTE ChannelString[16] = "Channel";
static struct IntuiText ChannelTxt =
{1, 2, JAM2, -80, 0, &font_choice, NULL, NULL};
static char ChannelBuff[80];
static struct StringInfo
ChannelInfo = {NULL, NULL, 0, STRINGSIZE, 0, 0, 0, 0,
LEFT, TOP, NULL, 0, NULL};
static struct Gadget ChannelGadg = {NULL, 90, 19,
CHANNELGADGETWIDE, GADGETHIGH,
GADGHCOMP, RELVERIFY|STRINGCENTER,
LONGINT|STRGADGET|REQGADGET, NULL, NULL, NULL, 0L, NULL, 5, NULL};
static UBYTE WalkString[16] = "Walk";
static short int WalkGadgBorderAry1 [14] = {
0,0,
0,WALKGADGHI-1,
1,WALKGADGHI-2,
1,1,
WALKGADGWIDE-2,1,
WALKGADGWIDE-1,0,0,0
};
static short int WalkGadgBorderAry2 [14] = {
WALKGADGWIDE-2,WALKGADGHI-2,
1,WALKGADGHI-2,
0,WALKGADGHI-1,
WALKGADGWIDE-1,WALKGADGHI-1,
WALKGADGWIDE-1,0,
WALKGADGWIDE-2,1,
WALKGADGWIDE-2,WALKGADGHI-2
};
static struct Border WalkGadgBorder1 =
{0,0,1,0,JAM1,7,WalkGadgBorderAry1,NULL};
static struct Border WalkGadgBorder2 =
{0,0,6,0,JAM1,7,WalkGadgBorderAry2, &WalkGadgBorder1};
static struct IntuiText WalkTxt=
{1, 2, JAM1, 15, 3, &font_choice, NULL, NULL};
static struct Gadget WalkGadg = {NULL, 140, 17, WALKGADGWIDE,
WALKGADGHI,
GADGHCOMP, TOGGLESELECT|RELVERIFY,
BOOLGADGET|REQGADGET, NULL, NULL, NULL, 0L, NULL, 6, NULL};
/*REQUESTER*/
static UBYTE RequestString[48];
static struct IntuiText RequestTxt = {1, 2, JAM2, 45, 4,
&font_choice, RequestString, NULL};
static SHORT RequesterPairs[] =
{209, 0, 209, 61, 0, 61, 1, 62, 210, 62, 210, 1, 209, 0, 0, 0, 0, 61};
static struct Border RequesterBorder =
{0, 0, 1, 0, JAM1, 9, NULL, NULL};
struct Requester AnswerRequest;
struct IntuiMessage *message;
register int classb;
int failure = 0;
USHORT GadgetNum;
struct Gadget *TempPtr;
BOOL Waiton = TRUE;
sprintf(RequestString, "%s %2d", "Setup Voice", Number);
TempHigh = Event->HighPitch;
TempLow = Event->LowPitch;
TempWalking = Event->Walking;
TempChannel = Event->Channel;
InitRequester(&AnswerRequest);
if (Event->Walking)
{
WalkGadg.Flags |= SELECTED;
}
else
{
WalkGadg.Flags &= ~(SELECTED);
}
OKGadget.NextGadget = NULL;
CancelGadget.NextGadget = &OKGadget;
HighGadg.NextGadget = &CancelGadget;
LowGadg.NextGadget = &HighGadg;
ChannelGadg.NextGadget = &LowGadg;
WalkGadg.NextGadget = &ChannelGadg;
OKTxt.IText = OKString;
CancelTxt.IText = CancelString;
HighTxt.IText = HighString;
LowTxt.IText = LowString;
ChannelTxt.IText = ChannelString;
WalkTxt.IText = WalkString;
OKBorder.XY = OKPairs;
HighBorder.XY = HighPairs;
OKGadget.GadgetRender = (APTR)&OKBorder;
CancelGadget.GadgetRender = (APTR)&OKBorder;
HighGadg.GadgetRender = (APTR)&HighBorder;
LowGadg.GadgetRender = (APTR)&HighBorder;
ChannelGadg.GadgetRender = (APTR)&HighBorder;
WalkGadg.GadgetRender = (APTR)&WalkGadgBorder2;
OKGadget.GadgetText = &OKTxt;
CancelGadget.GadgetText = &CancelTxt;
HighGadg.GadgetText = &HighTxt;
LowGadg.GadgetText = &LowTxt;
ChannelGadg.GadgetText = &ChannelTxt;
WalkGadg.GadgetText = &WalkTxt;
HighGadg.SpecialInfo = (APTR)&HighInfo;
LowGadg.SpecialInfo = (APTR)&LowInfo;
ChannelGadg.SpecialInfo = (APTR)&ChannelInfo;
HighInfo.Buffer = HighBuff;
LowInfo.Buffer = LowBuff;
ChannelInfo.Buffer = ChannelBuff;
AnswerRequest.OlderRequest = NULL;
AnswerRequest.LeftEdge = 94; /*position*/
AnswerRequest.TopEdge = 33;
AnswerRequest.Width = 210;
AnswerRequest.Height = 63;
AnswerRequest.RelLeft = 0;
AnswerRequest.RelTop = 0;
AnswerRequest.ReqGadget = &WalkGadg;
AnswerRequest.ReqBorder = &RequesterBorder;
AnswerRequest.ReqText = &RequestTxt;
AnswerRequest.Flags = 0;
AnswerRequest.BackFill = 3;
AnswerRequest.ReqLayer = NULL;
AnswerRequest.ImageBMap = NULL;
AnswerRequest.RWindow = w;
RequesterBorder.XY = RequesterPairs;
sprintf (ChannelBuff, "%2d", Event->Channel + 1);
MIDItoPitchName (Event->HighPitch, HighBuff);
MIDItoPitchName (Event->LowPitch, LowBuff);
Request (&AnswerRequest, w);
OnGadget (&WalkGadg, w, &AnswerRequest);
RefreshGadgets (&WalkGadg, w, &AnswerRequest);
Wait_Signal = 1L << w->UserPort->mp_SigBit;
while (Waiton)
{
Signal_Recvd = Wait (Wait_Signal);
if (!(Signal_Recvd & Wait_Signal))
{
continue;
}
while (message = (struct IntuiMessage *)GetMsg(w->UserPort))
{
if (message != NULL)
{
classb = message->Class;
ReplyMsg ((struct Message *)message);
if (classb == REQSET)
{
Waiton = FALSE;
}
}
}
}
Waiton = TRUE;
ActivateGadget (&ChannelGadg, w, &AnswerRequest);
while (Waiton)
{
Signal_Recvd = Wait (Wait_Signal);
if (!(Signal_Recvd & Wait_Signal))
{
continue;
}
while (message = (struct IntuiMessage *)GetMsg (w->UserPort))
{
if (message != NULL)
{
classb = message->Class;
TempPtr = (struct Gadget *)message->IAddress;
ReplyMsg ((struct Message *)message);
if (classb == GADGETUP)
{
GadgetNum = TempPtr->GadgetID;
switch (GadgetNum)
{
case 1: /*OK*/
failure = 0;
if (TempHigh > 0)
{
Event->HighPitch = TempHigh;
}
if (TempLow > 0)
{
Event->LowPitch =TempLow;
}
Event->Channel = TempChannel;
Event->Walking = TempWalking;
Waiton = FALSE;
break;
case 2: /*Cancel*/
failure = 1;
Waiton = FALSE;
break;
case 3: /*HighPitch*/
failure = 0;
TempHigh = PitchNametoMIDI (HighBuff);
break;
case 4: /*LowPitch*/
failure = 0;
TempLow = PitchNametoMIDI (LowBuff);
break;
case 5: /*Channel*/
failure = 0;
TempChannel = (atoi (ChannelBuff) - 1) & 0xF;
break;
case 6: /*Walking*/
failure = 0;
TempWalking = ((WalkGadg.Flags & SELECTED) != 0);
break;
default:
break;
}
}
}
}
}
EndRequest (&AnswerRequest, w);
return failure;
}
static int PitchNametoMIDI(char *PitchName)
{
/* convert pitch name strings to MIDI note numbers */
/* C4 is middle C is MIDI 60 */
char TempString[4] = {0, 0, 0, 0};
int PitchMIDI;
const int SmallScale[7] = {9, 11, 0, 2, 4, 5, 7};
if ((toupper(PitchName[0]) > 64) && (toupper(PitchName[0]) < 72))
{
PitchMIDI = SmallScale[toupper (PitchName[0])-65];
}
else return 0;
if ((strlen (PitchName) < 2) || (strlen (PitchName) >3)) return 0;
if (strlen (PitchName) == 3)
{
switch (PitchName[1])
{
case 'b':
PitchMIDI = PitchMIDI - 1;
break;
case 'B':
PitchMIDI = PitchMIDI - 1;
break;
case '#':
PitchMIDI = PitchMIDI + 1;
break;
default:
break;
}
}
TempString[0] = PitchName[strlen (PitchName) - 1];
PitchMIDI = PitchMIDI + (12 * (atoi (TempString) + 1));
return PitchMIDI;
}
static char *MIDItoPitchName (int NoteNum, char *PitchName)
{
/* convert MIDI note numbers to pitch name string */
/* C4 is middle C is MIDI 60 */
const char NoteNames[12][4] =
{"C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"};
sprintf (PitchName, "%s%1d", NoteNames[NoteNum % 12], (NoteNum/12)-1);
return PitchName;
}