💾 Archived View for blitter.com › OLGA › MUSIC › RESOURCES › DOS_TAB_UTILS › TABPLAY › SOURCES › TPL… captured on 2024-08-18 at 19:38:39.
View Raw
More Information
⬅️ Previous capture (2022-06-12)
-=-=-=-=-=-=-
/*
tplay.c * compact .tab player
------- * I got sick of very grotty printouts..
multi h/w * tplay plays on the screen..
version) * completely free/public domain
* needs 80286 or better, and SB or Serial Midi card.
* developed using TC v2.00
* use at your own risk
* no user support etc etc
* Lindsay Offer, September, 1995.
-----------------------------------------------------
usage tplay [filename] [dashtime] [showtab] [eraseall] [strgs] [dest h/w]
plays .tab files one row at a time.
� TPLAY KEYS:
<ESC> or <Return> to exit, don't use Cntl-C or you may
mess up the system by exiting without shutting down
properly.. This, or playing tabs full of garbage may
cause you system to hang..or crash.. sorry.. :-(
<space> to toggle pause, UP&DOWN ARROWS to fine tune
<+> to increase dash time, go slower,
<-> to decrease dash time, go faster.
CONTROL CHARACTERS(LEFT MARGIN IN TABS).
� use % in the .tab lm to indicate to show line above tab as
lyrics, for layout, directions etc. see example .tab's
� use @xxxx at .lm to set dash time, default is 100 per dash
notated in the tab. Any in the tab, but *only* once.
TAB FILES.
� zillions, (+/- a couple) of .tabs at OLGA, but need slight
modification to the non-standard ones..
I use ftp.uu.net /docs/music/guitar mostly.....
see also the alt.tab.guitar newsgroup
� new Australian site -
ftp.ucc.gu.uwa.edu.au /pub/mirror/guitar
� see readme.txt for more information..
#include "tplay.h"
main(int argc, char *argv[]){
int i,x,sleep=0;
if (argc>1)
strcpy(TabFilename,argv[1]);
else{
printf("\nUsage:\>tplay file.ext [time] [show] [erase] [strings] [dest h/w]\n\n");
exit(0);
}
if (argc>2)
dashtime = atoi(argv[2]);
if (argc>3)
showtab = atoi(argv[3]);
if (argc>4)
eraseall = atoi(argv[4]);
if (argc>5)
strgs = atoi(argv[5]);
if (argc>6)
dest_hw = atoi(argv[6]);
init_td(1000); /* initialise the timer */
ticks_td=0;
/* initialise some arrays and strings */
init_strgs();
/* display the introduction screen */
intro();
if(dest_hw==0||dest_hw==2){ /* Sound Card FM or both*/
/* destination hard ware is currently */
/* either the Sound card FM synth or a */
/* Serial MIDI interface card. */
sb_ok=SoundColdInit(PORT);
for (i=0;i<6;i++) SetVoiceVolume( i, Inst_Volume) ;
for (i=0;i<6;i++) SetVoicePitch( i, Fine_Tune) ;
for (i=6;i<11;i++) SetVoiceVolume( i, Drum_Volume) ;
switch(strgs){
case 4:
for (i=0;i<6;i++)
SetVoiceTimbre( i, BASSGTR);
break;
case 5:
for (i=0;i<6;i++)
SetVoiceTimbre( i, BANJOLIN);
break;
default:
for (i=0;i<6;i++)
SetVoiceTimbre( i, ACCGTR);
}
}
if(dest_hw==1||dest_hw==2){ /* Serial MIDI Card COM3, 3e8 adr or both*/
init(); /* need serl.asm for this routine */
}
i=0;
for (;;){
delay_td(100);
sleep++;
if(sleep>=50||i){
break;
}
if(kbhit())
i=getkey();
}
get_tab(TabFilename);
if (1)
exit(0);
return;
}
void init_strgs(void){
int x,y,z;
for (z=0;z<50;z++){
for (y=0;y<strgs;y++){
for (x=0;x<80;x++){
data[z][y][x]=0;
}
}
}
if (dest_hw>2){
dest_hw=2;
}
if (dest_hw<0){
dest_hw=0;
}
if (strgs>=6){
strgs=6;
}
if (strgs<=4){
strgs=4;
}
switch(strgs){
case 5:
strcpy(instrument,"banjo");
strcpy(tuning,"GDGBD");
tuning[6]=NULL;
break;
case 4:
strcpy(instrument,"bass");
strcpy(tuning,"GDAE");
tuning[6]=NULL;
bass=-12;
break;
default:
strcpy(instrument,"guitar");
strcpy(tuning,"EBGDAE");
tuning[6]=NULL;
break;
}
printf("%s tuned as :%s file:%s\n",instrument,tuning,TabFilename);
}
void intro(void){
FILE *ifp1;
char IntroFileline[100],IntroFilename[25];
char *c;
int lines=0,x;
/* display intro test */
strcpy(IntroFilename,"tpintro.txt");
ifp1 = fopen(IntroFilename,"r");
printf("�����������������������������������������������tplay %s<lo95>�����\n",version);
do {
c = fgets(IntroFileline,100,ifp1); /* get one line from the file */
if (c != NULL){
printf("%s",IntroFileline); /* display it on the monitor */
lines++;
if (lines >23){
getch();
lines=0;
}
}
} while (c != NULL); /* repeat until file is finished */
printf("������������������������������������������������������������������\n");
fclose(ifp1);
return;
}
void get_tab(char TabFilename[25]){
FILE *tfp1;
char fileline[100], tmbuf[5];
char *c, bfr[2];
char chordlines[100][LEN],lyriclines[100][LEN];
int x=0, y=0, z=0, zz, tbs=0, this_tab=0;
int cntr, ystart=15,xstart=4,offset=0;
int bars=0, dashes=0,live=0, played=0;
int toggle=0, measx=1, measy=12,step=0;
int xbeg, xtoggle, i,start_measure=0;
int step_key=0,in_key=0,cl=0,rptg=0,rptg_z=0;
tfp1 = fopen(TabFilename,"r");
if (! tfp1){
printf("\n\n*** TPLAY didn't find %s ***\n\n",TabFilename);
end_td();
textattr(LIGHTGRAY+(BLACK<<4));
gotoxy(1,23);
fclose(tfp1);
exit(0);
}
for (cl=0;cl<100;cl++){
chordlines[cl][0]='\0';
lyriclines[cl][0]='\0';
}
clrscr();
do {
c = fgets(fileline,100,tfp1); /* get one line from the file */
if (c != NULL){
/* set timing */
if (fileline[0] == '@'){
tmbuf[0] = fileline[1];
tmbuf[1] = fileline[2];
tmbuf[2] = fileline[3];
tmbuf[3] = fileline[4];
tmbuf[strlen(fileline)+1] = 0;
dashtime=atoi(tmbuf);
}
/* is it lyric or comment */
if (fileline[0] == '%'){
strcpy(&chordlines[tdone][0],fileline);
if(showtab)
printf("%s",fileline); /* display it on the monitor */
}
/* is it tab */
if ((fileline[0] == 'G' && fileline[1] == '-')
|| (fileline[0] == 'D' && fileline[1] == '-')
|| (fileline[0] == 'E' && fileline[1] == '-')
|| (fileline[0] == 'e' && fileline[1] == '-')
|| (fileline[0] == '|' && fileline[1] == '-')
|| (fileline[0] == '-' && fileline[1] == '-')
|| (fileline[0] == 'E' && fileline[1] == '�')
|| (fileline[0] == 'e' && fileline[1] == '�')
|| (fileline[0] == '�' && fileline[1] == '�')
|| (fileline[0] == '�' && fileline[1] == '�')
|| (fileline[0] == 'E' && fileline[1] == '|')
|| (fileline[0] == 'e' && fileline[1] == '|')) {
/* use midi note numbers for each open string */
/* then add fret number for actual note.. */
/* e=64 B=59 G=55 D=45 A=40 E=35 std tuning */
if (showtab){
printf("%s",fileline);
}
/* assume all lines in the tab are of equal length */
this_tab=strlen(fileline);
tabl[tdone]=this_tab;
for (x=1;x<this_tab;x++){
if ((fileline[x] != '-') && (fileline[x] != '|')){
if (strgs==5)
data[tdone][0][x]=(int)fileline[x]+14;
else
data[tdone][0][x]=(int)fileline[x]+16;
}
if (fileline[x] == '-'){
data[tdone][0][x]=-1;
}
if (fileline[x]=='|'){
data[tdone][0][x]=-99;
}
}
for (y=1;y<strgs;y++){
c = fgets(fileline,100,tfp1); /* get one line from the file */
/* remove unplayable junk */
if((fileline[x]=='\\')||(fileline[x]=='/')||(fileline[x]=='^')
||(fileline[x]=='@')||(fileline[x]=='h')||(fileline[x]=='H')
||(fileline[x]=='p')||(fileline[x]=='P')||(fileline[x]=='=')
||(fileline[x]=='~')||(fileline[x]==':')||(fileline[x]=='s')
||(fileline[x]=='S')||(fileline[x]=='.')||(fileline[x]=='x')
||(fileline[x]=='X')||(fileline[x]=='b')||(fileline[x]=='B'))
fileline[x]='-';
if (showtab){
printf("%s",fileline);
}
for (x=1;x<this_tab;x++){
if (fileline[x] != '-' && fileline[x] != '|' ){
switch (y){
case 1:
offset =11;
break;
case 2:
offset =7;
break;
case 3:
offset =2;
break;
case 4:
offset =-3;
break;
case 5:
offset =-8;
break;
default:
break;
}
data[tdone][y][x]=(int)fileline[x]+offset;
}
/* use -99 to indicate bars and -1 to indicate dashes
as entries in the array of notes to play.
use -2 to indicate a (REST) or (SILENCE) */
if (fileline[x]=='|'){
data[tdone][y][x]=-99;
}
if (fileline[x] == '-'){
data[tdone][y][x]=-1;
}
if (fileline[x] == 'Z' || fileline[x] == 'z'){
data[tdone][y][x]=-2;
}
}
}
c = fgets(fileline,100,tfp1); /* get one line from the file */
strcpy(&lyriclines[tdone][0],fileline);
if (showtab){
printf("%s",fileline); /* extra vocal line at bottom */
}
tdone++;
tbs++;
if (showtab){
if ((tdone+1)%2)
if((zz=(int)getch())==27){
if(sb_ok)
SoundColdInit(PORT);
end_td();
textattr(LIGHTGRAY+(BLACK<<4));
gotoxy(1,23);
fclose(tfp1);
exit(0);
}
printf("\n%d���������������������������������������������������������������\n\n",tbs);
}
}
}
} while (c != NULL); /* repeat until NULL */
if (!showtab){
clrscr();
score_board();
status_bar();
switch(strgs){
case 6:
drawfrets();
break;
case 5:
drawbanjofrets();
break;
case 4:
drawbassfrets();
break;
}
for (z=0;z<tdone;z++){
start_measure=bars;
for (x=1;x<tabl[z]-1;x++){
for (y=0;y<strgs;y++){
switch (y){
case 0:
if (strgs==5)
offset=14;
else
offset =16;
break;
case 1:
offset =11;
break;
case 2:
offset =7;
break;
case 3:
offset =2;
break;
case 4:
offset =-3;
break;
case 5:
offset =-8;
break;
default:
break;
}
gotoxy(xstart+x,ystart+y);
if(data[z][y][x] == -1)
cprintf("-");
else
if(data[z][y][x] == -99)
cprintf("|");
else
cprintf("%d",data[z][y][x]-48-offset);
}
}
gotoxy(xstart,ystart-1);
printf(" ");
if(chordlines[z][0]=='%'){
chordlines[z][0]=' ';
gotoxy(xstart,ystart-1);
printf("%s",&chordlines[z][0]);
}
gotoxy(xstart,ystart+strgs);
printf(" ");
gotoxy(xstart,ystart+strgs);
printf("%s",&lyriclines[z][0]);
for (x=1;x<tabl[z]-1;x++){
for (y=0;y<strgs;y++){
gotoxy(xstart+x,ystart+y);
if (data[z][y][x]<100 && data[z][y][x]>=40){
if(dest_hw==0||dest_hw==2){ /* Sound Card FM or both*/
if(sb_ok)
NoteOff(y);
/* play note that is DETUNE below calculated note */
/* and if banjo g string play 2 oct. higher */
if(strgs==5&&y==4)
NoteOn ( y, data[z][y][x]-DETUNE+24) ;
else{
NoteOn ( y, data[z][y][x]-DETUNE+bass) ;
}
played++;
}
if(dest_hw==1||dest_hw==2){ /* Serial MIDI Card or both*/
if(strgs==5&&y==4){
snon( 2, data[z][y][x]+24-DETUNE) ;
snon( 1, data[z][y][x]+24-DETUNE) ;
}
else{
snon( 2, data[z][y][x]-DETUNE) ;
snon( 1, data[z][y][x]-DETUNE) ;
}
played++;
}
}
if(data[z][y][x] == -1){
cprintf("-");
}
if((data[z][y][x] != -1 && data[z][y][x] != -99 && data[z][y][x] != -2)){
switch (y){
case 0:
if(strgs==5)
offset =14;
else
offset =16;
break;
case 1:
offset =11;
break;
case 2:
offset =7;
break;
case 3:
offset =2;
break;
case 4:
offset =-3;
break;
case 5:
offset =-8;
break;
default:
break;
}
textcolor(14);
/* allow for printing double digit fret numbers */
if(data[z][y][x]-48-offset >9 && data[z][y][x]-48-offset <=19){
gotoxy(xstart+x-1,ystart+y);
cprintf("%d",data[z][y][x]-48-offset);
gotoxy(xstart+x,ystart+y);
}
else
cprintf("%d",data[z][y][x]-48-offset);
drawnote(data[z][y][x]-48-offset,y);
/* remember notes played */
buffer[played]=data[z][y][x];
/* remember strings played */
string[played]=y;
if (toggle && y ==0)
dashes++;
toggle=0;
xtoggle=0;
live=1;
if (!xtoggle){
xbeg=x;
xtoggle=1;
}
if (x-xbeg>dashmax){
live=0;
}
}
if(data[z][y][x] == -99){
cprintf("|");
if (y==1){
live=0;
bars++;
}
}
if(data[z][y][x] == -2){
cprintf("z");
live=1;
}
}
if(rptg&&rptg_z==z){
gotoxy(xstart+x-1,ystart-2);
if(played >= 1){
textattr(LIGHTRED+(BLACK<<4));
cprintf(" %c",31);
textattr(LIGHTGRAY+(BLACK<<4));
}
else{
cprintf(" ");
}
}
else{
gotoxy(tabl[z]+2,ystart-2);
printf(" ");
}
if(bars>=1){
gotoxy(measx,measy);
cprintf(" ");
gotoxy(measx,measy);
cprintf("Measure: %d",bars+1);
}
if (live){
if(step && played>=1){
step_key=getkey();
if(step_key != 333)
step=0;
}
else{
delay_td(dashtime); /* wait for msec value of one tab dash */
}
if(dest_hw==1||dest_hw==2){ /* Serial MIDI Card or both*/
for(zz=0;zz<=played;zz++){
snoff(2,buffer[zz]-DETUNE) ;
if(string[zz]==4)
snoff(2,buffer[zz]-DETUNE+24) ;
snoff(1,buffer[zz]-DETUNE) ;
if(string[zz]==4)
snoff(1,buffer[zz]-DETUNE+24) ;
}
}
for(zz=0;zz<=played;zz++){
switch (string[zz]){
case 0:
if (strgs==5)
offset=14;
else
offset=16;
break;
case 1:
offset =11;
break;
case 2:
offset =7;
break;
case 3:
offset =2;
break;
case 4:
offset =-3;
break;
case 5:
offset =-8;
break;
default:
break;
}
/* check for user's keypress */
/* only stop at the next note on the fret board*/
if((kbhit() && played >=1)&& !step){
in_key=getkey();
switch(in_key){
case 3:
case 13:
case 27: /* escape to exit */
/* do a general clean up here */
if(dest_hw==0||dest_hw==2){
if(sb_ok){
for(i=0;i<6;i++)
NoteOff(i);
SoundColdInit(PORT);
}
}
end_td();
textattr(LIGHTGRAY+(BLACK<<4));
gotoxy(1,23);
fclose(tfp1);
exit(0);
break;
case 32: /* space to pause */
gotoxy(27,23);
textattr(GREEN+(BLACK<<4));
cprintf("�PAUSED�");
getch();
gotoxy(27,23);
textattr(LIGHTGREEN+(BLACK<<4));
cprintf("��������");
textattr(LIGHTGRAY+(BLACK<<4));
break;
case 45: /* - decrease dashtime, speed up */
dashtime -= 5;
if (dashtime <= 10) /* don't allow too quick */
dashtime=10;
status_bar();
break;
case 43: /* + increase dash time */
dashtime += 5;
status_bar();
break;
case 331:
gotoxy(xstart+x,ystart-2);
printf(" ");
x=1;
y=0;
rptg=1;
rptg_z=z;
bars=start_measure;
break;
case 333:
step=1;
break;
case 328:
Fine_Tune++;
for (i=0;i<6;i++)
SetVoicePitch( i, Fine_Tune) ;
gotoxy(37,23);
printf("�� ��");
textattr(GREEN+(BLACK<<4));
gotoxy(37,23);
cprintf("�FT:%d�",Fine_Tune);
textattr(LIGHTGRAY+(BLACK<<4));
break;
case 336:
Fine_Tune--;
for (i=0;i<6;i++)
SetVoicePitch( i, Fine_Tune) ;
gotoxy(37,23);
cprintf("�� ��");
textattr(GREEN+(BLACK<<4));
gotoxy(37,23);
cprintf("�FT:%d�",Fine_Tune);
textattr(LIGHTGRAY+(BLACK<<4));
break;
default:
;
}
} /* if kbhit */
erasenote(buffer[zz]-48-offset,string[zz]);
} /* switch */
} /* if live */
played=0;
toggle=1; /* enable dashes again */
} /* for x */
textcolor(LIGHTGRAY);
} /* for z */
} /* if not showtab */
if(dest_hw==0||dest_hw==2){
if(sb_ok){
for(i=0;i<6;i++)
NoteOff(i);
SoundColdInit(PORT);
}
}
end_td();
textattr(LIGHTGRAY+(BLACK<<4));
fclose(tfp1);
gotoxy(1,23);
return;
}
void drawfrets(void){
textattr(LIGHTGRAY+(BLACK<<4));
gotoxy(1,4);
printf(" ���������������������������������������������������������������������������--");
gotoxy(1,5);
printf(" �������������������������������������������������������������������������---");
gotoxy(1,6);
printf(" �������������������������������������������������������������������������--");
gotoxy(1,7);
printf(" ��������������������������������������������������������������������������");
gotoxy(1,8);
printf(" ��������������������������������������������������������������������������");
gotoxy(1,9);
printf(" ��������������������������������������������������������������������������--");
gotoxy(1,10);
printf(" ");
gotoxy(1,11);
printf(" 3 5 7 9 12 15 17 19");
return;
}
void drawbanjofrets(void){
textattr(LIGHTGRAY+(BLACK<<4));
gotoxy(1,4);
printf(" ���������������������������������������������������������������������������--");
gotoxy(1,5);
printf(" �������������������������������������������������������������������������---");
gotoxy(1,6);
printf(" �������������������������������������������������������������������������--");
gotoxy(1,7);
printf(" ���������������������������������������������������������������������������--");
gotoxy(1,8);
printf(" ������������������������������������������������������--");
gotoxy(1,9);
printf(" ");
gotoxy(1,10);
printf(" 3 5 7 9 12 15 17 19");
return;
}
void drawbassfrets(void){
textattr(LIGHTGRAY+(BLACK<<4));
gotoxy(1,4);
printf(" ���������������������������������������������������������������������������--");
gotoxy(1,5);
printf(" �������������������������������������������������������������������������---");
gotoxy(1,6);
printf(" �������������������������������������������������������������������������--");
gotoxy(1,7);
printf(" ��������������������������������������������������������������������������--");
gotoxy(1,8);
printf(" ");
gotoxy(1,9);
printf(" 3 5 7 9 12 15 17 19");
return;
}
void drawnote(int fret, int str){
int g_off=0;
textattr(LIGHTGREEN+(BLACK<<4));
if(fret==0 && strgs != 5){
gotoxy(1+g_off,4+str);
cprintf("�");
}
else if (strgs==5 && str==4 && fret >0){
g_off=0;
gotoxy(1+g_off+fret*4,4+str);
cprintf("�");
}
else if (strgs==5 && str==4 && fret == 0){
g_off=20;
gotoxy(1+g_off,4+str);
cprintf("�");
}
else{
gotoxy(1+g_off+fret*4,4+str);
cprintf("�");
}
textattr(LIGHTGRAY+(BLACK<<4));
return;
}
void erasenote(int fret, int str){
int g_off=0;
textattr(LIGHTGRAY+(BLACK<<4));
if(fret<1){
if (strgs == 5 && str == 4)
g_off = 20;
gotoxy(1+g_off,4+str);
if (eraseall){
cprintf(" ");
}
else{
cprintf("+");
}
}
else{
gotoxy(1+g_off+fret*4,4+str);
if (eraseall){
cprintf("�");
}
else{
cprintf("+");
}
}
if (strgs==5 && str==4 && fret == 0){
g_off=20;
gotoxy(1+g_off,4+str);
if (eraseall){
cprintf(" ");
}
else{
cprintf("+");
}
}
if (strgs==5 && str==4 && fret >0){
g_off=0;
gotoxy(1+g_off+fret*4,4+str);
if (eraseall){
cprintf("�");
}
else{
cprintf("+");
}
}
textattr(LIGHTGRAY+(BLACK<<4));
return;
}
int getkey(void)
{
int i;
switch (i = (int)getch())
{
case 0:
return 256 + (int)getch();
default:
return i;
}
}
void score_board(void){ /* simply update scoreboard */
textattr(LIGHTGREEN+(BLACK<<4));
gotoxy(2,2);
cprintf(" ����<tplay v%s>��������������������������(KEYS=Esc:Spc:%c:%c:%c:%c:+:-)���",version,17,16,24,25);
textattr(LIGHTGRAY+(BLACK<<4));
}
void status_bar(void){ /* simply update title/status bar */
textattr(LIGHTGREEN+(BLACK<<4));
gotoxy(2,23);
cprintf(" ����<%c dashtime=%d>�����������������������%s���<LO95>��",0x0e,dashtime,TabFilename);
textattr(LIGHTGRAY+(BLACK<<4));
}