annotate examples/unix/tcl/tcldisplay.c @ 13:32f80cd7bfee

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