music_nativemidi.c
author Sam Lantinga <slouken@libsdl.org>
Tue, 17 Oct 2017 02:33:47 -0700
changeset 777 92882ef2ab81
child 784 5cb894f15335
permissions -rw-r--r--
Rewrote music.c to support any number of decode libraries using a compiled-in plugin interface
Mix_LoadWAV_RW() can now load sound formats that were previously available only as music.

This is still work in progress. Testing and project updates need to happen on other platforms.
slouken@777
     1
/*
slouken@777
     2
  SDL_mixer:  An audio mixer library based on the SDL library
slouken@777
     3
  Copyright (C) 1997-2017 Sam Lantinga <slouken@libsdl.org>
slouken@777
     4
slouken@777
     5
  This software is provided 'as-is', without any express or implied
slouken@777
     6
  warranty.  In no event will the authors be held liable for any damages
slouken@777
     7
  arising from the use of this software.
slouken@777
     8
slouken@777
     9
  Permission is granted to anyone to use this software for any purpose,
slouken@777
    10
  including commercial applications, and to alter it and redistribute it
slouken@777
    11
  freely, subject to the following restrictions:
slouken@777
    12
slouken@777
    13
  1. The origin of this software must not be misrepresented; you must not
slouken@777
    14
     claim that you wrote the original software. If you use this software
slouken@777
    15
     in a product, an acknowledgment in the product documentation would be
slouken@777
    16
     appreciated but is not required.
slouken@777
    17
  2. Altered source versions must be plainly marked as such, and must not be
slouken@777
    18
     misrepresented as being the original software.
slouken@777
    19
  3. This notice may not be removed or altered from any source distribution.
slouken@777
    20
*/
slouken@777
    21
slouken@777
    22
#ifdef MUSIC_MID_NATIVE
slouken@777
    23
slouken@777
    24
/* This file supports playing MIDI files with OS APIs */
slouken@777
    25
slouken@777
    26
#include "music_nativemidi.h"
slouken@777
    27
#include "native_midi/native_midi.h"
slouken@777
    28
slouken@777
    29
slouken@777
    30
static void *NATIVEMIDI_CreateFromRW(SDL_RWops *src, int freesrc)
slouken@777
    31
{
slouken@777
    32
    NativeMidiSong *music = native_midi_loadsong_RW(src, freesrc);
slouken@777
    33
    if (!music) {
slouken@777
    34
        Mix_SetError("%s", native_midi_error());
slouken@777
    35
    }
slouken@777
    36
    return music;
slouken@777
    37
}
slouken@777
    38
slouken@777
    39
static int NATIVEMIDI_Play(void *context)
slouken@777
    40
{
slouken@777
    41
    NativeMidiSong *music = (NativeMidiSong *)context;
slouken@777
    42
    native_midi_start(music, music_loops);
slouken@777
    43
    return 0;
slouken@777
    44
}
slouken@777
    45
slouken@777
    46
static void NATIVEMIDI_SetVolume(void *context, int volume)
slouken@777
    47
{
slouken@777
    48
    native_midi_setvolume(volume);
slouken@777
    49
}
slouken@777
    50
slouken@777
    51
static SDL_bool NATIVEMIDI_IsPlaying(void *context)
slouken@777
    52
{
slouken@777
    53
    return native_midi_active() ? SDL_TRUE : SDL_FALSE;
slouken@777
    54
}
slouken@777
    55
slouken@777
    56
static void NATIVEMIDI_Stop(void *context)
slouken@777
    57
{
slouken@777
    58
    native_midi_stop();
slouken@777
    59
}
slouken@777
    60
slouken@777
    61
static void NATIVEMIDI_Delete(void *context)
slouken@777
    62
{
slouken@777
    63
    NativeMidiSong *music = (NativeMidiSong *)context;
slouken@777
    64
    native_midi_freesong(music);
slouken@777
    65
}
slouken@777
    66
slouken@777
    67
Mix_MusicInterface Mix_MusicInterface_NATIVEMIDI =
slouken@777
    68
{
slouken@777
    69
    "NATIVEMIDI",
slouken@777
    70
    MIX_MUSIC_NATIVEMIDI,
slouken@777
    71
    MUS_MID,
slouken@777
    72
    SDL_FALSE,
slouken@777
    73
    SDL_FALSE,
slouken@777
    74
slouken@777
    75
    NULL,   /* Load */
slouken@777
    76
    NULL,   /* Open */
slouken@777
    77
    NATIVEMIDI_CreateFromRW,
slouken@777
    78
    NULL,   /* CreateFromFile */
slouken@777
    79
    NATIVEMIDI_SetVolume,
slouken@777
    80
    NATIVEMIDI_Play,
slouken@777
    81
    NATIVEMIDI_IsPlaying,
slouken@777
    82
    NULL,   /* GetAudio */
slouken@777
    83
    NULL,   /* Seek */
slouken@777
    84
    NULL,   /* Pause */
slouken@777
    85
    NULL,   /* Resume */
slouken@777
    86
    NATIVEMIDI_Stop,
slouken@777
    87
    NATIVEMIDI_Delete,
slouken@777
    88
    NULL,   /* Close */
slouken@777
    89
    NULL,   /* Unload */
slouken@777
    90
};
slouken@777
    91
slouken@777
    92
#endif /* MUSIC_MID_NATIVE */
slouken@777
    93
slouken@777
    94
/* vi: set ts=4 sw=4 expandtab: */