/*
 * GLIB - a Generic LIBrarian and editor for synths
 *
 * TX81Z routines for Patch parameters
 */

#define OVERLAY1

#include "glib.h"
#include <ctype.h>

char *visnum(), *visonoff(), *vism3num(), *viswave(), *vismono();
char *visdx1a(), *vistxwave(), *vistxsft();
char *vistxf1(), *vistxf2(), *vistxf3(), *vistxf4();
char *visfx(), *visfix1(), *visfix2(), *visfix3(), *visfix4();
extern int Dopmap[];

#define RESERVESIZE 0

/* This array contains arbitrary screen labels */
struct labelinfo Ltx81z[] = {
#MENU

                                                 Algorithm   %
                                                 =============


 O       Dcy Lev Dcy               De  Out     Amp Eg  Key Key EG
 P   Atk  1   1   2  Rls Wav  Freq tun Lvl Vel Mod Bia Rat Scl Sft Fix/Ratio
 -   --- --- --- --- --- --- ----- --- --- --- --- --- --- --- --- ---------
 1    %   %   %   %   %   %   %     %   %   %  %    %   %   %  %     %
 2    %   %   %   %   %   %   %     %   %   %  %    %   %   %  %     %
 3    %   %   %   %   %   %   %     %   %   %  %    %   %   %  %     %
 4    %   %   %   %   %   %   %     %   %   %  %    %   %   %  %     %

           Reverb Rate  %        Feedback    %         Mono/Poly          %
           FC Pitch     %        Transpose   %         Amp Mod Depth      %
           FC Amp       %        LFO Speed   %         Amp Mod Sense      %
                                 LFO Delay   %         Pitch Mod Depth    %
-------------------------+       LFO Wave    %         Pitch Mod Sense    %
N = set name  q = quit   |       LFO Sync    %         Mod Pitch Range    %
K = incr      J = decr   |       Pitch Bend  %         Mod Amp Range      %
space = play auto-note   |       Port. Time  %         Breath Pitch       %
                         |       Port. Mode  %         Breath Amp         %
Auto-Note: Pitch %       |       Port. Foot  %         Breath Pitch Bias  %
Vol %   Dur %   Chan %   |       Sus. Foot   %         Breath EG Bias     %
#END
-1,-1,NULL
};

struct paraminfo  Ptx81z[] =  {
/*
NAME		TYPE	POS	MAX	OFFSET	MASK	SHIFT	ADHOC
 */
#O algorithm	dx1a	%%	7	0
#O op1attack	num	%%	31	0
#O op1decay1	num	%%	31	0
#O op1level1	num	%%	15	0
#O op1decay2	num	%%	31	0
#O op1release	num	%%	31	0
#O op1wave	txwave	%%	7	0
#O op1freq	txf1	%%	878	0
#O op1detune	m3num	%%	6	0
#O op1outlevel	num	%%	99	0
#O op1velocity	num	%%	7	0
#O op1ampmod	onoff	%%	1	0
#O op1egbias	num	%%	7	0
#O op1keyrate	num	%%	3	0
#O op1keyscale	num	%%	99	0
#O op1egsft	txsft	%%	3	0
#O op1fix	fix1	%%	1	0
#O op2attack	num	%%	31	0
#O op2decay1	num	%%	31	0
#O op2level1	num	%%	15	0
#O op2decay2	num	%%	31	0
#O op2release	num	%%	31	0
#O op2wave	txwave	%%	7	0
#O op2freq	txf2	%%	878	0
#O op2detune	m3num	%%	6	0
#O op2outlevel	num	%%	99	0
#O op2velocity	num	%%	7	0
#O op2ampmod	onoff	%%	1	0
#O op2egbias	num	%%	7	0
#O op2keyrate	num	%%	3	0
#O op2keyscale	num	%%	99	0
#O op2egsft	txsft	%%	3	0
#O op2fix	fix2	%%	1	0
#O op3attack	num	%%	31	0
#O op3decay1	num	%%	31	0
#O op3level1	num	%%	15	0
#O op3decay2	num	%%	31	0
#O op3release	num	%%	31	0
#O op3wave	txwave	%%	7	0
#O op3freq	txf3	%%	878	0
#O op3detune	m3num	%%	6	0
#O op3outlevel	num	%%	99	0
#O op3velocity	num	%%	7	0
#O op3ampmod	onoff	%%	1	0
#O op3egbias	num	%%	7	0
#O op3keyrate	num	%%	3	0
#O op3keyscale	num	%%	99	0
#O op3egsft	txsft	%%	3	0
#O op3fix	fix3	%%	1	0
#O op4decay1	num	%%	31	0
#O op4attack	num	%%	31	0
#O op4level1	num	%%	15	0
#O op4decay2	num	%%	31	0
#O op4release	num	%%	31	0
#O op4wave	txwave	%%	7	0
#O op4freq	txf4	%%	878	0
#O op4detune	m3num	%%	6	0
#O op4outlevel	num	%%	99	0
#O op4velocity	num	%%	7	0
#O op4ampmod	onoff	%%	1	0
#O op4egbias	num	%%	7	0
#O op4keyrate	num	%%	3	0
#O op4keyscale	num	%%	99	0
#O op4egsft	txsft	%%	3	0
#O op4fix	fix4	%%	1	0
#O feedback	num	%%	7	0
#O playmode	mono	%%	1	0
#O reverbrate	num	%%	7	0
#O transpose	num	%%	45	0
#O amoddepth	num	%%	99	0
#O fcpitch	num	%%	99	0
#O lfospeed	num	%%	99	0
#O amodsens	num	%%	3	0
#O fcamp	num	%%	99	0
#O lfodelay	num	%%	99	0
#O pmoddepth	num	%%	99	0
#O lfowave	wave	%%	3	0
#O pmodsens	num	%%	7	0
#O lfosync	onoff	%%	1	0
#O modprange	num	%%	99	0
#O pitchbend	num	%%	12	0
#O modarange	num	%%	99	0
#O portatime	num	%%	99	0
#O breathprange	num	%%	99	0
#O portmode	num	%%	1	0
#O breatharange	num	%%	99	0
#O autopitch	num	%%	127	-60
#O portfoot	onoff	%%	1	0
#O breathpbias	num	%%	99	0
#O autochan	num	%%	16	-1	*5
#O autodur	num	%%	20	-5	*5
#O autovol	num	%%	127	-63
#O susfoot	onoff	%%	1	0
#O breathegbias	num	%%	99	0
NULL,NULL,-1,-1,-1,-1,visnum,0,0,0,0
};


extern int *txindex;
extern int txleng;

char *
vistxwave(v)
{
	static char txbuff[3] = "W ";
	txbuff[1] = v + '1';
	return(txbuff);
}

char *visfix1(v) { return(visfx(1,v)); }
char *visfix2(v) { return(visfx(2,v)); }
char *visfix3(v) { return(visfx(3,v)); }
char *visfix4(v) { return(visfx(4,v)); }

char *visfx(n,v)
{
	static int lastfx[] = { 0, -1, -1, -1, -1 };
	char buff2[8];
	int fqindex;

	if ( lastfx[n] != -1 && lastfx[n] == v )
		goto nochange;

	lastfx[n] = v;
	sprintf(buff2,"op%dfreq",n);
	fqindex = parmindex(buff2);
	if ( v == 0 )
		P[fqindex].p_max = txleng-1;
	else
		P[fqindex].p_max = 247;
	if ( P[fqindex].p_val > P[fqindex].p_max )
		P[fqindex].p_val = P[fqindex].p_max;
	showparam(fqindex,0);
nochange:
	if ( v == 0 )
		return("ratio");
	else
		return("fixed");
}

char *
vistxsft(v)
{
	switch(v){
	case 0: return("off");
	case 1: return("48");
	case 2: return("24");
	case 3: return("12");
	}
	return("??");
}

extern int txfreq[];

char *
vistxq(v)
{
	static char fbuff[8];
	int f, n1, n2;

	txinit();
	f = txfreq[txindex[v]];
	n1 = f/100;
	n2 = f%100;
	sprintf(fbuff,n2<10?"%d.0%d":"%d.%d",n1,n2);
	return(fbuff);
}

char *
visfq(v)
{
	static char fixbuff[8];

	sprintf(fixbuff,"%-5d",v+8);
	return(fixbuff);
}

char *
visnfix(n,v)
{
	char buff[8];
	int fx;

	sprintf(buff,"op%dfix",n);
	fx = getval(buff);
	if ( fx == 0 )
		return(vistxq(v));
	else
		return(visfq(v));
}

char *vistxf1(v) { return(visnfix(1,v)); }
char *vistxf2(v) { return(visnfix(2,v)); }
char *vistxf3(v) { return(visnfix(3,v)); }
char *vistxf4(v) { return(visnfix(4,v)); }
