summaryrefslogtreecommitdiff
path: root/project/Core/Src/Project/parser.c
diff options
context:
space:
mode:
authorsowgro <tpoke.ferrari@gmail.com>2025-12-14 01:10:28 -0500
committersowgro <tpoke.ferrari@gmail.com>2025-12-14 01:10:28 -0500
commit0616056e336da34b0a84e98e6e0ee286d4b69b8b (patch)
treebe1c9de52e1a52dedbeed3cb13235eef54226a11 /project/Core/Src/Project/parser.c
parente68a05b29de507a56b8747557707e8d6cdd68542 (diff)
download340-repo-Sowgro-0616056e336da34b0a84e98e6e0ee286d4b69b8b.tar.gz
340-repo-Sowgro-0616056e336da34b0a84e98e6e0ee286d4b69b8b.tar.bz2
340-repo-Sowgro-0616056e336da34b0a84e98e6e0ee286d4b69b8b.zip
add comments
Diffstat (limited to '')
-rw-r--r--project/Core/Src/Project/parser.c44
1 files changed, 37 insertions, 7 deletions
diff --git a/project/Core/Src/Project/parser.c b/project/Core/Src/Project/parser.c
index c34b3ba..397dd7b 100644
--- a/project/Core/Src/Project/parser.c
+++ b/project/Core/Src/Project/parser.c
@@ -1,5 +1,6 @@
/*
- * player.c
+ * parser.c
+ * Handles parsing of songs and playing of the parsed notes
*
* Created on: Nov 25, 2025
* Author: sowgro
@@ -19,9 +20,21 @@ static int nTracks;
static int startTime;
static song_info_t song_info;
-void parser_play_notes() {
- int count = systick_get_count();
- int curAbsTime = count - startTime;
+/**
+ * Prepare the parser to play the notes
+ * Expected that parse_song() was called first
+ */
+void parser_play_init() {
+ startTime = systick_get_count();
+}
+
+/**
+ * Play any notes that are ready to be played
+ * Should be called continuously in the play state
+ * Expected that parse_song() was called first
+ */
+void parser_play_loop() {
+ int curAbsTime = systick_get_count() - startTime;
for (int i = 0; i < nTracks; i++) {
note_event_t curEvent = tracks[i].events[tracks[i].curEventIndex];
if (curEvent.abs_time >= curAbsTime) {
@@ -31,12 +44,16 @@ void parser_play_notes() {
case NOTE_ON_EVENT:
add_tone(curEvent.key_number, curEvent.value); break;
}
+ tracks[i].curEventIndex++;
}
- tracks[i].curEventIndex++;
}
play_tones();
}
+/**
+ * Parse a song and populate the static fields with its information
+ * @param p_song a pointer to the current position in the song
+ */
void parse_song(uint8_t *p_song) {
header_t header;
header = get_header(p_song);
@@ -50,8 +67,13 @@ void parse_song(uint8_t *p_song) {
}
}
+/**
+ * Parse the track and populate the track parameter with its information
+ * @param p_song a pointer to the current position in the song
+ * @param track a pointer to a track to output to
+ * @returns a pointer to the song after the track
+ */
uint8_t *parse_track(uint8_t *p_song, track_t *track) {
- printf("Parsing track \r\n");
p_song += 4; // skip MTrk
uint32_t MTrk_len = convert_to_uint32(p_song);
p_song += 4;
@@ -93,10 +115,15 @@ uint8_t *parse_track(uint8_t *p_song, track_t *track) {
track->nEvents = curEvent;
track->curEventIndex = 0;
- printf("parsing track done\r\n");
return p_song;
}
+/**
+ * Parses the track information
+ * @param p_song a pointer to the current position in the song
+ * @param ret the output parameter
+ * @returns a pointer to the song after the track info
+ */
uint8_t *parse_song_info(uint8_t *p_song, song_info_t *ret) {
ret->copyright = 0;
ret->tempo = 0;
@@ -136,6 +163,9 @@ uint8_t *parse_song_info(uint8_t *p_song, song_info_t *ret) {
return p_song;
}
+/**
+ * An accessor for other files to get the song information
+ */
song_info_t parser_get_song_info() {
return song_info;
}