Skip to content

Commit

Permalink
Florian Schulze - Sun Aug 19 14:55:37 PDT 2001
Browse files Browse the repository at this point in the history
 * Added native MIDI music support on Windows
  • Loading branch information
slouken committed Aug 19, 2001
1 parent 201c752 commit f04d92a
Show file tree
Hide file tree
Showing 4 changed files with 624 additions and 15 deletions.
2 changes: 2 additions & 0 deletions CHANGES
@@ -1,5 +1,7 @@

1.2.1:
Florian Schulze - Sun Aug 19 14:55:37 PDT 2001
* Added native MIDI music support on Windows
Sam Lantinga - Sun Aug 19 02:20:55 PDT 2001
* Added Project Builder projects for building MacOS X framework
Darrell Walisser - Sun Aug 19 00:47:22 PDT 2001
Expand Down
104 changes: 89 additions & 15 deletions music.c
Expand Up @@ -56,6 +56,9 @@
#endif
#ifdef MID_MUSIC
#include "timidity.h"
#ifdef USE_NATIVE_MIDI
#include "native_midi.h"
#endif
#endif
#ifdef OGG_MUSIC
#include "music_ogg.h"
Expand Down Expand Up @@ -97,6 +100,9 @@ struct _Mix_Music {
#endif
#ifdef MID_MUSIC
MidiSong *midi;
#ifdef USE_NATIVE_MIDI
NativeMidiSong *nativemidi;
#endif
#endif
#ifdef OGG_MUSIC
OGG_music *ogg;
Expand All @@ -113,6 +119,9 @@ struct _Mix_Music {
};
#ifdef MID_MUSIC
static int timidity_ok;
#ifdef USE_NATIVE_MIDI
static int native_midi_ok;
#endif
#endif

/* Used to calculate fading steps */
Expand Down Expand Up @@ -224,7 +233,10 @@ void music_mixer(void *udata, Uint8 *stream, int len)
#endif
#ifdef MID_MUSIC
case MUS_MID:
Timidity_PlaySome(stream, len/samplesize);
if ( timidity_ok ) {
int samples = len / samplesize;
Timidity_PlaySome(stream, samples);
}
break;
#endif
#ifdef OGG_MUSIC
Expand Down Expand Up @@ -312,11 +324,20 @@ int open_music(SDL_AudioSpec *mixer)
}
#endif
#ifdef MID_MUSIC
samplesize = mixer->size/mixer->samples;
if ( Timidity_Init(mixer->freq,
mixer->format, mixer->channels, mixer->samples) == 0 ) {
timidity_ok = 1;
samplesize = mixer->size/mixer->samples;
#ifdef USE_NATIVE_MIDI
if ( native_midi_init() ) {
native_midi_ok = 1;
} else {
native_midi_ok = 0;
}
timidity_ok = !native_midi_ok;
#else
timidity_ok = 1;
#endif
if ( timidity_ok &&
(Timidity_Init(mixer->freq, mixer->format,
mixer->channels, mixer->samples) != 0) ) {
timidity_ok = 0;
}
#endif
Expand Down Expand Up @@ -395,14 +416,22 @@ Mix_Music *Mix_LoadMUS(const char *file)
/* MIDI files have the magic four bytes "MThd" */
if ( strcmp(magic, "MThd") == 0 ) {
music->type = MUS_MID;
#ifdef USE_NATIVE_MIDI
if ( native_midi_ok ) {
music->data.nativemidi = native_midi_loadsong((char *)file);
if ( music->data.nativemidi == NULL ) {
Mix_SetError("%s", native_midi_error());
music->error = 1;
}
} else
#endif
if ( timidity_ok ) {
music->data.midi = Timidity_LoadSong((char *)file);
if ( music->data.midi == NULL ) {
Mix_SetError("%s", Timidity_Error());
music->error = 1;
}
}
else {
} else {
Mix_SetError("%s", Timidity_Error());
music->error = 1;
}
Expand Down Expand Up @@ -484,7 +513,14 @@ void Mix_FreeMusic(Mix_Music *music)
#endif
#ifdef MID_MUSIC
case MUS_MID:
Timidity_FreeSong(music->data.midi);
#ifdef USE_NATIVE_MIDI
if ( native_midi_ok ) {
native_midi_freesong(music->data.nativemidi);
} else
#endif
if ( timidity_ok ) {
Timidity_FreeSong(music->data.midi);
}
break;
#endif
#ifdef OGG_MUSIC
Expand Down Expand Up @@ -532,8 +568,16 @@ static int lowlevel_play(Mix_Music *music)
#endif
#ifdef MID_MUSIC
case MUS_MID:
Timidity_SetVolume(music_volume);
Timidity_Start(music->data.midi);
#ifdef USE_NATIVE_MIDI
if ( native_midi_ok ) {
native_midi_setvolume(music_volume);
native_midi_start(music->data.nativemidi);
} else
#endif
if ( timidity_ok ) {
Timidity_SetVolume(music_volume);
Timidity_Start(music->data.midi);
}
break;
#endif
#ifdef OGG_MUSIC
Expand Down Expand Up @@ -629,7 +673,14 @@ int Mix_VolumeMusic(int volume)
#endif
#ifdef MID_MUSIC
case MUS_MID:
Timidity_SetVolume(music_volume);
#ifdef USE_NATIVE_MIDI
if ( native_midi_ok ) {
native_midi_setvolume(music_volume);
} else
#endif
if ( timidity_ok ) {
Timidity_SetVolume(music_volume);
}
break;
#endif
#ifdef OGG_MUSIC
Expand Down Expand Up @@ -670,7 +721,14 @@ static void lowlevel_halt(void)
#endif
#ifdef MID_MUSIC
case MUS_MID:
Timidity_Stop();
#ifdef USE_NATIVE_MIDI
if ( native_midi_ok ) {
native_midi_stop();
} else
#endif
if ( timidity_ok ) {
Timidity_Stop();
}
break;
#endif
#ifdef OGG_MUSIC
Expand Down Expand Up @@ -761,6 +819,15 @@ void Mix_RewindMusic(void)
case MUS_MP3:
SMPEG_rewind(music_playing->data.mp3);
break;
#endif
#ifdef MID_MUSIC
case MUS_MID:
#ifdef USE_NATIVE_MIDI
if ( native_midi_ok ) {
native_midi_stop();
}
#endif
break;
#endif
default:
/* TODO: Implement this for other music backends */
Expand Down Expand Up @@ -802,8 +869,15 @@ int Mix_PlayingMusic(void)
#endif
#ifdef MID_MUSIC
case MUS_MID:
if ( ! Timidity_Active() ) {
return(0);
#ifdef USE_NATIVE_MIDI
if ( native_midi_ok ) {
if ( ! native_midi_active() )
return(0);
} else
#endif
if ( timidity_ok ) {
if ( ! Timidity_Active() )
return(0);
}
break;
#endif
Expand All @@ -816,7 +890,7 @@ int Mix_PlayingMusic(void)
#endif
#ifdef MP3_MUSIC
case MUS_MP3:
if(SMPEG_status(music_playing->data.mp3)!=SMPEG_PLAYING)
if ( SMPEG_status(music_playing->data.mp3) != SMPEG_PLAYING )
return(0);
break;
#endif
Expand Down
72 changes: 72 additions & 0 deletions native_midi/native_midi.h
@@ -0,0 +1,72 @@
/*
native_midi: Hardware Midi support for the SDL_mixer library
Copyright (C) 2000 Florian 'Proff' Schulze
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Florian 'Proff' Schulze
florian.proff.schulze@gmx.net
*/

#ifndef _NATIVE_MIDI_H_
#define _NATIVE_MIDI_H_

#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <windowsx.h>
#include <mmsystem.h>

#define MIDI_TRACKS 32

typedef unsigned char byte;
typedef struct MIDI /* a midi file */
{
int divisions; /* number of ticks per quarter note */
struct {
unsigned char *data; /* MIDI message stream */
int len; /* length of the track data */
} track[MIDI_TRACKS];
int loaded;
} MIDI;

struct _NativeMidiSong {
MIDI mididata;
int MusicLoaded;
int MusicPlaying;
MIDIEVENT *MidiEvents[MIDI_TRACKS];
MIDIHDR MidiStreamHdr;
MIDIEVENT *NewEvents;
int NewSize;
int NewPos;
int BytesRecorded[MIDI_TRACKS];
int BufferSize[MIDI_TRACKS];
int CurrentTrack;
int CurrentPos;
};
#endif /* WINDOWS */

typedef struct _NativeMidiSong NativeMidiSong;

int native_midi_init();
NativeMidiSong *native_midi_loadsong(char *midifile);
void native_midi_freesong(NativeMidiSong *song);
void native_midi_start(NativeMidiSong *song);
void native_midi_stop();
int native_midi_active();
void native_midi_setvolume(int volume);
char *native_midi_error();

#endif /* _NATIVE_MIDI_H_ */

0 comments on commit f04d92a

Please sign in to comment.