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 
20 /* iMelody for newer Ericsson, Motorola, Siemens and others */
21 
write_imelody_header(FILE * out,struct note_t * note)22 void write_imelody_header(FILE *out, struct note_t *note)
23 {
24 char header[2048];
25 char temp[128];
26 
27   header[0]=0;
28 
29   if (headers>=2)
30   {
31     strcat(header,"BEGIN:IMELODY\r\n");
32   }
33 
34   if (headers>=5)
35   {
36     strcat(header,"VERSION:1.0\r\n");
37     strcat(header,"FORMAT:CLASS 1.0\r\n");
38   }
39 
40   if (headers>=3)
41   {
42     sprintf(temp,"NAME:%s\r\n",note->songname);
43     strcat(header,temp);
44     sprintf(temp,"BEAT:%d\r\n",note->bpm);
45     strcat(header,temp);
46   }
47 
48   if (headers>=4)
49   {
50     sprintf(temp,"STYLE:S%d\r\n",note->style);
51     strcat(header,temp);
52   }
53 
54   if (headers>=1)
55   {
56     strcat(header,"MELODY:");
57   }
58 
59   if (note->ems==0)
60   { fprintf(out,header); }
61     else
62   {
63     write_ems(header);
64   }
65 
66   note->prev_scale=1;
67 }
68 
write_imelody_note(FILE * out,struct note_t * note)69 void write_imelody_note(FILE *out, struct note_t *note)
70 {
71 char outchars[16];
72 char temp[16];
73 
74   outchars[0]=0;
75 
76   /* if (note->prev_scale!=note->scale) */
77 
78   if (note->tone!=0)
79   {
80     sprintf(outchars,"*%d",note->scale+3);
81     note->prev_scale=note->scale;
82   }
83 
84   if (note->tone==0) strcat(outchars,"r");
85     else
86   if (note->tone==1) strcat(outchars,"c");
87     else
88   if (note->tone==2) strcat(outchars,"#c");
89     else
90   if (note->tone==3) strcat(outchars,"d");
91     else
92   if (note->tone==4) strcat(outchars,"#d");
93     else
94   if (note->tone==5) strcat(outchars,"e");
95     else
96   if (note->tone==6) strcat(outchars,"f");
97     else
98   if (note->tone==7) strcat(outchars,"#f");
99     else
100   if (note->tone==8) strcat(outchars,"g");
101     else
102   if (note->tone==9) strcat(outchars,"#g");
103     else
104   if (note->tone==10) strcat(outchars,"a");
105     else
106   if (note->tone==11) strcat(outchars,"#a");
107     else
108   if (note->tone==12) strcat(outchars,"b");
109     else
110   { strcat(outchars,"c"); }
111 
112   if (note->length<6)
113   { sprintf(temp,"%d",note->length); }
114     else
115   { sprintf(temp,"5"); }
116   strcat(outchars,temp);
117 
118   if (note->modifier==1) strcat(outchars,".");
119     else
120   if (note->modifier==2) strcat(outchars,":");
121     else
122   if (note->modifier==3) strcat(outchars,";");
123 
124   if (note->ems==0)
125   { fprintf(out,"%s",outchars); }
126     else
127   { write_ems(outchars); }
128 }
129 
write_imelody_footer(FILE * out,struct note_t * note)130 void write_imelody_footer(FILE *out, struct note_t *note)
131 {
132 char header[64];
133 
134   header[0]=0;
135 
136   strcat(header,"\r\n");
137 
138   if (headers>=2)
139   {
140     strcat(header,"END:IMELODY\r\n");
141   }
142 
143   if (note->ems==0)
144   { fprintf(out,"%s",header); }
145     else
146   {
147     write_ems(header);
148     write_ems_footer(out,note);
149   }
150 }
151 
152 
153