Add external input to Lua via extX and extY variables

pull/285/head
DJLevel3 2025-02-17 10:53:01 -05:00
rodzic 15f6a0ffbb
commit 2ec70104cf
6 zmienionych plików z 38 dodań i 5 usunięć

Wyświetl plik

@ -495,6 +495,13 @@ void OscirenderAudioProcessor::processBlock(juce::AudioBuffer<float>& buffer, ju
} else {
juce::SpinLock::ScopedLockType lock1(parsersLock);
juce::SpinLock::ScopedLockType lock2(effectsLock);
for (int i = 0; i < synth.getNumVoices(); i++) {
ShapeVoice* voice = dynamic_cast<ShapeVoice*>(synth.getVoice(i));
if (voice->renderingSample) {
voice->setExternalAudio(inputBuffer);
}
else voice->clearExternalAudio();
}
synth.renderNextBlock(outputBuffer3d, midiMessages, 0, buffer.getNumSamples());
for (int i = 0; i < synth.getNumVoices(); i++) {
auto voice = dynamic_cast<ShapeVoice*>(synth.getVoice(i));

Wyświetl plik

@ -22,7 +22,6 @@ public:
using Ptr = juce::ReferenceCountedObjectPtr<ShapeSound>;
private:
BlockingQueue frames{10};
std::unique_ptr<FrameProducer> producer;
double frameLength = 0.0;

Wyświetl plik

@ -2,6 +2,7 @@
#include "../PluginProcessor.h"
ShapeVoice::ShapeVoice(OscirenderAudioProcessor& p) : audioProcessor(p) {
clearExternalAudio();
actualTraceStart = audioProcessor.trace->getValue(0);
actualTraceLength = audioProcessor.trace->getValue(1);
}
@ -17,6 +18,10 @@ void ShapeVoice::startNote(int midiNoteNumber, float velocity, juce::Synthesiser
currentlyPlaying = true;
this->sound = shapeSound;
auto parser = this->sound.load()->parser;
renderingSample = parser != nullptr && parser->isSample();
if (shapeSound != nullptr) {
int tries = 0;
while (frame.empty() && tries < 50) {
@ -72,9 +77,22 @@ double ShapeVoice::getFrequency() {
void ShapeVoice::updateSound(juce::SynthesiserSound* sound) {
if (currentlyPlaying) {
this->sound = dynamic_cast<ShapeSound*>(sound);
auto parser = this->sound.load()->parser;
renderingSample = parser != nullptr && parser->isSample();
}
}
// Expects 2 or more channes each with 1 or more samples in input buffer, will use empty buffer if this is the case
void ShapeVoice::setExternalAudio(juce::AudioSampleBuffer buf) {
if (buf.getNumChannels() < 2 || buf.getNumSamples() < 1) clearExternalAudio();
else externalAudio = buf;
}
void ShapeVoice::clearExternalAudio() {
externalAudio.clear();
externalAudio.setSize(2, 1, false, true);
}
void ShapeVoice::renderNextBlock(juce::AudioSampleBuffer& outputBuffer, int startSample, int numSamples) {
juce::ScopedNoDenormals noDenormals;
@ -100,15 +118,14 @@ void ShapeVoice::renderNextBlock(juce::AudioSampleBuffer& outputBuffer, int star
double y = 0.0;
double z = 0.0;
bool renderingSample = true;
if (sound.load() != nullptr) {
auto parser = sound.load()->parser;
renderingSample = parser != nullptr && parser->isSample();
if (renderingSample) {
vars.sampleRate = audioProcessor.currentSampleRate;
vars.frequency = actualFrequency;
vars.extX = externalAudio.getSample(0, sample % externalAudio.getNumSamples());
vars.extY = externalAudio.getSample(1, sample % externalAudio.getNumSamples());
std::copy(std::begin(audioProcessor.luaValues), std::end(audioProcessor.luaValues), std::begin(vars.sliders));
channels = parser->nextSample(L, vars);

Wyświetl plik

@ -12,14 +12,16 @@ public:
void startNote(int midiNoteNumber, float velocity, juce::SynthesiserSound* sound, int currentPitchWheelPosition) override;
void updateSound(juce::SynthesiserSound* sound);
void renderNextBlock(juce::AudioSampleBuffer& outputBuffer, int startSample, int numSamples) override;
void setExternalAudio(juce::AudioSampleBuffer buf);
void clearExternalAudio();
void stopNote(float velocity, bool allowTailOff) override;
void pitchWheelMoved(int newPitchWheelValue) override;
void controllerMoved(int controllerNumber, int newControllerValue) override;
void incrementShapeDrawing();
double getFrequency();
bool renderingSample = false;
private:
const double MIN_TRACE = 0.005;
const double MIN_LENGTH_INCREMENT = 0.000001;
@ -51,5 +53,7 @@ private:
double endTime = 99999999;
bool waitingForRelease = false;
juce::AudioSampleBuffer externalAudio;
void noteStopped();
};

Wyświetl plik

@ -445,6 +445,9 @@ void LuaParser::setGlobalVariables(lua_State*& L, LuaVariables& vars) {
setGlobalVariable(L, "y", vars.y);
setGlobalVariable(L, "z", vars.z);
}
setGlobalVariable(L, "extX", vars.extX);
setGlobalVariable(L, "extY", vars.extY);
}
void LuaParser::incrementVars(LuaVariables& vars) {

Wyświetl plik

@ -56,6 +56,9 @@ struct LuaVariables {
double x = 0;
double y = 0;
double z = 0;
double extX = 0;
double extY = 0;
};
struct lua_State;