diff options
| author | sowgro <tpoke.ferrari@gmail.com> | 2025-10-17 22:01:03 -0400 |
|---|---|---|
| committer | sowgro <tpoke.ferrari@gmail.com> | 2025-10-17 22:01:03 -0400 |
| commit | 06ba9e05c166c48a739683766f09c4abf242fb81 (patch) | |
| tree | fb22c0052f075522e6882b462cb310deb4238ed0 /project/Core/Src/Project | |
| parent | 0e0f83905bb3ee79f4917927479cdaf710e8ac07 (diff) | |
| download | 340-repo-Sowgro-06ba9e05c166c48a739683766f09c4abf242fb81.tar.gz 340-repo-Sowgro-06ba9e05c166c48a739683766f09c4abf242fb81.tar.bz2 340-repo-Sowgro-06ba9e05c166c48a739683766f09c4abf242fb81.zip | |
Complete project
Diffstat (limited to 'project/Core/Src/Project')
| -rw-r--r-- | project/Core/Src/Project/project.c | 18 | ||||
| -rw-r--r-- | project/Core/Src/Project/song_info.c | 50 |
2 files changed, 67 insertions, 1 deletions
diff --git a/project/Core/Src/Project/project.c b/project/Core/Src/Project/project.c index 379f380..1311219 100644 --- a/project/Core/Src/Project/project.c +++ b/project/Core/Src/Project/project.c @@ -11,6 +11,8 @@ #include <stdio.h> #include "hw4.h" #include <string.h> +#include "song_info.h" +#include "song.h" #define PLAYING_STATE (1) #define PAUSED_STATE (2) @@ -80,7 +82,21 @@ void help() { } void next() { - // TODO + static int current_song = -1; + current_song++; + if (current_song > 4) + current_song = 0; + + void *song = get_song(current_song).p_song; + song_info_t song_info = get_song_info(song); + + printf("Song #%i\r\n", current_song + 1); + if (song_info.title) + printf("Title: %s\r\n", song_info.title); + if (song_info.copyright) + printf("Copyright: %s\r\n", song_info.copyright); + if (song_info.tempo) + printf("Tempo: %i\r\n", song_info.tempo); } void play() { diff --git a/project/Core/Src/Project/song_info.c b/project/Core/Src/Project/song_info.c new file mode 100644 index 0000000..4d3f232 --- /dev/null +++ b/project/Core/Src/Project/song_info.c @@ -0,0 +1,50 @@ +/* + * song_info.c + * + * Created on: Oct 9, 2025 + * Author: sowgro + */ + +#include "song.h" +#include "activity4.h" +#include <stdint.h> +#include "song_info.h" +#include "endian_converters.h" + +song_info_t get_song_info(uint8_t *p_song) { + song_info_t ret = {0, 0, 0}; +// header_t *header = (header_t *) p_song; + p_song += sizeof(header_t) - 2; // move pointer past header + p_song += 4; // move past MTrk label + + uint32_t MTrk_len = convert_to_uint32(p_song); // read in size of MTrk + + for (uint8_t *p_end = p_song + MTrk_len; p_song != p_end; p_song++) { + // FF 02 - copyright + if (convert_to_uint16(p_song) == 0xFF02) { + p_song += sizeof(uint16_t); + uint8_t ev_len = *(uint8_t *) p_song; + p_song += sizeof(ev_len); + ret.copyright = (char *) p_song; + ret.copyright[ev_len] = 0; + } + + // FF 03 - title + if (convert_to_uint16(p_song) == 0xFF03) { + p_song += sizeof(uint16_t); + uint8_t ev_len = *(uint8_t *) p_song; + p_song += sizeof(ev_len); + ret.title = (char *) p_song; + ret.title[ev_len] = 0; + } + + // FF 51 - tempo + if (convert_to_uint16(p_song) == 0xFF51) { + p_song += sizeof(uint16_t); + p_song += sizeof(uint8_t); // skip length, always 03 + ret.tempo = convert_to_uint24(p_song); + } + } + + return ret; +} |
