2 |
* * |
* * |
3 |
* libsf2 - C++ cross-platform SF2 format file access library * |
* libsf2 - C++ cross-platform SF2 format file access library * |
4 |
* * |
* * |
5 |
* Copyright (C) 2009 Grigor Iliev <grigor@grigoriliev.com> * |
* Copyright (C) 2009-2010 Grigor Iliev <grigor@grigoriliev.com>, * |
6 |
* Copyright (C) 2009 Christian Schoenebeck * |
* Christian Schoenebeck and Andreas Persson * |
|
* Copyright (C) 2009 Andreas Persson * |
|
7 |
* * |
* * |
8 |
* This library is free software; you can redistribute it and/or modify * |
* This library is free software; you can redistribute it and/or modify * |
9 |
* it under the terms of the GNU General Public License as published by * |
* it under the terms of the GNU General Public License as published by * |
21 |
* MA 02111-1307 USA * |
* MA 02111-1307 USA * |
22 |
***************************************************************************/ |
***************************************************************************/ |
23 |
|
|
|
#include <vector> |
|
|
|
|
24 |
#include "RIFF.h" |
#include "RIFF.h" |
25 |
|
|
26 |
#include "SF.h" |
#include "SF.h" |
613 |
if (pPresetRegion == NULL || pPresetRegion->freqModLfo == NONE) return ToHz(freqModLfo); |
if (pPresetRegion == NULL || pPresetRegion->freqModLfo == NONE) return ToHz(freqModLfo); |
614 |
return ToHz(pPresetRegion->freqModLfo + freqModLfo); |
return ToHz(pPresetRegion->freqModLfo + freqModLfo); |
615 |
} |
} |
616 |
|
|
617 |
double Region::GetDelayModLfo(Region* pPresetRegion) { |
double Region::GetDelayModLfo(Region* pPresetRegion) { |
618 |
if (pPresetRegion == NULL || pPresetRegion->delayModLfo == NONE) return ToSeconds(delayModLfo); |
if (pPresetRegion == NULL || pPresetRegion->delayModLfo == NONE) return ToSeconds(delayModLfo); |
619 |
return ToSeconds(pPresetRegion->delayModLfo + delayModLfo); |
return ToSeconds(pPresetRegion->delayModLfo + delayModLfo); |
657 |
return regions[idx]; |
return regions[idx]; |
658 |
} |
} |
659 |
|
|
660 |
std::vector<Region*> InstrumentBase::GetRegionsOnKey(int key, uint8_t vel) { |
Query::Query(InstrumentBase& instrument) : instrument(instrument) { |
661 |
std::vector<Region*> v; |
i = 0; |
662 |
for (int i = 0; i < GetRegionCount(); i++) { |
} |
663 |
Region* r = GetRegion(i); |
|
664 |
if ( |
Region* Query::next() { |
665 |
((r->loKey == NONE && r->hiKey == NONE) || (key >= r->loKey && key <= r->hiKey)) && |
while (i < instrument.GetRegionCount()) { |
666 |
((r->minVel == NONE && r->maxVel == NONE) || (vel >= r->minVel && vel <= r->maxVel)) |
Region* r = instrument.GetRegion(i++); |
667 |
) { |
if (((r->loKey == NONE && r->hiKey == NONE) || (key >= r->loKey && key <= r->hiKey)) && |
668 |
v.push_back(r); |
((r->minVel == NONE && r->maxVel == NONE) || (vel >= r->minVel && vel <= r->maxVel))) { |
669 |
|
return r; |
670 |
} |
} |
671 |
} |
} |
672 |
|
return 0; |
|
return v; |
|
673 |
} |
} |
674 |
|
|
675 |
Instrument::Instrument(sf2::File* pFile, RIFF::Chunk* ck) : InstrumentBase(pFile) { |
Instrument::Instrument(sf2::File* pFile, RIFF::Chunk* ck) : InstrumentBase(pFile) { |
679 |
} |
} |
680 |
|
|
681 |
Instrument::~Instrument() { |
Instrument::~Instrument() { |
|
|
|
682 |
} |
} |
683 |
|
|
684 |
Region* Instrument::CreateRegion() { |
Region* Instrument::CreateRegion() { |
767 |
} |
} |
768 |
|
|
769 |
Region* reg = CreateRegion(); |
Region* reg = CreateRegion(); |
770 |
|
|
771 |
for (int j = gIdx1; j < gIdx2; j++) { |
for (int j = gIdx1; j < gIdx2; j++) { |
772 |
reg->SetGenerator(pFile, pFile->InstGenLists[j]); |
reg->SetGenerator(pFile, pFile->InstGenLists[j]); |
773 |
// TODO: ignore generators following a sampleID generator |
// TODO: ignore generators following a sampleID generator |
802 |
} |
} |
803 |
|
|
804 |
Preset::~Preset() { |
Preset::~Preset() { |
|
|
|
805 |
} |
} |
806 |
|
|
807 |
Region* Preset::CreateRegion() { |
Region* Preset::CreateRegion() { |
1069 |
if (Samples[i]) delete (Samples[i]); |
if (Samples[i]) delete (Samples[i]); |
1070 |
} |
} |
1071 |
} |
} |
1072 |
|
|
1073 |
int File::GetPresetCount() { |
int File::GetPresetCount() { |
1074 |
return Presets.size() - 1; // exclude terminal preset (EOP) |
return Presets.size() - 1; // exclude terminal preset (EOP) |
1075 |
} |
} |
1180 |
* that the size is given in bytes! You get the number of actually cached |
* that the size is given in bytes! You get the number of actually cached |
1181 |
* samples by dividing it by the frame size of the sample: |
* samples by dividing it by the frame size of the sample: |
1182 |
* @code |
* @code |
1183 |
* buffer_t buf = pSample->LoadSampleData(acquired_samples); |
* buffer_t buf = pSample->LoadSampleData(acquired_samples); |
1184 |
* long cachedsamples = buf.Size / pSample->FrameSize; |
* long cachedsamples = buf.Size / pSample->FrameSize; |
1185 |
* @endcode |
* @endcode |
1186 |
* |
* |
1187 |
* @param SampleCount - number of sample points to load into RAM |
* @param SampleCount - number of sample points to load into RAM |
1225 |
* that the size is given in bytes! You get the number of actually cached |
* that the size is given in bytes! You get the number of actually cached |
1226 |
* samples by dividing it by the frame size of the sample: |
* samples by dividing it by the frame size of the sample: |
1227 |
* @code |
* @code |
1228 |
* buffer_t buf = pSample->LoadSampleDataWithNullSamplesExtension(acquired_samples, null_samples); |
* buffer_t buf = pSample->LoadSampleDataWithNullSamplesExtension(acquired_samples, null_samples); |
1229 |
* long cachedsamples = buf.Size / pSample->FrameSize; |
* long cachedsamples = buf.Size / pSample->FrameSize; |
1230 |
* @endcode |
* @endcode |
1231 |
* The method will add \a NullSamplesCount silence samples past the |
* The method will add \a NullSamplesCount silence samples past the |
1232 |
* official buffer end (this won't affect the 'Size' member of the |
* official buffer end (this won't affect the 'Size' member of the |
1332 |
if (SampleCount == 0) return 0; |
if (SampleCount == 0) return 0; |
1333 |
long pos = GetPos(); |
long pos = GetPos(); |
1334 |
if (pos + SampleCount > GetTotalFrameCount()) SampleCount = GetTotalFrameCount() - pos; |
if (pos + SampleCount > GetTotalFrameCount()) SampleCount = GetTotalFrameCount() - pos; |
1335 |
|
|
1336 |
if (GetFrameSize() / GetChannelCount() == 3 /* 24 bit */) { |
if (GetFrameSize() / GetChannelCount() == 3 /* 24 bit */) { |
1337 |
uint8_t* pBuf = (uint8_t*)pBuffer; |
uint8_t* pBuf = (uint8_t*)pBuffer; |
1338 |
if (SampleType == MONO_SAMPLE || SampleType == ROM_MONO_SAMPLE) { |
if (SampleType == MONO_SAMPLE || SampleType == ROM_MONO_SAMPLE) { |