singe/src/midi.h

56 lines
2 KiB
C

/*
*
* Singe 3
* Copyright (C) 2006-2026 Scott Duensing <scott@kangaroopunch.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 3
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*
*/
#ifndef MIDI_H
#define MIDI_H
#include <stdint.h>
#include <stdbool.h>
#include "decode.h"
// Playing a MIDI file means synthesising it, and synthesising it means a sound bank. Singe ships
// none: a good one is tens of megabytes and would be carried by every platform for a format almost
// no game uses. Point --soundfont at a .sf2, or put one where midiInit looks, and MIDI plays.
// Finds and loads the sound bank. Called once at start up; quiet when there is none to find.
void midiInit(const char *wanted);
// Whether the bytes begin a standard MIDI file. True regardless of whether a bank is loaded, so
// the caller can tell "this is a MIDI" from "this will not play".
bool midiIs(const void *bytes, size_t size);
// Renders a whole MIDI file to interleaved float samples. False when there is no sound bank or the
// file will not parse, with the reason in SDL_GetError.
bool midiRender(const void *bytes, size_t size, DecodedAudioT *out);
// Releases the sound bank.
void midiQuit(void);
// The bank in use for the trace header, or a line saying why there is none. Never NULL.
const char *midiSoundfont(void);
#endif // MIDI_H