Commit 315a4347 authored by Lyberta's avatar Lyberta

Improved sample rate handling.

parent b86405d9
......@@ -50,13 +50,7 @@ template <typename Generator, typename PluginSettings>
void OpenCLPluginTemplate<Generator, PluginSettings>::sampleRateChanged(
double new_sample_rate)
{
this->settings.SetSampleRate(new_sample_rate);
auto generator_settings = synth->GetGeneratorSettings();
generator_settings.SetSampleRate(new_sample_rate);
synth->SetGeneratorSettings(std::move(generator_settings));
auto envelope = synth->GetEnvelopeSettings();
envelope.SetSampleRate(new_sample_rate);
synth->SetEnvelopeSettings(std::move(envelope));
this->SampleRateChanged(*synth, new_sample_rate);
}
}
......@@ -72,6 +72,7 @@ protected:
/// \brief Sets the value of the plugin parameter.
/// \tparam Synth Type of the synth.
/// \param[in,out] synth Synth to change.
/// \param[in] index Index of the parameter.
/// \param[in] value Value to set.
template <typename Synth>
......@@ -90,6 +91,13 @@ protected:
const MidiEvent* midi_events, std::uint32_t midi_event_count)
override;
/// \brief Adjusts the plugin to the new sample rate.
/// \tparam Synth Type of the synth.
/// \param[in,out] synth Synth to adjust.
/// \param[in] new_sample_rate Sample rate to adjust to.
template <typename Synth>
void SampleRateChanged(Synth& synth, double new_sample_rate);
ftz::MIDI::InputChannel channel; ///< Holds the MIDI channel.
/// \brief Holds synth settings.
ftz::Audio::SynthSettings<typename PluginSettings::CalcType> settings;
......
......@@ -250,4 +250,17 @@ void PluginBaseTemplate<PluginSettings>::run(const float**, float** outputs,
effects.Render(first, std::end(buffer));
}
template <typename PluginSettings> template <typename Synth>
void PluginBaseTemplate<PluginSettings>::SampleRateChanged(Synth& synth,
double new_sample_rate)
{
settings.SetSampleRate(new_sample_rate);
auto generator_settings = synth.GetGeneratorSettings();
generator_settings.SetSampleRate(new_sample_rate);
synth.SetGeneratorSettings(std::move(generator_settings));
auto envelope = synth.GetEnvelopeSettings();
envelope.SetSampleRate(new_sample_rate);
synth.SetEnvelopeSettings(std::move(envelope));
}
}
......@@ -48,6 +48,7 @@ inline BaseParameterIndex ToBaseParameterIndex(std::uint32_t index)
return BaseParameterIndex::ReleaseTime;
}
}
throw std::out_of_range{"ToBaseParameterIndex: Invalid index."};
}
template <typename Generator, typename PluginSettings>
......@@ -97,13 +98,7 @@ template <typename Generator, typename PluginSettings>
void PulsePluginTemplate<Generator, PluginSettings>::sampleRateChanged(
double new_sample_rate)
{
this->settings.SetSampleRate(new_sample_rate);
auto generator_settings = synth.GetGeneratorSettings();
generator_settings.SetSampleRate(new_sample_rate);
synth.SetGeneratorSettings(std::move(generator_settings));
auto envelope = synth.GetEnvelopeSettings();
envelope.SetSampleRate(new_sample_rate);
synth.SetEnvelopeSettings(std::move(envelope));
this->SampleRateChanged(synth, new_sample_rate);
}
}
......@@ -48,13 +48,7 @@ template <typename Generator, typename PluginSettings>
void SimplePluginTemplate<Generator, PluginSettings>::sampleRateChanged(
double new_sample_rate)
{
this->settings.SetSampleRate(new_sample_rate);
auto generator_settings = synth.GetGeneratorSettings();
generator_settings.SetSampleRate(new_sample_rate);
synth.SetGeneratorSettings(std::move(generator_settings));
auto envelope = synth.GetEnvelopeSettings();
envelope.SetSampleRate(new_sample_rate);
synth.SetEnvelopeSettings(std::move(envelope));
this->SampleRateChanged(synth, new_sample_rate);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment