diff --git a/src/Makefile b/src/Makefile index f7181ef6..be0d8332 100644 --- a/src/Makefile +++ b/src/Makefile @@ -9,8 +9,8 @@ BIN = ../prince OS := $(shell uname) -CPPFLAGS += -Wall -D_GNU_SOURCE=1 -CFLAGS += -std=gnu99 -O2 +CPPFLAGS += -Wall -D_XOPEN_SOURCE=700 +CFLAGS += -std=c11 -O2 ifeq ($(OS),Darwin) LIBS := $(shell sdl2-config --libs) -lSDL2_image diff --git a/src/midi.c b/src/midi.c index 3b4923db..12fe0fcc 100644 --- a/src/midi.c +++ b/src/midi.c @@ -122,7 +122,7 @@ bool parse_midi(midi_raw_chunk_type* midi, parsed_midi_type* parsed_midi) { printf("Warning: Midi sound does not have any tracks.\n"); return 0; } - int division = SDL_SwapBE16(midi->header.time_division); + int division = SDL_SwapBE16(midi->header.delta); if (division < 0) { division = (-(division / 256)) * (division & 0xFF); // Translate time delta from the alternative SMTPE format. } @@ -130,7 +130,7 @@ bool parse_midi(midi_raw_chunk_type* midi, parsed_midi_type* parsed_midi) { parsed_midi->tracks = calloc(1, num_tracks * sizeof(midi_track_type)); parsed_midi->num_tracks = num_tracks; - midi_raw_chunk_type* next_track_chunk = (midi_raw_chunk_type*) midi->header.tracks; // The first track chunk starts after the header chunk. + midi_raw_chunk_type* next_track_chunk = (midi_raw_chunk_type*) midi->tracks; // The first track chunk starts after the header chunk. byte last_event_type = 0; for (int track_index = 0; track_index < num_tracks; ++track_index) { midi_raw_chunk_type* track_chunk = next_track_chunk; @@ -140,9 +140,9 @@ bool parse_midi(midi_raw_chunk_type* midi, parsed_midi_type* parsed_midi) { memset(&parsed_midi, 0, sizeof(parsed_midi)); return 0; } - next_track_chunk = (midi_raw_chunk_type*) (track_chunk->data + (dword) SDL_SwapBE32(track_chunk->chunk_length)); + next_track_chunk = (midi_raw_chunk_type*) ((byte *)&track_chunk->header.format + (dword) SDL_SwapBE32(track_chunk->chunk_length)); midi_track_type* track = &parsed_midi->tracks[track_index]; - byte* buffer_position = track_chunk->data; + byte* buffer_position = (byte *)&track_chunk->header.format; for (;;) { track->events = realloc(track->events, (++track->num_events) * sizeof(midi_event_type)); midi_event_type* event = &track->events[track->num_events - 1]; diff --git a/src/types.h b/src/types.h index ab922e8f..e4b9a438 100644 --- a/src/types.h +++ b/src/types.h @@ -546,19 +546,17 @@ typedef struct digi_new_type { // wave in 1.3 and 1.4 (and PoP2) } digi_new_type; SDL_COMPILE_TIME_ASSERT(digi_new_type, sizeof(digi_new_type) == 9); -typedef struct midi_type { - char chunk_type[4]; - dword chunk_length; - union { - struct { +typedef struct midi_type_header { word format; word num_tracks; word delta; - byte tracks[0]; - } header; - byte data[0]; - }; +} midi_type_header; +typedef struct midi_type { + char chunk_type[4]; + dword chunk_length; + midi_type_header header; + byte tracks[]; } midi_type; typedef struct ogg_type { @@ -589,16 +587,8 @@ typedef struct sound_buffer_type { typedef struct midi_raw_chunk_type { char chunk_type[4]; dword chunk_length; - union { - struct { - word format; - word num_tracks; - word time_division; - byte tracks[0]; - } header; - byte data[0]; - }; - + midi_type_header header; + byte tracks[]; } midi_raw_chunk_type; typedef struct midi_event_type {