Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/midi.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,15 @@ 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.
}
parsed_midi->ticks_per_beat = division;

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;
Expand All @@ -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];
Expand Down
28 changes: 9 additions & 19 deletions src/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down