Skip to content

Commit

Permalink
fix midi player
Browse files Browse the repository at this point in the history
  • Loading branch information
xesf committed Nov 3, 2024
1 parent 30b15c4 commit eb126ed
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"stdlib.h": "c",
"debug_font.h": "c",
"chrono": "c",
"locale": "c"
"locale": "c",
"system_error": "c"
}
}
6 changes: 4 additions & 2 deletions src/lib/xmidi.c
Original file line number Diff line number Diff line change
Expand Up @@ -721,8 +721,10 @@ static i32 read_XMIDI_header(u8* data, u32 size, struct XMIDI_info* info)
pos += (len + 1) & ~1;
++tracksRead;
} else {
//warning("Hit invalid block '%c%c%c%c' while scanning for track locations", pos[0], pos[1], pos[2], pos[3]);
return 0;
printf("xmidi: invalid block '%c%c%c%c' while scanning for track locations", pos[0], pos[1], pos[2], pos[3]);
pos += 4;
len = read4high(&pos);
pos += (len + 1) & ~1;
}
}

Expand Down
9 changes: 6 additions & 3 deletions src/system_sdl_mixer.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ void system_mixer_init(i32 sound_config) {
exit(1);
}

if (Mix_Init(MIX_INIT_MP3 | MIX_INIT_OGG) == -1) {
if (Mix_Init(MIX_INIT_MID | MIX_INIT_MP3 | MIX_INIT_OGG) == -1) {
printf("Mix_Init: %s\n", SDL_GetError());
exit(1);
}
Expand Down Expand Up @@ -102,6 +102,7 @@ void system_mixer_music_fade_out(i32 ms) {

inline void system_mixer_load_music(u8 *music_ptr, i32 music_size) {
SDL_IOStream *rw = SDL_IOFromMem(music_ptr, music_size);
printf("IOStream: %p\n", rw);
if (current_track != NULL) {
Mix_FreeMusic(current_track);
}
Expand All @@ -120,13 +121,15 @@ i32 system_mixer_free_music() {

i32 system_mixer_play_music(u8 *music_ptr, i32 music_size, i32 loop) {
system_mixer_load_music(music_ptr, music_size);
if (!Mix_PlayMusic(current_track, loop)) {
i32 error_code = Mix_PlayMusic(current_track, loop);
if (!error_code) {
printf("Mix_PlayMusic: %s\n", SDL_GetError());
}
return error_code;
}

i32 system_mixer_play_music_mp3(c8 *music_file) {
int error_code = 0;
i32 error_code = 0;
current_track = Mix_LoadMUS(music_file);
if (current_track == NULL) {
printf("Mix_LoadMUS: %s\n", SDL_GetError());
Expand Down

0 comments on commit eb126ed

Please sign in to comment.