music_nativemidi.c
author Ozkan Sezer <sezeroz@gmail.com>
Wed, 03 Oct 2018 21:55:00 +0300
changeset 863 b81eb791d10d
parent 848 3907db698eb5
child 926 d6c9518fb5ee
permissions -rw-r--r--
readmidi.c (groom_list): avoid integer overflow when recomputing time.

from libtimidity -- see:
https://sourceforge.net/p/libtimidity/libtimidity/ci/11be98a89eac229111420e6a3d521edbfddb0dbc/
slouken@777
     1
/*
slouken@777
     2
  SDL_mixer:  An audio mixer library based on the SDL library
slouken@848
     3
  Copyright (C) 1997-2018 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@797
    39
static int NATIVEMIDI_Play(void *context, int play_count)
slouken@777
    40
{
slouken@777
    41
    NativeMidiSong *music = (NativeMidiSong *)context;
slouken@797
    42
    int loops = play_count;
slouken@797
    43
    if (loops > 0) {
slouken@797
    44
        --loops;
slouken@797
    45
    }
slouken@797
    46
    native_midi_start(music, loops);
slouken@777
    47
    return 0;
slouken@777
    48
}
slouken@777
    49
slouken@777
    50
static void NATIVEMIDI_SetVolume(void *context, int volume)
slouken@777
    51
{
slouken@777
    52
    native_midi_setvolume(volume);
slouken@777
    53
}
slouken@777
    54
slouken@777
    55
static SDL_bool NATIVEMIDI_IsPlaying(void *context)
slouken@777
    56
{
slouken@777
    57
    return native_midi_active() ? SDL_TRUE : SDL_FALSE;
slouken@777
    58
}
slouken@777
    59
slouken@784
    60
static void NATIVEMIDI_Pause(void *context)
slouken@784
    61
{
slouken@784
    62
    native_midi_pause();
slouken@784
    63
}
slouken@784
    64
slouken@784
    65
static void NATIVEMIDI_Resume(void *context)
slouken@784
    66
{
slouken@784
    67
    native_midi_resume();
slouken@784
    68
}
slouken@784
    69
slouken@777
    70
static void NATIVEMIDI_Stop(void *context)
slouken@777
    71
{
slouken@777
    72
    native_midi_stop();
slouken@777
    73
}
slouken@777
    74
slouken@777
    75
static void NATIVEMIDI_Delete(void *context)
slouken@777
    76
{
slouken@777
    77
    NativeMidiSong *music = (NativeMidiSong *)context;
slouken@777
    78
    native_midi_freesong(music);
slouken@777
    79
}
slouken@777
    80
slouken@777
    81
Mix_MusicInterface Mix_MusicInterface_NATIVEMIDI =
slouken@777
    82
{
slouken@777
    83
    "NATIVEMIDI",
slouken@777
    84
    MIX_MUSIC_NATIVEMIDI,
slouken@777
    85
    MUS_MID,
slouken@777
    86
    SDL_FALSE,
slouken@777
    87
    SDL_FALSE,
slouken@777
    88
slouken@777
    89
    NULL,   /* Load */
slouken@777
    90
    NULL,   /* Open */
slouken@777
    91
    NATIVEMIDI_CreateFromRW,
slouken@777
    92
    NULL,   /* CreateFromFile */
slouken@777
    93
    NATIVEMIDI_SetVolume,
slouken@777
    94
    NATIVEMIDI_Play,
slouken@777
    95
    NATIVEMIDI_IsPlaying,
slouken@777
    96
    NULL,   /* GetAudio */
slouken@777
    97
    NULL,   /* Seek */
slouken@784
    98
    NATIVEMIDI_Pause,
slouken@784
    99
    NATIVEMIDI_Resume,
slouken@777
   100
    NATIVEMIDI_Stop,
slouken@777
   101
    NATIVEMIDI_Delete,
slouken@777
   102
    NULL,   /* Close */
slouken@777
   103
    NULL,   /* Unload */
slouken@777
   104
};
slouken@777
   105
slouken@777
   106
#endif /* MUSIC_MID_NATIVE */
slouken@777
   107
slouken@777
   108
/* vi: set ts=4 sw=4 expandtab: */