annotate ringtools/imy/convert.c @ 882:fd4c9bc7835d

fc-imy2pwt program written, compiles
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 03 Apr 2022 03:30:27 +0000
parents
children 3e398f9c31a0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
882
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * This module implements the second pass of fc-imy2pwt processing:
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * stepping through the captured melody and converting it to PWT.
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 */
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <ctype.h>
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <stdio.h>
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <stdlib.h>
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <string.h>
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <strings.h>
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 extern char melody_str_buf[];
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 extern unsigned tdma_durations[6][4];
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 extern FILE *outF;
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 static int cur_octave = 4;
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 static char *pwt_note_names[12] = {"c", "cs", "d", "ds", "e", "f", "fs",
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 "g", "gs", "a", "as", "b"};
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 static void
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 process_octave_cmd(octchar)
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 {
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 if (!isdigit(octchar)) {
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 fprintf(stderr,
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 "melody error: '*' octave prefix not followed by digit\n");
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 exit(1);
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 }
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 cur_octave = octchar - '0';
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 }
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 static int
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 process_note(str, type)
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 char *str;
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 {
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 int note, dur_basic, dur_mod;
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 switch (*str) {
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 case 'c':
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 note = 0;
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 break;
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 case 'd':
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 note = 2;
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 break;
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 case 'e':
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 note = 4;
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 break;
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 case 'f':
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 note = 5;
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 break;
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 case 'g':
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 note = 7;
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 break;
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 case 'a':
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 note = 9;
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 break;
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 case 'b':
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 note = 11;
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 break;
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 default:
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 fprintf(stderr,
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 "melody error: note letter expected after '&' or '#'\n");
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 exit(1);
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 }
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 switch (type) {
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 case 1:
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 if (note == 0 || note == 5) {
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 fprintf(stderr, "melody error: invalid flat note\n");
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 exit(1);
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 }
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 note--;
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 break;
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 case 2:
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 if (note == 4 || note == 11) {
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 fprintf(stderr, "melody error: invalid sharp note\n");
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 exit(1);
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 }
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 note++;
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 break;
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 }
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 if (str[1] < '0' || str[1] > '5') {
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 fprintf(stderr,
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 "melody error: missing expected note duration digit\n");
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 exit(1);
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 }
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 dur_basic = str[1] - '0';
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 switch (str[2]) {
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 case '.':
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 dur_mod = 1;
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 break;
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 case ':':
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 dur_mod = 2;
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 break;
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 case ';':
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 dur_mod = 3;
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 break;
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 default:
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98 dur_mod = 0;
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
99 break;
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
100 }
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
101 fprintf(outF, "%s%d\t64\t%u\n", pwt_note_names[note], cur_octave + 1,
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
102 tdma_durations[dur_basic][dur_mod]);
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
103 if (dur_mod)
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
104 return 3;
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
105 else
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
106 return 2;
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
107 }
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
108
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
109 static int
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
110 process_rest(str)
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
111 char *str;
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
112 {
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
113 int dur_basic, dur_mod;
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
114
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
115 if (str[1] < '0' || str[1] > '5') {
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
116 fprintf(stderr,
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
117 "melody error: missing expected rest duration digit\n");
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
118 exit(1);
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
119 }
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
120 dur_basic = str[1] - '0';
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
121 switch (str[2]) {
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
122 case '.':
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
123 dur_mod = 1;
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
124 break;
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
125 case ':':
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
126 dur_mod = 2;
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
127 break;
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
128 case ';':
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
129 dur_mod = 3;
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
130 break;
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
131 default:
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
132 dur_mod = 0;
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
133 break;
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
134 }
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
135 fprintf(outF, "rest\t\t%u\n", tdma_durations[dur_basic][dur_mod]);
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
136 if (dur_mod)
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
137 return 3;
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
138 else
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
139 return 2;
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
140 }
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
141
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
142 melody_convert_pass()
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
143 {
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
144 char *cp, *repeat_start_ptr;
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
145 int repeat_start_octave, repeat_count, rpt_set;
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
146
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
147 repeat_start_ptr = 0;
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
148 for (cp = melody_str_buf; *cp; ) {
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
149 /* skip junk first */
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
150 if (!strncmp(cp, "vibeon", 6)) {
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
151 cp += 6;
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
152 continue;
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
153 }
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
154 if (!strncmp(cp, "vibeoff", 7)) {
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
155 cp += 7;
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
156 continue;
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
157 }
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
158 if (!strncmp(cp, "ledon", 5)) {
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
159 cp += 5;
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
160 continue;
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
161 }
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
162 if (!strncmp(cp, "ledoff", 6)) {
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
163 cp += 6;
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
164 continue;
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
165 }
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
166 if (!strncmp(cp, "backon", 6)) {
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
167 cp += 6;
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
168 continue;
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
169 }
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
170 if (!strncmp(cp, "backoff", 7)) {
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
171 cp += 7;
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
172 continue;
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
173 }
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
174 /* real stuff */
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
175 switch (*cp) {
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
176 case '*':
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
177 process_octave_cmd(cp[1]);
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
178 cp += 2;
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
179 continue;
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
180 case 'c':
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
181 case 'd':
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
182 case 'e':
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
183 case 'f':
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
184 case 'g':
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
185 case 'a':
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
186 case 'b':
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
187 cp += process_note(cp, 0);
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
188 continue;
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
189 case '&':
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
190 cp++;
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
191 cp += process_note(cp, 1);
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
192 continue;
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
193 case '#':
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
194 cp++;
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
195 cp += process_note(cp, 2);
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
196 continue;
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
197 case 'r':
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
198 cp += process_rest(cp);
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
199 continue;
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
200 case 'V':
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
201 /* skip unimplemented volume control */
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
202 cp++;
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
203 if (*cp == '+' || *cp == '-') {
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
204 cp++;
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
205 continue;
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
206 }
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
207 if (!isdigit(*cp)) {
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
208 fprintf(stderr,
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
209 "melody error: invalid character after 'V'\n");
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
210 exit(1);
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
211 }
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
212 if (*cp == '1' && cp[1] >= '0' && cp[1] <= '5')
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
213 cp += 2;
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
214 else
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
215 cp++;
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
216 continue;
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
217 case '(':
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
218 if (repeat_start_ptr) {
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
219 fprintf(stderr,
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
220 "melody error: nested repeat\n");
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
221 exit(1);
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
222 }
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
223 cp++;
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
224 repeat_start_ptr = cp;
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
225 repeat_start_octave = cur_octave;
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
226 repeat_count = 0;
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
227 continue;
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
228 case '@':
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
229 if (!repeat_start_ptr) {
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
230 fprintf(stderr,
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
231 "melody error: '@' not in repeat block\n");
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
232 exit(1);
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
233 }
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
234 cp++;
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
235 if (!isdigit(*cp)) {
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
236 fprintf(stderr,
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
237 "melody error: '@' not followed by digit\n");
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
238 exit(1);
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
239 }
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
240 rpt_set = *cp - '0';
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
241 if (!rpt_set) {
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
242 fprintf(stderr,
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
243 "melody error: infinite repeat not supported\n");
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
244 exit(1);
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
245 }
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
246 cp++;
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
247 if (!repeat_count)
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
248 repeat_count = rpt_set;
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
249 continue;
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
250 case ')':
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
251 if (!repeat_start_ptr) {
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
252 fprintf(stderr,
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
253 "melody error: ')' without opening '('\n");
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
254 exit(1);
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
255 }
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
256 if (!repeat_count) {
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
257 fprintf(stderr,
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
258 "melody error: repeat block without count\n");
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
259 exit(1);
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
260 }
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
261 repeat_count--;
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
262 if (repeat_count) {
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
263 cp = repeat_start_ptr;
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
264 cur_octave = repeat_start_octave;
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
265 } else {
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
266 cp++;
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
267 repeat_start_ptr = 0;
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
268 }
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
269 continue;
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
270 default:
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
271 fprintf(stderr,
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
272 "melody error: non-understood character\n");
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
273 exit(1);
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
274 }
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
275 }
fd4c9bc7835d fc-imy2pwt program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
276 }