OPNMIDI: Natively disable embedded MUS and XMI, and MIDI sequencer

This commit is contained in:
Vitaly Novichkov 2018-03-24 23:46:05 +03:00
parent 0816018d36
commit be1b884a04
7 changed files with 211 additions and 23 deletions

View file

@ -646,10 +646,11 @@ if( NOT SEND_ANON_STATS )
endif() endif()
# OPLMIDI needs for USE_LEGACY_EMULATOR macro to be correctly built # OPLMIDI needs for USE_LEGACY_EMULATOR macro to be correctly built
add_definitions(-DUSE_LEGACY_EMULATOR) add_definitions(-DOPNMIDI_USE_LEGACY_EMULATOR)
# Disable ADLMIDI's MIDI Sequencer, MUS and XMI converters # Disable ADLMIDI's and OPNMIDI's MIDI Sequencer, MUS and XMI converters
add_definitions(-DADLMIDI_DISABLE_MUS_SUPPORT -DADLMIDI_DISABLE_XMI_SUPPORT -DADLMIDI_DISABLE_MIDI_SEQUENCER) add_definitions(-DADLMIDI_DISABLE_MUS_SUPPORT -DADLMIDI_DISABLE_XMI_SUPPORT -DADLMIDI_DISABLE_MIDI_SEQUENCER)
add_definitions(-DOPNMIDI_DISABLE_MUS_SUPPORT -DOPNMIDI_DISABLE_XMI_SUPPORT -DOPNMIDI_DISABLE_MIDI_SEQUENCER)
# Project files should be aware of the header files. We can GLOB these since # Project files should be aware of the header files. We can GLOB these since
# there's generally a new cpp for every header so this file will get changed # there's generally a new cpp for every header so this file will get changed

View file

@ -160,6 +160,7 @@ OPNMIDI_EXPORT int opn2_openFile(OPN2_MIDIPlayer *device, const char *filePath)
if(device && device->opn2_midiPlayer) if(device && device->opn2_midiPlayer)
{ {
OPNMIDIplay *play = reinterpret_cast<OPNMIDIplay *>(device->opn2_midiPlayer); OPNMIDIplay *play = reinterpret_cast<OPNMIDIplay *>(device->opn2_midiPlayer);
#ifndef OPNMIDI_DISABLE_MIDI_SEQUENCER
play->m_setup.tick_skip_samples_delay = 0; play->m_setup.tick_skip_samples_delay = 0;
if(!play->LoadMIDI(filePath)) if(!play->LoadMIDI(filePath))
{ {
@ -169,6 +170,11 @@ OPNMIDI_EXPORT int opn2_openFile(OPN2_MIDIPlayer *device, const char *filePath)
return -1; return -1;
} }
else return 0; else return 0;
#else
(void)filePath;
play->setErrorString("OPNMIDI: MIDI Sequencer is not supported in this build of library!");
return -1;
#endif
} }
OPN2MIDI_ErrorString = "Can't load file: OPN2 MIDI is not initialized"; OPN2MIDI_ErrorString = "Can't load file: OPN2 MIDI is not initialized";
@ -180,6 +186,7 @@ OPNMIDI_EXPORT int opn2_openData(OPN2_MIDIPlayer *device, const void *mem, unsig
if(device && device->opn2_midiPlayer) if(device && device->opn2_midiPlayer)
{ {
OPNMIDIplay *play = reinterpret_cast<OPNMIDIplay *>(device->opn2_midiPlayer); OPNMIDIplay *play = reinterpret_cast<OPNMIDIplay *>(device->opn2_midiPlayer);
#ifndef OPNMIDI_DISABLE_MIDI_SEQUENCER
play->m_setup.tick_skip_samples_delay = 0; play->m_setup.tick_skip_samples_delay = 0;
if(!play->LoadMIDI(mem, static_cast<size_t>(size))) if(!play->LoadMIDI(mem, static_cast<size_t>(size)))
{ {
@ -189,6 +196,11 @@ OPNMIDI_EXPORT int opn2_openData(OPN2_MIDIPlayer *device, const void *mem, unsig
return -1; return -1;
} }
else return 0; else return 0;
#else
(void)mem;(void)size;
play->setErrorString("OPNMIDI: MIDI Sequencer is not supported in this build of library!");
return -1;
#endif
} }
OPN2MIDI_ErrorString = "Can't load file: OPN2 MIDI is not initialized"; OPN2MIDI_ErrorString = "Can't load file: OPN2 MIDI is not initialized";
@ -197,7 +209,7 @@ OPNMIDI_EXPORT int opn2_openData(OPN2_MIDIPlayer *device, const void *mem, unsig
OPNMIDI_EXPORT const char *opn2_emulatorName() OPNMIDI_EXPORT const char *opn2_emulatorName()
{ {
#ifdef USE_LEGACY_EMULATOR #ifdef OPNMIDI_USE_LEGACY_EMULATOR
return "GENS 2.10 YM2612"; return "GENS 2.10 YM2612";
#else #else
return "Nuked OPN2 YM3438"; return "Nuked OPN2 YM3438";
@ -233,10 +245,14 @@ OPNMIDI_EXPORT const char *opn2_getMusicTitle(struct OPN2_MIDIPlayer *device)
{ {
if(!device) if(!device)
return ""; return "";
#ifndef OPNMIDI_DISABLE_MIDI_SEQUENCER
OPNMIDIplay *play = reinterpret_cast<OPNMIDIplay *>(device->opn2_midiPlayer); OPNMIDIplay *play = reinterpret_cast<OPNMIDIplay *>(device->opn2_midiPlayer);
if(!play) if(!play)
return ""; return "";
return play->musTitle.c_str(); return play->musTitle.c_str();
#else
return "";
#endif
} }
OPNMIDI_EXPORT void opn2_close(OPN2_MIDIPlayer *device) OPNMIDI_EXPORT void opn2_close(OPN2_MIDIPlayer *device)
@ -263,10 +279,12 @@ OPNMIDI_EXPORT double opn2_totalTimeLength(struct OPN2_MIDIPlayer *device)
{ {
if(!device) if(!device)
return -1.0; return -1.0;
#ifndef OPNMIDI_DISABLE_MIDI_SEQUENCER
OPNMIDIplay *play = reinterpret_cast<OPNMIDIplay *>(device->opn2_midiPlayer); OPNMIDIplay *play = reinterpret_cast<OPNMIDIplay *>(device->opn2_midiPlayer);
if(play) if(play)
return play->timeLength(); return play->timeLength();
else else
#endif
return -1.0; return -1.0;
} }
@ -274,10 +292,12 @@ OPNMIDI_EXPORT double opn2_loopStartTime(struct OPN2_MIDIPlayer *device)
{ {
if(!device) if(!device)
return -1.0; return -1.0;
#ifndef OPNMIDI_DISABLE_MIDI_SEQUENCER
OPNMIDIplay *play = reinterpret_cast<OPNMIDIplay *>(device->opn2_midiPlayer); OPNMIDIplay *play = reinterpret_cast<OPNMIDIplay *>(device->opn2_midiPlayer);
if(play) if(play)
return play->getLoopStart(); return play->getLoopStart();
else else
#endif
return -1.0; return -1.0;
} }
@ -285,10 +305,12 @@ OPNMIDI_EXPORT double opn2_loopEndTime(struct OPN2_MIDIPlayer *device)
{ {
if(!device) if(!device)
return -1.0; return -1.0;
#ifndef OPNMIDI_DISABLE_MIDI_SEQUENCER
OPNMIDIplay *play = reinterpret_cast<OPNMIDIplay *>(device->opn2_midiPlayer); OPNMIDIplay *play = reinterpret_cast<OPNMIDIplay *>(device->opn2_midiPlayer);
if(play) if(play)
return play->getLoopEnd(); return play->getLoopEnd();
else else
#endif
return -1.0; return -1.0;
} }
@ -296,10 +318,12 @@ OPNMIDI_EXPORT double opn2_positionTell(struct OPN2_MIDIPlayer *device)
{ {
if(!device) if(!device)
return -1.0; return -1.0;
#ifndef OPNMIDI_DISABLE_MIDI_SEQUENCER
OPNMIDIplay *play = reinterpret_cast<OPNMIDIplay *>(device->opn2_midiPlayer); OPNMIDIplay *play = reinterpret_cast<OPNMIDIplay *>(device->opn2_midiPlayer);
if(play) if(play)
return play->tell(); return play->tell();
else else
#endif
return -1.0; return -1.0;
} }
@ -307,27 +331,35 @@ OPNMIDI_EXPORT void opn2_positionSeek(struct OPN2_MIDIPlayer *device, double sec
{ {
if(!device) if(!device)
return; return;
#ifndef OPNMIDI_DISABLE_MIDI_SEQUENCER
OPNMIDIplay *play = reinterpret_cast<OPNMIDIplay *>(device->opn2_midiPlayer); OPNMIDIplay *play = reinterpret_cast<OPNMIDIplay *>(device->opn2_midiPlayer);
if(play) if(play)
return play->seek(seconds); play->seek(seconds);
#else
(void)seconds;
#endif
} }
OPNMIDI_EXPORT void opn2_positionRewind(struct OPN2_MIDIPlayer *device) OPNMIDI_EXPORT void opn2_positionRewind(struct OPN2_MIDIPlayer *device)
{ {
if(!device) if(!device)
return; return;
#ifndef OPNMIDI_DISABLE_MIDI_SEQUENCER
OPNMIDIplay *play = reinterpret_cast<OPNMIDIplay *>(device->opn2_midiPlayer); OPNMIDIplay *play = reinterpret_cast<OPNMIDIplay *>(device->opn2_midiPlayer);
if(play) if(play)
return play->rewind(); play->rewind();
#endif
} }
OPNMIDI_EXPORT void opn2_setTempo(struct OPN2_MIDIPlayer *device, double tempo) OPNMIDI_EXPORT void opn2_setTempo(struct OPN2_MIDIPlayer *device, double tempo)
{ {
if(!device || (tempo <= 0.0)) if(!device || (tempo <= 0.0))
return; return;
#ifndef OPNMIDI_DISABLE_MIDI_SEQUENCER
OPNMIDIplay *play = reinterpret_cast<OPNMIDIplay *>(device->opn2_midiPlayer); OPNMIDIplay *play = reinterpret_cast<OPNMIDIplay *>(device->opn2_midiPlayer);
if(play) if(play)
return play->setTempo(tempo); play->setTempo(tempo);
#endif
} }
@ -336,10 +368,12 @@ OPNMIDI_EXPORT const char *opn2_metaMusicTitle(struct OPN2_MIDIPlayer *device)
{ {
if(!device) if(!device)
return ""; return "";
#ifndef OPNMIDI_DISABLE_MIDI_SEQUENCER
OPNMIDIplay *play = reinterpret_cast<OPNMIDIplay *>(device->opn2_midiPlayer); OPNMIDIplay *play = reinterpret_cast<OPNMIDIplay *>(device->opn2_midiPlayer);
if(play) if(play)
return play->musTitle.c_str(); return play->musTitle.c_str();
else else
#endif
return ""; return "";
} }
@ -348,10 +382,12 @@ OPNMIDI_EXPORT const char *opn2_metaMusicCopyright(struct OPN2_MIDIPlayer *devic
{ {
if(!device) if(!device)
return ""; return "";
#ifndef OPNMIDI_DISABLE_MIDI_SEQUENCER
OPNMIDIplay *play = reinterpret_cast<OPNMIDIplay *>(device->opn2_midiPlayer); OPNMIDIplay *play = reinterpret_cast<OPNMIDIplay *>(device->opn2_midiPlayer);
if(play) if(play)
return play->musCopyright.c_str(); return play->musCopyright.c_str();
else else
#endif
return ""; return "";
} }
@ -359,10 +395,12 @@ OPNMIDI_EXPORT size_t opn2_metaTrackTitleCount(struct OPN2_MIDIPlayer *device)
{ {
if(!device) if(!device)
return 0; return 0;
#ifndef OPNMIDI_DISABLE_MIDI_SEQUENCER
OPNMIDIplay *play = reinterpret_cast<OPNMIDIplay *>(device->opn2_midiPlayer); OPNMIDIplay *play = reinterpret_cast<OPNMIDIplay *>(device->opn2_midiPlayer);
if(play) if(play)
return play->musTrackTitles.size(); return play->musTrackTitles.size();
else else
#endif
return 0; return 0;
} }
@ -370,10 +408,15 @@ OPNMIDI_EXPORT const char *opn2_metaTrackTitle(struct OPN2_MIDIPlayer *device, s
{ {
if(!device) if(!device)
return 0; return 0;
#ifndef OPNMIDI_DISABLE_MIDI_SEQUENCER
OPNMIDIplay *play = reinterpret_cast<OPNMIDIplay *>(device->opn2_midiPlayer); OPNMIDIplay *play = reinterpret_cast<OPNMIDIplay *>(device->opn2_midiPlayer);
if(index >= play->musTrackTitles.size()) if(index >= play->musTrackTitles.size())
return "INVALID"; return "INVALID";
return play->musTrackTitles[index].c_str(); return play->musTrackTitles[index].c_str();
#else
(void)index;
return "NOT SUPPORTED";
#endif
} }
@ -381,16 +424,19 @@ OPNMIDI_EXPORT size_t opn2_metaMarkerCount(struct OPN2_MIDIPlayer *device)
{ {
if(!device) if(!device)
return 0; return 0;
#ifndef OPNMIDI_DISABLE_MIDI_SEQUENCER
OPNMIDIplay *play = reinterpret_cast<OPNMIDIplay *>(device->opn2_midiPlayer); OPNMIDIplay *play = reinterpret_cast<OPNMIDIplay *>(device->opn2_midiPlayer);
if(play) if(play)
return play->musMarkers.size(); return play->musMarkers.size();
else else
#endif
return 0; return 0;
} }
OPNMIDI_EXPORT Opn2_MarkerEntry opn2_metaMarker(struct OPN2_MIDIPlayer *device, size_t index) OPNMIDI_EXPORT Opn2_MarkerEntry opn2_metaMarker(struct OPN2_MIDIPlayer *device, size_t index)
{ {
struct Opn2_MarkerEntry marker; struct Opn2_MarkerEntry marker;
#ifndef OPNMIDI_DISABLE_MIDI_SEQUENCER
OPNMIDIplay *play = reinterpret_cast<OPNMIDIplay *>(device->opn2_midiPlayer); OPNMIDIplay *play = reinterpret_cast<OPNMIDIplay *>(device->opn2_midiPlayer);
if(!device || !play || (index >= play->musMarkers.size())) if(!device || !play || (index >= play->musMarkers.size()))
{ {
@ -406,6 +452,12 @@ OPNMIDI_EXPORT Opn2_MarkerEntry opn2_metaMarker(struct OPN2_MIDIPlayer *device,
marker.pos_time = mk.pos_time; marker.pos_time = mk.pos_time;
marker.pos_ticks = (unsigned long)mk.pos_ticks; marker.pos_ticks = (unsigned long)mk.pos_ticks;
} }
#else
(void)device; (void)index;
marker.label = "NOT SUPPORTED";
marker.pos_time = 0.0;
marker.pos_ticks = 0;
#endif
return marker; return marker;
} }
@ -458,6 +510,7 @@ inline static void SendStereoAudio(int &samples_requested,
OPNMIDI_EXPORT int opn2_play(OPN2_MIDIPlayer *device, int sampleCount, short *out) OPNMIDI_EXPORT int opn2_play(OPN2_MIDIPlayer *device, int sampleCount, short *out)
{ {
#ifndef OPNMIDI_DISABLE_MIDI_SEQUENCER
sampleCount -= sampleCount % 2; //Avoid even sample requests sampleCount -= sampleCount % 2; //Avoid even sample requests
if(sampleCount < 0) if(sampleCount < 0)
return 0; return 0;
@ -514,7 +567,7 @@ OPNMIDI_EXPORT int opn2_play(OPN2_MIDIPlayer *device, int sampleCount, short *ou
unsigned int chips = player->opn.NumCards; unsigned int chips = player->opn.NumCards;
if(chips == 1) if(chips == 1)
{ {
#ifdef USE_LEGACY_EMULATOR #ifdef OPNMIDI_USE_LEGACY_EMULATOR
player->opn.cardsOP2[0]->run(int(in_generatedStereo), out_buf); player->opn.cardsOP2[0]->run(int(in_generatedStereo), out_buf);
#else #else
OPN2_GenerateStream(player->opn.cardsOP2[0], out_buf, (Bit32u)in_generatedStereo); OPN2_GenerateStream(player->opn.cardsOP2[0], out_buf, (Bit32u)in_generatedStereo);
@ -525,7 +578,7 @@ OPNMIDI_EXPORT int opn2_play(OPN2_MIDIPlayer *device, int sampleCount, short *ou
/* Generate data from every chip and mix result */ /* Generate data from every chip and mix result */
for(unsigned card = 0; card < chips; ++card) for(unsigned card = 0; card < chips; ++card)
{ {
#ifdef USE_LEGACY_EMULATOR #ifdef OPNMIDI_USE_LEGACY_EMULATOR
player->opn.cardsOP2[card]->run(int(in_generatedStereo), out_buf); player->opn.cardsOP2[card]->run(int(in_generatedStereo), out_buf);
#else #else
OPN2_GenerateStreamMix(player->opn.cardsOP2[card], out_buf, (Bit32u)in_generatedStereo); OPN2_GenerateStreamMix(player->opn.cardsOP2[card], out_buf, (Bit32u)in_generatedStereo);
@ -549,6 +602,9 @@ OPNMIDI_EXPORT int opn2_play(OPN2_MIDIPlayer *device, int sampleCount, short *ou
} }
return static_cast<int>(gotten_len); return static_cast<int>(gotten_len);
#else
return 0;
#endif //OPNMIDI_DISABLE_MIDI_SEQUENCER
} }
@ -593,7 +649,7 @@ OPNMIDI_EXPORT int opn2_generate(struct OPN2_MIDIPlayer *device, int sampleCount
unsigned int chips = player->opn.NumCards; unsigned int chips = player->opn.NumCards;
if(chips == 1) if(chips == 1)
{ {
#ifdef USE_LEGACY_EMULATOR #ifdef OPNMIDI_USE_LEGACY_EMULATOR
player->opn.cardsOP2[0]->run(int(in_generatedStereo), out_buf); player->opn.cardsOP2[0]->run(int(in_generatedStereo), out_buf);
#else #else
OPN2_GenerateStream(player->opn.cardsOP2[0], out_buf, (Bit32u)in_generatedStereo); OPN2_GenerateStream(player->opn.cardsOP2[0], out_buf, (Bit32u)in_generatedStereo);
@ -604,7 +660,7 @@ OPNMIDI_EXPORT int opn2_generate(struct OPN2_MIDIPlayer *device, int sampleCount
/* Generate data from every chip and mix result */ /* Generate data from every chip and mix result */
for(unsigned card = 0; card < chips; ++card) for(unsigned card = 0; card < chips; ++card)
{ {
#ifdef USE_LEGACY_EMULATOR #ifdef OPNMIDI_USE_LEGACY_EMULATOR
player->opn.cardsOP2[card]->run(int(in_generatedStereo), out_buf); player->opn.cardsOP2[card]->run(int(in_generatedStereo), out_buf);
#else #else
OPN2_GenerateStreamMix(player->opn.cardsOP2[card], out_buf, (Bit32u)in_generatedStereo); OPN2_GenerateStreamMix(player->opn.cardsOP2[card], out_buf, (Bit32u)in_generatedStereo);
@ -629,20 +685,29 @@ OPNMIDI_EXPORT double opn2_tickEvents(struct OPN2_MIDIPlayer *device, double sec
{ {
if(!device) if(!device)
return -1.0; return -1.0;
#ifndef OPNMIDI_DISABLE_MIDI_SEQUENCER
OPNMIDIplay *player = reinterpret_cast<OPNMIDIplay *>(device->opn2_midiPlayer); OPNMIDIplay *player = reinterpret_cast<OPNMIDIplay *>(device->opn2_midiPlayer);
if(!player) if(!player)
return -1.0; return -1.0;
return player->Tick(seconds, granuality); return player->Tick(seconds, granuality);
#else
(void)seconds; (void)granuality;
return -1.0;
#endif
} }
OPNMIDI_EXPORT int opn2_atEnd(struct OPN2_MIDIPlayer *device) OPNMIDI_EXPORT int opn2_atEnd(struct OPN2_MIDIPlayer *device)
{ {
if(!device) if(!device)
return 1; return 1;
#ifndef OPNMIDI_DISABLE_MIDI_SEQUENCER
OPNMIDIplay *player = reinterpret_cast<OPNMIDIplay *>(device->opn2_midiPlayer); OPNMIDIplay *player = reinterpret_cast<OPNMIDIplay *>(device->opn2_midiPlayer);
if(!player) if(!player)
return 1; return 1;
return (int)player->atEnd; return (int)player->atEnd;
#else
return 1;
#endif
} }
OPNMIDI_EXPORT void opn2_panic(struct OPN2_MIDIPlayer *device) OPNMIDI_EXPORT void opn2_panic(struct OPN2_MIDIPlayer *device)

View file

@ -30,7 +30,7 @@ extern "C" {
#define OPNMIDI_VERSION_MAJOR 1 #define OPNMIDI_VERSION_MAJOR 1
#define OPNMIDI_VERSION_MINOR 1 #define OPNMIDI_VERSION_MINOR 1
#define OPNMIDI_VERSION_PATCHLEVEL 0 #define OPNMIDI_VERSION_PATCHLEVEL 1
#define OPNMIDI_TOSTR(s) #s #define OPNMIDI_TOSTR(s) #s
#define OPNMIDI_VERSION \ #define OPNMIDI_VERSION \

View file

@ -23,6 +23,15 @@
#include "opnmidi_private.hpp" #include "opnmidi_private.hpp"
#ifndef OPNMIDI_DISABLE_MIDI_SEQUENCER
# ifndef OPNMIDI_DISABLE_MUS_SUPPORT
# include "opnmidi_mus2mid.h"
# endif
# ifndef OPNMIDI_DISABLE_XMI_SUPPORT
# include "opnmidi_xmi2mid.h"
# endif
#endif //OPNMIDI_DISABLE_MIDI_SEQUENCER
uint64_t OPNMIDIplay::ReadBEint(const void *buffer, size_t nbytes) uint64_t OPNMIDIplay::ReadBEint(const void *buffer, size_t nbytes)
{ {
uint64_t result = 0; uint64_t result = 0;
@ -299,6 +308,7 @@ bool OPNMIDIplay::LoadBank(OPNMIDIplay::fileReader &fr)
return true; return true;
} }
#ifndef OPNMIDI_DISABLE_MIDI_SEQUENCER
bool OPNMIDIplay::LoadMIDI(const std::string &filename) bool OPNMIDIplay::LoadMIDI(const std::string &filename)
{ {
fileReader file; fileReader file;
@ -367,6 +377,83 @@ riffskip:
fr.seek(7 - static_cast<long>(HeaderSize), SEEK_CUR); fr.seek(7 - static_cast<long>(HeaderSize), SEEK_CUR);
is_GMF = true; is_GMF = true;
} }
#ifndef OPNMIDI_DISABLE_MUS_SUPPORT
else if(std::memcmp(HeaderBuf, "MUS\x1A", 4) == 0)
{
// MUS/DMX files (Doom)
fr.seek(0, SEEK_END);
size_t mus_len = fr.tell();
fr.seek(0, SEEK_SET);
uint8_t *mus = (uint8_t *)malloc(mus_len);
if(!mus)
{
errorStringOut = "Out of memory!";
return false;
}
fr.read(mus, 1, mus_len);
//Close source stream
fr.close();
uint8_t *mid = NULL;
uint32_t mid_len = 0;
int m2mret = OpnMidi_mus2midi(mus, static_cast<uint32_t>(mus_len),
&mid, &mid_len, 0);
if(mus) free(mus);
if(m2mret < 0)
{
errorStringOut = "Invalid MUS/DMX data format!";
return false;
}
cvt_buf.reset(mid);
//Open converted MIDI file
fr.openData(mid, static_cast<size_t>(mid_len));
//Re-Read header again!
goto riffskip;
}
#endif //OPNMIDI_DISABLE_MUS_SUPPORT
#ifndef OPNMIDI_DISABLE_XMI_SUPPORT
else if(std::memcmp(HeaderBuf, "FORM", 4) == 0)
{
if(std::memcmp(HeaderBuf + 8, "XDIR", 4) != 0)
{
fr.close();
errorStringOut = fr._fileName + ": Invalid format\n";
return false;
}
fr.seek(0, SEEK_END);
size_t mus_len = fr.tell();
fr.seek(0, SEEK_SET);
uint8_t *mus = (uint8_t*)malloc(mus_len);
if(!mus)
{
errorStringOut = "Out of memory!";
return false;
}
fr.read(mus, 1, mus_len);
//Close source stream
fr.close();
uint8_t *mid = NULL;
uint32_t mid_len = 0;
int m2mret = OpnMidi_xmi2midi(mus, static_cast<uint32_t>(mus_len),
&mid, &mid_len, XMIDI_CONVERT_NOCONVERSION);
if(mus) free(mus);
if(m2mret < 0)
{
errorStringOut = "Invalid XMI data format!";
return false;
}
cvt_buf.reset(mid);
//Open converted MIDI file
fr.openData(mid, static_cast<size_t>(mid_len));
//Re-Read header again!
goto riffskip;
}
#endif //OPNMIDI_DISABLE_XMI_SUPPORT
else else
{ {
// Try to identify RSXX format // Try to identify RSXX format
@ -482,3 +569,4 @@ riffskip:
ch.resize(opn.NumChannels); ch.resize(opn.NumChannels);
return true; return true;
} }
#endif //OPNMIDI_DISABLE_MIDI_SEQUENCER

View file

@ -93,6 +93,8 @@ void OPNMIDIplay::OpnChannel::AddAge(int64_t ms)
} }
} }
#ifndef OPNMIDI_DISABLE_MIDI_SEQUENCER
OPNMIDIplay::MidiEvent::MidiEvent() : OPNMIDIplay::MidiEvent::MidiEvent() :
type(T_UNKNOWN), type(T_UNKNOWN),
subtype(T_UNKNOWN), subtype(T_UNKNOWN),
@ -211,7 +213,9 @@ void OPNMIDIplay::MidiTrackRow::sortEvents(bool *noteStates)
events.insert(events.end(), controllers.begin(), controllers.end()); events.insert(events.end(), controllers.begin(), controllers.end());
events.insert(events.end(), anyOther.begin(), anyOther.end()); events.insert(events.end(), anyOther.begin(), anyOther.end());
} }
#endif //OPNMIDI_DISABLE_MIDI_SEQUENCER
#ifndef OPNMIDI_DISABLE_MIDI_SEQUENCER
bool OPNMIDIplay::buildTrackData() bool OPNMIDIplay::buildTrackData()
{ {
fullSongTimeLength = 0.0; fullSongTimeLength = 0.0;
@ -648,12 +652,12 @@ bool OPNMIDIplay::buildTrackData()
return true; return true;
} }
#endif //OPNMIDI_DISABLE_MIDI_SEQUENCER
OPNMIDIplay::OPNMIDIplay(unsigned long sampleRate)
OPNMIDIplay::OPNMIDIplay(unsigned long sampleRate): #ifndef OPNMIDI_DISABLE_MIDI_SEQUENCER
//cmf_percussion_mode(false), : fullSongTimeLength(0.0),
fullSongTimeLength(0.0),
postSongWaitDelay(1.0), postSongWaitDelay(1.0),
loopStartTime(-1.0), loopStartTime(-1.0),
loopEndTime(-1.0), loopEndTime(-1.0),
@ -662,6 +666,7 @@ OPNMIDIplay::OPNMIDIplay(unsigned long sampleRate):
loopStart(false), loopStart(false),
loopEnd(false), loopEnd(false),
invalidLoop(false) invalidLoop(false)
#endif
{ {
devices.clear(); devices.clear();
@ -735,7 +740,7 @@ uint64_t OPNMIDIplay::ReadVarLenEx(uint8_t **ptr, uint8_t *end, bool &ok)
return result; return result;
} }
#ifndef OPNMIDI_DISABLE_MIDI_SEQUENCER
double OPNMIDIplay::Tick(double s, double granularity) double OPNMIDIplay::Tick(double s, double granularity)
{ {
s *= tempoMultiplier; s *= tempoMultiplier;
@ -770,6 +775,7 @@ double OPNMIDIplay::Tick(double s, double granularity)
return CurrentPositionNew.wait; return CurrentPositionNew.wait;
} }
#endif //OPNMIDI_DISABLE_MIDI_SEQUENCER
void OPNMIDIplay::TickIteratos(double s) void OPNMIDIplay::TickIteratos(double s)
{ {
@ -779,6 +785,7 @@ void OPNMIDIplay::TickIteratos(double s)
UpdateArpeggio(s); UpdateArpeggio(s);
} }
#ifndef OPNMIDI_DISABLE_MIDI_SEQUENCER
void OPNMIDIplay::seek(double seconds) void OPNMIDIplay::seek(double seconds)
{ {
if(seconds < 0.0) if(seconds < 0.0)
@ -884,6 +891,7 @@ void OPNMIDIplay::setTempo(double tempo)
{ {
tempoMultiplier = tempo; tempoMultiplier = tempo;
} }
#endif //OPNMIDI_DISABLE_MIDI_SEQUENCER
void OPNMIDIplay::realTime_ResetState() void OPNMIDIplay::realTime_ResetState()
{ {
@ -1534,7 +1542,7 @@ void OPNMIDIplay::NoteUpdate(uint16_t MidCh,
Ch[MidCh].activenotes.erase(i); Ch[MidCh].activenotes.erase(i);
} }
#ifndef OPNMIDI_DISABLE_MIDI_SEQUENCER
bool OPNMIDIplay::ProcessEventsNew(bool isSeek) bool OPNMIDIplay::ProcessEventsNew(bool isSeek)
{ {
if(CurrentPositionNew.track.size() == 0) if(CurrentPositionNew.track.size() == 0)
@ -1646,7 +1654,9 @@ bool OPNMIDIplay::ProcessEventsNew(bool isSeek)
return true;//Has events in queue return true;//Has events in queue
} }
#endif //OPNMIDI_DISABLE_MIDI_SEQUENCER
#ifndef OPNMIDI_DISABLE_MIDI_SEQUENCER
OPNMIDIplay::MidiEvent OPNMIDIplay::parseEvent(uint8_t **pptr, uint8_t *end, int &status) OPNMIDIplay::MidiEvent OPNMIDIplay::parseEvent(uint8_t **pptr, uint8_t *end, int &status)
{ {
uint8_t *&ptr = *pptr; uint8_t *&ptr = *pptr;
@ -1850,6 +1860,7 @@ OPNMIDIplay::MidiEvent OPNMIDIplay::parseEvent(uint8_t **pptr, uint8_t *end, int
return evt; return evt;
} }
#endif //OPNMIDI_DISABLE_MIDI_SEQUENCER
const std::string &OPNMIDIplay::getErrorString() const std::string &OPNMIDIplay::getErrorString()
{ {
@ -1861,7 +1872,7 @@ void OPNMIDIplay::setErrorString(const std::string &err)
errorStringOut = err; errorStringOut = err;
} }
#ifndef OPNMIDI_DISABLE_MIDI_SEQUENCER
void OPNMIDIplay::HandleEvent(size_t tk, const OPNMIDIplay::MidiEvent &evt, int &status) void OPNMIDIplay::HandleEvent(size_t tk, const OPNMIDIplay::MidiEvent &evt, int &status)
{ {
if(hooks.onEvent) if(hooks.onEvent)
@ -2018,6 +2029,7 @@ void OPNMIDIplay::HandleEvent(size_t tk, const OPNMIDIplay::MidiEvent &evt, int
} }
} }
} }
#endif //OPNMIDI_DISABLE_MIDI_SEQUENCER
long OPNMIDIplay::CalculateAdlChannelGoodness(size_t c, uint16_t ins, uint16_t) const long OPNMIDIplay::CalculateAdlChannelGoodness(size_t c, uint16_t ins, uint16_t) const
{ {

View file

@ -81,7 +81,7 @@ OPN2::~OPN2()
void OPN2::PokeO(size_t card, uint8_t port, uint8_t index, uint8_t value) void OPN2::PokeO(size_t card, uint8_t port, uint8_t index, uint8_t value)
{ {
#ifdef USE_LEGACY_EMULATOR #ifdef OPNMIDI_USE_LEGACY_EMULATOR
if(port == 1) if(port == 1)
cardsOP2[card]->write1(index, value); cardsOP2[card]->write1(index, value);
else else
@ -281,12 +281,12 @@ void OPN2::Reset(unsigned long PCM_RATE)
regBD.clear(); regBD.clear();
cardsOP2.resize(NumCards, NULL); cardsOP2.resize(NumCards, NULL);
#ifndef USE_LEGACY_EMULATOR #ifndef OPNMIDI_USE_LEGACY_EMULATOR
OPN2_SetChipType(ym3438_type_asic); OPN2_SetChipType(ym3438_type_asic);
#endif #endif
for(size_t i = 0; i < cardsOP2.size(); i++) for(size_t i = 0; i < cardsOP2.size(); i++)
{ {
#ifdef USE_LEGACY_EMULATOR #ifdef OPNMIDI_USE_LEGACY_EMULATOR
cardsOP2[i] = new OPNMIDI_Ym2612_Emu(); cardsOP2[i] = new OPNMIDI_Ym2612_Emu();
cardsOP2[i]->set_rate(PCM_RATE, 7670454.0); cardsOP2[i]->set_rate(PCM_RATE, 7670454.0);
#else #else

View file

@ -49,6 +49,10 @@ typedef __int32 ssize_t;
# include <windows.h> # include <windows.h>
#endif #endif
#ifdef USE_LEGACY_EMULATOR // Kept for a backward compatibility
#define OPNMIDI_USE_LEGACY_EMULATOR
#endif
#include <vector> #include <vector>
#include <list> #include <list>
#include <string> #include <string>
@ -75,7 +79,7 @@ typedef __int32 ssize_t;
#include <algorithm> #include <algorithm>
#include "fraction.hpp" #include "fraction.hpp"
#ifdef USE_LEGACY_EMULATOR #ifdef OPNMIDI_USE_LEGACY_EMULATOR
#include "Ym2612_ChipEmu.h" #include "Ym2612_ChipEmu.h"
#else #else
#include "ym3438.h" #include "ym3438.h"
@ -131,7 +135,7 @@ public:
friend class OPNMIDIplay; friend class OPNMIDIplay;
uint32_t NumChannels; uint32_t NumChannels;
char ____padding[4]; char ____padding[4];
#ifdef USE_LEGACY_EMULATOR #ifdef OPNMIDI_USE_LEGACY_EMULATOR
std::vector<OPNMIDI_Ym2612_Emu*> cardsOP2; std::vector<OPNMIDI_Ym2612_Emu*> cardsOP2;
#else #else
std::vector<ym3438_t*> cardsOP2; std::vector<ym3438_t*> cardsOP2;
@ -508,6 +512,7 @@ public:
void AddAge(int64_t ms); void AddAge(int64_t ms);
}; };
#ifndef OPNMIDI_DISABLE_MIDI_SEQUENCER
/** /**
* @brief MIDI Event utility container * @brief MIDI Event utility container
*/ */
@ -632,6 +637,7 @@ public:
PositionNew(): began(false), wait(0.0), absTimePosition(0.0), track() PositionNew(): began(false), wait(0.0), absTimePosition(0.0), track()
{} {}
}; };
#endif //OPNMIDI_DISABLE_MIDI_SEQUENCER
struct Setup struct Setup
{ {
@ -675,6 +681,8 @@ private:
std::map<uint64_t /*track*/, uint64_t /*channel begin index*/> current_device; std::map<uint64_t /*track*/, uint64_t /*channel begin index*/> current_device;
std::vector<OpnChannel> ch; std::vector<OpnChannel> ch;
#ifndef OPNMIDI_DISABLE_MIDI_SEQUENCER
std::vector<std::vector<uint8_t> > TrackData; std::vector<std::vector<uint8_t> > TrackData;
PositionNew CurrentPositionNew, LoopBeginPositionNew, trackBeginPositionNew; PositionNew CurrentPositionNew, LoopBeginPositionNew, trackBeginPositionNew;
@ -688,13 +696,16 @@ private:
double loopStartTime; double loopStartTime;
//! Loop end time //! Loop end time
double loopEndTime; double loopEndTime;
#endif
//! Local error string //! Local error string
std::string errorString; std::string errorString;
//! Local error string //! Local error string
std::string errorStringOut; std::string errorStringOut;
#ifndef OPNMIDI_DISABLE_MIDI_SEQUENCER
//! Pre-processed track data storage //! Pre-processed track data storage
std::vector<MidiTrackQueue > trackDataNew; std::vector<MidiTrackQueue > trackDataNew;
#endif
//! Missing instruments catches //! Missing instruments catches
std::set<uint8_t> caugh_missing_instruments; std::set<uint8_t> caugh_missing_instruments;
@ -703,6 +714,7 @@ private:
//! Missing percussion banks catches //! Missing percussion banks catches
std::set<uint16_t> caugh_missing_banks_percussion; std::set<uint16_t> caugh_missing_banks_percussion;
#ifndef OPNMIDI_DISABLE_MIDI_SEQUENCER
/** /**
* @brief Build MIDI track data from the raw track data storage * @brief Build MIDI track data from the raw track data storage
* @return true if everything successfully processed, or false on any error * @return true if everything successfully processed, or false on any error
@ -717,12 +729,14 @@ private:
* @return Parsed MIDI event entry * @return Parsed MIDI event entry
*/ */
MidiEvent parseEvent(uint8_t **ptr, uint8_t *end, int &status); MidiEvent parseEvent(uint8_t **ptr, uint8_t *end, int &status);
#endif
public: public:
const std::string &getErrorString(); const std::string &getErrorString();
void setErrorString(const std::string &err); void setErrorString(const std::string &err);
#ifndef OPNMIDI_DISABLE_MIDI_SEQUENCER
std::string musTitle; std::string musTitle;
std::string musCopyright; std::string musCopyright;
std::vector<std::string> musTrackTitles; std::vector<std::string> musTrackTitles;
@ -736,6 +750,7 @@ public:
loopEnd, loopEnd,
invalidLoop; /*Loop points are invalid (loopStart after loopEnd or loopStart and loopEnd are on same place)*/ invalidLoop; /*Loop points are invalid (loopStart after loopEnd or loopStart and loopEnd are on same place)*/
char ____padding2[2]; char ____padding2[2];
#endif
OPN2 opn; OPN2 opn;
int16_t outBuf[1024]; int16_t outBuf[1024];
@ -764,6 +779,7 @@ public:
bool LoadBank(const void *data, size_t size); bool LoadBank(const void *data, size_t size);
bool LoadBank(fileReader &fr); bool LoadBank(fileReader &fr);
#ifndef OPNMIDI_DISABLE_MIDI_SEQUENCER
bool LoadMIDI(const std::string &filename); bool LoadMIDI(const std::string &filename);
bool LoadMIDI(const void *data, size_t size); bool LoadMIDI(const void *data, size_t size);
bool LoadMIDI(fileReader &fr); bool LoadMIDI(fileReader &fr);
@ -775,6 +791,7 @@ public:
* @return desired number of seconds until next call * @return desired number of seconds until next call
*/ */
double Tick(double s, double granularity); double Tick(double s, double granularity);
#endif
/** /**
* @brief Process extra iterators like vibrato or arpeggio * @brief Process extra iterators like vibrato or arpeggio
@ -782,6 +799,7 @@ public:
*/ */
void TickIteratos(double s); void TickIteratos(double s);
#ifndef OPNMIDI_DISABLE_MIDI_SEQUENCER
/** /**
* @brief Change current position to specified time position in seconds * @brief Change current position to specified time position in seconds
* @param seconds Absolute time position in seconds * @param seconds Absolute time position in seconds
@ -822,6 +840,7 @@ public:
* @param tempo Tempo multiplier: 1.0 - original tempo. >1 - faster, <1 - slower * @param tempo Tempo multiplier: 1.0 - original tempo. >1 - faster, <1 - slower
*/ */
void setTempo(double tempo); void setTempo(double tempo);
#endif
/* RealTime event triggers */ /* RealTime event triggers */
void realTime_ResetState(); void realTime_ResetState();
@ -860,8 +879,11 @@ private:
MIDIchannel::activenoteiterator i, MIDIchannel::activenoteiterator i,
unsigned props_mask, unsigned props_mask,
int32_t select_adlchn = -1); int32_t select_adlchn = -1);
#ifndef OPNMIDI_DISABLE_MIDI_SEQUENCER
bool ProcessEventsNew(bool isSeek = false); bool ProcessEventsNew(bool isSeek = false);
void HandleEvent(size_t tk, const MidiEvent &evt, int &status); void HandleEvent(size_t tk, const MidiEvent &evt, int &status);
#endif
// Determine how good a candidate this adlchannel // Determine how good a candidate this adlchannel
// would be for playing a note from this instrument. // would be for playing a note from this instrument.