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