Add scale X/Y/Z, distort Z, Swirl effects, and support 3D Lua files

pull/218/head
James Ball 2024-02-16 21:09:39 +00:00
rodzic 3423ccd893
commit ff1b62dfb3
4 zmienionych plików z 51 dodań i 32 usunięć

Wyświetl plik

@ -35,7 +35,7 @@ OscirenderAudioProcessor::OscirenderAudioProcessor()
toggleableEffects.push_back(std::make_shared<Effect>( toggleableEffects.push_back(std::make_shared<Effect>(
std::make_shared<BitCrushEffect>(), std::make_shared<BitCrushEffect>(),
new EffectParameter("Bit Crush", "Limits the resolution of points drawn to the screen, making the image look pixelated, and making the audio sound more 'digital' and distorted.", "bitCrush", VERSION_HINT, 0.0, 0.0, 1.0) new EffectParameter("Bit Crush", "Limits the resolution of points drawn to the screen, making the object look pixelated, and making the audio sound more 'digital' and distorted.", "bitCrush", VERSION_HINT, 0.0, 0.0, 1.0)
)); ));
toggleableEffects.push_back(std::make_shared<Effect>( toggleableEffects.push_back(std::make_shared<Effect>(
std::make_shared<BulgeEffect>(), std::make_shared<BulgeEffect>(),
@ -45,13 +45,25 @@ OscirenderAudioProcessor::OscirenderAudioProcessor()
std::make_shared<VectorCancellingEffect>(), std::make_shared<VectorCancellingEffect>(),
new EffectParameter("Vector Cancelling", "Inverts the audio and image every few samples to 'cancel out' the audio, making the audio quiet, and distorting the image.", "vectorCancelling", VERSION_HINT, 0.0, 0.0, 1.0) new EffectParameter("Vector Cancelling", "Inverts the audio and image every few samples to 'cancel out' the audio, making the audio quiet, and distorting the image.", "vectorCancelling", VERSION_HINT, 0.0, 0.0, 1.0)
)); ));
toggleableEffects.push_back(std::make_shared<Effect>(
[this](int index, Point input, const std::vector<double>& values, double sampleRate) {
return input * Point(values[0], values[1], values[2]);
}, std::vector<EffectParameter*>{
new EffectParameter("Scale X", "Scales the object in the horizontal direction.", "scaleX", VERSION_HINT, 1.0, -5.0, 5.0),
new EffectParameter("Scale Y", "Scales the object in the vertical direction.", "scaleY", VERSION_HINT, 1.0, -5.0, 5.0),
new EffectParameter("Scale Z", "Scales the depth of the object.", "scaleZ", VERSION_HINT, 1.0, -5.0, 5.0),
}
));
toggleableEffects.push_back(std::make_shared<Effect>( toggleableEffects.push_back(std::make_shared<Effect>(
std::make_shared<DistortEffect>(false), [this](int index, Point input, const std::vector<double>& values, double sampleRate) {
new EffectParameter("Distort X", "Distorts the image in the horizontal direction by jittering the audio sample being drawn.", "distortX", VERSION_HINT, 0.0, 0.0, 1.0) int flip = index % 2 == 0 ? 1 : -1;
)); Point jitter = Point(flip * values[0], flip * values[1], flip * values[2]);
toggleableEffects.push_back(std::make_shared<Effect>( return input + jitter;
std::make_shared<DistortEffect>(true), }, std::vector<EffectParameter*>{
new EffectParameter("Distort Y", "Distorts the image in the vertical direction by jittering the audio sample being drawn.", "distortY", VERSION_HINT, 0.0, 0.0, 1.0) new EffectParameter("Distort X", "Distorts the image in the horizontal direction by jittering the audio sample being drawn.", "distortX", VERSION_HINT, 0.0, 0.0, 1.0),
new EffectParameter("Distort Y", "Distorts the image in the vertical direction by jittering the audio sample being drawn.", "distortY", VERSION_HINT, 0.0, 0.0, 1.0),
new EffectParameter("Distort Z", "Distorts the depth of the image by jittering the audio sample being drawn.", "distortZ", VERSION_HINT, 0.0, 0.0, 1.0),
}
)); ));
toggleableEffects.push_back(std::make_shared<Effect>( toggleableEffects.push_back(std::make_shared<Effect>(
[this](int index, Point input, const std::vector<double>& values, double sampleRate) { [this](int index, Point input, const std::vector<double>& values, double sampleRate) {
@ -77,16 +89,23 @@ OscirenderAudioProcessor::OscirenderAudioProcessor()
)); ));
toggleableEffects.push_back(std::make_shared<Effect>( toggleableEffects.push_back(std::make_shared<Effect>(
[this](int index, Point input, const std::vector<double>& values, double sampleRate) { [this](int index, Point input, const std::vector<double>& values, double sampleRate) {
input.x += values[0]; return input + Point(values[0], values[1], values[2]);
input.y += values[1];
input.z += values[2];
return input;
}, std::vector<EffectParameter*>{ }, std::vector<EffectParameter*>{
new EffectParameter("Translate X", "Moves the object horizontally.", "translateX", VERSION_HINT, 0.0, -1.0, 1.0), new EffectParameter("Translate X", "Moves the object horizontally.", "translateX", VERSION_HINT, 0.0, -1.0, 1.0),
new EffectParameter("Translate Y", "Moves the object vertically.", "translateY", VERSION_HINT, 0.0, -1.0, 1.0), new EffectParameter("Translate Y", "Moves the object vertically.", "translateY", VERSION_HINT, 0.0, -1.0, 1.0),
new EffectParameter("Translate Z", "Moves the object away from the camera.", "translateZ", VERSION_HINT, 0.0, -1.0, 1.0), new EffectParameter("Translate Z", "Moves the object away from the camera.", "translateZ", VERSION_HINT, 0.0, -1.0, 1.0),
} }
)); ));
toggleableEffects.push_back(std::make_shared<Effect>(
[this](int index, Point input, const std::vector<double>& values, double sampleRate) {
double length = 10 * values[0] * input.magnitude();
double newX = input.x * std::cos(length) - input.y * std::sin(length);
double newY = input.x * std::sin(length) + input.y * std::cos(length);
return Point(newX, newY, input.z);
}, std::vector<EffectParameter*>{
new EffectParameter("Swirl", "Swirls the image in a spiral pattern.", "swirl", VERSION_HINT, 0.0, -1.0, 1.0),
}
));
toggleableEffects.push_back(std::make_shared<Effect>( toggleableEffects.push_back(std::make_shared<Effect>(
std::make_shared<SmoothEffect>(), std::make_shared<SmoothEffect>(),
new EffectParameter("Smoothing", "This works as a low-pass frequency filter that removes high frequencies, making the image look smoother, and audio sound less harsh.", "smoothing", VERSION_HINT, 0.0, 0.0, 1.0) new EffectParameter("Smoothing", "This works as a low-pass frequency filter that removes high frequencies, making the image look smoother, and audio sound less harsh.", "smoothing", VERSION_HINT, 0.0, 0.0, 1.0)

Wyświetl plik

@ -86,7 +86,7 @@ void SettingsComponent::mouseMove(const juce::MouseEvent& event) {
} }
void SettingsComponent::mouseDown(const juce::MouseEvent& event) { void SettingsComponent::mouseDown(const juce::MouseEvent& event) {
for (int i = 0; i < 4; i++) { for (int i = 0; i < 1; i++) {
if (toggleComponents[i]->getBounds().removeFromTop(pluginEditor.CLOSED_PREF_SIZE).contains(event.getPosition())) { if (toggleComponents[i]->getBounds().removeFromTop(pluginEditor.CLOSED_PREF_SIZE).contains(event.getPosition())) {
pluginEditor.toggleLayout(*toggleLayouts[i], prefSizes[i]); pluginEditor.toggleLayout(*toggleLayouts[i], prefSizes[i]);
resized(); resized();

Wyświetl plik

@ -18,33 +18,33 @@ void LuaParser::reset(lua_State*& L, juce::String script) {
void LuaParser::reportError(const char* errorChars) { void LuaParser::reportError(const char* errorChars) {
std::string error = errorChars; std::string error = errorChars;
std::regex nilRegex = std::regex(R"(attempt to.*nil value.*'slider_\w')"); std::regex nilRegex = std::regex(R"(attempt to.*nil value.*'slider_\w')");
// ignore nil errors about global variables, these are likely caused by other errors // ignore nil errors about global variables, these are likely caused by other errors
if (std::regex_search(error, nilRegex)) { if (std::regex_search(error, nilRegex)) {
return; return;
} }
// remove any newlines from error message // remove any newlines from error message
error = std::regex_replace(error, std::regex(R"(\n|\r)"), ""); error = std::regex_replace(error, std::regex(R"(\n|\r)"), "");
// remove script content from error message // remove script content from error message
error = std::regex_replace(error, std::regex(R"(^\[string ".*"\]:)"), ""); error = std::regex_replace(error, std::regex(R"(^\[string ".*"\]:)"), "");
// extract line number from start of error message // extract line number from start of error message
std::regex lineRegex(R"(^(\d+): )"); std::regex lineRegex(R"(^(\d+): )");
std::smatch lineMatch; std::smatch lineMatch;
std::regex_search(error, lineMatch, lineRegex); std::regex_search(error, lineMatch, lineRegex);
if (lineMatch.size() > 1) { if (lineMatch.size() > 1) {
int line = std::stoi(lineMatch[1]); int line = std::stoi(lineMatch[1]);
// remove line number from error message // remove line number from error message
error = std::regex_replace(error, lineRegex, ""); error = std::regex_replace(error, lineRegex, "");
errorCallback(line, fileName, error); errorCallback(line, fileName, error);
} }
} }
void LuaParser::parse(lua_State*& L) { void LuaParser::parse(lua_State*& L) {
const int ret = luaL_loadstring(L, script.toUTF8()); const int ret = luaL_loadstring(L, script.toUTF8());
if (ret != 0) { if (ret != 0) {
const char* error = lua_tostring(L, -1); const char* error = lua_tostring(L, -1);
reportError(error); reportError(error);
lua_pop(L, 1); lua_pop(L, 1);
functionRef = -1; functionRef = -1;
@ -96,8 +96,8 @@ std::vector<float> LuaParser::run(lua_State*& L, const LuaVariables vars, long&
if (lua_isfunction(L, -1)) { if (lua_isfunction(L, -1)) {
const int ret = lua_pcall(L, 0, LUA_MULTRET, 0); const int ret = lua_pcall(L, 0, LUA_MULTRET, 0);
if (ret != LUA_OK) { if (ret != LUA_OK) {
const char* error = lua_tostring(L, -1); const char* error = lua_tostring(L, -1);
reportError(error); reportError(error);
functionRef = -1; functionRef = -1;
usingFallbackScript = true; usingFallbackScript = true;

Wyświetl plik

@ -53,7 +53,7 @@ Point FileParser::nextSample(lua_State*& L, const LuaVariables vars, long& step,
if (values.size() < 2) { if (values.size() < 2) {
return Point(); return Point();
} }
return Point(values[0], values[1]); return Point(values[0], values[1], values[2]);
} }
} }