music_nativemidi.c
changeset 777 92882ef2ab81
child 784 5cb894f15335
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/music_nativemidi.c	Tue Oct 17 02:33:47 2017 -0700
     1.3 @@ -0,0 +1,94 @@
     1.4 +/*
     1.5 +  SDL_mixer:  An audio mixer library based on the SDL library
     1.6 +  Copyright (C) 1997-2017 Sam Lantinga <slouken@libsdl.org>
     1.7 +
     1.8 +  This software is provided 'as-is', without any express or implied
     1.9 +  warranty.  In no event will the authors be held liable for any damages
    1.10 +  arising from the use of this software.
    1.11 +
    1.12 +  Permission is granted to anyone to use this software for any purpose,
    1.13 +  including commercial applications, and to alter it and redistribute it
    1.14 +  freely, subject to the following restrictions:
    1.15 +
    1.16 +  1. The origin of this software must not be misrepresented; you must not
    1.17 +     claim that you wrote the original software. If you use this software
    1.18 +     in a product, an acknowledgment in the product documentation would be
    1.19 +     appreciated but is not required.
    1.20 +  2. Altered source versions must be plainly marked as such, and must not be
    1.21 +     misrepresented as being the original software.
    1.22 +  3. This notice may not be removed or altered from any source distribution.
    1.23 +*/
    1.24 +
    1.25 +#ifdef MUSIC_MID_NATIVE
    1.26 +
    1.27 +/* This file supports playing MIDI files with OS APIs */
    1.28 +
    1.29 +#include "music_nativemidi.h"
    1.30 +#include "native_midi/native_midi.h"
    1.31 +
    1.32 +
    1.33 +static void *NATIVEMIDI_CreateFromRW(SDL_RWops *src, int freesrc)
    1.34 +{
    1.35 +    NativeMidiSong *music = native_midi_loadsong_RW(src, freesrc);
    1.36 +    if (!music) {
    1.37 +        Mix_SetError("%s", native_midi_error());
    1.38 +    }
    1.39 +    return music;
    1.40 +}
    1.41 +
    1.42 +static int NATIVEMIDI_Play(void *context)
    1.43 +{
    1.44 +    NativeMidiSong *music = (NativeMidiSong *)context;
    1.45 +    native_midi_start(music, music_loops);
    1.46 +    return 0;
    1.47 +}
    1.48 +
    1.49 +static void NATIVEMIDI_SetVolume(void *context, int volume)
    1.50 +{
    1.51 +    native_midi_setvolume(volume);
    1.52 +}
    1.53 +
    1.54 +static SDL_bool NATIVEMIDI_IsPlaying(void *context)
    1.55 +{
    1.56 +    return native_midi_active() ? SDL_TRUE : SDL_FALSE;
    1.57 +}
    1.58 +
    1.59 +static void NATIVEMIDI_Stop(void *context)
    1.60 +{
    1.61 +    native_midi_stop();
    1.62 +}
    1.63 +
    1.64 +static void NATIVEMIDI_Delete(void *context)
    1.65 +{
    1.66 +    NativeMidiSong *music = (NativeMidiSong *)context;
    1.67 +    native_midi_freesong(music);
    1.68 +}
    1.69 +
    1.70 +Mix_MusicInterface Mix_MusicInterface_NATIVEMIDI =
    1.71 +{
    1.72 +    "NATIVEMIDI",
    1.73 +    MIX_MUSIC_NATIVEMIDI,
    1.74 +    MUS_MID,
    1.75 +    SDL_FALSE,
    1.76 +    SDL_FALSE,
    1.77 +
    1.78 +    NULL,   /* Load */
    1.79 +    NULL,   /* Open */
    1.80 +    NATIVEMIDI_CreateFromRW,
    1.81 +    NULL,   /* CreateFromFile */
    1.82 +    NATIVEMIDI_SetVolume,
    1.83 +    NATIVEMIDI_Play,
    1.84 +    NATIVEMIDI_IsPlaying,
    1.85 +    NULL,   /* GetAudio */
    1.86 +    NULL,   /* Seek */
    1.87 +    NULL,   /* Pause */
    1.88 +    NULL,   /* Resume */
    1.89 +    NATIVEMIDI_Stop,
    1.90 +    NATIVEMIDI_Delete,
    1.91 +    NULL,   /* Close */
    1.92 +    NULL,   /* Unload */
    1.93 +};
    1.94 +
    1.95 +#endif /* MUSIC_MID_NATIVE */
    1.96 +
    1.97 +/* vi: set ts=4 sw=4 expandtab: */