2020-01-02 16:52:30 +00:00
|
|
|
/*
|
2020-09-28 18:23:55 +00:00
|
|
|
* libOPNMIDI is a free Software MIDI synthesizer library with OPN2 (YM2612) emulation
|
2020-01-02 16:52:30 +00:00
|
|
|
*
|
|
|
|
* MIDI parser and player (Original code from ADLMIDI): Copyright (c) 2010-2014 Joel Yliluoma <bisqwit@iki.fi>
|
2023-01-01 22:24:15 +00:00
|
|
|
* ADLMIDI Library API: Copyright (c) 2016-2022 Vitaly Novichkov <admin@wohlnet.ru>
|
2020-01-02 16:52:30 +00:00
|
|
|
*
|
|
|
|
* Library is based on the ADLMIDI, a MIDI player for Linux and Windows with OPL3 emulation:
|
|
|
|
* http://iki.fi/bisqwit/source/adlmidi.html
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* 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, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef OPNMIDI_OPNBANK_H
|
|
|
|
#define OPNMIDI_OPNBANK_H
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
#ifdef ADLMIDI_buildAsApp
|
|
|
|
#include <SDL2/SDL.h>
|
|
|
|
class MutexType
|
|
|
|
{
|
|
|
|
SDL_mutex* mut;
|
|
|
|
public:
|
|
|
|
MutexType() : mut(SDL_CreateMutex()) { }
|
|
|
|
~MutexType() { SDL_DestroyMutex(mut); }
|
|
|
|
void Lock() { SDL_mutexP(mut); }
|
|
|
|
void Unlock() { SDL_mutexV(mut); }
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
enum { opnNoteOnMaxTime = 40000 };
|
|
|
|
|
|
|
|
/* *********** FM Operator indexes *********** */
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
OPERATOR1 = 0,
|
|
|
|
OPERATOR2 = 1,
|
|
|
|
OPERATOR3 = 2,
|
2020-09-28 18:23:55 +00:00
|
|
|
OPERATOR4 = 3
|
2020-01-02 16:52:30 +00:00
|
|
|
};
|
|
|
|
/* *********** FM Operator indexes *end******* */
|
|
|
|
|
|
|
|
#pragma pack(push, 1)
|
|
|
|
#define OPNDATA_BYTE_COMPARABLE(T) \
|
|
|
|
inline bool operator==(const T &a, const T &b) \
|
|
|
|
{ return !memcmp(&a, &b, sizeof(T)); } \
|
|
|
|
inline bool operator!=(const T &a, const T &b) \
|
|
|
|
{ return !operator==(a, b); }
|
|
|
|
|
|
|
|
struct OPN_Operator
|
|
|
|
{
|
|
|
|
//! Raw register data
|
|
|
|
uint8_t data[7];
|
|
|
|
/*
|
|
|
|
Bytes:
|
|
|
|
0 - Deture/Multiple
|
|
|
|
1 - Total Level
|
|
|
|
2 - Rate Scale / Attack
|
|
|
|
3 - Amplitude modulation / Decay-1
|
|
|
|
4 - Decay-2
|
|
|
|
5 - Systain / Release
|
|
|
|
6 - SSG-EG byte
|
|
|
|
*/
|
|
|
|
};
|
|
|
|
OPNDATA_BYTE_COMPARABLE(struct OPN_Operator)
|
|
|
|
|
2020-09-28 18:23:55 +00:00
|
|
|
struct OpnTimbre
|
2020-01-02 16:52:30 +00:00
|
|
|
{
|
|
|
|
//! Operators prepared for sending to OPL chip emulator
|
|
|
|
OPN_Operator OPS[4];
|
2020-09-28 18:23:55 +00:00
|
|
|
//! Feedback / algorithm
|
2020-01-02 16:52:30 +00:00
|
|
|
uint8_t fbalg;
|
2020-09-28 18:23:55 +00:00
|
|
|
//! LFO sensitivity
|
2020-01-02 16:52:30 +00:00
|
|
|
uint8_t lfosens;
|
2020-09-28 18:23:55 +00:00
|
|
|
//! Semi-tone offset
|
|
|
|
int16_t noteOffset;
|
2020-01-02 16:52:30 +00:00
|
|
|
};
|
2020-09-28 18:23:55 +00:00
|
|
|
OPNDATA_BYTE_COMPARABLE(struct OpnTimbre)
|
2020-01-02 16:52:30 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Instrument data with operators included
|
|
|
|
*/
|
2020-09-28 18:23:55 +00:00
|
|
|
struct OpnInstMeta
|
2020-01-02 16:52:30 +00:00
|
|
|
{
|
2020-09-28 18:23:55 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
Flag_Pseudo8op = 0x01,
|
|
|
|
Flag_NoSound = 0x02
|
|
|
|
};
|
|
|
|
|
|
|
|
//! Operator data
|
|
|
|
OpnTimbre op[2];
|
|
|
|
//! Fixed note for drum instruments
|
|
|
|
uint8_t drumTone;
|
|
|
|
//! Instrument flags
|
2020-01-02 16:52:30 +00:00
|
|
|
uint8_t flags;
|
2020-09-28 18:23:55 +00:00
|
|
|
//! Number of milliseconds it produces sound while key on
|
|
|
|
uint16_t soundKeyOnMs;
|
|
|
|
//! Number of milliseconds it produces sound while releasing after key off
|
|
|
|
uint16_t soundKeyOffMs;
|
|
|
|
//! MIDI velocity offset
|
|
|
|
int8_t midiVelocityOffset;
|
|
|
|
//! Second voice detune
|
|
|
|
double voice2_fine_tune;
|
2020-01-02 16:52:30 +00:00
|
|
|
};
|
2020-09-28 18:23:55 +00:00
|
|
|
OPNDATA_BYTE_COMPARABLE(struct OpnInstMeta)
|
2020-01-02 16:52:30 +00:00
|
|
|
|
|
|
|
#undef OPNDATA_BYTE_COMPARABLE
|
|
|
|
#pragma pack(pop)
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Bank global setup
|
|
|
|
*/
|
|
|
|
struct OpnBankSetup
|
|
|
|
{
|
|
|
|
int volumeModel;
|
|
|
|
int lfoEnable;
|
|
|
|
int lfoFrequency;
|
2020-09-28 18:23:55 +00:00
|
|
|
int chipType;
|
2023-01-01 22:24:15 +00:00
|
|
|
bool mt32defaults;
|
2020-01-02 16:52:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Convert external instrument to internal instrument
|
|
|
|
*/
|
2020-09-28 18:23:55 +00:00
|
|
|
void cvt_OPNI_to_FMIns(OpnInstMeta &dst, const struct OPN2_Instrument &src);
|
2020-01-02 16:52:30 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Convert internal instrument to external instrument
|
|
|
|
*/
|
2020-09-28 18:23:55 +00:00
|
|
|
void cvt_FMIns_to_OPNI(struct OPN2_Instrument &dst, const OpnInstMeta &src);
|
2020-01-02 16:52:30 +00:00
|
|
|
|
|
|
|
#endif // OPNMIDI_OPNBANK_H
|