--- linuxsampler/trunk/src/engines/gig/Engine.cpp 2005/01/29 15:17:59 354 +++ linuxsampler/trunk/src/engines/gig/Engine.cpp 2005/02/19 02:40:24 392 @@ -26,7 +26,12 @@ #include "EGADSR.h" #include "Engine.h" -#include + +#if defined(__APPLE__) +# include +#else +# include +#endif namespace LinuxSampler { namespace gig { @@ -210,14 +215,31 @@ } /** - * Load an instrument from a .gig file. + * More or less a workaround to set the instrument name, index and load + * status variable to zero percent immediately, that is without blocking + * the calling thread. It might be used in future for other preparations + * as well though. + * + * @param FileName - file name of the Gigasampler instrument file + * @param Instrument - index of the instrument in the .gig file + * @see LoadInstrument() + */ + void Engine::PrepareLoadInstrument(const char* FileName, uint Instrument) { + InstrumentFile = FileName; + InstrumentIdx = Instrument; + InstrumentStat = 0; + } + + /** + * Load an instrument from a .gig file. PrepareLoadInstrument() has to + * be called first to provide the information which instrument to load. + * This method will then actually start to load the instrument and block + * the calling thread until loading was completed. * - * @param FileName - file name of the Gigasampler instrument file - * @param Instrument - index of the instrument in the .gig file - * @throws LinuxSamplerException on error - * @returns detailed description of the method call result + * @returns detailed description of the method call result + * @see PrepareLoadInstrument() */ - void Engine::LoadInstrument(const char* FileName, uint Instrument) { + void Engine::LoadInstrument() { DisableAndLock(); @@ -229,18 +251,14 @@ Instruments.HandBack(pInstrument, this); } - InstrumentFile = FileName; - InstrumentIdx = Instrument; - InstrumentStat = 0; - // delete all key groups ActiveKeyGroups.clear(); // request gig instrument from instrument manager try { instrument_id_t instrid; - instrid.FileName = FileName; - instrid.iInstrument = Instrument; + instrid.FileName = InstrumentFile; + instrid.iInstrument = InstrumentIdx; pInstrument = Instruments.Borrow(instrid, this); if (!pInstrument) { InstrumentStat = -1; @@ -267,6 +285,7 @@ for (::gig::Region* pRegion = pInstrument->GetFirstRegion(); pRegion; pRegion = pInstrument->GetNextRegion()) if (pRegion->KeyGroup) ActiveKeyGroups[pRegion->KeyGroup] = NULL; + InstrumentIdxName = pInstrument->pInfo->Name; InstrumentStat = 100; // inform audio driver for the need of two channels @@ -353,7 +372,12 @@ // (re)allocate synthesis parameter matrix if (pSynthesisParameters[0]) free(pSynthesisParameters[0]); + + #if defined(__APPLE__) + pSynthesisParameters[0] = (float *) malloc(Event::destination_count * sizeof(float) * pAudioOut->MaxSamplesPerCycle()); + #else pSynthesisParameters[0] = (float *) memalign(16,(Event::destination_count * sizeof(float) * pAudioOut->MaxSamplesPerCycle())); + #endif for (int dst = 1; dst < Event::destination_count; dst++) pSynthesisParameters[dst] = pSynthesisParameters[dst - 1] + pAudioOut->MaxSamplesPerCycle(); @@ -1171,6 +1195,10 @@ return InstrumentFile; } + String Engine::InstrumentName() { + return InstrumentIdxName; + } + int Engine::InstrumentIndex() { return InstrumentIdx; } @@ -1184,7 +1212,7 @@ } String Engine::Version() { - String s = "$Revision: 1.22 $"; + String s = "$Revision: 1.25 $"; return s.substr(11, s.size() - 13); // cut dollar signs, spaces and CVS macro keyword }