Direct OSC updates into the regions
This commit is contained in:
parent
ce246e0f1b
commit
7b6eb953c6
3 changed files with 31 additions and 60 deletions
|
|
@ -898,26 +898,6 @@ void Synth::setSampleRate(float sampleRate) noexcept
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Synth::Impl::updateRegions() noexcept
|
|
||||||
{
|
|
||||||
std::unique_lock<SpinMutex> lock { regionUpdatesMutex_, std::try_to_lock };
|
|
||||||
if (!lock.owns_lock())
|
|
||||||
return;
|
|
||||||
|
|
||||||
absl::c_sort(regionUpdates_, [](const OpcodeUpdate& lhs, const OpcodeUpdate& rhs) {
|
|
||||||
return lhs.delay < rhs.delay;
|
|
||||||
});
|
|
||||||
|
|
||||||
for (auto& update: regionUpdates_) {
|
|
||||||
if (!update.region)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
update.region->parseOpcode(update.opcode, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
regionUpdates_.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Synth::renderBlock(AudioSpan<float> buffer) noexcept
|
void Synth::renderBlock(AudioSpan<float> buffer) noexcept
|
||||||
{
|
{
|
||||||
Impl& impl = *impl_;
|
Impl& impl = *impl_;
|
||||||
|
|
@ -947,8 +927,6 @@ void Synth::renderBlock(AudioSpan<float> buffer) noexcept
|
||||||
impl.resources_.filePool.triggerGarbageCollection();
|
impl.resources_.filePool.triggerGarbageCollection();
|
||||||
}
|
}
|
||||||
|
|
||||||
impl.updateRegions();
|
|
||||||
|
|
||||||
auto tempSpan = impl.resources_.bufferPool.getStereoBuffer(numFrames);
|
auto tempSpan = impl.resources_.bufferPool.getStereoBuffer(numFrames);
|
||||||
auto tempMixSpan = impl.resources_.bufferPool.getStereoBuffer(numFrames);
|
auto tempMixSpan = impl.resources_.bufferPool.getStereoBuffer(numFrames);
|
||||||
auto rampSpan = impl.resources_.bufferPool.getBuffer(numFrames);
|
auto rampSpan = impl.resources_.bufferPool.getBuffer(numFrames);
|
||||||
|
|
|
||||||
|
|
@ -1364,45 +1364,54 @@ void sfz::Synth::dispatchMessage(Client& client, int delay, const char* path, co
|
||||||
Layer& layer = *impl.layers_[idx]; \
|
Layer& layer = *impl.layers_[idx]; \
|
||||||
Region& region = layer.getRegion();
|
Region& region = layer.getRegion();
|
||||||
|
|
||||||
|
#define GET_FILTER_OR_BREAK(idx) \
|
||||||
|
if (idx >= region.filters.size()) \
|
||||||
|
break; \
|
||||||
|
auto& filter = region.filters[idx];
|
||||||
|
|
||||||
|
#define GET_LFO_OR_BREAK(idx) \
|
||||||
|
if (idx >= region.lfos.size()) \
|
||||||
|
break; \
|
||||||
|
auto& lfo = region.lfos[idx];
|
||||||
|
|
||||||
|
#define GET_LFO_SUB_OR_BREAK(idx) \
|
||||||
|
if (idx >= lfo.sub.size()) \
|
||||||
|
break; \
|
||||||
|
auto& sub = lfo.sub[idx];
|
||||||
|
|
||||||
MATCH("/region&/pitch_keycenter", "i") {
|
MATCH("/region&/pitch_keycenter", "i") {
|
||||||
GET_REGION_OR_BREAK(indices[0])
|
GET_REGION_OR_BREAK(indices[0])
|
||||||
std::lock_guard<SpinMutex> lock { impl.regionUpdatesMutex_ };
|
region.pitchKeycenter = Opcode::transform(Default::key, args[0].i);
|
||||||
Impl::OpcodeUpdate update { delay, ®ion,
|
|
||||||
Opcode { "pitch_keycenter", std::to_string(args[0].i) } };
|
|
||||||
impl.regionUpdates_.emplace_back(update);
|
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
MATCH("/region&/loop_mode", "s") {
|
MATCH("/region&/loop_mode", "s") {
|
||||||
GET_REGION_OR_BREAK(indices[0])
|
GET_REGION_OR_BREAK(indices[0])
|
||||||
std::lock_guard<SpinMutex> lock { impl.regionUpdatesMutex_ };
|
region.loopMode = Opcode::readOptional(Default::loopMode, args[0].s);
|
||||||
Impl::OpcodeUpdate update { delay, ®ion,
|
|
||||||
Opcode { "loop_mode", args[0].s } };
|
|
||||||
impl.regionUpdates_.emplace_back(update);
|
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
MATCH("/region&/filter&/type", "s") {
|
MATCH("/region&/filter&/type", "s") {
|
||||||
GET_REGION_OR_BREAK(indices[0])
|
GET_REGION_OR_BREAK(indices[0])
|
||||||
if (indices[1] >= region.filters.size())
|
GET_FILTER_OR_BREAK(indices[1])
|
||||||
break;
|
filter.type = Opcode::read(Default::filter, args[0].s);
|
||||||
|
|
||||||
std::lock_guard<SpinMutex> lock { impl.regionUpdatesMutex_ };
|
|
||||||
Impl::OpcodeUpdate update { delay, ®ion,
|
|
||||||
Opcode { absl::StrCat("fil", indices[1] + 1 , "_type "), args[0].s } };
|
|
||||||
impl.regionUpdates_.emplace_back(update);
|
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
MATCH("/region&/lfo&/wave", "i") {
|
MATCH("/region&/lfo&/wave", "i") {
|
||||||
GET_REGION_OR_BREAK(indices[0])
|
indices[2] = 0;
|
||||||
if (indices[1] >= region.lfos.size())
|
goto set_lfoN_wave;
|
||||||
break;
|
}
|
||||||
|
|
||||||
std::lock_guard<SpinMutex> lock { impl.regionUpdatesMutex_ };
|
MATCH("/region&/lfo&/wave&", "i") {
|
||||||
Impl::OpcodeUpdate update { delay, ®ion,
|
set_lfoN_wave:
|
||||||
Opcode { absl::StrCat("lfo", indices[1] + 1, "_wave1"), std::to_string(args[0].i) } };
|
GET_REGION_OR_BREAK(indices[0])
|
||||||
impl.regionUpdates_.emplace_back(update);
|
GET_LFO_OR_BREAK(indices[1])
|
||||||
|
GET_LFO_SUB_OR_BREAK(indices[2])
|
||||||
|
sub.wave = Opcode::transform(Default::lfoWave, args[0].i);
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
#undef GET_REGION_OR_BREAK
|
#undef GET_REGION_OR_BREAK
|
||||||
|
#undef GET_FILTER_OR_BREAK
|
||||||
|
#undef GET_LFO_OR_BREAK
|
||||||
|
#undef GET_LFO_SUB_OR_BREAK
|
||||||
|
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
// Voices
|
// Voices
|
||||||
|
|
|
||||||
|
|
@ -180,12 +180,6 @@ struct Synth::Impl final: public Parser::Listener {
|
||||||
*/
|
*/
|
||||||
void finalizeSfzLoad();
|
void finalizeSfzLoad();
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Update the regions with the opcodes received through OSC if necessary
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
void updateRegions() noexcept;
|
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
static void collectUsedCCsFromCCMap(BitArray<config::numCCs>& usedCCs, const CCMap<T> map) noexcept
|
static void collectUsedCCsFromCCMap(BitArray<config::numCCs>& usedCCs, const CCMap<T> map) noexcept
|
||||||
{
|
{
|
||||||
|
|
@ -348,16 +342,6 @@ struct Synth::Impl final: public Parser::Listener {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool playheadMoved_ { false };
|
bool playheadMoved_ { false };
|
||||||
|
|
||||||
struct OpcodeUpdate
|
|
||||||
{
|
|
||||||
int delay;
|
|
||||||
Region* region;
|
|
||||||
Opcode opcode;
|
|
||||||
};
|
|
||||||
|
|
||||||
std::vector<OpcodeUpdate> regionUpdates_;
|
|
||||||
SpinMutex regionUpdatesMutex_;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace sfz
|
} // namespace sfz
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue