13
0

Even more Lua bindings

This commit is contained in:
Robin Gareus 2022-09-27 19:57:09 +02:00
parent 0d5fd0de0c
commit 1abf6a77d6
Signed by: rgareus
GPG Key ID: A090BCE02CF57F04
2 changed files with 20 additions and 3 deletions

View File

@ -619,18 +619,21 @@ LuaBindings::common (lua_State* L)
.addFunction ("round_to_beat", &Temporal::Beats::round_to_beat)
.addFunction ("round_up_to_beat", &Temporal::Beats::round_up_to_beat)
.addFunction ("round_down_to_beat", &Temporal::Beats::round_down_to_beat)
.addFunction ("str", &Temporal::Beats::str)
.addMetamethod ("__tostring", &Temporal::Beats::str)
.endClass ()
.beginClass <Temporal::timepos_t> ("timepos_t")
.addConstructor <void (*) (Temporal::samplepos_t)> ()
.addOperator ("__add", CPPOPERATORALT(Temporal::timepos_t, Temporal::timecnt_t, +))
.addOperator ("__sub", CPPOPERATOR2(Temporal::timecnt_t, Temporal::timepos_t, Temporal::timepos_t, .distance))
.addOperator ("__sub", CPPOPERATORALT(Temporal::timepos_t, Temporal::timecnt_t, .earlier))
//.addOperator ("__mod", CPPOPERATOR2(Temporal::timepos_t, Temporal::timepos_t, Temporal::timecnt_t, %))
.addOperator ("__lt", CPPCOMPERATORALT(Temporal::timepos_t, Temporal::timecnt_t, <))
.addOperator ("__le", CPPCOMPERATORALT(Temporal::timepos_t, Temporal::timecnt_t, <=))
.addOperator ("__eq", CPPCOMPERATOR(Temporal::timepos_t, ==))
.addStaticFunction ("zero", &Temporal::timepos_t::zero)
.addStaticFunction ("max", &Temporal::timepos_t::max)
.addStaticFunction ("smallest_step", &Temporal::timepos_t::smallest_step)
.addStaticFunction ("from_ticks", &Temporal::timepos_t::from_ticks)
#ifdef WITH_SUPERCLOCK_BINDINGS
.addStaticFunction ("from_superclock", &Temporal::timepos_t::from_superclock)
@ -642,10 +645,12 @@ LuaBindings::common (lua_State* L)
.addFunction ("is_zero", &Temporal::timepos_t::is_zero)
.addFunction ("is_beats", &Temporal::timepos_t::is_beats)
.addFunction ("samples", &Temporal::timepos_t::samples)
.addFunction ("time_domain", &Temporal::timepos_t::time_domain)
.addFunction ("ticks", &Temporal::timepos_t::ticks)
.addFunction ("beats", &Temporal::timepos_t::beats)
.addFunction ("str", &Temporal::timepos_t::str)
.addFunction ("scale", &Temporal::timepos_t::scale)
.addFunction ("distance", &Temporal::timepos_t::distance)
.addFunction ("increment", &Temporal::timepos_t::increment)
.addFunction ("decrement", &Temporal::timepos_t::decrement)
.addMetamethod ("__tostring", &Temporal::timepos_t::str)
@ -660,6 +665,7 @@ LuaBindings::common (lua_State* L)
.addOperator ("__le", CPPCOMPERATOR(Temporal::timecnt_t, <=))
.addOperator ("__eq", CPPCOMPERATOR(Temporal::timecnt_t, ==))
.addStaticFunction ("zero", &Temporal::timecnt_t::zero)
.addStaticFunction ("max", (Temporal::timecnt_t const & (*)()) &Temporal::timecnt_t::max)
.addStaticFunction ("from_samples", static_cast<Temporal::timecnt_t(*)(Temporal::samplepos_t)>(&Temporal::timecnt_t::from_samples))
.addStaticFunction ("from_ticks", static_cast<Temporal::timecnt_t(*)(int64_t)>(&Temporal::timecnt_t::from_ticks))
#ifdef WITH_SUPERCLOCK_BINDINGS
@ -677,6 +683,7 @@ LuaBindings::common (lua_State* L)
.addFunction ("time_domain", &Temporal::timecnt_t::time_domain)
.addFunction ("set_time_domain", &Temporal::timecnt_t::set_time_domain)
.addFunction ("samples", &Temporal::timecnt_t::samples)
.addFunction ("scale", &Temporal::timecnt_t::scale)
.addFunction ("beats", &Temporal::timecnt_t::beats)
.addFunction ("ticks", &Temporal::timecnt_t::ticks)
.addFunction ("str", &Temporal::timecnt_t::str)
@ -693,6 +700,7 @@ LuaBindings::common (lua_State* L)
.addOperator ("__lt", CPPCOMPERATOR(Temporal::BBT_Time, <))
.addOperator ("__le", CPPCOMPERATOR(Temporal::BBT_Time, <=))
.addOperator ("__eq", CPPCOMPERATOR(Temporal::BBT_Time, ==))
.addFunction ("str", &Temporal::BBT_Time::str)
.addMetamethod ("__tostring", &Temporal::BBT_Time::str)
// .addStaticData ("ticks_per_beat", &Temporal::ticks_per_beat, false)
.endClass ()
@ -1037,11 +1045,17 @@ LuaBindings::common (lua_State* L)
// templated class definitions
.beginClass <PBD::PropertyDescriptor<bool> > ("BoolProperty").endClass ()
.beginClass <PBD::PropertyDescriptor<float> > ("FloatProperty").endClass ()
.beginClass <PBD::PropertyDescriptor<samplepos_t> > ("SampleposProperty").endClass ()
.beginClass <PBD::PropertyDescriptor<std::string> > ("StringProperty").endClass ()
.beginClass <PBD::PropertyDescriptor<samplepos_t> > ("SamplePosProperty").endClass ()
.beginClass <PBD::PropertyDescriptor<timepos_t> > ("TimePosProperty").endClass ()
.beginClass <PBD::PropertyDescriptor<timecnt_t> > ("TimeCntProperty").endClass ()
// actual references (TODO: also expose GQuark for std::set)
// ardour/region.h
.addConst ("Start", &ARDOUR::Properties::start)
.addConst ("Length", &ARDOUR::Properties::length)
.addConst ("Layer", &ARDOUR::Properties::layer)
.addConst ("Muted", &ARDOUR::Properties::muted)
.addConst ("Opaque", &ARDOUR::Properties::opaque)
.endNamespace ()
.beginClass <PBD::PropertyChange> ("PropertyChange")
@ -1051,7 +1065,10 @@ LuaBindings::common (lua_State* L)
// expand templated PropertyDescriptor<T>
.addFunction ("containsBool", &PBD::PropertyChange::contains<bool>)
.addFunction ("containsFloat", &PBD::PropertyChange::contains<float>)
.addFunction ("containsString", &PBD::PropertyChange::contains<std::string>)
.addFunction ("containsSamplePos", &PBD::PropertyChange::contains<samplepos_t>)
.addFunction ("containsTimePos", &PBD::PropertyChange::contains<timepos_t>)
.addFunction ("containsTimeCnt", &PBD::PropertyChange::contains<timecnt_t>)
.endClass ()
.beginClass <PBD::PropertyList> ("PropertyList")

View File

@ -5275,7 +5275,7 @@ Session::setup_lua ()
" assert(type(a) == 'table' or type(a) == 'nil', 'Given argument is invalid')"
" assert(self.scripts[n] == nil, 'Callback \"'.. n ..'\" already exists.')"
" self.scripts[n] = { ['f'] = f, ['a'] = a }"
" local env = { print = print, tostring = tostring, assert = assert, ipairs = ipairs, error = error, select = select, string = string, type = type, tonumber = tonumber, collectgarbage = collectgarbage, pairs = pairs, math = math, table = table, pcall = pcall, bit32=bit32, Session = Session, PBD = PBD, Timecode = Timecode, Evoral = Evoral, C = C, ARDOUR = ARDOUR }"
" local env = { print = print, tostring = tostring, assert = assert, ipairs = ipairs, error = error, select = select, string = string, type = type, tonumber = tonumber, collectgarbage = collectgarbage, pairs = pairs, math = math, table = table, pcall = pcall, bit32=bit32, Session = Session, PBD = PBD, Temporal = Temporal, Timecode = Timecode, Evoral = Evoral, C = C, ARDOUR = ARDOUR }"
" self.instances[n] = load (string.dump(f, true), nil, nil, env)(a)"
" Session:scripts_changed()" // call back
" end"