ptttl v0.3.0
C implementation of a PTTTL parser. PTTTL is a superset of NOKIA's RTTTL that adds polyphony & vibrato.
ptttl_parser.h
Go to the documentation of this file.
1 
27 #ifndef PTTTL_PARSER_H
28 #define PTTTL_PARSER_H
29 
30 
31 #include <stdint.h>
32 
33 
34 #ifdef __cplusplus
35  extern "C" {
36 #endif
37 
38 #define PTTTL_VERSION "v0.3.0"
39 
45 #ifndef PTTTL_MAX_CHANNELS_PER_FILE
46 #define PTTTL_MAX_CHANNELS_PER_FILE (16u)
47 #endif // PTTTL_MAX_CHANNELS_PER_FILE
48 
49 
55 #ifndef PTTTL_MAX_NAME_LEN
56 #define PTTTL_MAX_NAME_LEN (256u)
57 #endif // PTTTL_MAX_NAME_LEN
58 
59 
60 // Read vibrato frequency from vibrato settings
61 #define PTTTL_NOTE_VIBRATO_FREQ(note) (((note)->vibrato_settings) & 0xffffu)
62 
63 // Read vibrato variance from vibrato settings
64 #define PTTTL_NOTE_VIBRATO_VAR(note) ((((note)->vibrato_settings) >> 16u) & 0xffffu)
65 
66 // Read the musical note value from note settings
67 #define PTTTL_NOTE_VALUE(note) (((note)->note_settings) & 0x7fu)
68 
69 /* Read the note duration fraction index from note settings
70  * Index maps to note duration: 0=1(whole), 1=2(half), 2=4(quarter),
71  * 3=8(8th), 4=16(16th), 5=32(32nd) */
72 #define PTTTL_NOTE_DURATION_IDX(note) ((((note)->note_settings) >> 7u) & 0x7u)
73 
74 // Read the note dot flag from note settings (1 = dotted, 0 = not dotted)
75 #define PTTTL_NOTE_DOT(note) ((((note)->note_settings) >> 10u) & 0x1u)
76 
77 
81 typedef struct
82 {
95  uint32_t note_settings;
96 
104 
105 
109 typedef struct
110 {
111  uint32_t position;
112  uint32_t line;
113  uint32_t column;
114  uint32_t block;
115  uint8_t have_saved_char;
116  char saved_char;
118 
119 
124 typedef struct
125 {
134  int (*read)(char *input_char);
135 
147  int (*seek)(uint32_t position);
148 
150 
151 
155 typedef struct
156 {
157  const char *error_message;
158  int line;
159  int column;
161 
162 
166 typedef struct
167 {
168  char name[PTTTL_MAX_NAME_LEN];
169  unsigned int bpm;
170  unsigned int default_duration;
171  unsigned int default_octave;
172  unsigned int default_vibrato_freq;
173  unsigned int default_vibrato_var;
175  uint32_t channel_count;
181 
182 
183 
191 
192 
204 
205 
219 int ptttl_parse_next(ptttl_parser_t *parser, uint32_t channel_idx, ptttl_output_note_t *note);
220 
221 #ifdef __cplusplus
222  }
223 #endif
224 
225 #endif // PTTTL_PARSER_H
int ptttl_parse_init(ptttl_parser_t *parser, ptttl_parser_input_iface_t iface)
#define PTTTL_MAX_CHANNELS_PER_FILE
Definition: ptttl_parser.h:46
int ptttl_parse_next(ptttl_parser_t *parser, uint32_t channel_idx, ptttl_output_note_t *note)
ptttl_parser_error_t ptttl_parser_error(ptttl_parser_t *state)
#define PTTTL_MAX_NAME_LEN
Definition: ptttl_parser.h:56
Definition: ptttl_parser.h:82
uint32_t note_settings
Definition: ptttl_parser.h:95
uint32_t vibrato_settings
Definition: ptttl_parser.h:102
Definition: ptttl_parser.h:156
const char * error_message
Human-readable error message.
Definition: ptttl_parser.h:157
int column
Column number within input text.
Definition: ptttl_parser.h:159
int line
Line number within input text.
Definition: ptttl_parser.h:158
Definition: ptttl_parser.h:125
Definition: ptttl_parser.h:110
uint32_t line
Current line number in input text.
Definition: ptttl_parser.h:112
uint32_t column
Current column number in input text.
Definition: ptttl_parser.h:113
uint32_t block
Current block number, starting from 0.
Definition: ptttl_parser.h:114
uint32_t position
Current position in input text stream.
Definition: ptttl_parser.h:111
char saved_char
Unused character.
Definition: ptttl_parser.h:116
uint8_t have_saved_char
1 if a character has been read but not yet used
Definition: ptttl_parser.h:115
Definition: ptttl_parser.h:167
unsigned int default_duration
Default note duration from the "settings" section.
Definition: ptttl_parser.h:170
ptttl_parser_error_t error
Last parsing error that occurred.
Definition: ptttl_parser.h:174
uint32_t channel_count
Total number of channels present in input text.
Definition: ptttl_parser.h:175
ptttl_parser_input_iface_t iface
Input interface for reading PTTTL source.
Definition: ptttl_parser.h:179
unsigned int default_vibrato_freq
Default vibrato frequency from the "settings" section.
Definition: ptttl_parser.h:172
ptttl_parser_input_stream_t stream
Input stream used for 'settings' section.
Definition: ptttl_parser.h:177
unsigned int default_vibrato_var
Default vibrato variance from the "settings" section.
Definition: ptttl_parser.h:173
unsigned int bpm
BPM from the "settings" section.
Definition: ptttl_parser.h:169
unsigned int default_octave
Default octave from the "settings" section.
Definition: ptttl_parser.h:171
ptttl_parser_input_stream_t * active_stream
Input stream currently being parsed.
Definition: ptttl_parser.h:176