From 380d08e1a234efb17cf15a6b6c2d00c52e4fc648 Mon Sep 17 00:00:00 2001 From: Wohlstand Date: Wed, 18 Oct 2017 02:22:01 +0300 Subject: Smooth finalizing, rewinding, and a bit more crash safety * Smooth finalizing of song when loop is disabled (old ugly hack has been removed :wink:) * Added an ability to reset song position to begin (very helpful when song reaches the end) * Avoided possible crashes on attempt to fetch sample data without opening of MIDI file --- src/adlmidi_load.cpp | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'src/adlmidi_load.cpp') diff --git a/src/adlmidi_load.cpp b/src/adlmidi_load.cpp index 5258dc9..a1242d7 100644 --- a/src/adlmidi_load.cpp +++ b/src/adlmidi_load.cpp @@ -200,9 +200,8 @@ static bool readInstrument(MIDIplay::fileReader &file, WOPL_Inst &ins, bool isPe bool MIDIplay::LoadBank(MIDIplay::fileReader &fr) { -#define qqq(x) (void)x size_t fsize; - qqq(fsize); + ADL_UNUSED(fsize); if(!fr.isValid()) { ADLMIDI_ErrorString = "Custom bank: Invalid data stream!"; @@ -296,6 +295,7 @@ bool MIDIplay::LoadBank(MIDIplay::fileReader &fr) } } + opl.AdlBank = opl._parent->AdlBank; opl.dynamic_metainstruments.clear(); opl.dynamic_instruments.clear(); @@ -351,10 +351,7 @@ bool MIDIplay::LoadMIDI(const std::string &filename) file.openFile(filename.c_str()); if(!LoadMIDI(file)) - { - std::perror(filename.c_str()); return false; - } return true; } @@ -368,16 +365,23 @@ bool MIDIplay::LoadMIDI(void *data, unsigned long size) bool MIDIplay::LoadMIDI(MIDIplay::fileReader &fr) { -#define qqq(x) (void)x size_t fsize; - qqq(fsize); + ADL_UNUSED(fsize); //! Temp buffer for conversion AdlMIDI_CPtr cvt_buf; - //std::FILE* fr = std::fopen(filename.c_str(), "rb"); + #ifdef DISABLE_EMBEDDED_BANKS + if((opl.AdlBank != ~0u) || (opl.dynamic_metainstruments.size() < 256)) + { + ADLMIDI_ErrorString = "Bank is not set! Please load any instruments bank by using of adl_openBankFile() or adl_openBankData() functions!"; + return false; + } + #endif + if(!fr.isValid()) { - ADLMIDI_ErrorString = "Invalid data stream!"; + ADLMIDI_ErrorString = "Invalid data stream!\n"; + ADLMIDI_ErrorString += std::strerror(errno); return false; } @@ -429,6 +433,7 @@ bool MIDIplay::LoadMIDI(MIDIplay::fileReader &fr) opl.Reset(); trackStart = true; + atEnd = false; loopStart = true; loopStart_passed = false; invalidLoop = false; -- cgit v1.2.3