diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/adlmidi.cpp | 76 | ||||
-rw-r--r-- | src/adlmidi_load.cpp | 16 | ||||
-rw-r--r-- | src/adlmidi_midiplay.cpp | 26 | ||||
-rw-r--r-- | src/adlmidi_private.hpp | 18 |
4 files changed, 129 insertions, 7 deletions
diff --git a/src/adlmidi.cpp b/src/adlmidi.cpp index d40db53..e878354 100644 --- a/src/adlmidi.cpp +++ b/src/adlmidi.cpp @@ -272,6 +272,7 @@ ADLMIDI_EXPORT int adl_openFile(ADL_MIDIPlayer *device, const char *filePath) if(device && device->adl_midiPlayer) { MIDIplay *play = reinterpret_cast<MIDIplay *>(device->adl_midiPlayer); +#ifndef ADLMIDI_DISABLE_MIDI_SEQUENCER play->m_setup.tick_skip_samples_delay = 0; if(!play->LoadMIDI(filePath)) { @@ -281,6 +282,10 @@ ADLMIDI_EXPORT int adl_openFile(ADL_MIDIPlayer *device, const char *filePath) return -1; } else return 0; +#else + play->setErrorString("ADLMIDI: MIDI Sequencer is not supported in this build of library!"); + return -1; +#endif //ADLMIDI_DISABLE_MIDI_SEQUENCER } ADLMIDI_ErrorString = "Can't load file: ADL MIDI is not initialized"; @@ -292,6 +297,7 @@ ADLMIDI_EXPORT int adl_openData(ADL_MIDIPlayer *device, const void *mem, unsigne if(device && device->adl_midiPlayer) { MIDIplay *play = reinterpret_cast<MIDIplay *>(device->adl_midiPlayer); +#ifndef ADLMIDI_DISABLE_MIDI_SEQUENCER play->m_setup.tick_skip_samples_delay = 0; if(!play->LoadMIDI(mem, static_cast<size_t>(size))) { @@ -301,6 +307,10 @@ ADLMIDI_EXPORT int adl_openData(ADL_MIDIPlayer *device, const void *mem, unsigne return -1; } else return 0; +#else + play->setErrorString("ADLMIDI: MIDI Sequencer is not supported in this build of library!"); + return -1; +#endif //ADLMIDI_DISABLE_MIDI_SEQUENCER } ADLMIDI_ErrorString = "Can't load file: ADL MIDI is not initialized"; return -1; @@ -348,7 +358,11 @@ ADLMIDI_EXPORT const char *adl_getMusicTitle(struct ADL_MIDIPlayer *device) MIDIplay *play = reinterpret_cast<MIDIplay *>(device->adl_midiPlayer); if(!play) return ""; + #ifndef ADLMIDI_DISABLE_MIDI_SEQUENCER return play->musTitle.c_str(); + #else + return ""; + #endif } ADLMIDI_EXPORT void adl_close(struct ADL_MIDIPlayer *device) @@ -375,49 +389,71 @@ ADLMIDI_EXPORT double adl_totalTimeLength(struct ADL_MIDIPlayer *device) { if(!device) return -1.0; + #ifndef ADLMIDI_DISABLE_MIDI_SEQUENCER return reinterpret_cast<MIDIplay *>(device->adl_midiPlayer)->timeLength(); + #else + return -1.0; + #endif } ADLMIDI_EXPORT double adl_loopStartTime(struct ADL_MIDIPlayer *device) { if(!device) return -1.0; + #ifndef ADLMIDI_DISABLE_MIDI_SEQUENCER return reinterpret_cast<MIDIplay *>(device->adl_midiPlayer)->getLoopStart(); + #else + return -1.0; + #endif } ADLMIDI_EXPORT double adl_loopEndTime(struct ADL_MIDIPlayer *device) { if(!device) return -1.0; + #ifndef ADLMIDI_DISABLE_MIDI_SEQUENCER return reinterpret_cast<MIDIplay *>(device->adl_midiPlayer)->getLoopEnd(); + #else + return -1.0; + #endif } ADLMIDI_EXPORT double adl_positionTell(struct ADL_MIDIPlayer *device) { if(!device) return -1.0; + #ifndef ADLMIDI_DISABLE_MIDI_SEQUENCER return reinterpret_cast<MIDIplay *>(device->adl_midiPlayer)->tell(); + #else + return -1.0; + #endif } ADLMIDI_EXPORT void adl_positionSeek(struct ADL_MIDIPlayer *device, double seconds) { if(!device) return; + #ifndef ADLMIDI_DISABLE_MIDI_SEQUENCER reinterpret_cast<MIDIplay *>(device->adl_midiPlayer)->seek(seconds); + #endif } ADLMIDI_EXPORT void adl_positionRewind(struct ADL_MIDIPlayer *device) { if(!device) return; + #ifndef ADLMIDI_DISABLE_MIDI_SEQUENCER reinterpret_cast<MIDIplay *>(device->adl_midiPlayer)->rewind(); + #endif } ADLMIDI_EXPORT void adl_setTempo(struct ADL_MIDIPlayer *device, double tempo) { if(!device || (tempo <= 0.0)) return; + #ifndef ADLMIDI_DISABLE_MIDI_SEQUENCER reinterpret_cast<MIDIplay *>(device->adl_midiPlayer)->setTempo(tempo); + #endif } @@ -425,7 +461,11 @@ ADLMIDI_EXPORT const char *adl_metaMusicTitle(struct ADL_MIDIPlayer *device) { if(!device) return ""; + #ifndef ADLMIDI_DISABLE_MIDI_SEQUENCER return reinterpret_cast<MIDIplay *>(device->adl_midiPlayer)->musTitle.c_str(); + #else + return ""; + #endif } @@ -433,24 +473,37 @@ ADLMIDI_EXPORT const char *adl_metaMusicCopyright(struct ADL_MIDIPlayer *device) { if(!device) return ""; + #ifndef ADLMIDI_DISABLE_MIDI_SEQUENCER return reinterpret_cast<MIDIplay *>(device->adl_midiPlayer)->musCopyright.c_str(); + #else + return ""; + #endif } ADLMIDI_EXPORT size_t adl_metaTrackTitleCount(struct ADL_MIDIPlayer *device) { if(!device) return 0; +#ifndef ADLMIDI_DISABLE_MIDI_SEQUENCER return reinterpret_cast<MIDIplay *>(device->adl_midiPlayer)->musTrackTitles.size(); +#else + return 0; +#endif } ADLMIDI_EXPORT const char *adl_metaTrackTitle(struct ADL_MIDIPlayer *device, size_t index) { if(!device) return 0; +#ifndef ADLMIDI_DISABLE_MIDI_SEQUENCER MIDIplay *play = reinterpret_cast<MIDIplay *>(device->adl_midiPlayer); if(index >= play->musTrackTitles.size()) return "INVALID"; return play->musTrackTitles[index].c_str(); +#else + (void)device; (void)index; + return "NOT SUPPORTED"; +#endif } @@ -458,12 +511,17 @@ ADLMIDI_EXPORT size_t adl_metaMarkerCount(struct ADL_MIDIPlayer *device) { if(!device) return 0; +#ifndef ADLMIDI_DISABLE_MIDI_SEQUENCER return reinterpret_cast<MIDIplay *>(device->adl_midiPlayer)->musMarkers.size(); +#else + return 0; +#endif } ADLMIDI_EXPORT Adl_MarkerEntry adl_metaMarker(struct ADL_MIDIPlayer *device, size_t index) { struct Adl_MarkerEntry marker; + #ifndef ADLMIDI_DISABLE_MIDI_SEQUENCER MIDIplay *play = reinterpret_cast<MIDIplay *>(device->adl_midiPlayer); if(!device || !play || (index >= play->musMarkers.size())) { @@ -479,6 +537,12 @@ ADLMIDI_EXPORT Adl_MarkerEntry adl_metaMarker(struct ADL_MIDIPlayer *device, siz marker.pos_time = mk.pos_time; 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; } @@ -531,6 +595,7 @@ inline static void SendStereoAudio(int &samples_requested, ADLMIDI_EXPORT int adl_play(ADL_MIDIPlayer *device, int sampleCount, short *out) { + #ifndef ADLMIDI_DISABLE_MIDI_SEQUENCER #ifdef ADLMIDI_HW_OPL (void)device; (void)sampleCount; @@ -633,6 +698,9 @@ ADLMIDI_EXPORT int adl_play(ADL_MIDIPlayer *device, int sampleCount, short *out) return static_cast<int>(gotten_len); #endif + #else + return 0; + #endif //ADLMIDI_DISABLE_MIDI_SEQUENCER } @@ -720,22 +788,30 @@ ADLMIDI_EXPORT int adl_generate(struct ADL_MIDIPlayer *device, int sampleCount, ADLMIDI_EXPORT double adl_tickEvents(struct ADL_MIDIPlayer *device, double seconds, double granuality) { +#ifndef ADLMIDI_DISABLE_MIDI_SEQUENCER if(!device) return -1.0; MIDIplay *player = reinterpret_cast<MIDIplay *>(device->adl_midiPlayer); if(!player) return -1.0; return player->Tick(seconds, granuality); +#else + return -1.0; +#endif } ADLMIDI_EXPORT int adl_atEnd(struct ADL_MIDIPlayer *device) { +#ifndef ADLMIDI_DISABLE_MIDI_SEQUENCER if(!device) return 1; MIDIplay *player = reinterpret_cast<MIDIplay *>(device->adl_midiPlayer); if(!player) return 1; return (int)player->atEnd; +#else + return 1; +#endif } ADLMIDI_EXPORT void adl_panic(struct ADL_MIDIPlayer *device) diff --git a/src/adlmidi_load.cpp b/src/adlmidi_load.cpp index c67076b..03206bc 100644 --- a/src/adlmidi_load.cpp +++ b/src/adlmidi_load.cpp @@ -23,8 +23,14 @@ #include "adlmidi_private.hpp" -#include "adlmidi_mus2mid.h" -#include "adlmidi_xmi2mid.h" +#ifndef ADLMIDI_DISABLE_MIDI_SEQUENCER +# ifndef ADLMIDI_DISABLE_MUS_SUPPORT +# include "adlmidi_mus2mid.h" +# endif//MUS +# ifndef ADLMIDI_DISABLE_XMI_SUPPORT +# include "adlmidi_xmi2mid.h" +# endif//XMI +#endif //ADLMIDI_DISABLE_MIDI_SEQUENCER uint64_t MIDIplay::ReadBEint(const void *buffer, size_t nbytes) { @@ -339,6 +345,7 @@ tryAgain: return true; } +#ifndef ADLMIDI_DISABLE_MIDI_SEQUENCER bool MIDIplay::LoadMIDI(const std::string &filename) { fileReader file; @@ -412,6 +419,7 @@ riffskip: fr.seek(7 - static_cast<long>(HeaderSize), SEEK_CUR); is_GMF = true; } + #ifndef ADLMIDI_DISABLE_MUS_SUPPORT else if(std::memcmp(HeaderBuf, "MUS\x1A", 4) == 0) { // MUS/DMX files (Doom) @@ -444,6 +452,8 @@ riffskip: //Re-Read header again! goto riffskip; } + #endif //ADLMIDI_DISABLE_MUS_SUPPORT + #ifndef ADLMIDI_DISABLE_XMI_SUPPORT else if(std::memcmp(HeaderBuf, "FORM", 4) == 0) { if(std::memcmp(HeaderBuf + 8, "XDIR", 4) != 0) @@ -482,6 +492,7 @@ riffskip: //Re-Read header again! goto riffskip; } + #endif //ADLMIDI_DISABLE_XMI_SUPPORT else if(std::memcmp(HeaderBuf, "CTMF", 4) == 0) { opl.dynamic_instruments.clear(); @@ -761,3 +772,4 @@ riffskip: ch.resize(opl.NumChannels); return true; } +#endif //ADLMIDI_DISABLE_MIDI_SEQUENCER diff --git a/src/adlmidi_midiplay.cpp b/src/adlmidi_midiplay.cpp index 432785f..ea3b1fe 100644 --- a/src/adlmidi_midiplay.cpp +++ b/src/adlmidi_midiplay.cpp @@ -133,6 +133,8 @@ void MIDIplay::AdlChannel::AddAge(int64_t ms) } } +#ifndef ADLMIDI_DISABLE_MIDI_SEQUENCER + MIDIplay::MidiEvent::MidiEvent() : type(T_UNKNOWN), subtype(T_UNKNOWN), @@ -250,7 +252,9 @@ void MIDIplay::MidiTrackRow::sortEvents(bool *noteStates) events.insert(events.end(), controllers.begin(), controllers.end()); events.insert(events.end(), anyOther.begin(), anyOther.end()); } +#endif //ADLMIDI_DISABLE_MIDI_SEQUENCER +#ifndef ADLMIDI_DISABLE_MIDI_SEQUENCER bool MIDIplay::buildTrackData() { fullSongTimeLength = 0.0; @@ -687,10 +691,13 @@ bool MIDIplay::buildTrackData() return true; } +#endif + MIDIplay::MIDIplay(unsigned long sampleRate): - cmf_percussion_mode(false), - fullSongTimeLength(0.0), + cmf_percussion_mode(false) +#ifndef ADLMIDI_DISABLE_MIDI_SEQUENCER + , fullSongTimeLength(0.0), postSongWaitDelay(1.0), loopStartTime(-1.0), loopEndTime(-1.0), @@ -699,6 +706,7 @@ MIDIplay::MIDIplay(unsigned long sampleRate): loopStart(false), loopEnd(false), invalidLoop(false) +#endif { devices.clear(); @@ -781,7 +789,7 @@ uint64_t MIDIplay::ReadVarLenEx(uint8_t **ptr, uint8_t *end, bool &ok) return result; } - +#ifndef ADLMIDI_DISABLE_MIDI_SEQUENCER double MIDIplay::Tick(double s, double granularity) { s *= tempoMultiplier; @@ -816,6 +824,7 @@ double MIDIplay::Tick(double s, double granularity) return CurrentPositionNew.wait; } +#endif void MIDIplay::TickIteratos(double s) { @@ -825,6 +834,8 @@ void MIDIplay::TickIteratos(double s) UpdateArpeggio(s); } +#ifndef ADLMIDI_DISABLE_MIDI_SEQUENCER + void MIDIplay::seek(double seconds) { if(seconds < 0.0) @@ -930,6 +941,7 @@ void MIDIplay::setTempo(double tempo) { tempoMultiplier = tempo; } +#endif void MIDIplay::realTime_ResetState() { @@ -1608,7 +1620,7 @@ void MIDIplay::NoteUpdate(uint16_t MidCh, Ch[MidCh].activenotes.erase(i); } - +#ifndef ADLMIDI_DISABLE_MIDI_SEQUENCER bool MIDIplay::ProcessEventsNew(bool isSeek) { if(CurrentPositionNew.track.size() == 0) @@ -1720,7 +1732,9 @@ bool MIDIplay::ProcessEventsNew(bool isSeek) return true;//Has events in queue } +#endif +#ifndef ADLMIDI_DISABLE_MIDI_SEQUENCER MIDIplay::MidiEvent MIDIplay::parseEvent(uint8_t **pptr, uint8_t *end, int &status) { uint8_t *&ptr = *pptr; @@ -1924,6 +1938,7 @@ MIDIplay::MidiEvent MIDIplay::parseEvent(uint8_t **pptr, uint8_t *end, int &stat return evt; } +#endif const std::string &MIDIplay::getErrorString() { @@ -1935,7 +1950,7 @@ void MIDIplay::setErrorString(const std::string &err) errorStringOut = err; } - +#ifndef ADLMIDI_DISABLE_MIDI_SEQUENCER void MIDIplay::HandleEvent(size_t tk, const MIDIplay::MidiEvent &evt, int &status) { if(hooks.onEvent) @@ -2092,6 +2107,7 @@ void MIDIplay::HandleEvent(size_t tk, const MIDIplay::MidiEvent &evt, int &statu } } } +#endif long MIDIplay::CalculateAdlChannelGoodness(unsigned c, const MIDIchannel::NoteInfo::Phys &ins, uint16_t) const { diff --git a/src/adlmidi_private.hpp b/src/adlmidi_private.hpp index 9ff18e6..8b2bf19 100644 --- a/src/adlmidi_private.hpp +++ b/src/adlmidi_private.hpp @@ -577,6 +577,7 @@ public: void AddAge(int64_t ms); }; +#ifndef ADLMIDI_DISABLE_MIDI_SEQUENCER /** * @brief MIDI Event utility container */ @@ -701,6 +702,7 @@ public: PositionNew(): began(false), wait(0.0), absTimePosition(0.0), track() {} }; +#endif//ADLMIDI_DISABLE_MIDI_SEQUENCER struct Setup { @@ -751,6 +753,8 @@ private: char ____padding[7]; std::vector<AdlChannel> ch; + +#ifndef ADLMIDI_DISABLE_MIDI_SEQUENCER std::vector<std::vector<uint8_t> > TrackData; PositionNew CurrentPositionNew, LoopBeginPositionNew, trackBeginPositionNew; @@ -764,13 +768,16 @@ private: double loopStartTime; //! Loop end time double loopEndTime; +#endif //! Local error string std::string errorString; //! Local error string std::string errorStringOut; +#ifndef ADLMIDI_DISABLE_MIDI_SEQUENCER //! Pre-processed track data storage std::vector<MidiTrackQueue > trackDataNew; +#endif //! Missing instruments catches std::set<uint8_t> caugh_missing_instruments; @@ -779,6 +786,7 @@ private: //! Missing percussion banks catches std::set<uint16_t> caugh_missing_banks_percussion; +#ifndef ADLMIDI_DISABLE_MIDI_SEQUENCER /** * @brief Build MIDI track data from the raw track data storage * @return true if everything successfully processed, or false on any error @@ -793,12 +801,14 @@ private: * @return Parsed MIDI event entry */ MidiEvent parseEvent(uint8_t **ptr, uint8_t *end, int &status); +#endif//ADLMIDI_DISABLE_MIDI_SEQUENCER public: const std::string &getErrorString(); void setErrorString(const std::string &err); +#ifndef ADLMIDI_DISABLE_MIDI_SEQUENCER std::string musTitle; std::string musCopyright; std::vector<std::string> musTrackTitles; @@ -812,6 +822,7 @@ public: loopEnd, invalidLoop; /*Loop points are invalid (loopStart after loopEnd or loopStart and loopEnd are on same place)*/ char ____padding2[2]; +#endif OPL3 opl; int16_t outBuf[1024]; @@ -840,6 +851,7 @@ public: bool LoadBank(const void *data, size_t size); bool LoadBank(fileReader &fr); +#ifndef ADLMIDI_DISABLE_MIDI_SEQUENCER bool LoadMIDI(const std::string &filename); bool LoadMIDI(const void *data, size_t size); bool LoadMIDI(fileReader &fr); @@ -851,6 +863,7 @@ public: * @return desired number of seconds until next call */ double Tick(double s, double granularity); +#endif /** * @brief Process extra iterators like vibrato or arpeggio @@ -858,6 +871,7 @@ public: */ void TickIteratos(double s); +#ifndef ADLMIDI_DISABLE_MIDI_SEQUENCER /** * @brief Change current position to specified time position in seconds * @param seconds Absolute time position in seconds @@ -898,6 +912,7 @@ public: * @param tempo Tempo multiplier: 1.0 - original tempo. >1 - faster, <1 - slower */ void setTempo(double tempo); +#endif//ADLMIDI_DISABLE_MIDI_SEQUENCER /* RealTime event triggers */ void realTime_ResetState(); @@ -936,8 +951,11 @@ private: MIDIchannel::activenoteiterator i, unsigned props_mask, int32_t select_adlchn = -1); + +#ifndef ADLMIDI_DISABLE_MIDI_SEQUENCER bool ProcessEventsNew(bool isSeek = false); void HandleEvent(size_t tk, const MidiEvent &evt, int &status); +#endif // Determine how good a candidate this adlchannel // would be for playing a note from this instrument. |