Allow Lua effects to access frequency, step, phase, sampleRate variables

pull/218/head
James Ball 2024-02-22 13:10:24 +00:00
rodzic d553e94c6f
commit 6802455301
5 zmienionych plików z 27 dodań i 6 usunięć

Wyświetl plik

@ -617,6 +617,13 @@ void OscirenderAudioProcessor::processBlock(juce::AudioBuffer<float>& buffer, ju
juce::SpinLock::ScopedLockType lock1(parsersLock);
juce::SpinLock::ScopedLockType lock2(effectsLock);
synth.renderNextBlock(outputBuffer3d, midiMessages, 0, buffer.getNumSamples());
for (int i = 0; i < synth.getNumVoices(); i++) {
auto voice = dynamic_cast<ShapeVoice*>(synth.getVoice(i));
if (voice->isVoiceActive()) {
customEffect->frequency = voice->getFrequency();
break;
}
}
}
midiMessages.clear();

Wyświetl plik

@ -24,17 +24,23 @@ Point CustomEffect::apply(int index, Point input, const std::vector<double>& val
parser->setVariable("y", y);
parser->setVariable("z", z);
auto result = parser->run(L, LuaVariables{sampleRate, 0}, step, phase);
if (result.size() >= 3) {
auto result = parser->run(L, LuaVariables{sampleRate, frequency}, step, phase);
if (result.size() >= 2) {
x = result[0];
y = result[1];
z = result[2];
if (result.size() >= 3) {
z = result[2];
}
}
} else {
parser->resetErrors();
}
}
step++;
phase += 2 * std::numbers::pi * frequency / sampleRate;
phase = MathUtil::wrapAngle(phase);
return Point(
(1 - effectScale) * input.x + effectScale * x,
(1 - effectScale) * input.y + effectScale * y,

Wyświetl plik

@ -18,6 +18,8 @@ public:
juce::String getCode();
double frequency = 0;
private:
const juce::String DEFAULT_SCRIPT = "return { x, y, z }";
juce::String code = DEFAULT_SCRIPT;

Wyświetl plik

@ -63,6 +63,10 @@ void ShapeVoice::incrementShapeDrawing() {
}
}
double ShapeVoice::getFrequency() {
return actualFrequency;
}
// should be called if the current file is changed so that we interrupt
// any currently playing sounds / voices
void ShapeVoice::updateSound(juce::SynthesiserSound* sound) {
@ -76,9 +80,9 @@ void ShapeVoice::renderNextBlock(juce::AudioSampleBuffer& outputBuffer, int star
int numChannels = outputBuffer.getNumChannels();
float actualFrequency = frequency * pitchWheelAdjustment;
if (!audioProcessor.midiEnabled->getBoolValue()) {
if (audioProcessor.midiEnabled->getBoolValue()) {
actualFrequency = frequency * pitchWheelAdjustment;
} else {
actualFrequency = audioProcessor.frequency;
}

Wyświetl plik

@ -18,6 +18,7 @@ public:
void incrementShapeDrawing();
double getFrequency();
private:
const double MIN_TRACE = 0.005;
@ -37,6 +38,7 @@ private:
bool currentlyPlaying = false;
double frequency = 1.0;
std::atomic<double> actualFrequency = 1.0;
double velocity = 1.0;
double pitchWheelAdjustment = 1.0;