annotate loadtools/buzplaypwt.c @ 851:526a8cfbbfd8

CHANGES: fc-host-tools-r16 released
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 18 Aug 2021 15:48:35 +0000
parents 502aec4c1e8e
children 85091e14be9c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
502aec4c1e8e fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents: 86
diff changeset
69 cmd_playt(argc, argv)
86
684eddecbc62 fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 char **argv;
684eddecbc62 fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 {
684eddecbc62 fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 FILE *f;
828
502aec4c1e8e fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents: 86
diff changeset
73 char linebuf[256], *cp, *fields[3];
502aec4c1e8e fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents: 86
diff changeset
74 int lineno, nfields;
502aec4c1e8e fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents: 86
diff changeset
75 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
76 struct pwt_note *tp;
502aec4c1e8e fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents: 86
diff changeset
77 u_long global_vol, note_vol, duration, total_ms;
86
684eddecbc62 fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 int rc, timeout;
684eddecbc62 fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79
684eddecbc62 fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 f = fopen(argv[1], "r");
684eddecbc62 fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 if (!f) {
684eddecbc62 fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 perror(argv[1]);
684eddecbc62 fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 return(-1);
684eddecbc62 fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 }
828
502aec4c1e8e fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents: 86
diff changeset
85 if (argv[2]) {
502aec4c1e8e fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents: 86
diff changeset
86 global_vol = strtoul(argv[2], 0, 0);
502aec4c1e8e fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents: 86
diff changeset
87 if (global_vol < 1 || global_vol > 64) {
502aec4c1e8e fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents: 86
diff changeset
88 fprintf(stderr,
502aec4c1e8e fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents: 86
diff changeset
89 "error: invalid global volume argument\n");
502aec4c1e8e fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents: 86
diff changeset
90 fclose(f);
502aec4c1e8e fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents: 86
diff changeset
91 return(-1);
502aec4c1e8e fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents: 86
diff changeset
92 }
502aec4c1e8e fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents: 86
diff changeset
93 } else
502aec4c1e8e fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents: 86
diff changeset
94 global_vol = 64;
86
684eddecbc62 fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 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
96 targv[0] = "IT";
86
684eddecbc62 fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 targv[1] = 0;
684eddecbc62 fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98 tpinterf_make_cmd(targv);
684eddecbc62 fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
99 if (tpinterf_send_cmd() < 0) {
684eddecbc62 fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
100 fclose(f);
684eddecbc62 fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
101 return(-1);
684eddecbc62 fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
102 }
684eddecbc62 fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
103 rc = tpinterf_pass_output(1);
684eddecbc62 fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
104 if (rc) {
684eddecbc62 fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
105 fclose(f);
684eddecbc62 fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
106 return(rc);
684eddecbc62 fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
107 }
684eddecbc62 fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
108 total_ms = 0;
684eddecbc62 fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
109 for (lineno = 1; fgets(linebuf, sizeof linebuf, f); lineno++) {
684eddecbc62 fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
110 cp = index(linebuf, '\n');
684eddecbc62 fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
111 if (!cp) {
684eddecbc62 fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
112 fprintf(stderr, "%s line %d: missing newline\n",
684eddecbc62 fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
113 argv[1], lineno);
684eddecbc62 fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
114 fclose(f);
684eddecbc62 fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
115 return(-1);
684eddecbc62 fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
116 }
828
502aec4c1e8e fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents: 86
diff changeset
117 cp = linebuf;
502aec4c1e8e fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents: 86
diff changeset
118 nfields = 0;
502aec4c1e8e fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents: 86
diff changeset
119 for (;;) {
502aec4c1e8e fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents: 86
diff changeset
120 while (isspace(*cp))
502aec4c1e8e fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents: 86
diff changeset
121 cp++;
502aec4c1e8e fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents: 86
diff changeset
122 if (*cp == '\0' || *cp == '#')
502aec4c1e8e fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents: 86
diff changeset
123 break;
502aec4c1e8e fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents: 86
diff changeset
124 if (nfields >= 3) {
502aec4c1e8e fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents: 86
diff changeset
125 fprintf(stderr, "%s line %d: too many fields\n",
502aec4c1e8e fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents: 86
diff changeset
126 argv[1], lineno);
502aec4c1e8e fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents: 86
diff changeset
127 fclose(f);
502aec4c1e8e fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents: 86
diff changeset
128 return(-1);
502aec4c1e8e fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents: 86
diff changeset
129 }
502aec4c1e8e fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents: 86
diff changeset
130 fields[nfields++] = cp;
502aec4c1e8e fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents: 86
diff changeset
131 while (*cp && !isspace(*cp))
502aec4c1e8e fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents: 86
diff changeset
132 cp++;
502aec4c1e8e fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents: 86
diff changeset
133 if (*cp)
502aec4c1e8e fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents: 86
diff changeset
134 *cp++ = '\0';
86
684eddecbc62 fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
135 }
828
502aec4c1e8e fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents: 86
diff changeset
136 if (!nfields)
502aec4c1e8e fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents: 86
diff changeset
137 continue;
502aec4c1e8e fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents: 86
diff changeset
138 if (nfields == 3) {
502aec4c1e8e fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents: 86
diff changeset
139 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
140 if (!strcmp(tp->name, fields[0]))
502aec4c1e8e fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents: 86
diff changeset
141 break;
502aec4c1e8e fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents: 86
diff changeset
142 if (tp->code < 0) {
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 name\n",
502aec4c1e8e fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents: 86
diff changeset
145 argv[1], lineno);
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 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
150 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
151 fprintf(stderr,
502aec4c1e8e fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents: 86
diff changeset
152 "%s line %d: invalid note volume\n",
502aec4c1e8e fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents: 86
diff changeset
153 argv[1], lineno);
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 duration = strtoul(fields[2], 0, 0);
502aec4c1e8e fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents: 86
diff changeset
158 if (duration < 1 || duration > 0xFFFF) {
502aec4c1e8e fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents: 86
diff changeset
159 fprintf(stderr,
86
684eddecbc62 fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
160 "%s line %d: the duration number is out of range\n",
828
502aec4c1e8e fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents: 86
diff changeset
161 argv[1], lineno);
502aec4c1e8e fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents: 86
diff changeset
162 fclose(f);
502aec4c1e8e fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents: 86
diff changeset
163 return(-1);
502aec4c1e8e fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents: 86
diff changeset
164 }
502aec4c1e8e fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents: 86
diff changeset
165 sprintf(argbuf1, "%u", (unsigned) tp->code);
502aec4c1e8e fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents: 86
diff changeset
166 sprintf(argbuf2, "%u",
502aec4c1e8e fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents: 86
diff changeset
167 ((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
168 sprintf(argbuf3, "%u", duration);
502aec4c1e8e fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents: 86
diff changeset
169 targv[0] = "ET";
502aec4c1e8e fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents: 86
diff changeset
170 targv[1] = argbuf1;
502aec4c1e8e fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents: 86
diff changeset
171 targv[2] = argbuf2;
502aec4c1e8e fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents: 86
diff changeset
172 targv[3] = argbuf3;
502aec4c1e8e fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents: 86
diff changeset
173 targv[4] = 0;
502aec4c1e8e fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents: 86
diff changeset
174 } 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
175 duration = strtoul(fields[1], 0, 0);
502aec4c1e8e fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents: 86
diff changeset
176 if (duration < 1 || duration > 0xFFFF) {
502aec4c1e8e fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents: 86
diff changeset
177 fprintf(stderr,
502aec4c1e8e fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents: 86
diff changeset
178 "%s line %d: the duration number is out of range\n",
502aec4c1e8e fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents: 86
diff changeset
179 argv[1], lineno);
502aec4c1e8e fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents: 86
diff changeset
180 fclose(f);
502aec4c1e8e fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents: 86
diff changeset
181 return(-1);
502aec4c1e8e fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents: 86
diff changeset
182 }
502aec4c1e8e fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents: 86
diff changeset
183 sprintf(argbuf1, "%u", duration);
502aec4c1e8e fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents: 86
diff changeset
184 targv[0] = "EP";
502aec4c1e8e fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents: 86
diff changeset
185 targv[1] = argbuf1;
502aec4c1e8e fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents: 86
diff changeset
186 targv[2] = 0;
502aec4c1e8e fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents: 86
diff changeset
187 } else {
502aec4c1e8e fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents: 86
diff changeset
188 fprintf(stderr, "%s line %d: invalid syntax\n",
86
684eddecbc62 fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
189 argv[1], lineno);
684eddecbc62 fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
190 fclose(f);
684eddecbc62 fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
191 return(-1);
684eddecbc62 fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
192 }
684eddecbc62 fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
193 /* send it to the target */
684eddecbc62 fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
194 tpinterf_make_cmd(targv);
684eddecbc62 fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
195 if (tpinterf_send_cmd() < 0) {
684eddecbc62 fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
196 fclose(f);
684eddecbc62 fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
197 return(-1);
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 rc = tpinterf_pass_output(1);
684eddecbc62 fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
200 if (rc) {
684eddecbc62 fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
201 fclose(f);
684eddecbc62 fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
202 return(rc);
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 /* account for the duration */
828
502aec4c1e8e fc-buzplay: implement playt command for PWT melodies
Mychaela Falconia <falcon@freecalypso.org>
parents: 86
diff changeset
205 total_ms += duration * 5;
86
684eddecbc62 fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
206 }
684eddecbc62 fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
207 fclose(f);
684eddecbc62 fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
208 if (!total_ms) {
684eddecbc62 fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
209 fprintf(stderr, "%s is empty!\n", argv[1]);
684eddecbc62 fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
210 return(-1);
684eddecbc62 fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
211 }
684eddecbc62 fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
212 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
213 targv[0] = "P";
684eddecbc62 fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
214 targv[1] = 0;
684eddecbc62 fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
215 tpinterf_make_cmd(targv);
684eddecbc62 fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
216 if (tpinterf_send_cmd() < 0)
684eddecbc62 fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
217 return(-1);
684eddecbc62 fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
218 timeout = total_ms / 1000 + 2;
684eddecbc62 fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
219 return tpinterf_pass_output(timeout);
684eddecbc62 fc-buzplay play command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
220 }