From f05f19bdd4c376d8427f488ab9c812df4d400fbc Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Thu, 8 Dec 2016 12:44:36 +0100 Subject: add Lua bindings for Timecode conversion --- libs/ardour/lua_api.cc | 122 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 122 insertions(+) (limited to 'libs/ardour/lua_api.cc') diff --git a/libs/ardour/lua_api.cc b/libs/ardour/lua_api.cc index 6a2dbbe9f6..5af9a6c960 100644 --- a/libs/ardour/lua_api.cc +++ b/libs/ardour/lua_api.cc @@ -252,6 +252,128 @@ ARDOUR::LuaAPI::plugin_automation (lua_State *L) return 3; } +int +ARDOUR::LuaAPI::sample_to_timecode (lua_State *L) +{ + int top = lua_gettop (L); + if (top < 3) { + return luaL_argerror (L, 1, "invalid number of arguments sample_to_timecode (TimecodeFormat, sample_rate, sample)"); + } + typedef Timecode::TimecodeFormat T; + T tf = luabridge::Stack::get (L, 1); + double sample_rate = luabridge::Stack::get (L, 2); + int64_t sample = luabridge::Stack::get (L, 3); + + Timecode::Time timecode; + + Timecode::sample_to_timecode ( + sample, timecode, false, false, + Timecode::timecode_to_frames_per_second (tf), + Timecode::timecode_has_drop_frames (tf), + sample_rate, + 0, false, 0); + + luabridge::Stack::push (L, timecode.hours); + luabridge::Stack::push (L, timecode.minutes); + luabridge::Stack::push (L, timecode.seconds); + luabridge::Stack::push (L, timecode.frames); + return 4; +} + +int +ARDOUR::LuaAPI::timecode_to_sample (lua_State *L) +{ + int top = lua_gettop (L); + if (top < 6) { + return luaL_argerror (L, 1, "invalid number of arguments sample_to_timecode (TimecodeFormat, sample_rate, hh, mm, ss, ff)"); + } + typedef Timecode::TimecodeFormat T; + T tf = luabridge::Stack::get (L, 1); + double sample_rate = luabridge::Stack::get (L, 2); + int hh = luabridge::Stack::get (L, 3); + int mm = luabridge::Stack::get (L, 4); + int ss = luabridge::Stack::get (L, 5); + int ff = luabridge::Stack::get (L, 6); + + Timecode::Time timecode; + timecode.negative = false; + timecode.hours = hh; + timecode.minutes = mm; + timecode.seconds = ss; + timecode.frames = ff; + timecode.subframes = 0; + timecode.rate = Timecode::timecode_to_frames_per_second (tf); + timecode.drop = Timecode::timecode_has_drop_frames (tf); + + int64_t sample; + + Timecode::timecode_to_sample ( + timecode, sample, false, false, + sample_rate, 0, false, 0); + + luabridge::Stack::push (L, sample); + return 1; +} + +int +ARDOUR::LuaAPI::sample_to_timecode_lua (lua_State *L) +{ + int top = lua_gettop (L); + if (top < 2) { + return luaL_argerror (L, 1, "invalid number of arguments sample_to_timecode (sample)"); + } + Session const* const s = luabridge::Userdata::get (L, 1, true); + int64_t sample = luabridge::Stack::get (L, 2); + + Timecode::Time timecode; + + Timecode::sample_to_timecode ( + sample, timecode, false, false, + s->timecode_frames_per_second (), + s->timecode_drop_frames (), + s->frame_rate (), + 0, false, 0); + + luabridge::Stack::push (L, timecode.hours); + luabridge::Stack::push (L, timecode.minutes); + luabridge::Stack::push (L, timecode.seconds); + luabridge::Stack::push (L, timecode.frames); + return 4; +} +int +ARDOUR::LuaAPI::timecode_to_sample_lua (lua_State *L) +{ + int top = lua_gettop (L); + if (top < 5) { + return luaL_argerror (L, 1, "invalid number of arguments sample_to_timecode (hh, mm, ss, ff)"); + } + Session const* const s = luabridge::Userdata::get (L, 1, true); + int hh = luabridge::Stack::get (L, 2); + int mm = luabridge::Stack::get (L, 3); + int ss = luabridge::Stack::get (L, 4); + int ff = luabridge::Stack::get (L, 5); + + Timecode::Time timecode; + timecode.negative = false; + timecode.hours = hh; + timecode.minutes = mm; + timecode.seconds = ss; + timecode.frames = ff; + timecode.subframes = 0; + timecode.rate = s->timecode_frames_per_second (); + timecode.drop = s->timecode_drop_frames (); + + int64_t sample; + + Timecode::timecode_to_sample ( + timecode, sample, false, false, + s->frame_rate (), + 0, false, 0); + + luabridge::Stack::push (L, sample); + return 1; +} + int ARDOUR::LuaOSC::Address::send (lua_State *L) { -- cgit v1.2.3