From f169ff3db3943b9992042e71048cade2ca1fe39d Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Sat, 2 Jul 2016 23:35:00 +0200 Subject: extend lua API: * add a basic FFT spectrum analyzer * prepare Cairo::ImageSurface * HSL colorspace conversion --- libs/ardour/lua_api.cc | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'libs/ardour/lua_api.cc') diff --git a/libs/ardour/lua_api.cc b/libs/ardour/lua_api.cc index 911280305a..94b3f816c3 100644 --- a/libs/ardour/lua_api.cc +++ b/libs/ardour/lua_api.cc @@ -304,3 +304,44 @@ ARDOUR::LuaOSC::Address::send (lua_State *L) luabridge::Stack::push (L, (rv == 0)); return 1; } + +static double hue2rgb (const double p, const double q, double t) { + if (t < 0.0) t += 1.0; + if (t > 1.0) t -= 1.0; + if (t < 1.0 / 6.0) return p + (q - p) * 6.0 * t; + if (t < 1.0 / 2.0) return q; + if (t < 2.0 / 3.0) return p + (q - p) * (2.0 / 3.0 - t) * 6.0; + return p; +} + +int +ARDOUR::LuaAPI::hsla_to_rgba (lua_State *L) +{ + int top = lua_gettop(L); + if (top < 3) { + return luaL_argerror (L, 1, "invalid number of arguments, :hsla_to_rgba (h, s, l [,a])"); + } + double h = luabridge::Stack::get (L, 1); + double s = luabridge::Stack::get (L, 2); + double l = luabridge::Stack::get (L, 3); + double a = 1.0; + if (top > 3) { + a = luabridge::Stack::get (L, 4); + } + + // we can't use ArdourCanvas::hsva_to_color here + // besides we want HSL not HSV and without intermediate + // color_to_rgba (rgba_to_color ()) + double r,g,b; + const double cq = l < 0.5 ? l * (1 + s) : l + s - l * s; + const double cp = 2.f * l - cq; + r = hue2rgb (cp, cq, h + 1.0 / 3.0); + g = hue2rgb (cp, cq, h); + b = hue2rgb (cp, cq, h - 1.0 / 3.0); + + luabridge::Stack::push (L, r); + luabridge::Stack::push (L, g); + luabridge::Stack::push (L, b); + luabridge::Stack::push (L, a); + return 4; +} -- cgit v1.2.3