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

Set SF2 voice tuning relative to initial value #6924

Merged
merged 1 commit into from
Oct 10, 2023
Merged
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: 9 additions & 4 deletions plugins/Sf2Player/Sf2Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,21 +73,25 @@ Plugin::Descriptor PLUGIN_EXPORT sf2player_plugin_descriptor =
}

/**
* A non-owning reference to a single FluidSynth voice, for tracking whether the
* referenced voice is still the same voice that was passed to the constructor.
* A non-owning reference to a single FluidSynth voice. Captures some initial
* properties of the referenced voice to help manage changes to it over time.
*/
class FluidVoice
{
public:
//! Create a reference to the voice currently pointed at by `voice`.
explicit FluidVoice(fluid_voice_t* voice) :
m_voice{voice},
m_id{fluid_voice_get_id(voice)}
m_id{fluid_voice_get_id(voice)},
m_coarseTune{fluid_voice_gen_get(voice, GEN_COARSETUNE)}
{ }

//! Get a pointer to the referenced voice.
fluid_voice_t* get() const noexcept { return m_voice; }

//! Get the original coarse tuning of the referenced voice.
float coarseTune() const noexcept { return m_coarseTune; }

//! Test whether this object still refers to the original voice.
bool isValid() const
{
Expand All @@ -97,6 +101,7 @@ class FluidVoice
private:
fluid_voice_t* m_voice;
unsigned int m_id;
float m_coarseTune;
};

struct Sf2PluginData
Expand Down Expand Up @@ -740,7 +745,7 @@ void Sf2Instrument::playNote( NotePlayHandle * _n, sampleFrame * )
const auto detuning = _n->currentDetuning();
for (const auto& voice : data->fluidVoices) {
if (voice.isValid()) {
fluid_voice_gen_set(voice.get(), GEN_COARSETUNE, detuning);
fluid_voice_gen_set(voice.get(), GEN_COARSETUNE, voice.coarseTune() + detuning);
fluid_voice_update_param(voice.get(), GEN_COARSETUNE);
}
}
Expand Down