1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <ctype.h>
5
6 #include "general.h"
7 #include "fileoutput.h"
8
9 /*
10
11 Ringtone Tools - Copyright 2001-2005 Michael Kohn (mike@mikekohn.net)
12 This falls under the Kohnian license. Please read
13 it at http://ringtonetools.mikekohn.net/
14
15 This program is NOT opensourced. You may not use any part
16 of this program for your own software.
17
18 */
19
parse_morsecode(FILE * in,FILE * out,int out_type,struct note_t * note)20 int parse_morsecode(FILE *in, FILE *out, int out_type, struct note_t *note)
21 {
22 int ch,s,t;
23 char *p;
24 char code_alpha[50][5]={".-","-...","-.-.","-..",".","..-.","--.", /* A - G */
25 "....","..",".---","-.-",".-..","--", /* H - M */
26 "-.","---",".--.","--.-",".-.","...","-", /* N - T */
27 "..-","...-",".--","-..-","-.--","--.." }; /* U - Z */
28 char code_numbers[14][7]={"-----",".----","..---","...--","....-", /* 0 - 4 */
29 ".....","-....","--...","---..","----.", /* 5 - 9 */
30 ".-.-.-","--..--","..--.."," " }; /* Stop , ? */
31
32 header_route(out,note,0,out_type);
33 note->scale=0;
34 note->modifier=0;
35 note->tone=1;
36
37 while ((ch=getc(in))!=EOF)
38 {
39 ch=tolower(ch);
40 if (ch>='a' && ch <='z') p=code_alpha[ch-'a'];
41 else
42 if (ch>='0' && ch <='9') p=code_numbers[ch-'0'];
43 else
44 if (ch==',') p=code_numbers[11];
45 else
46 if (ch=='?') p=code_numbers[12];
47 else
48 if (ch=='$') p=code_numbers[10]; /* Full Stop? */
49 else
50 if (ch==' ') p=code_numbers[13];
51 else
52 { continue; }
53
54 s=strlen(p);
55
56 for (t=0; t<s; t++)
57 {
58 if (p[t]=='-')
59 {
60 note->length=3;
61 note->tone=9;
62 note->modifier=1;
63 note_route(out,note,0,out_type);
64 }
65 else
66 if (p[t]=='.')
67 {
68 note->length=4;
69 note->tone=9;
70 note->modifier=0;
71 note_route(out,note,0,out_type);
72 /*
73 note->length=4;
74 note->tone=0;
75 note_route(out,note,0,out_type);
76 */
77 }
78 else
79 if (p[t]==' ')
80 {
81 note->length=3;
82 note->tone=0;
83 note->modifier=1;
84 note_route(out,note,0,out_type);
85 }
86 }
87 }
88
89 footer_route(out,note,0,out_type);
90
91 return (0);
92 }
93
94
95
96