music_nativemidi.c
author Sam Lantinga <slouken@libsdl.org>
Tue, 17 Oct 2017 22:29:19 -0700
changeset 784 5cb894f15335
parent 777 92882ef2ab81
child 797 b4b6adff699a
permissions -rw-r--r--
Fixed bug 2909 - Mix_PauseMusic and Mix_ResumeMusic not working on MIDI (.mid)

Philipp Wiesemann

This is a patch to make Mix_PauseMusic() and Mix_ResumeMusic() work with the Windows native MIDI decoder.
     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_Pause(void *context)
    57 {
    58     native_midi_pause();
    59 }
    60 
    61 static void NATIVEMIDI_Resume(void *context)
    62 {
    63     native_midi_resume();
    64 }
    65 
    66 static void NATIVEMIDI_Stop(void *context)
    67 {
    68     native_midi_stop();
    69 }
    70 
    71 static void NATIVEMIDI_Delete(void *context)
    72 {
    73     NativeMidiSong *music = (NativeMidiSong *)context;
    74     native_midi_freesong(music);
    75 }
    76 
    77 Mix_MusicInterface Mix_MusicInterface_NATIVEMIDI =
    78 {
    79     "NATIVEMIDI",
    80     MIX_MUSIC_NATIVEMIDI,
    81     MUS_MID,
    82     SDL_FALSE,
    83     SDL_FALSE,
    84 
    85     NULL,   /* Load */
    86     NULL,   /* Open */
    87     NATIVEMIDI_CreateFromRW,
    88     NULL,   /* CreateFromFile */
    89     NATIVEMIDI_SetVolume,
    90     NATIVEMIDI_Play,
    91     NATIVEMIDI_IsPlaying,
    92     NULL,   /* GetAudio */
    93     NULL,   /* Seek */
    94     NATIVEMIDI_Pause,
    95     NATIVEMIDI_Resume,
    96     NATIVEMIDI_Stop,
    97     NATIVEMIDI_Delete,
    98     NULL,   /* Close */
    99     NULL,   /* Unload */
   100 };
   101 
   102 #endif /* MUSIC_MID_NATIVE */
   103 
   104 /* vi: set ts=4 sw=4 expandtab: */