1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 
5 #include "general.h"
6 #include "fileoutput.h"
7 
8 /*
9 
10 Ringtonetools - Copyright 2001-2005 Michael Kohn (mike@mikekohn.net)
11 This falls under the Kohnian license.  Please read
12 it at http://ringtonetools.mikekohn.net/
13 
14 This program is NOT opensourced.  You may not use any part
15 of this program for your own software.
16 
17 */
18 
19 /* RTTTL and RTX */
20 
21 #define DEFAULT_LENGTH 2
22 
write_rtttl_header(FILE * out,struct note_t * note)23 void write_rtttl_header(FILE *out, struct note_t *note)
24 {
25   if (note->songname[0]==0)
26   { strcpy(note->songname,"unamed"); }
27 
28   if (note->channels==0)
29   { fprintf(out,"%s:d=%d,o=5,b=%d:",note->songname,1<<DEFAULT_LENGTH,note->bpm); }
30     else
31   {
32     if (note->loop==0)
33     { fprintf(out,"%s:d=%d,o=4,b=%d:",note->songname,1<<DEFAULT_LENGTH,note->bpm); }
34       else
35     { fprintf(out,"%s:d=%d,o=4,b=%d,l=%d:",note->songname,1<<DEFAULT_LENGTH,note->bpm,note->loop); }
36   }
37 }
38 
write_rtttl_note(FILE * out,struct note_t * note)39 void write_rtttl_note(FILE *out, struct note_t *note)
40 {
41   if (note->note_count>0) fprintf(out,",");
42 
43   if (note->length!=DEFAULT_LENGTH) fprintf(out,"%d",(1<<(note->length)));
44 
45   if (note->tone==0) fprintf(out,"p");
46     else
47   if (note->tone==1) fprintf(out,"c");
48     else
49   if (note->tone==2) fprintf(out,"c#");
50     else
51   if (note->tone==3) fprintf(out,"d");
52     else
53   if (note->tone==4) fprintf(out,"d#");
54     else
55   if (note->tone==5) fprintf(out,"e");
56     else
57   if (note->tone==6) fprintf(out,"f");
58     else
59   if (note->tone==7) fprintf(out,"f#");
60     else
61   if (note->tone==8) fprintf(out,"g");
62     else
63   if (note->tone==9) fprintf(out,"g#");
64     else
65   if (note->tone==10) fprintf(out,"a");
66     else
67   if (note->tone==11) fprintf(out,"a#");
68     else
69   if (note->tone==12) fprintf(out,"h");
70 
71   if (note->tone!=0)
72   {
73     if (note->channels==0)
74     { if (note->scale!=0) fprintf(out,"%d",note->scale+5); }
75       else
76     { if (note->scale!=0) fprintf(out,"%d",note->scale+4); }
77   }
78 
79   if (note->modifier!=0) fprintf(out,".");
80 }
81 
write_rtttl_footer(FILE * out,struct note_t * note)82 void write_rtttl_footer(FILE *out, struct note_t *note)
83 {
84   /* fprintf(out,";"); */
85 }
86 
write_rtx_bpm(FILE * out,struct note_t * note)87 void write_rtx_bpm(FILE *out, struct note_t *note)
88 {
89   if (note->note_count>0) fprintf(out,",");
90   fprintf(out,"b=%d",note->bpm);
91 }
92 
93 
94