Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the API to receive hdcc values #244

Merged
merged 1 commit into from
Jun 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/sfizz.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,19 @@ SFIZZ_EXPORTED_API void sfizz_send_note_off(sfizz_synth_t* synth, int delay, int
*/
SFIZZ_EXPORTED_API void sfizz_send_cc(sfizz_synth_t* synth, int delay, int cc_number, char cc_value);

/**
* @brief Send a high precision CC event to the synth. As with all MIDI
* events, this needs to happen before the call to
* sfizz_render_block in each block and should appear in order of
* the delays.
*
* @param synth The synth.
* @param delay The delay of the event in the block, in samples.
* @param cc_number The MIDI CC number.
* @param norm_value The normalized CC value, in domain 0 to 1.
*/
SFIZZ_EXPORTED_API void sfizz_send_hdcc(sfizz_synth_t* synth, int delay, int cc_number, float norm_value);

/**
* @brief Send a pitch wheel event. As with all MIDI events, this needs
* to happen before the call to sfizz_render_block in each block and
Expand Down
10 changes: 10 additions & 0 deletions src/sfizz.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,16 @@ class SFIZZ_EXPORTED_API Sfizz
*/
void cc(int delay, int ccNumber, uint8_t ccValue) noexcept;

/**
* @brief Send a high precision CC event to the synth
*
* @param delay the delay at which the event occurs; this should be lower than the size of
* the block in the next call to renderBlock().
* @param ccNumber the cc number.
* @param normValue the normalized cc value, in domain 0 to 1.
*/
void hdcc(int delay, int ccNumber, float normValue) noexcept;

/**
* @brief Send a pitch bend event to the synth
*
Expand Down
15 changes: 10 additions & 5 deletions src/sfizz/Synth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -844,13 +844,18 @@ void sfz::Synth::noteOnDispatch(int delay, int noteNumber, float velocity) noexc
}

void sfz::Synth::cc(int delay, int ccNumber, uint8_t ccValue) noexcept
{
const auto normalizedCC = normalizeCC(ccValue);
hdcc(delay, ccNumber, normalizedCC);
}

void sfz::Synth::hdcc(int delay, int ccNumber, float normValue) noexcept
{
ASSERT(ccNumber < config::numCCs);
ASSERT(ccNumber >= 0);
const auto normalizedCC = normalizeCC(ccValue);

ScopedTiming logger { dispatchDuration, ScopedTiming::Operation::addToDuration };
resources.midiState.ccEvent(delay, ccNumber, normalizedCC);
resources.midiState.ccEvent(delay, ccNumber, normValue);
paulfd marked this conversation as resolved.
Show resolved Hide resolved

const std::unique_lock<std::mutex> lock { callbackGuard, std::try_to_lock };
if (!lock.owns_lock())
Expand All @@ -862,15 +867,15 @@ void sfz::Synth::cc(int delay, int ccNumber, uint8_t ccValue) noexcept
}

for (auto& voice : voices)
voice->registerCC(delay, ccNumber, normalizedCC);
voice->registerCC(delay, ccNumber, normValue);

for (auto& region : ccActivationLists[ccNumber]) {
if (region->registerCC(ccNumber, normalizedCC)) {
if (region->registerCC(ccNumber, normValue)) {
auto voice = findFreeVoice();
if (voice == nullptr)
continue;

voice->startVoice(region, delay, ccNumber, normalizedCC, Voice::TriggerType::CC);
voice->startVoice(region, delay, ccNumber, normValue, Voice::TriggerType::CC);
}
}
}
Expand Down
9 changes: 9 additions & 0 deletions src/sfizz/Synth.h
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,15 @@ class Synth final : public Parser::Listener {
* @param ccValue the cc value
*/
void cc(int delay, int ccNumber, uint8_t ccValue) noexcept;
/**
* @brief Send a high precision CC event to the synth
*
* @param delay the delay at which the event occurs; this should be lower than the size of
* the block in the next call to renderBlock().
* @param ccNumber the cc number
* @param normValue the normalized cc value, in domain 0 to 1
*/
void hdcc(int delay, int ccNumber, float normValue) noexcept;
/**
* @brief Send a pitch bend event to the synth
*
Expand Down
5 changes: 5 additions & 0 deletions src/sfizz/sfizz.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ void sfz::Sfizz::cc(int delay, int ccNumber, uint8_t ccValue) noexcept
synth->cc(delay, ccNumber, ccValue);
}

void sfz::Sfizz::hdcc(int delay, int ccNumber, float normValue) noexcept
{
synth->hdcc(delay, ccNumber, normValue);
}

void sfz::Sfizz::pitchWheel(int delay, int pitch) noexcept
{
synth->pitchWheel(delay, pitch);
Expand Down
5 changes: 5 additions & 0 deletions src/sfizz/sfizz_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ void sfizz_send_cc(sfizz_synth_t* synth, int delay, int cc_number, char cc_value
auto self = reinterpret_cast<sfz::Synth*>(synth);
self->cc(delay, cc_number, cc_value);
}
void sfizz_send_hdcc(sfizz_synth_t* synth, int delay, int cc_number, float norm_value)
{
auto self = reinterpret_cast<sfz::Synth*>(synth);
self->hdcc(delay, cc_number, norm_value);
}
void sfizz_send_pitch_wheel(sfizz_synth_t* synth, int delay, int pitch)
{
auto self = reinterpret_cast<sfz::Synth*>(synth);
Expand Down