FreeCalypso > hg > freecalypso-tools
annotate loadtools/buzplaypwt.c @ 989:a5bff8104b45
pln-ppb-test: implement program operation
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 03 Dec 2023 00:16:17 +0000 |
parents | 85091e14be9c |
children |
rev | line source |
---|---|
86
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
828
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
2 * fc-buzplay: in this module we are going to implement parsing, |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
3 * uploading and play of PWT melodies. |
86
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 */ |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <sys/types.h> |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <ctype.h> |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <stdio.h> |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <string.h> |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <strings.h> |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include <stdlib.h> |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 |
828
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
13 static struct pwt_note { |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
14 char *name; |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
15 int code; |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
16 } pwt_notes_table[] = { |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
17 {"f4", 47}, /* 349 Hz */ |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
18 {"fs4", 43}, /* 370 Hz */ |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
19 {"g4", 39}, /* 392 Hz */ |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
20 {"gs4", 35}, /* 415 Hz */ |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
21 {"a4", 31}, /* 440 Hz */ |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
22 {"as4", 27}, /* 466 Hz */ |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
23 {"b4", 23}, /* 494 Hz */ |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
24 {"c5", 19}, /* 523 Hz */ |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
25 {"cs5", 15}, /* 554 Hz */ |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
26 {"d5", 11}, /* 587 Hz */ |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
27 {"ds5", 7}, /* 622 Hz */ |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
28 {"e5", 3}, /* 659 Hz */ |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
29 {"f5", 46}, /* 698 Hz */ |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
30 {"fs5", 42}, /* 740 Hz */ |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
31 {"g5", 38}, /* 784 Hz */ |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
32 {"gs5", 34}, /* 831 Hz */ |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
33 {"a5", 30}, /* 880 Hz */ |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
34 {"as5", 26}, /* 932 Hz */ |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
35 {"b5", 22}, /* 988 Hz */ |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
36 {"c6", 18}, /* 1047 Hz */ |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
37 {"cs6", 14}, /* 1109 Hz */ |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
38 {"d6", 10}, /* 1175 Hz */ |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
39 {"ds6", 6}, /* 1245 Hz */ |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
40 {"e6", 2}, /* 1319 Hz */ |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
41 {"f6", 45}, /* 1397 Hz */ |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
42 {"fs6", 41}, /* 1480 Hz */ |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
43 {"g6", 37}, /* 1568 Hz */ |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
44 {"gs6", 33}, /* 1661 Hz */ |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
45 {"a6", 29}, /* 1760 Hz */ |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
46 {"as6", 25}, /* 1865 Hz */ |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
47 {"b6", 21}, /* 1976 Hz */ |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
48 {"c7", 17}, /* 2093 Hz */ |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
49 {"cs7", 13}, /* 2217 Hz */ |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
50 {"d7", 9}, /* 2349 Hz */ |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
51 {"ds7", 5}, /* 2489 Hz */ |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
52 {"e7", 1}, /* 2637 Hz */ |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
53 {"f7", 44}, /* 2794 Hz */ |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
54 {"fs7", 40}, /* 2960 Hz */ |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
55 {"g7", 36}, /* 3136 Hz */ |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
56 {"gs7", 32}, /* 3322 Hz */ |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
57 {"a7", 28}, /* 3520 Hz */ |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
58 {"as7", 24}, /* 3729 Hz */ |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
59 {"b7", 20}, /* 3951 Hz */ |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
60 {"c8", 16}, /* 4186 Hz */ |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
61 {"cs8", 12}, /* 4435 Hz */ |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
62 {"d8", 8}, /* 4699 Hz */ |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
63 {"ds8", 4}, /* 4978 Hz */ |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
64 {"e8", 0}, /* 5274 Hz */ |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
65 /* table search terminator */ |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
66 {0, -1} |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
67 }; |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
68 |
893
85091e14be9c
fc-buzplay: PWT refactoring, first step
Mychaela Falconia <falcon@freecalypso.org>
parents:
828
diff
changeset
|
69 buzplay_pwt_file(filename, global_vol) |
85091e14be9c
fc-buzplay: PWT refactoring, first step
Mychaela Falconia <falcon@freecalypso.org>
parents:
828
diff
changeset
|
70 char *filename; |
85091e14be9c
fc-buzplay: PWT refactoring, first step
Mychaela Falconia <falcon@freecalypso.org>
parents:
828
diff
changeset
|
71 unsigned global_vol; |
86
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 { |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 FILE *f; |
828
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
74 char linebuf[256], *cp, *fields[3]; |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
75 int lineno, nfields; |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
76 char *targv[5], argbuf1[16], argbuf2[16], argbuf3[16]; |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
77 struct pwt_note *tp; |
893
85091e14be9c
fc-buzplay: PWT refactoring, first step
Mychaela Falconia <falcon@freecalypso.org>
parents:
828
diff
changeset
|
78 unsigned note_vol, duration; |
85091e14be9c
fc-buzplay: PWT refactoring, first step
Mychaela Falconia <falcon@freecalypso.org>
parents:
828
diff
changeset
|
79 u_long total_ms; |
86
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 int rc, timeout; |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 |
893
85091e14be9c
fc-buzplay: PWT refactoring, first step
Mychaela Falconia <falcon@freecalypso.org>
parents:
828
diff
changeset
|
82 f = fopen(filename, "r"); |
86
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 if (!f) { |
893
85091e14be9c
fc-buzplay: PWT refactoring, first step
Mychaela Falconia <falcon@freecalypso.org>
parents:
828
diff
changeset
|
84 perror(filename); |
86
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 return(-1); |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 } |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 printf("Uploading the melody to the target\n"); |
828
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
88 targv[0] = "IT"; |
86
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 targv[1] = 0; |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 tpinterf_make_cmd(targv); |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 if (tpinterf_send_cmd() < 0) { |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
92 fclose(f); |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
93 return(-1); |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
94 } |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
95 rc = tpinterf_pass_output(1); |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
96 if (rc) { |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
97 fclose(f); |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
98 return(rc); |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
99 } |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
100 total_ms = 0; |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
101 for (lineno = 1; fgets(linebuf, sizeof linebuf, f); lineno++) { |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
102 cp = index(linebuf, '\n'); |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
103 if (!cp) { |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
104 fprintf(stderr, "%s line %d: missing newline\n", |
893
85091e14be9c
fc-buzplay: PWT refactoring, first step
Mychaela Falconia <falcon@freecalypso.org>
parents:
828
diff
changeset
|
105 filename, lineno); |
86
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
106 fclose(f); |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
107 return(-1); |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
108 } |
828
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
109 cp = linebuf; |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
110 nfields = 0; |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
111 for (;;) { |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
112 while (isspace(*cp)) |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
113 cp++; |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
114 if (*cp == '\0' || *cp == '#') |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
115 break; |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
116 if (nfields >= 3) { |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
117 fprintf(stderr, "%s line %d: too many fields\n", |
893
85091e14be9c
fc-buzplay: PWT refactoring, first step
Mychaela Falconia <falcon@freecalypso.org>
parents:
828
diff
changeset
|
118 filename, lineno); |
828
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
119 fclose(f); |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
120 return(-1); |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
121 } |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
122 fields[nfields++] = cp; |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
123 while (*cp && !isspace(*cp)) |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
124 cp++; |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
125 if (*cp) |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
126 *cp++ = '\0'; |
86
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
127 } |
828
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
128 if (!nfields) |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
129 continue; |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
130 if (nfields == 3) { |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
131 for (tp = pwt_notes_table; tp->name; tp++) |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
132 if (!strcmp(tp->name, fields[0])) |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
133 break; |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
134 if (tp->code < 0) { |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
135 fprintf(stderr, |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
136 "%s line %d: invalid note name\n", |
893
85091e14be9c
fc-buzplay: PWT refactoring, first step
Mychaela Falconia <falcon@freecalypso.org>
parents:
828
diff
changeset
|
137 filename, lineno); |
828
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
138 fclose(f); |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
139 return(-1); |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
140 } |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
141 note_vol = strtoul(fields[1], 0, 0); |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
142 if (note_vol < 1 || note_vol > 64) { |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
143 fprintf(stderr, |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
144 "%s line %d: invalid note volume\n", |
893
85091e14be9c
fc-buzplay: PWT refactoring, first step
Mychaela Falconia <falcon@freecalypso.org>
parents:
828
diff
changeset
|
145 filename, lineno); |
828
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
146 fclose(f); |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
147 return(-1); |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
148 } |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
149 duration = strtoul(fields[2], 0, 0); |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
150 if (duration < 1 || duration > 0xFFFF) { |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
151 fprintf(stderr, |
86
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
152 "%s line %d: the duration number is out of range\n", |
893
85091e14be9c
fc-buzplay: PWT refactoring, first step
Mychaela Falconia <falcon@freecalypso.org>
parents:
828
diff
changeset
|
153 filename, lineno); |
828
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
154 fclose(f); |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
155 return(-1); |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
156 } |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
157 sprintf(argbuf1, "%u", (unsigned) tp->code); |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
158 sprintf(argbuf2, "%u", |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
159 ((global_vol * note_vol + 63) >> 6) - 1); |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
160 sprintf(argbuf3, "%u", duration); |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
161 targv[0] = "ET"; |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
162 targv[1] = argbuf1; |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
163 targv[2] = argbuf2; |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
164 targv[3] = argbuf3; |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
165 targv[4] = 0; |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
166 } else if (nfields == 2 && !strcmp(fields[0], "rest")) { |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
167 duration = strtoul(fields[1], 0, 0); |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
168 if (duration < 1 || duration > 0xFFFF) { |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
169 fprintf(stderr, |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
170 "%s line %d: the duration number is out of range\n", |
893
85091e14be9c
fc-buzplay: PWT refactoring, first step
Mychaela Falconia <falcon@freecalypso.org>
parents:
828
diff
changeset
|
171 filename, lineno); |
828
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
172 fclose(f); |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
173 return(-1); |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
174 } |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
175 sprintf(argbuf1, "%u", duration); |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
176 targv[0] = "EP"; |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
177 targv[1] = argbuf1; |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
178 targv[2] = 0; |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
179 } else { |
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
180 fprintf(stderr, "%s line %d: invalid syntax\n", |
893
85091e14be9c
fc-buzplay: PWT refactoring, first step
Mychaela Falconia <falcon@freecalypso.org>
parents:
828
diff
changeset
|
181 filename, lineno); |
86
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
182 fclose(f); |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
183 return(-1); |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
184 } |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
185 /* send it to the target */ |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
186 tpinterf_make_cmd(targv); |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
187 if (tpinterf_send_cmd() < 0) { |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
188 fclose(f); |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
189 return(-1); |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
190 } |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
191 rc = tpinterf_pass_output(1); |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
192 if (rc) { |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
193 fclose(f); |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
194 return(rc); |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
195 } |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
196 /* account for the duration */ |
828
502aec4c1e8e
fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents:
86
diff
changeset
|
197 total_ms += duration * 5; |
86
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
198 } |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
199 fclose(f); |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
200 if (!total_ms) { |
893
85091e14be9c
fc-buzplay: PWT refactoring, first step
Mychaela Falconia <falcon@freecalypso.org>
parents:
828
diff
changeset
|
201 fprintf(stderr, "%s is empty!\n", filename); |
86
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
202 return(-1); |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
203 } |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
204 printf("Requesting play of the uploaded melody on the target\n"); |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
205 targv[0] = "P"; |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
206 targv[1] = 0; |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
207 tpinterf_make_cmd(targv); |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
208 if (tpinterf_send_cmd() < 0) |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
209 return(-1); |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
210 timeout = total_ms / 1000 + 2; |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
211 return tpinterf_pass_output(timeout); |
684eddecbc62
fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
212 } |
893
85091e14be9c
fc-buzplay: PWT refactoring, first step
Mychaela Falconia <falcon@freecalypso.org>
parents:
828
diff
changeset
|
213 |
85091e14be9c
fc-buzplay: PWT refactoring, first step
Mychaela Falconia <falcon@freecalypso.org>
parents:
828
diff
changeset
|
214 cmd_play_pwt(argc, argv) |
85091e14be9c
fc-buzplay: PWT refactoring, first step
Mychaela Falconia <falcon@freecalypso.org>
parents:
828
diff
changeset
|
215 char **argv; |
85091e14be9c
fc-buzplay: PWT refactoring, first step
Mychaela Falconia <falcon@freecalypso.org>
parents:
828
diff
changeset
|
216 { |
85091e14be9c
fc-buzplay: PWT refactoring, first step
Mychaela Falconia <falcon@freecalypso.org>
parents:
828
diff
changeset
|
217 unsigned global_vol; |
85091e14be9c
fc-buzplay: PWT refactoring, first step
Mychaela Falconia <falcon@freecalypso.org>
parents:
828
diff
changeset
|
218 |
85091e14be9c
fc-buzplay: PWT refactoring, first step
Mychaela Falconia <falcon@freecalypso.org>
parents:
828
diff
changeset
|
219 if (argv[2]) { |
85091e14be9c
fc-buzplay: PWT refactoring, first step
Mychaela Falconia <falcon@freecalypso.org>
parents:
828
diff
changeset
|
220 global_vol = strtoul(argv[2], 0, 0); |
85091e14be9c
fc-buzplay: PWT refactoring, first step
Mychaela Falconia <falcon@freecalypso.org>
parents:
828
diff
changeset
|
221 if (global_vol < 1 || global_vol > 64) { |
85091e14be9c
fc-buzplay: PWT refactoring, first step
Mychaela Falconia <falcon@freecalypso.org>
parents:
828
diff
changeset
|
222 fprintf(stderr, |
85091e14be9c
fc-buzplay: PWT refactoring, first step
Mychaela Falconia <falcon@freecalypso.org>
parents:
828
diff
changeset
|
223 "error: invalid global volume argument\n"); |
85091e14be9c
fc-buzplay: PWT refactoring, first step
Mychaela Falconia <falcon@freecalypso.org>
parents:
828
diff
changeset
|
224 return(-1); |
85091e14be9c
fc-buzplay: PWT refactoring, first step
Mychaela Falconia <falcon@freecalypso.org>
parents:
828
diff
changeset
|
225 } |
85091e14be9c
fc-buzplay: PWT refactoring, first step
Mychaela Falconia <falcon@freecalypso.org>
parents:
828
diff
changeset
|
226 } else |
85091e14be9c
fc-buzplay: PWT refactoring, first step
Mychaela Falconia <falcon@freecalypso.org>
parents:
828
diff
changeset
|
227 global_vol = 64; |
85091e14be9c
fc-buzplay: PWT refactoring, first step
Mychaela Falconia <falcon@freecalypso.org>
parents:
828
diff
changeset
|
228 return buzplay_pwt_file(argv[1], global_vol); |
85091e14be9c
fc-buzplay: PWT refactoring, first step
Mychaela Falconia <falcon@freecalypso.org>
parents:
828
diff
changeset
|
229 } |