summaryrefslogtreecommitdiff
path: root/libs/ardour/lua_api.cc
diff options
context:
space:
mode:
authorRobin Gareus <robin@gareus.org>2016-07-02 23:35:00 +0200
committerRobin Gareus <robin@gareus.org>2016-07-02 23:36:34 +0200
commitf169ff3db3943b9992042e71048cade2ca1fe39d (patch)
tree47d8f30c2c88668b48215a115ca03260d9d8c1c7 /libs/ardour/lua_api.cc
parent8b142a2fd6214c51ca1d1ccdcf043c6445141e24 (diff)
extend lua API:
* add a basic FFT spectrum analyzer * prepare Cairo::ImageSurface * HSL colorspace conversion
Diffstat (limited to 'libs/ardour/lua_api.cc')
-rw-r--r--libs/ardour/lua_api.cc41
1 files changed, 41 insertions, 0 deletions
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<bool>::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<double>::get (L, 1);
+ double s = luabridge::Stack<double>::get (L, 2);
+ double l = luabridge::Stack<double>::get (L, 3);
+ double a = 1.0;
+ if (top > 3) {
+ a = luabridge::Stack<double>::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<double>::push (L, r);
+ luabridge::Stack<double>::push (L, g);
+ luabridge::Stack<double>::push (L, b);
+ luabridge::Stack<double>::push (L, a);
+ return 4;
+}