3
|
1 /*
|
|
2
|
|
3 Name:
|
|
4 TCLDISPLAY.C
|
|
5
|
|
6 Description:
|
|
7 TCL display section of mikmod
|
|
8
|
|
9 Peter Amstutz <amstpi@freenet.tlh.fl.us>
|
|
10
|
|
11 HISTORY
|
|
12 =======
|
|
13
|
|
14 v1.00 (19/01/97) - split off from display.c to utilize TCL/TK frontend
|
|
15 v1.01 (27/03/97) - added version verification, so the version of the
|
|
16 tcl/tk script has to match up with the version
|
|
17 that tclmikmod expects. Also upper-ascii translation,
|
|
18 so mods that have ibm upper-ascii characters are translated
|
|
19 into something that vaguly resembles what it was supposed
|
|
20 to look like, rather than the gobbledygook that you end
|
|
21 up with otherwise... translation table is stored in
|
|
22 "asc8-to-7.txt" (that is, 8 bit to 7 bit ascii)
|
|
23 v1.02 (22/04/97) - modified to work with MikMod 3.0
|
|
24 */
|
|
25
|
|
26 #include <stdio.h>
|
|
27 #include <stdlib.h>
|
|
28 #include <signal.h>
|
|
29 #include <string.h>
|
|
30 #include <unistd.h>
|
|
31 #include "mikmod.h"
|
|
32
|
|
33 extern int quiet;
|
|
34 extern float speed_constant; /* multiplier for tempo,initialised to 1 */
|
|
35 int readme;
|
|
36 int writeme;
|
|
37 pid_t pid;
|
|
38 extern UNIMOD *mf;
|
|
39 extern int dorandom;
|
|
40
|
|
41 void init_display(void)
|
|
42 {
|
|
43 int pipe1[2];
|
|
44 int pipe2[2];
|
|
45 FILE *tclfile;
|
|
46 char c;
|
|
47 char verline[40];
|
|
48
|
|
49 if(quiet) return;
|
|
50
|
|
51 pipe(pipe1);
|
|
52 pipe(pipe2);
|
|
53
|
|
54 pid=fork();
|
|
55
|
|
56 if(pid==0)
|
|
57 {
|
|
58 dup2(pipe1[0],STDIN_FILENO);
|
|
59 close(pipe1[0]);
|
|
60 dup2(pipe2[1],STDOUT_FILENO);
|
|
61 close(pipe2[1]);
|
|
62 execlp("wish","wish",NULL);
|
|
63 perror("Error in fork() call to start wish!!!");
|
|
64 exit(1);
|
|
65 }
|
|
66 readme=pipe2[0];
|
|
67 writeme=pipe1[1];
|
|
68 if((tclfile=fopen("start.tcl","r"))==NULL)
|
|
69 {
|
|
70 perror("Error reading start.tcl file!");
|
|
71 exit(1);
|
|
72 }
|
|
73 fgets(verline,40,tclfile);
|
|
74 if(strcmp(verline,"#V1.13\n")!=0)
|
|
75 {
|
|
76 perror("start.tcl version mismatch!");
|
|
77 exit(1);
|
|
78 }
|
|
79 while(!feof(tclfile))
|
|
80 {
|
|
81 c=fgetc(tclfile);
|
|
82 write(writeme,&c,1);
|
|
83 }
|
|
84 c='\n';
|
|
85 write(writeme,&c,1);
|
|
86 usleep(500000);
|
|
87 }
|
|
88
|
|
89 void display_driver_error(char *myerr)
|
|
90 {
|
|
91 if(quiet) return;
|
|
92 printf("Driver error: %s.\n",myerr);
|
|
93 }
|
|
94
|
|
95 void display_driver(void)
|
|
96 {
|
|
97 char string[512];
|
|
98 if(quiet) return;
|
|
99 sprintf(string,
|
|
100 ".top1.fra2.fra62.fra98.che5 %s\n"
|
|
101 ".top1.fra2.fra62.fra98.che6 %s\n"
|
|
102 ".top1.fra2.fra62.fra98.che7 %s\n"
|
|
103 ".top1.fra2.fra62.fra77.che1 %s\n"
|
|
104 ".top1.fra2.fra62.fra16.lab18 configure -text {%u}\n",
|
|
105 (md_mode&DMODE_16BITS) ? "deselect":"select",
|
|
106 (md_mode&DMODE_INTERP) ? "deselect":"select",
|
|
107 (md_mode&DMODE_STEREO) ? "deselect":"select",
|
|
108 (dorandom) ? "select":"deselect",
|
|
109 md_mixfreq);
|
|
110 write(writeme,string,strlen(string));
|
|
111 }
|
|
112
|
|
113 void display_file(void)
|
|
114 {
|
|
115 char filename[255];
|
|
116 char arc[255];
|
|
117 char string[512];
|
|
118 if(quiet) return;
|
|
119 PL_GetCurrent(&playlist,filename,arc);
|
|
120 sprintf(string,"File: %s\n",filename);
|
|
121 write(writeme,string,strlen(string));
|
|
122 }
|
|
123
|
|
124 void display_name()
|
|
125 {
|
|
126 char string[512];
|
|
127 if(quiet) return;
|
|
128
|
|
129 sprintf(string,
|
|
130 ".top1.fra2.lab10 configure -text {\"%s\"}\n"
|
|
131 ".top1.fra2.fra22.lab25 configure -text {Type: %s}\n"
|
|
132 ".top1.fra2.fra22.lab30 configure -text {Periods: %s}\n",
|
|
133 mf->songname==NULL?"":mf->songname,
|
|
134 mf->modtype,
|
|
135 (mf->flags&UF_XMPERIODS) ? "XM type" : "mod type");
|
|
136 write(writeme,string,strlen(string));
|
|
137
|
|
138 }
|
|
139
|
|
140 void display_status()
|
|
141 {
|
|
142 char string[512];
|
|
143 if(quiet) return;
|
|
144
|
|
145 sprintf(string,
|
|
146 ".top1.fra2.fra22.lab27 configure -text {Pattern: %i/ %i}\n"
|
|
147 ".top1.fra2.fra22.lab28 configure -text {Position: %i}\n"
|
|
148 ".top1.fra2.fra22.lab29 configure -text {Tempo: %i}\n",
|
|
149 mf->sngpos, mf->numpos,
|
|
150 mf->patpos, mf->sngspd);
|
|
151 write(writeme,string,strlen(string));
|
|
152 }
|
|
153
|
|
154 void exit_display()
|
|
155 {
|
|
156 if(quiet) return;
|
|
157 write(writeme,"destroy .\n",10);
|
|
158 kill(pid,SIGKILL);
|
|
159 }
|
|
160
|
|
161 void display_instruments()
|
|
162 {
|
|
163 int t, i, n;
|
|
164 char string[255];
|
|
165 unsigned char string2[255];
|
|
166 unsigned char upasc2lowasc[128];
|
|
167 FILE *table;
|
|
168
|
|
169 table=fopen("asc8-to-7.txt","r");
|
|
170 if(table!=NULL)
|
|
171 {
|
|
172 for(i=0;i<128;i++)
|
|
173 {
|
|
174 fgets(string,255,table);
|
|
175 upasc2lowasc[i]=string[4];
|
|
176 }
|
|
177 }
|
|
178
|
|
179 write(writeme,".inst.lb delete 0 end\n",31);
|
|
180
|
|
181 for(t=0;t<mf->numins;t++)
|
|
182 {
|
|
183 if(mf->instruments[t].insname!=NULL)
|
|
184 {
|
|
185 /* get rid of {}[]$ chars... You won't belive what a pain in
|
|
186 the ass it was to find the bug that makes this code
|
|
187 essential */
|
|
188 for(i=0,n=0;i<strlen(mf->instruments[t].insname);i++,n++)
|
|
189 {
|
|
190 /* quote all possible characters that the tcl
|
|
191 interpreter might try to interpret
|
|
192 (yes, there are a lot) */
|
|
193 if(mf->instruments[t].insname[i]=='{' ||
|
|
194 mf->instruments[t].insname[i]=='}' ||
|
|
195 mf->instruments[t].insname[i]=='[' ||
|
|
196 mf->instruments[t].insname[i]==']' ||
|
|
197 mf->instruments[t].insname[i]=='$' ||
|
|
198 mf->instruments[t].insname[i]=='\"' ||
|
|
199 mf->instruments[t].insname[i]=='\\' ||
|
|
200 mf->instruments[t].insname[i]=='(' ||
|
|
201 mf->instruments[t].insname[i]==')' ||
|
|
202 mf->instruments[t].insname[i]=='@' ||
|
|
203 mf->instruments[t].insname[i]=='%' ||
|
|
204 mf->instruments[t].insname[i]=='#')
|
|
205 {
|
|
206 string2[n]='\\';
|
|
207 n++;
|
|
208 }
|
|
209 string2[n]=mf->instruments[t].insname[i];
|
|
210 if(string2[n]>127)
|
|
211 {
|
|
212 string2[n]=upasc2lowasc[string2[n]-128];
|
|
213 }
|
|
214 }
|
|
215 string2[n]=0;
|
|
216 sprintf(string,".inst.lb insert end \"%s\"\n",string2);
|
|
217 }
|
|
218 else sprintf(string,".inst.lb insert end \"\"\n");
|
|
219 write(writeme,string,strlen(string));
|
|
220 }
|
|
221 fclose(table);
|
|
222 }
|
|
223
|
|
224 void display_all(void)
|
|
225 {
|
|
226 if(quiet) return;
|
|
227 display_driver();
|
|
228 display_file();
|
|
229 display_name();
|
|
230 display_status();
|
|
231 }
|