SDL_mixer: style clean-up. (c7742)

From c774255aadf6f28e19f956e88583392eec4cb51c Mon Sep 17 00:00:00 2001
From: Ozkan Sezer <[EMAIL REDACTED]>
Date: Mon, 15 Jan 2024 17:00:02 +0300
Subject: [PATCH] style clean-up.

---
 examples/playmus.c                          |  32 +--
 examples/playwave.c                         |  21 +-
 src/codecs/load_aiff.c                      |   6 +-
 src/codecs/load_voc.c                       | 173 ++++++++--------
 src/codecs/music_cmd.c                      |   6 +-
 src/codecs/native_midi/native_midi_common.c | 153 +++++++--------
 src/effect_position.c                       | 118 ++++++-----
 src/effect_stereoreverse.c                  |  16 +-
 src/effects_internal.c                      |   6 +-
 src/mixer.c                                 | 206 ++++++++++----------
 src/music.c                                 |  36 ++--
 11 files changed, 384 insertions(+), 389 deletions(-)

diff --git a/examples/playmus.c b/examples/playmus.c
index 70c52917..85e5fc27 100644
--- a/examples/playmus.c
+++ b/examples/playmus.c
@@ -74,7 +74,7 @@ static void Menu(void)
     printf("Available commands: (p)ause (r)esume (h)alt volume(v#) > ");
     fflush(stdin);
     if (scanf("%s",buf) == 1) {
-        switch(buf[0]){
+        switch(buf[0]) {
 #if defined(SEEK_TEST)
         case '0': Mix_SetMusicPosition(0); break;
         case '1': Mix_SetMusicPosition(10);break;
@@ -104,9 +104,9 @@ static void Menu(void)
 static void IntHandler(int sig)
 {
     switch (sig) {
-            case SIGINT:
-            next_track++;
-            break;
+    case SIGINT:
+        next_track++;
+        break;
     }
 }
 #endif
@@ -134,7 +134,7 @@ int main(int argc, char *argv[])
     spec.channels = MIX_DEFAULT_CHANNELS;
 
     /* Check command line usage */
-    for (i=1; argv[i] && (*argv[i] == '-'); ++i) {
+    for (i = 1; argv[i] && (*argv[i] == '-'); ++i) {
         if ((SDL_strcmp(argv[i], "-r") == 0) && argv[i+1]) {
             ++i;
             spec.freq = SDL_atoi(argv[i]);
@@ -170,18 +170,18 @@ int main(int argc, char *argv[])
             rwops = 1;
         } else {
             Usage(argv[0]);
-            return(1);
+            return 1;
         }
     }
-    if (! argv[i]) {
+    if (!argv[i]) {
         Usage(argv[0]);
-        return(1);
+        return 1;
     }
 
     /* Initialize the SDL library */
     if (SDL_Init(SDL_INIT_AUDIO) < 0) {
         SDL_Log("Couldn't initialize SDL: %s\n",SDL_GetError());
-        return(255);
+        return 255;
     }
 
 #ifdef HAVE_SIGNAL_H
@@ -190,10 +190,9 @@ int main(int argc, char *argv[])
 #endif
 
     /* Open the audio device */
-
     if (Mix_OpenAudio(0, &spec) < 0) {
         SDL_Log("Couldn't open audio: %s\n", SDL_GetError());
-        return(2);
+        return 2;
     } else {
         Mix_QuerySpec(&spec.freq, &spec.format, &spec.channels);
         SDL_Log("Opened audio at %d Hz %d bit%s %s audio buffer\n", spec.freq,
@@ -219,8 +218,7 @@ int main(int argc, char *argv[])
             music = Mix_LoadMUS(argv[i]);
         }
         if (music == NULL) {
-            SDL_Log("Couldn't load %s: %s\n",
-                argv[i], SDL_GetError());
+            SDL_Log("Couldn't load %s: %s\n", argv[i], SDL_GetError());
             CleanUp(2);
         }
 
@@ -292,9 +290,9 @@ int main(int argc, char *argv[])
         }
         Mix_FadeInMusic(music,looping,2000);
         while (!next_track && (Mix_PlayingMusic() || Mix_PausedMusic())) {
-            if(interactive)
+            if (interactive) {
                 Menu();
-            else {
+            } else {
                 current_position = Mix_GetMusicPosition(music);
                 if (current_position >= 0.0) {
                     printf("Position: %g seconds             \r", current_position);
@@ -308,7 +306,9 @@ int main(int argc, char *argv[])
 
         /* If the user presses Ctrl-C more than once, exit. */
         SDL_Delay(500);
-        if (next_track > 1) break;
+        if (next_track > 1) {
+            break;
+        }
 
         i++;
     }
diff --git a/examples/playwave.c b/examples/playwave.c
index 2090388a..b66223f0 100644
--- a/examples/playwave.c
+++ b/examples/playwave.c
@@ -147,9 +147,9 @@ static void SDLCALL channel_complete_callback (int chan)
 static int still_playing(void)
 {
 #ifdef TEST_MIX_CHANNELFINISHED
-    return(!channel_is_done);
+    return !channel_is_done;
 #else
-    return(Mix_Playing(0));
+    return Mix_Playing(0);
 #endif
 }
 
@@ -164,7 +164,7 @@ static void do_panning_update(void)
     static int panningok = 1;
     static Uint32 next_panning_update = 0;
 
-    if ((panningok) && (SDL_GetTicks() >= next_panning_update)) {
+    if (panningok && (SDL_GetTicks() >= next_panning_update)) {
         panningok = Mix_SetPanning(0, leftvol, rightvol);
         if (!panningok) {
             SDL_Log("Mix_SetPanning(0, %d, %d) failed!\n",
@@ -235,7 +235,7 @@ static void do_position_update(void)
     static int positionok = 1;
     static Uint32 next_position_update = 0;
 
-    if ((positionok) && (SDL_GetTicks() >= next_position_update)) {
+    if (positionok && (SDL_GetTicks() >= next_position_update)) {
         positionok = Mix_SetPosition(0, angle, (Uint8)distance);
         if (!positionok) {
             SDL_Log("Mix_SetPosition(0, %d, %d) failed!\n",
@@ -377,7 +377,7 @@ int main(int argc, char *argv[])
     spec.channels = MIX_DEFAULT_CHANNELS;
 
     /* Check command line usage */
-    for (i=1; argv[i] && (*argv[i] == '-'); ++i) {
+    for (i = 1; argv[i] && (*argv[i] == '-'); ++i) {
         if ((SDL_strcmp(argv[i], "-r") == 0) && argv[i+1]) {
             ++i;
             spec.freq = SDL_atoi(argv[i]);
@@ -405,18 +405,18 @@ int main(int argc, char *argv[])
             reverse_sample = 1;
         } else {
             Usage(argv[0]);
-            return(1);
+            return 1;
         }
     }
-    if (! argv[i]) {
+    if (!argv[i]) {
         Usage(argv[0]);
-        return(1);
+        return 1;
     }
 
     /* Initialize the SDL library */
     if (SDL_Init(SDL_INIT_AUDIO) < 0) {
         SDL_Log("Couldn't initialize SDL: %s\n",SDL_GetError());
-        return(255);
+        return 255;
     }
 #ifdef HAVE_SIGNAL_H
     signal(SIGINT, CleanUp);
@@ -453,8 +453,7 @@ int main(int argc, char *argv[])
     /* Load the requested wave file */
     g_wave = Mix_LoadWAV(argv[i]);
     if (g_wave == NULL) {
-        SDL_Log("Couldn't load %s: %s\n",
-                        argv[i], SDL_GetError());
+        SDL_Log("Couldn't load %s: %s\n", argv[i], SDL_GetError());
         CleanUp(2);
     }
 
diff --git a/src/codecs/load_aiff.c b/src/codecs/load_aiff.c
index e2001094..8bea7a44 100644
--- a/src/codecs/load_aiff.c
+++ b/src/codecs/load_aiff.c
@@ -65,11 +65,11 @@ static Uint32 SANE_to_Uint32 (Uint8 *sanebuf)
 SDL_AudioSpec *Mix_LoadAIFF_RW (SDL_RWops *src, SDL_bool freesrc,
     SDL_AudioSpec *spec, Uint8 **audio_buf, Uint32 *audio_len)
 {
-    SDL_bool was_error = SDL_TRUE;
     int found_SSND;
     int found_COMM;
     int found_VHDR;
     int found_BODY;
+    SDL_bool was_error = SDL_TRUE;
     Sint64 start = 0;
 
     Uint32 chunk_type;
@@ -146,9 +146,11 @@ SDL_AudioSpec *Mix_LoadAIFF_RW (SDL_RWops *src, SDL_bool freesrc,
             goto done;
         }
         next_chunk  = SDL_RWtell(src) + chunk_length;
+
         /* Paranoia to avoid infinite loops */
-        if (chunk_length == 0)
+        if (chunk_length == 0) {
             break;
+        }
 
         switch (chunk_type) {
             case SSND:
diff --git a/src/codecs/load_voc.c b/src/codecs/load_voc.c
index 0bc28582..82f21cd8 100644
--- a/src/codecs/load_voc.c
+++ b/src/codecs/load_voc.c
@@ -88,24 +88,27 @@ static int voc_check_header(SDL_RWops *src)
 
     SDL_RWseek(src, 0, SDL_RW_SEEK_SET);
 
-    if (SDL_RWread(src, signature, sizeof(signature)) != sizeof(signature))
-        return(0);
+    if (SDL_RWread(src, signature, sizeof(signature)) != sizeof(signature)) {
+        return 0;
+    }
 
     if (SDL_memcmp(signature, "Creative Voice File\032", sizeof(signature)) != 0) {
         SDL_SetError("Unrecognized file type (not VOC)");
-        return(0);
+        return 0;
     }
 
     /* get the offset where the first datablock is located */
-    if (SDL_RWread(src, &datablockofs, sizeof(Uint16)) != sizeof(Uint16))
-        return(0);
+    if (SDL_RWread(src, &datablockofs, sizeof(Uint16)) != sizeof(Uint16)) {
+        return 0;
+    }
 
     datablockofs = SDL_SwapLE16(datablockofs);
 
-    if (SDL_RWseek(src, datablockofs, SDL_RW_SEEK_SET) != datablockofs)
-        return(0);
+    if (SDL_RWseek(src, datablockofs, SDL_RW_SEEK_SET) != datablockofs) {
+        return 0;
+    }
 
-    return(1);  /* success! */
+    return 1;  /* success! */
 } /* voc_check_header */
 
 
@@ -122,38 +125,37 @@ static int voc_get_block(SDL_RWops *src, vs_t *v, SDL_AudioSpec *spec)
     unsigned int i;
 
     v->silent = 0;
-    while (v->rest == 0)
-    {
-        if (SDL_RWread(src, &block, sizeof(block)) != sizeof(block))
+    while (v->rest == 0) {
+        if (SDL_RWread(src, &block, sizeof(block)) != sizeof(block)) {
             return 1;  /* assume that's the end of the file. */
+        }
 
-        if (block == VOC_TERM)
+        if (block == VOC_TERM) {
             return 1;
+        }
 
-        if (SDL_RWread(src, bits24, sizeof(bits24)) != sizeof(bits24))
+        if (SDL_RWread(src, bits24, sizeof(bits24)) != sizeof(bits24)) {
             return 1;  /* assume that's the end of the file. */
+        }
 
         /* Size is an 24-bit value. Ugh. */
         sblen = (Uint32)((bits24[0]) | (bits24[1] << 8) | (bits24[2] << 16));
 
-        switch(block)
-        {
+        switch(block) {
             case VOC_DATA:
-                if (SDL_RWread(src, &uc, sizeof(uc)) != sizeof(uc))
+                if (SDL_RWread(src, &uc, sizeof(uc)) != sizeof(uc)) {
                     return 0;
+                }
 
                 /* When DATA block preceeded by an EXTENDED     */
                 /* block, the DATA blocks rate value is invalid */
-                if (!v->has_extended)
-                {
-                    if (uc == 0)
-                    {
+                if (!v->has_extended) {
+                    if (uc == 0) {
                         SDL_SetError("VOC Sample rate is zero?");
                         return 0;
                     }
 
-                    if ((v->rate != VOC_BAD_RATE) && (uc != v->rate))
-                    {
+                    if ((v->rate != VOC_BAD_RATE) && (uc != v->rate)) {
                         SDL_SetError("VOC sample rate codes differ");
                         return 0;
                     }
@@ -163,11 +165,11 @@ static int voc_get_block(SDL_RWops *src, vs_t *v, SDL_AudioSpec *spec)
                     v->channels = 1;
                 }
 
-                if (SDL_RWread(src, &uc, sizeof(uc)) != sizeof(uc))
+                if (SDL_RWread(src, &uc, sizeof(uc)) != sizeof(uc)) {
                     return 0;
+                }
 
-                if (uc != 0)
-                {
+                if (uc != 0) {
                     SDL_SetError("VOC decoder only interprets 8-bit data");
                     return 0;
                 }
@@ -178,27 +180,26 @@ static int voc_get_block(SDL_RWops *src, vs_t *v, SDL_AudioSpec *spec)
                 return 1;
 
             case VOC_DATA_16:
-                if (SDL_RWread(src, &new_rate_long, sizeof(new_rate_long)) != sizeof(new_rate_long))
+                if (SDL_RWread(src, &new_rate_long, sizeof(new_rate_long)) != sizeof(new_rate_long)) {
                     return 0;
+                }
                 new_rate_long = SDL_SwapLE32(new_rate_long);
-                if (new_rate_long == 0)
-                {
+                if (new_rate_long == 0) {
                     SDL_SetError("VOC Sample rate is zero?");
                     return 0;
                 }
-                if ((v->rate != VOC_BAD_RATE) && (new_rate_long != v->rate))
-                {
+                if ((v->rate != VOC_BAD_RATE) && (new_rate_long != v->rate)) {
                     SDL_SetError("VOC sample rate codes differ");
                     return 0;
                 }
                 v->rate = new_rate_long;
                 spec->freq = (int)new_rate_long;
 
-                if (SDL_RWread(src, &uc, sizeof(uc)) != sizeof(uc))
+                if (SDL_RWread(src, &uc, sizeof(uc)) != sizeof(uc)) {
                     return 0;
+                }
 
-                switch (uc)
-                {
+                switch (uc) {
                     case 8:  v->size = ST_SIZE_BYTE; break;
                     case 16: v->size = ST_SIZE_WORD; break;
                     default:
@@ -206,11 +207,13 @@ static int voc_get_block(SDL_RWops *src, vs_t *v, SDL_AudioSpec *spec)
                         return 0;
                 }
 
-                if (SDL_RWread(src, &v->channels, sizeof(Uint8)) != sizeof(Uint8))
+                if (SDL_RWread(src, &v->channels, sizeof(Uint8)) != sizeof(Uint8)) {
                     return 0;
+                }
 
-                if (SDL_RWread(src, trash, 6) != 6)
+                if (SDL_RWread(src, trash, 6) != 6) {
                     return 0;
+                }
 
                 v->rest = sblen - 12;
                 return 1;
@@ -220,14 +223,15 @@ static int voc_get_block(SDL_RWops *src, vs_t *v, SDL_AudioSpec *spec)
                 return 1;
 
             case VOC_SILENCE:
-                if (SDL_RWread(src, &period, sizeof(period)) != sizeof(period))
+                if (SDL_RWread(src, &period, sizeof(period)) != sizeof(period)) {
                     return 0;
+                }
                 period = SDL_SwapLE16(period);
 
-                if (SDL_RWread(src, &uc, sizeof(uc)) != sizeof(uc))
+                if (SDL_RWread(src, &uc, sizeof(uc)) != sizeof(uc)) {
                     return 0;
-                if (uc == 0)
-                {
+                }
+                if (uc == 0) {
                     SDL_SetError("VOC silence sample rate is zero");
                     return 0;
                 }
@@ -247,10 +251,10 @@ static int voc_get_block(SDL_RWops *src, vs_t *v, SDL_AudioSpec *spec)
 
             case VOC_LOOP:
             case VOC_LOOPEND:
-                for(i = 0; i < sblen; i++)   /* skip repeat loops. */
-                {
-                    if (SDL_RWread(src, trash, sizeof(Uint8)) != sizeof(Uint8))
+                for (i = 0; i < sblen; i++) { /* skip repeat loops. */
+                    if (SDL_RWread(src, trash, sizeof(Uint8)) != sizeof(Uint8)) {
                         return 0;
+                    }
                 }
                 break;
 
@@ -260,60 +264,61 @@ static int voc_get_block(SDL_RWops *src, vs_t *v, SDL_AudioSpec *spec)
                 /* value from the extended block and not the     */
                 /* data block.                     */
                 v->has_extended = 1;
-                if (SDL_RWread(src, &new_rate_short, sizeof(new_rate_short)) != sizeof(new_rate_short))
+                if (SDL_RWread(src, &new_rate_short, sizeof(new_rate_short)) != sizeof(new_rate_short)) {
                     return 0;
+                }
                 new_rate_short = SDL_SwapLE16(new_rate_short);
-                if (new_rate_short == 0)
-                {
+                if (new_rate_short == 0) {
                    SDL_SetError("VOC sample rate is zero");
                    return 0;
                 }
-                if ((v->rate != VOC_BAD_RATE) && (new_rate_short != v->rate))
-                {
+                if ((v->rate != VOC_BAD_RATE) && (new_rate_short != v->rate)) {
                    SDL_SetError("VOC sample rate codes differ");
                    return 0;
                 }
                 v->rate = new_rate_short;
 
-                if (SDL_RWread(src, &uc, sizeof(uc)) != sizeof(uc))
+                if (SDL_RWread(src, &uc, sizeof(uc)) != sizeof(uc)) {
                     return 0;
+                }
 
-                if (uc != 0)
-                {
+                if (uc != 0) {
                     SDL_SetError("VOC decoder only interprets 8-bit data");
                     return 0;
                 }
 
-                if (SDL_RWread(src, &uc, sizeof(uc)) != sizeof(uc))
+                if (SDL_RWread(src, &uc, sizeof(uc)) != sizeof(uc)) {
                     return 0;
+                }
 
-                if (uc)
-                    spec->channels = 2;  /* Stereo */
+                if (uc) /* Stereo */
+                     spec->channels = 2;
                 /* VOC_EXTENDED may be read before spec->channels inited: */
                 else spec->channels = 1;
                 /* Needed number of channels before finishing
                    compute for rate */
-                spec->freq = (256000000L/(65536L - v->rate))/spec->channels;
+                spec->freq = (256000000L / (65536L - v->rate)) / spec->channels;
                 /* An extended block must be followed by a data */
                 /* block to be valid so loop back to top so it  */
                 /* can be grabed.                */
                 continue;
 
             case VOC_MARKER:
-                if (SDL_RWread(src, trash, 2) != 2)
+                if (SDL_RWread(src, trash, 2) != 2) {
                     return 0;
-
+                }
                 /* fallthrough */
 
             default:  /* text block or other krapola. */
-                for(i = 0; i < sblen; i++)
-                {
-                    if (SDL_RWread(src, trash, sizeof(Uint8)) != sizeof(Uint8))
+                for (i = 0; i < sblen; i++) {
+                    if (SDL_RWread(src, trash, sizeof(Uint8)) != sizeof(Uint8)) {
                         return 0;
+                    }
                 }
 
-                if (block == VOC_TEXT)
+                if (block == VOC_TEXT) {
                     continue;    /* get next block */
+                }
         }
     }
 
@@ -326,38 +331,37 @@ static Uint32 voc_read(SDL_RWops *src, vs_t *v, Uint8 *buf, SDL_AudioSpec *spec)
     Sint64 done = 0;
     Uint8 silence = 0x80;
 
-    if (v->rest == 0)
-    {
-        if (!voc_get_block(src, v, spec))
+    if (v->rest == 0) {
+        if (!voc_get_block(src, v, spec)) {
             return 0;
+        }
     }
 
-    if (v->rest == 0)
+    if (v->rest == 0) {
         return 0;
+    }
 
-    if (v->silent)
-    {
-        if (v->size == ST_SIZE_WORD)
+    if (v->silent) {
+        if (v->size == ST_SIZE_WORD) {
             silence = 0x00;
+        }
 
         /* Fill in silence */
         SDL_memset(buf, silence, v->rest);
         done = v->rest;
         v->rest = 0;
     }
-    else
-    {
+    else {
         done = SDL_RWread(src, buf, v->rest);
-        if (done <= 0)
+        if (done <= 0) {
             return 0;
+        }
 
         v->rest = (Uint32)(v->rest - done);
-        if (v->size == ST_SIZE_WORD)
-        {
+        if (v->size == ST_SIZE_WORD) {
             #if (SDL_BYTEORDER == SDL_BIG_ENDIAN)
             Uint16 *samples = (Uint16 *)buf;
-            for (; v->rest > 0; v->rest -= 2)
-            {
+            for (; v->rest > 0; v->rest -= 2) {
                 *samples = SDL_SwapLE16(*samples);
                 samples++;
             }
@@ -401,16 +405,18 @@ SDL_AudioSpec *Mix_LoadVOC_RW (SDL_RWops *src, SDL_bool freesrc,
         goto done;
     }
 
-    if (!voc_check_header(src))
+    if (!voc_check_header(src)) {
         goto done;
+    }
 
     SDL_zero(v);
     v.rate = VOC_BAD_RATE;
     v.rest = 0;
     v.has_extended = 0;
 
-    if (!voc_get_block(src, &v, spec))
+    if (!voc_get_block(src, &v, spec)) {
         goto done;
+    }
 
     if (v.rate == VOC_BAD_RATE) {
         SDL_SetError("VOC data had no sound!");
@@ -424,25 +430,26 @@ SDL_AudioSpec *Mix_LoadVOC_RW (SDL_RWops *src, SDL_bool freesrc,
 
     SDL_zerop(spec);
     spec->format = ((v.size == ST_SIZE_WORD) ? SDL_AUDIO_S16 : SDL_AUDIO_U8);
-    if (spec->channels == 0)
+    if (spec->channels == 0) {
         spec->channels = v.channels;
+    }
 
     *audio_len = v.rest;
     *audio_buf = (v.rest == 0) ? NULL : SDL_malloc(v.rest);
-    if (*audio_buf == NULL)
+    if (*audio_buf == NULL) {
         goto done;
+    }
 
     fillptr = *audio_buf;
 
-    while (voc_read(src, &v, fillptr, spec))
-    {
-        if (!voc_get_block(src, &v, spec))
+    while (voc_read(src, &v, fillptr, spec)) {
+        if (!voc_get_block(src, &v, spec)) {
             goto done;
+        }
 
         *audio_len += v.rest;
         ptr = SDL_realloc(*audio_buf, *audio_len);
-        if (ptr == NULL)
-        {
+        if (ptr == NULL) {
             goto done;
         }
 
diff --git a/src/codecs/music_cmd.c b/src/codecs/music_cmd.c
index 96510c91..10441be4 100644
--- a/src/codecs/music_cmd.c
+++ b/src/codecs/music_cmd.c
@@ -123,7 +123,7 @@ static int ParseCommandLine(char *cmdline, char **argv)
     if (argv) {
         argv[argc] = NULL;
     }
-    return(argc);
+    return argc;
 }
 
 static char **parse_args(char *command, char *last_arg)
@@ -138,7 +138,7 @@ static char **parse_args(char *command, char *last_arg)
     }
     argv = (char **)SDL_malloc((argc+1)*(sizeof *argv));
     if (argv == NULL) {
-        return(NULL);
+        return NULL;
     }
     argc = ParseCommandLine(command, argv);
 
@@ -149,7 +149,7 @@ static char **parse_args(char *command, char *last_arg)
     argv[argc] = NULL;
 
     /* We're ready! */
-    return(argv);
+    return argv;
 }
 
 /* Start playback of a given music stream */
diff --git a/src/codecs/native_midi/native_midi_common.c b/src/codecs/native_midi/native_midi_common.c
index 91dc1dde..a4d60870 100644
--- a/src/codecs/native_midi/native_midi_common.c
+++ b/src/codecs/native_midi/native_midi_common.c
@@ -58,19 +58,18 @@ typedef struct
 #endif
 
 
-
 /* Get Variable Length Quantity */
 static int GetVLQ(MIDITrack *track, int *currentPos)
 {
     int l = 0;
     Uint8 c;
-    while(1)
-    {
+    while (1) {
         c = track->data[*currentPos];
         (*currentPos)++;
         l += (c & 0x7f);
-        if (!(c & 0x80))
+        if (!(c & 0x80)) {
             return l;
+        }
         l <<= 7;
     }
 }
@@ -82,15 +81,14 @@ static MIDIEvent *CreateEvent(Uint32 time, Uint8 event, Uint8 a, Uint8 b)
 
     newEvent = SDL_calloc(1, sizeof(MIDIEvent));
 
-    if (newEvent)
-    {
+    if (newEvent) {
         newEvent->time = time;
         newEvent->status = event;
         newEvent->data[0] = a;
         newEvent->data[1] = b;
-    }
-    else
+    } else {
         Mix_OutOfMemory();
+    }
 
     return newEvent;
 }
@@ -108,23 +106,20 @@ static MIDIEvent *MIDITracktoStream(MIDITrack *track)
     MIDIEvent *head = CreateEvent(0,0,0,0); /* dummy event to make handling the list easier */
     MIDIEvent *currentEvent = head;
 
-    while (!end)
-    {
-        if (currentPos >= track->len)
+    while (!end) {
+        if (currentPos >= track->len) {
             break; /* End of data stream reached */
+        }
 
         atime += GetVLQ(track, &currentPos);
         event = track->data[currentPos++];
 
         /* Handle SysEx seperatly */
-        if (((event>>4) & 0x0F) == MIDI_STATUS_SYSEX)
-        {
-            if (event == 0xFF)
-            {
+        if (((event>>4) & 0x0F) == MIDI_STATUS_SYSEX) {
+            if (event == 0xFF) {
                 type = track->data[currentPos];
                 currentPos++;
-                switch(type)
-                {
+                switch(type) {
                     case 0x2f: /* End of data marker */
                         end = 1;
                     case 0x51: /* Tempo change */
@@ -136,33 +131,28 @@ static MIDIEvent *MIDITracktoStream(MIDITrack *track)
                         */
                         break;
                 }
-            }
-            else
+            } else {
                 type = 0;
+            }
 
             len = GetVLQ(track, &currentPos);
 
             /* Create an event and attach the extra data, if any */
             currentEvent->next = CreateEvent(atime, event, type, 0);
             currentEvent = currentEvent->next;
-            if (NULL == currentEvent)
-            {
+            if (NULL == currentEvent) {
                 FreeMIDIEventList(head);
                 return NULL;
             }
-            if (len)
-            {
+            if (len) {
                 currentEvent->extraLen = len;
                 currentEvent->extraData = SDL_malloc(len);
                 SDL_memcpy(currentEvent->extraData, &(track->data[currentPos]), len);
                 currentPos += len;
             }
-        }
-        else
-        {
+        } else {
             a = event;
-            if (a & 0x80) /* It's a status byte */
-            {
+            if (a & 0x80) { /* It's a status byte */
                 /* Extract channel and status information */
                 lastchan = a & 0x0F;
                 laststatus = (a>>4) & 0x0F;
@@ -170,8 +160,7 @@ static MIDIEvent *MIDITracktoStream(MIDITrack *track)
                 /* Read the next byte which should always be a data byte */
                 a = track->data[currentPos++] & 0x7F;
             }
-            switch(laststatus)
-            {
+            switch(laststatus) {
                 case MIDI_STATUS_NOTE_OFF:
                 case MIDI_STATUS_NOTE_ON: /* Note on */
                 case MIDI_STATUS_AFTERTOUCH: /* Key Pressure */
@@ -180,8 +169,7 @@ static MIDIEvent *MIDITracktoStream(MIDITrack *track)
                     b = track->data[currentPos++] & 0x7F;
                     currentEvent->next = CreateEvent(atime, (Uint8)((laststatus<<4)+lastchan), a, b);
                     currentEvent = currentEvent->next;
-                    if (NULL == currentEvent)
-                    {
+                    if (NULL == currentEvent) {
                         FreeMIDIEventList(head);
                         return NULL;
                     }
@@ -192,8 +180,7 @@ static MIDIEvent *MIDITracktoStream(MIDITrack *track)
                     a &= 0x7f;
                     currentEvent->next = CreateEvent(atime, (Uint8)((laststatus<<4)+lastchan), a, 0);
                     currentEvent = currentEvent->next;
-                    if (NULL == currentEvent)
-                    {
+                    if (NULL == currentEvent) {
                         FreeMIDIEventList(head);
                         return NULL;
                     }
@@ -222,47 +209,45 @@ static MIDIEvent *MIDItoStream(MIDIFile *mididata)
     MIDIEvent *currentEvent = head;
     int trackID;
 
-    if (NULL == head)
+    if (NULL == head) {
         return NULL;
+    }
 
     track = (MIDIEvent**) SDL_calloc(1, sizeof(MIDIEvent*) * mididata->nTracks);
-    if (NULL == track)
-    {
+    if (NULL == track) {
         SDL_free(head);
         return NULL;
     }
 
     /* First, convert all tracks to MIDIEvent lists */
-    for (trackID = 0; trackID < mididata->nTracks; trackID++)
+    for (trackID = 0; trackID < mididata->nTracks; trackID++) {
         track[trackID] = MIDITracktoStream(&mididata->track[trackID]);
+    }
 
     /* Now, merge the lists. */
     /* TODO */
-    while(1)
-    {
+    while (1) {
         Uint32 lowestTime = 0x7FFFFFFF; /* INT_MAX */
         int currentTrackID = -1;
 
         /* Find the next event */
-        for (trackID = 0; trackID < mididata->nTracks; trackID++)
-        {
-            if (track[trackID] && (track[trackID]->time < lowestTime))
-            {
+        for (trackID = 0; trackID < mididata->nTracks; trackID++) {
+            if (track[trackID] && (track[trackID]->time < lowestTime)) {
                 currentTrackID = trackID;
                 lowestTime = track[currentTrackID]->time;
             }
         }
 
         /* Check if we processes all events */
-        if (currentTrackID == -1)
+        if (currentTrackID == -1) {
             break;
+        }
 
         currentEvent->next = track[currentTrackID];
         track[currentTrackID] = track[currentTrackID]->next;
 
         currentEvent = currentEvent->next;
 
-
         lowestTime = 0;
     }
 
@@ -278,16 +263,18 @@ static MIDIEvent *MIDItoStream(MIDIFile *mididata)
 static int ReadMIDIFile(MIDIFile *mididata, SDL_RWops *src)
 {
     int i = 0;
-    Uint32  ID = 0;
-    Uint32  size = 0;
-    Uint16  format = 0;
-    Uint16  tracks = 0;
-    Uint16  division = 0;
+    Uint32 ID = 0;
+    Uint32 size = 0;
+    Uint16 format = 0;
+    Uint16 tracks = 0;
+    Uint16 division = 0;
 
-    if (!mididata)
+    if (!mididata) {
         return 0;
-    if (!src)
+    }
+    if (!src) {
         return 0;
+    }
 
     /* Make sure this is really a MIDI file */
     if (SDL_RWread(src, &ID, 4) != 4) {
@@ -299,24 +286,27 @@ static int ReadMIDIFile(MIDIFile *mididata, SDL_RWops *src)
             return 0;
         }
     }
-    if (BE_LONG(ID) != MIDI_MAGIC)
+    if (BE_LONG(ID) != MIDI_MAGIC) {
         return 0;
+    }
 
     /* Header size must be 6 */
     if (SDL_RWread(src, &size, 4) != 4) {
         return 0;
     }
     size = BE_LONG(size);
-    if (size != 6)
+    if (size != 6) {
         return 0;
+    }
 
     /* We only support format 0 and 1, but not 2 */
     if (SDL_RWread(src, &format, 2) != 2) {
         return 0;
     }
     format = BE_SHORT(format);
-    if (format != 0 && format != 1)
+    if (format != 0 && format != 1) {
         return 0;
+    }
 
     if (SDL_RWread(src, &tracks, 2) != 2) {
         return 0;
@@ -326,8 +316,7 @@ static int ReadMIDIFile(MIDIFile *mididata, SDL_RWops *src)
 
     /* Allocate tracks */
     mididata->track = (MIDITrack*) SDL_calloc(1, sizeof(MIDITrack) * mididata->nTracks);
-    if (NULL == mididata->track)
-    {
+    if (NULL == mididata->track) {
         Mix_OutOfMemory();
         goto bail;
     }
@@ -338,9 +327,7 @@ static int ReadMIDIFile(MIDIFile *mididata, SDL_RWops *src)
     }
     mididata->division = BE_SHORT(division);
 
-
-    for (i=0; i<tracks; i++)
-    {
+    for (i = 0; i < tracks; i++) {
         if (SDL_RWread(src, &ID, 4) != 4) {  /* We might want to verify this is MTrk... */
             goto bail;
         }
@@ -350,8 +337,7 @@ static int ReadMIDIFile(MIDIFile *mididata, SDL_RWops *src)
         size = BE_LONG(size);
         mididata->track[i].len = size;
         mididata->track[i].data = SDL_malloc(size);
-        if (NULL == mididata->track[i].data)
-        {
+        if (NULL == mididata->track[i].data) {
             Mix_OutOfMemory();
             goto bail;
         }
@@ -362,10 +348,10 @@ static int ReadMIDIFile(MIDIFile *mididata, SDL_RWops *src)
     return 1;
 
 bail:
-    for(;i >= 0; i--)
-    {
-        if (mididata->track[i].data)
+    for (; i >= 0; i--) {
+        if (mididata->track[i].data) {
             SDL_free(mididata->track[i].data);
+        }
     }
 
     SDL_free(mididata->track);
@@ -379,38 +365,35 @@ MIDIEvent *CreateMIDIEventList(SDL_RWops *src, Uint16 *division)
     int trackID;
 
     mididata = SDL_calloc(1, sizeof(MIDIFile));
-    if (!mididata)
+    if (!mididata) {
         return NULL;
+    }
 
     /* Open the file */
-    if ( src != NULL )
-    {
+    if (src != NULL) {
         /* Read in the data */
-        if ( ! ReadMIDIFile(mididata, src))
-        {
+        if (!ReadMIDIFile(mididata, src)) {
             SDL_free(mididata);
             return NULL;
         }
-    }
-    else
-    {
+    } else {
         SDL_free(mididata);
         return NULL;
     }
 
-    if (division)
+    if (division) {
         *division = mididata->division;
+    }
 
     eventList = MIDItoStream(mididata);
-    if (eventList == NULL)
-    {
+    if (eventList == NULL) {
         SDL_free(mididata)

(Patch may be truncated, please check the link at the top of this post.)