ptttl v0.2.0
C implementation of a PTTTL parser. PTTTL is a superset of NOKIA's RTTTL that adds polyphony & vibrato.
Loading...
Searching...
No Matches
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.2.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 from note settings
70#define PTTTL_NOTE_DURATION(note) ((((note)->note_settings) >> 7u) & 0xffffu)
71
72
76typedef struct
77{
87 uint32_t note_settings;
88
96
97
101typedef struct
102{
103 uint32_t position;
104 uint32_t line;
105 uint32_t column;
106 uint32_t block;
110
111
116typedef struct
117{
126 int (*read)(char *input_char);
127
139 int (*seek)(uint32_t position);
140
142
143
147typedef struct
148{
149 const char *error_message;
150 int line;
151 int column;
153
154
158typedef struct
159{
161 unsigned int bpm;
162 unsigned int default_duration;
163 unsigned int default_octave;
164 unsigned int default_vibrato_freq;
165 unsigned int default_vibrato_var;
167 uint32_t channel_count;
173
174
175
183
184
196
197
211int ptttl_parse_next(ptttl_parser_t *parser, uint32_t channel_idx, ptttl_output_note_t *note);
212
213#ifdef __cplusplus
214 }
215#endif
216
217#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:77
uint32_t note_settings
Definition: ptttl_parser.h:87
uint32_t vibrato_settings
Definition: ptttl_parser.h:94
Definition: ptttl_parser.h:148
const char * error_message
Human-readable error message.
Definition: ptttl_parser.h:149
int column
Column number within input text.
Definition: ptttl_parser.h:151
int line
Line number within input text.
Definition: ptttl_parser.h:150
Definition: ptttl_parser.h:117
Definition: ptttl_parser.h:102
uint32_t line
Current line number in input text.
Definition: ptttl_parser.h:104
uint32_t column
Current column number in input text.
Definition: ptttl_parser.h:105
uint32_t block
Current block number, starting from 0.
Definition: ptttl_parser.h:106
uint32_t position
Current position in input text stream.
Definition: ptttl_parser.h:103
char saved_char
Unused character.
Definition: ptttl_parser.h:108
uint8_t have_saved_char
1 if a character has been read but not yet used
Definition: ptttl_parser.h:107
Definition: ptttl_parser.h:159
unsigned int default_duration
Default note duration from the "settings" section.
Definition: ptttl_parser.h:162
ptttl_parser_error_t error
Last parsing error that occurred.
Definition: ptttl_parser.h:166
uint32_t channel_count
Total number of channels present in input text.
Definition: ptttl_parser.h:167
ptttl_parser_input_iface_t iface
Input interface for reading PTTTL source.
Definition: ptttl_parser.h:171
unsigned int default_vibrato_freq
Default vibrato frequency from the "settings" section.
Definition: ptttl_parser.h:164
ptttl_parser_input_stream_t stream
Input stream used for 'settings' section.
Definition: ptttl_parser.h:169
unsigned int default_vibrato_var
Default vibrato variance from the "settings" section.
Definition: ptttl_parser.h:165
unsigned int bpm
BPM from the "settings" section.
Definition: ptttl_parser.h:161
unsigned int default_octave
Default octave from the "settings" section.
Definition: ptttl_parser.h:163
ptttl_parser_input_stream_t * active_stream
Input stream currently being parsed.
Definition: ptttl_parser.h:168