music_nativemidi.c
author Sam Lantinga <slouken@libsdl.org>
Thu, 01 Mar 2018 09:34:14 -0800
changeset 848 3907db698eb5
parent 797 b4b6adff699a
child 926 d6c9518fb5ee
permissions -rw-r--r--
Updated copyright for 2018
     1 /*
     2   SDL_mixer:  An audio mixer library based on the SDL library
     3   Copyright (C) 1997-2018 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, int play_count)
    40 {
    41     NativeMidiSong *music = (NativeMidiSong *)context;
    42     int loops = play_count;
    43     if (loops > 0) {
    44         --loops;
    45     }
    46     native_midi_start(music, loops);
    47     return 0;
    48 }
    49 
    50 static void NATIVEMIDI_SetVolume(void *context, int volume)
    51 {
    52     native_midi_setvolume(volume);
    53 }
    54 
    55 static SDL_bool NATIVEMIDI_IsPlaying(void *context)
    56 {
    57     return native_midi_active() ? SDL_TRUE : SDL_FALSE;
    58 }
    59 
    60 static void NATIVEMIDI_Pause(void *context)
    61 {
    62     native_midi_pause();
    63 }
    64 
    65 static void NATIVEMIDI_Resume(void *context)
    66 {
    67     native_midi_resume();
    68 }
    69 
    70 static void NATIVEMIDI_Stop(void *context)
    71 {
    72     native_midi_stop();
    73 }
    74 
    75 static void NATIVEMIDI_Delete(void *context)
    76 {
    77     NativeMidiSong *music = (NativeMidiSong *)context;
    78     native_midi_freesong(music);
    79 }
    80 
    81 Mix_MusicInterface Mix_MusicInterface_NATIVEMIDI =
    82 {
    83     "NATIVEMIDI",
    84     MIX_MUSIC_NATIVEMIDI,
    85     MUS_MID,
    86     SDL_FALSE,
    87     SDL_FALSE,
    88 
    89     NULL,   /* Load */
    90     NULL,   /* Open */
    91     NATIVEMIDI_CreateFromRW,
    92     NULL,   /* CreateFromFile */
    93     NATIVEMIDI_SetVolume,
    94     NATIVEMIDI_Play,
    95     NATIVEMIDI_IsPlaying,
    96     NULL,   /* GetAudio */
    97     NULL,   /* Seek */
    98     NATIVEMIDI_Pause,
    99     NATIVEMIDI_Resume,
   100     NATIVEMIDI_Stop,
   101     NATIVEMIDI_Delete,
   102     NULL,   /* Close */
   103     NULL,   /* Unload */
   104 };
   105 
   106 #endif /* MUSIC_MID_NATIVE */
   107 
   108 /* vi: set ts=4 sw=4 expandtab: */