Skip to content

Commit 2cad0d1

Browse files
committed
Add midi decoder option
1 parent acafc68 commit 2cad0d1

File tree

5 files changed

+72
-17
lines changed

5 files changed

+72
-17
lines changed

Diff for: src/GameSrc/wrapper.c

+21
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
5555
#include "player.h"
5656
#include "popups.h"
5757
#include "olhext.h"
58+
#include "Xmi.h"
5859
#include "Prefs.h"
5960

6061
#include "OpenGL.h"
@@ -361,11 +362,19 @@ uchar fv;
361362
#define REF_STR_Software 0x10000001
362363
#define REF_STR_OpenGL 0x10000002
363364

365+
#define REF_STR_Seqer 0x20000000
366+
#define REF_STR_ADLMIDI 0x20000001
367+
#define REF_STR_FluidSyn 0x20000002
368+
364369
static char *_get_temp_string(int num) {
365370
switch (num) {
366371
case REF_STR_Renderer: return "Renderer";
367372
case REF_STR_Software: return "Software";
368373
case REF_STR_OpenGL: return "OpenGL";
374+
375+
case REF_STR_Seqer: return "Midi Player";
376+
case REF_STR_ADLMIDI: return "ADLMIDI";
377+
case REF_STR_FluidSyn: return "FluidSynth";
369378
default: return get_temp_string(num);
370379
}
371380
}
@@ -1402,6 +1411,10 @@ void digichan_dealfunc(short val) {
14021411
// snd_set_digital_channels(cur_digi_channels);
14031412
}
14041413

1414+
static void seqer_dealfunc(bool use_sequencer) {
1415+
ReloadDecXMI(); // Reload Midi decoder
1416+
}
1417+
14051418
#pragma enable_message(202)
14061419

14071420
#define SLIDER_OFFSET_3 0
@@ -1432,6 +1445,14 @@ void soundopt_screen_init() {
14321445
i++;
14331446
#endif
14341447

1448+
#ifdef USE_FLUIDSYNTH
1449+
standard_button_rect(&r, i, 2, 2, 5);
1450+
multi_init(i, 'p', REF_STR_Seqer, REF_STR_ADLMIDI, ID_NULL,
1451+
sizeof(gShockPrefs.soMidiBackend), &gShockPrefs.soMidiBackend, 2, seqer_dealfunc, &r);
1452+
1453+
i++;
1454+
#endif
1455+
14351456
standard_button_rect(&r, 5, 2, 2, 5);
14361457
retkey = tolower(get_temp_string(REF_STR_MusicText + 2)[0]);
14371458
pushbutton_init(RETURN_BUTTON, retkey, REF_STR_MusicText + 2, wrapper_pushbutton_func, &r);

Diff for: src/MacSrc/Prefs.c

+1
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ void SetDefaultPrefs(void) {
9191
gShockPrefs.prefPlayIntro = 1; // First time through, play the intro
9292
gShockPrefs.goPopupLabels = true;
9393
gShockPrefs.soBackMusic = true;
94+
gShockPrefs.soMidiBackend = true; // Use fluidsynth by default.
9495
gShockPrefs.soSoundFX = true;
9596
gShockPrefs.doUseQD = false;
9697

Diff for: src/MacSrc/Prefs.h

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ typedef struct {
4646
short soMusicVolume;
4747
short soSfxVolume;
4848
short soAudioLogVolume;
49+
Boolean soMidiBackend;
4950

5051
// Display Options
5152
short doVideoMode;

Diff for: src/MacSrc/Xmi.c

+47-17
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include "Xmi.h"
44
#include "MusicDevice.h"
5+
#include "Prefs.h"
56

67

78

@@ -605,19 +606,47 @@ void InitReadXMI(void)
605606
int channel, i;
606607
SDL_Thread *thread;
607608

608-
// Start the ADL Midi device
609+
InitDecXMI();
610+
611+
MyMutex = SDL_CreateMutex();
612+
613+
for (channel=0; channel<16; channel++) ChannelThread[channel] = -1;
614+
615+
for (i=0; i<NUM_THREADS; i++)
616+
{
617+
SDL_AtomicSet(&ThreadPlaying[i], 0);
618+
SDL_AtomicSet(&ThreadCommand[i], THREAD_INIT);
619+
}
620+
621+
thread = SDL_CreateThread(MyThread, "MyThread", NULL);
622+
SDL_DetachThread(thread); //thread will go away on its own upon completion
623+
624+
i = 0;
625+
while (SDL_AtomicGet(&ThreadCommand[i]) == THREAD_INIT) SDL_Delay(1);
626+
627+
atexit(ShutdownReadXMI);
628+
}
629+
630+
631+
632+
void InitDecXMI(void)
633+
{
634+
// Start the Midi device
609635
MusicDevice *musicdev = NULL;
610636
int musicrate = 48000;
611637

612638
#ifdef USE_FLUIDSYNTH
613639
if (!musicdev)
614640
{
615-
INFO("try FluidSynth MIDI driver");
616-
musicdev = CreateMusicDevice(Music_FluidSynth);
617-
if (musicdev && musicdev->init(musicdev, musicrate) != 0)
641+
if(gShockPrefs.soMidiBackend)
618642
{
619-
musicdev->destroy(musicdev);
620-
musicdev = NULL;
643+
INFO("try FluidSynth MIDI driver");
644+
musicdev = CreateMusicDevice(Music_FluidSynth);
645+
if (musicdev && musicdev->init(musicdev, musicrate) != 0)
646+
{
647+
musicdev->destroy(musicdev);
648+
musicdev = NULL;
649+
}
621650
}
622651
}
623652
#endif
@@ -641,24 +670,25 @@ void InitReadXMI(void)
641670
}
642671

643672
MusicDev = musicdev;
673+
}
644674

645-
MyMutex = SDL_CreateMutex();
646675

647-
for (channel=0; channel<16; channel++) ChannelThread[channel] = -1;
676+
677+
void ReloadDecXMI(void)
678+
{
679+
int i;
680+
681+
SDL_LockMutex(MyMutex);
682+
MusicDev->destroy(MusicDev);
683+
MusicDev = NULL;
684+
SDL_UnlockMutex(MyMutex);
648685

649686
for (i=0; i<NUM_THREADS; i++)
650687
{
651-
SDL_AtomicSet(&ThreadPlaying[i], 0);
652-
SDL_AtomicSet(&ThreadCommand[i], THREAD_INIT);
688+
StopTrack(i);
653689
}
654690

655-
thread = SDL_CreateThread(MyThread, "MyThread", NULL);
656-
SDL_DetachThread(thread); //thread will go away on its own upon completion
657-
658-
i = 0;
659-
while (SDL_AtomicGet(&ThreadCommand[i]) == THREAD_INIT) SDL_Delay(1);
660-
661-
atexit(ShutdownReadXMI);
691+
InitDecXMI();
662692
}
663693

664694

Diff for: src/MacSrc/Xmi.h

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ void StopTrack(int i);
2020
void StopTheMusic(void);
2121
int IsPlaying(int i);
2222
void InitReadXMI(void);
23+
void InitDecXMI(void);
24+
void ReloadDecXMI(void);
2325
void ShutdownReadXMI(void);
2426

2527
struct midi_event_struct

0 commit comments

Comments
 (0)