1 /**
2  * \file gammu-ringtone.h
3  * \author Michal Čihař
4  *
5  * Ringtone data and functions.
6  */
7 #ifndef __gammu_ringtone_h
8 #define __gammu_ringtone_h
9 
10 #ifdef	__cplusplus
11 extern "C" {
12 #endif
13 
14 /**
15  * \defgroup Ringtone Ringtone
16  * Ringtones manipulations.
17  */
18 
19 #include <gammu-types.h>
20 #include <gammu-error.h>
21 #include <gammu-limits.h>
22 #include <gammu-statemachine.h>
23 
24 #include <stdio.h>
25 
26 typedef enum {
27 	/**
28 	 * Natural style (rest between notes)
29 	 */
30 	NaturalStyle = 0x00 << 6,
31 	/**
32 	 * Continuous style (no rest between notes)
33 	 */
34 	ContinuousStyle = 0x01 << 6,
35 	/**
36 	 * Staccato style (shorter notes and longer rest period)
37 	 */
38 	StaccatoStyle = 0x02 << 6,
39 
40 	INVALIDStyle
41 } GSM_RingNoteStyle;
42 
43 typedef enum {
44 	Note_Pause = 0x00 << 4,
45 	Note_C = 0x01 << 4,
46 	Note_Cis = 0x02 << 4,
47 	Note_D = 0x03 << 4,
48 	Note_Dis = 0x04 << 4,
49 	Note_E = 0x05 << 4,
50 	Note_F = 0x06 << 4,
51 	Note_Fis = 0x07 << 4,
52 	Note_G = 0x08 << 4,
53 	Note_Gis = 0x09 << 4,
54 	Note_A = 0x0a << 4,
55 	Note_Ais = 0x0b << 4,
56 	Note_H = 0x0c << 4,
57 
58 	Note_INVALID
59 } GSM_RingNoteNote;
60 
61 typedef enum {
62 	Duration_Full = 0x00 << 5,
63 	Duration_1_2 = 0x01 << 5,
64 	Duration_1_4 = 0x02 << 5,
65 	Duration_1_8 = 0x03 << 5,
66 	Duration_1_16 = 0x04 << 5,
67 	Duration_1_32 = 0x05 << 5,
68 
69 	Duration_INVALID
70 } GSM_RingNoteDuration;
71 
72 typedef enum {
73 	NoSpecialDuration = 0x00 << 6,
74 	DottedNote = 0x01 << 6,
75 	DoubleDottedNote = 0x02 << 6,
76 	Length_2_3 = 0x03 << 6,
77 
78 	DurationSpec_INVALID
79 } GSM_RingNoteDurationSpec;
80 
81 typedef enum {
82 	/**
83 	 * 55 Hz for note A
84 	 */
85 	Scale_55 = 1,
86 	/**
87 	 * 110 Hz for note A
88 	 */
89 	Scale_110,
90 	Scale_220,
91 	/**
92 	 * first scale for Nokia
93 	 */
94 	Scale_440,
95 	Scale_880,
96 	Scale_1760,
97 	/**
98 	 * last scale for Nokia
99 	 */
100 	Scale_3520,
101 	Scale_7040,
102 	Scale_14080
103 } GSM_RingNoteScale;
104 
105 typedef struct {
106 	GSM_RingNoteDuration Duration;
107 	GSM_RingNoteDurationSpec DurationSpec;
108 	GSM_RingNoteNote Note;
109 	GSM_RingNoteStyle Style;
110 	GSM_RingNoteScale Scale;
111 	int Tempo;
112 } GSM_RingNote;
113 
114 typedef enum {
115 	RING_Note = 1,
116 	RING_EnableVibra,
117 	RING_DisableVibra,
118 	RING_EnableLight,
119 	RING_DisableLight,
120 	RING_EnableLED,
121 	RING_DisableLED,
122 	RING_Repeat
123 } GSM_RingCommandType;
124 
125 typedef struct {
126 	GSM_RingCommandType Type;
127 	GSM_RingNote Note;
128 	unsigned char Value;
129 } GSM_RingCommand;
130 
131 typedef struct {
132 	int NrCommands;
133 	gboolean AllNotesScale;
134 	GSM_RingCommand Commands[GSM_MAX_RINGTONE_NOTES];
135 } GSM_NoteRingtone;
136 
137 /* FIXME: should use BinaryTone instead? */
138 /* Structure to hold Nokia binary ringtones. */
139 typedef struct {
140 	unsigned char Frame[50000];
141 	size_t Length;
142 } GSM_NokiaBinaryRingtone;
143 
144 typedef struct {
145 	unsigned char *Buffer;
146 	size_t Length;
147 } GSM_BinaryTone;
148 
149 typedef enum {
150 	RING_NOTETONE = 1,
151 	RING_NOKIABINARY,
152 	RING_MIDI,
153 	RING_MMF
154 } GSM_RingtoneFormat;
155 
156 /**
157  * Structure for saving various ringtones formats
158  */
159 typedef struct {
160 	/**
161 	 * Ringtone saved in one of three formats
162 	 */
163 	GSM_NokiaBinaryRingtone NokiaBinary;
164 	GSM_BinaryTone BinaryTone;
165 	GSM_NoteRingtone NoteTone;
166 	/**
167 	 * Ringtone format
168 	 */
169 	GSM_RingtoneFormat Format;
170 	/**
171 	 * Ringtone name
172 	 */
173 	unsigned char Name[(GSM_MAX_RINGTONE_NAME_LENGTH + 1) * 2];
174 	/**
175 	 * Ringtone location
176 	 */
177 	int Location;
178 } GSM_Ringtone;
179 
180 typedef struct {
181 	/**
182 	 * Nokia specific
183 	 */
184 	int Group;
185 	int ID;
186 	unsigned char Name[30 * 2];
187 } GSM_RingtoneInfo;
188 
189 typedef struct {
190 	int Number;
191 	GSM_RingtoneInfo *Ringtone;
192 } GSM_AllRingtonesInfo;
193 
194 /**
195  * Play one note using state machine interface.
196  */
197 GSM_Error PHONE_RTTLPlayOneNote(GSM_StateMachine * s, GSM_RingNote note,
198 				gboolean first);
199 
200 /**
201  * Makes phone beek using state machine interface.
202  */
203 GSM_Error PHONE_Beep(GSM_StateMachine * s);
204 
205 /**
206  * Gets ringtone from phone.
207  */
208 GSM_Error GSM_GetRingtone(GSM_StateMachine * s, GSM_Ringtone * Ringtone,
209 			  gboolean PhoneRingtone);
210 /**
211  * Sets ringtone in phone.
212  */
213 GSM_Error GSM_SetRingtone(GSM_StateMachine * s, GSM_Ringtone * Ringtone,
214 			  int *maxlength);
215 /**
216  * Acquires ringtone informaiton.
217  */
218 GSM_Error GSM_GetRingtonesInfo(GSM_StateMachine * s,
219 			       GSM_AllRingtonesInfo * Info);
220 /**
221  * Deletes user defined ringtones from phone.
222  */
223 GSM_Error GSM_DeleteUserRingtones(GSM_StateMachine * s);
224 
225 /**
226  * Plays tone.
227  */
228 GSM_Error GSM_PlayTone(GSM_StateMachine * s, int Herz, unsigned char Volume,
229 		       gboolean start);
230 
231 GSM_Error GSM_RingtoneConvert(GSM_Ringtone * dest, GSM_Ringtone * src,
232 			      GSM_RingtoneFormat Format);
233 GSM_Error GSM_ReadRingtoneFile(char *FileName, GSM_Ringtone * ringtone);
234 
235 GSM_Error GSM_SaveRingtoneFile(char *FileName, GSM_Ringtone * ringtone);
236 
237 GSM_Error GSM_SaveRingtoneOtt(FILE * file, GSM_Ringtone * ringtone);
238 
239 GSM_Error GSM_SaveRingtoneMidi(FILE * file, GSM_Ringtone * ringtone);
240 
241 GSM_Error GSM_SaveRingtoneIMelody(FILE * file, GSM_Ringtone * ringtone);
242 
243 GSM_Error GSM_SaveRingtoneWav(FILE * file, GSM_Ringtone * ringtone);
244 
245 GSM_Error GSM_SaveRingtoneRttl(FILE * file, GSM_Ringtone * ringtone);
246 
247 /**
248  * Returns ringtone name, NULL if not found.
249  */
250 const unsigned char *GSM_GetRingtoneName(const GSM_AllRingtonesInfo * Info, const int ID);
251 
252 int GSM_RTTLGetTempo(int Beats);
253 
254 #ifdef	__cplusplus
255 }
256 #endif
257 #endif
258 
259 /* Editor configuration
260  * vim: noexpandtab sw=8 ts=8 sts=8 tw=72:
261  */
262