From 8312f460ac59f9f5aad587c229c11c2f72b06038 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Wed, 9 Oct 2024 11:17:18 -0700
Subject: [PATCH] Use bool as appropriate for native MIDI code
---
src/codecs/music_nativemidi.c | 2 +-
src/codecs/native_midi/native_midi.h | 4 +--
src/codecs/native_midi/native_midi_haiku.cpp | 6 ++---
src/codecs/native_midi/native_midi_macosx.c | 14 +++++------
src/codecs/native_midi/native_midi_win32.c | 26 ++++++++++----------
5 files changed, 26 insertions(+), 26 deletions(-)
diff --git a/src/codecs/music_nativemidi.c b/src/codecs/music_nativemidi.c
index 2ddd0d5db..4ff0cbf92 100644
--- a/src/codecs/music_nativemidi.c
+++ b/src/codecs/music_nativemidi.c
@@ -56,7 +56,7 @@ static void NATIVEMIDI_SetVolume(void *context, int volume)
static bool NATIVEMIDI_IsPlaying(void *context)
{
(void)context;
- return native_midi_active() ? true : false;
+ return native_midi_active();
}
static void NATIVEMIDI_Pause(void *context)
diff --git a/src/codecs/native_midi/native_midi.h b/src/codecs/native_midi/native_midi.h
index 86ccd7f63..1981eca78 100644
--- a/src/codecs/native_midi/native_midi.h
+++ b/src/codecs/native_midi/native_midi.h
@@ -26,14 +26,14 @@
typedef struct _NativeMidiSong NativeMidiSong;
-int native_midi_detect(void);
+bool native_midi_detect(void);
NativeMidiSong *native_midi_loadsong_IO(SDL_IOStream *src, bool closeio);
void native_midi_freesong(NativeMidiSong *song);
void native_midi_start(NativeMidiSong *song, int loops);
void native_midi_pause(void);
void native_midi_resume(void);
void native_midi_stop(void);
-int native_midi_active(void);
+bool native_midi_active(void);
void native_midi_setvolume(int volume);
const char *native_midi_error(void);
diff --git a/src/codecs/native_midi/native_midi_haiku.cpp b/src/codecs/native_midi/native_midi_haiku.cpp
index 8ad2b55a8..ad21cae4e 100644
--- a/src/codecs/native_midi/native_midi_haiku.cpp
+++ b/src/codecs/native_midi/native_midi_haiku.cpp
@@ -206,7 +206,7 @@ struct _NativeMidiSong {
char lasterr[1024];
-int native_midi_detect(void)
+bool native_midi_detect(void)
{
status_t res = synth.EnableInput(true, false);
return res == B_OK;
@@ -281,9 +281,9 @@ void native_midi_stop(void)
currentSong = NULL;
}
-int native_midi_active(void)
+bool native_midi_active(void)
{
- if (currentSong == NULL) return 0;
+ if (currentSong == NULL) return false;
return currentSong->store->IsPlaying();
}
diff --git a/src/codecs/native_midi/native_midi_macosx.c b/src/codecs/native_midi/native_midi_macosx.c
index d5dd43f91..f0f2ef185 100644
--- a/src/codecs/native_midi/native_midi_macosx.c
+++ b/src/codecs/native_midi/native_midi_macosx.c
@@ -191,9 +191,9 @@ SetSequenceSoundFont(MusicSequence sequence)
return;
}
-int native_midi_detect(void)
+bool native_midi_detect(void)
{
- return 1; /* always available. */
+ return true; /* always available. */
}
NativeMidiSong *native_midi_loadsong_IO(SDL_IOStream *src, bool closeio)
@@ -319,22 +319,22 @@ void native_midi_stop(void)
}
}
-int native_midi_active(void)
+bool native_midi_active(void)
{
MusicTimeStamp currentTime = 0;
if (currentsong == NULL)
- return 0;
+ return false;
MusicPlayerGetTime(currentsong->player, ¤tTime);
if ((currentTime < currentsong->endTime) ||
(currentTime >= kMusicTimeStamp_EndOfTrack)) {
- return 1;
+ return true;
} else if (currentsong->loops) {
--currentsong->loops;
MusicPlayerSetTime(currentsong->player, 0);
- return 1;
+ return true;
}
- return 0;
+ return false;
}
void native_midi_setvolume(int volume)
diff --git a/src/codecs/native_midi/native_midi_win32.c b/src/codecs/native_midi/native_midi_win32.c
index 6cfbd955a..af6a62422 100644
--- a/src/codecs/native_midi/native_midi_win32.c
+++ b/src/codecs/native_midi/native_midi_win32.c
@@ -32,8 +32,8 @@
#include "native_midi_common.h"
struct _NativeMidiSong {
- int MusicLoaded;
- int MusicPlaying;
+ bool MusicLoaded;
+ bool MusicPlaying;
int Loops;
int CurrentHdr;
MIDIHDR MidiStreamHdr[2];
@@ -159,7 +159,7 @@ static void MIDItoStream(NativeMidiSong *song, MIDIEvent *evntlist)
}
}
song->NewPos=0;
- song->MusicLoaded=1;
+ song->MusicLoaded = true;
}
void CALLBACK MidiProc( HMIDIIN hMidi, UINT uMsg, DWORD_PTR dwInstance,
@@ -188,12 +188,12 @@ void CALLBACK MidiProc( HMIDIIN hMidi, UINT uMsg, DWORD_PTR dwInstance,
song->NewPos=0;
BlockOut(song);
} else {
- song->MusicPlaying=0;
+ song->MusicPlaying = false;
}
}
break;
case MOM_CLOSE:
- song->MusicPlaying=0;
+ song->MusicPlaying = false;
break;
default:
break;
@@ -201,16 +201,16 @@ void CALLBACK MidiProc( HMIDIIN hMidi, UINT uMsg, DWORD_PTR dwInstance,
SDL_UnlockMutex(song->mutex);
}
-int native_midi_detect(void)
+bool native_midi_detect(void)
{
MMRESULT merr;
HMIDISTRM MidiStream;
merr=midiStreamOpen(&MidiStream,&MidiDevice,(DWORD)1,(DWORD_PTR)MidiProc,(DWORD_PTR)0,CALLBACK_FUNCTION);
- if (merr!=MMSYSERR_NOERROR)
- return 0;
+ if (merr != MMSYSERR_NOERROR)
+ return false;
midiStreamClose(MidiStream);
- return 1;
+ return true;
}
NativeMidiSong *native_midi_loadsong_IO(SDL_IOStream *src, bool closeio)
@@ -272,7 +272,7 @@ void native_midi_start(NativeMidiSong *song, int loops)
/* midiStreamStop(hMidiStream); */
currentsong=song;
currentsong->NewPos=0;
- currentsong->MusicPlaying=1;
+ currentsong->MusicPlaying = true;
currentsong->Loops=loops;
mptd.cbStruct=sizeof(MIDIPROPTIMEDIV);
mptd.dwTimeDiv=currentsong->ppqn;
@@ -311,12 +311,12 @@ void native_midi_stop(void)
SDL_UnlockMutex(song->mutex);
}
-int native_midi_active(void)
+bool native_midi_active(void)
{
if (!hMidiStream)
- return 0;
+ return false;
if (!currentsong)
- return 0;
+ return false;
return currentsong->MusicPlaying;
}