Lua bindings to access MIDI region/source note-events
authorRobin Gareus <robin@gareus.org>
Sat, 18 Mar 2017 17:37:19 +0000 (18:37 +0100)
committerRobin Gareus <robin@gareus.org>
Sat, 18 Mar 2017 18:07:03 +0000 (19:07 +0100)
libs/ardour/ardour/lua_api.h
libs/ardour/lua_api.cc
libs/ardour/luabindings.cc

index cbbe750164357f5c52927987f56c5db291fe5de6..bd71576e7cf6aaddadd195a50b5c8a3adda163e4 100644 (file)
@@ -28,6 +28,7 @@
 
 #include "ardour/libardour_visibility.h"
 
+#include "ardour/midi_model.h"
 #include "ardour/processor.h"
 #include "ardour/session.h"
 
@@ -300,6 +301,9 @@ namespace ARDOUR { namespace LuaAPI {
        boost::shared_ptr<Evoral::Note<Evoral::Beats> >
                new_noteptr (uint8_t, Evoral::Beats, Evoral::Beats, uint8_t, uint8_t);
 
+       std::list<boost::shared_ptr< Evoral::Note<Evoral::Beats> > >
+               note_list (boost::shared_ptr<ARDOUR::MidiModel>);
+
 } } /* namespace */
 
 namespace ARDOUR { namespace LuaOSC {
index c32a9e9338744e6c7953ddb0df5a5c8ddcf25447..8499e5c7ffa483e97007eebc2458ce93ef66410d 100644 (file)
@@ -820,3 +820,17 @@ LuaAPI::new_noteptr (uint8_t chan, Evoral::Beats beat_time, Evoral::Beats length
 {
        return boost::shared_ptr<Evoral::Note<Evoral::Beats> > (new Evoral::Note<Evoral::Beats>(chan, beat_time, length, note, velocity));
 }
+
+std::list<boost::shared_ptr<Evoral::Note<Evoral::Beats> > >
+LuaAPI::note_list (boost::shared_ptr<MidiModel> mm)
+{
+       typedef typename boost::shared_ptr<Evoral::Note<Evoral::Beats> > NotePtr;
+
+       std::list<NotePtr> note_ptr_list;
+
+       const MidiModel::Notes& notes = mm->notes();
+       for (MidiModel::Notes::const_iterator i = notes.begin(); i != notes.end(); ++i) {
+               note_ptr_list.push_back (*i);
+       }
+       return note_ptr_list;
+}
index d9f460461f4628dc70b1e5c960ad271d88d2a189..299356787681785e674b761a1d5263c1bbcd084e 100644 (file)
@@ -35,6 +35,7 @@
 #include "ardour/audio_track.h"
 #include "ardour/audioplaylist.h"
 #include "ardour/buffer_set.h"
+#include "ardour/beats_frames_converter.h"
 #include "ardour/chan_mapping.h"
 #include "ardour/dB.h"
 #include "ardour/dsp_filter.h"
@@ -165,6 +166,7 @@ CLASSKEYS(Selectable*);
 CLASSKEYS(std::list<Selectable*>);
 
 CLASSKEYS(ARDOUR::AudioEngine);
+CLASSKEYS(ARDOUR::BeatsFramesConverter);
 CLASSKEYS(ARDOUR::BufferSet);
 CLASSKEYS(ARDOUR::ChanCount);
 CLASSKEYS(ARDOUR::ChanMapping);
@@ -1132,7 +1134,7 @@ LuaBindings::common (lua_State* L)
                .deriveWSPtrClass <MidiRegion, Region> ("MidiRegion")
                .addFunction ("do_export", &MidiRegion::do_export)
                .addFunction ("midi_source", &MidiRegion::midi_source)
-               .addFunction ("model", (boost::shared_ptr<MidiModel> (MidiRegion::*)())&MidiRegion::midi_source)
+               .addFunction ("model", (boost::shared_ptr<MidiModel> (MidiRegion::*)())&MidiRegion::model)
                .addFunction ("start_beats", &MidiRegion::start_beats)
                .addFunction ("length_beats", &MidiRegion::length_beats)
                .endClass ()
@@ -1476,6 +1478,9 @@ LuaBindings::common (lua_State* L)
                .addVoidPtrConstructor<std::list<boost::shared_ptr <AutomationControl> > > ()
                .endClass ()
 
+               .beginStdList <boost::shared_ptr<Evoral::Note<Evoral::Beats> > > ("NotePtrList")
+               .endClass ()
+
 #if 0  // depends on Evoal:: Note, Beats see note_fixer.h
        // typedef Evoral::Note<Evoral::Beats> Note;
        // std::set< boost::weak_ptr<Note> >
@@ -1504,6 +1509,12 @@ LuaBindings::common (lua_State* L)
                .addFunction ("frames_per_grid", &Meter::frames_per_grid)
                .endClass ()
 
+               .beginClass <BeatsFramesConverter> ("BeatsFramesConverter")
+               .addConstructor <void (*) (const TempoMap&, framepos_t)> ()
+               .addFunction ("to", &BeatsFramesConverter::to)
+               .addFunction ("from", &BeatsFramesConverter::from)
+               .endClass ()
+
                .beginClass <TempoMap> ("TempoMap")
                .addFunction ("add_tempo", &TempoMap::add_tempo)
                .addFunction ("add_meter", &TempoMap::add_meter)
@@ -1514,6 +1525,8 @@ LuaBindings::common (lua_State* L)
                .addFunction ("bbt_at_frame", &TempoMap::bbt_at_frame)
                .addFunction ("exact_beat_at_frame", &TempoMap::exact_beat_at_frame)
                .addFunction ("exact_qn_at_frame", &TempoMap::exact_qn_at_frame)
+               .addFunction ("framepos_plus_qn", &TempoMap::framepos_plus_qn)
+               .addFunction ("framewalk_to_qn", &TempoMap::framewalk_to_qn)
                .endClass ()
 
                .beginClass <MetricSection> ("MetricSection")
@@ -1963,6 +1976,7 @@ LuaBindings::common (lua_State* L)
                .addFunction ("monotonic_time", ::g_get_monotonic_time)
                .addCFunction ("build_filename", ARDOUR::LuaAPI::build_filename)
                .addFunction ("new_noteptr", ARDOUR::LuaAPI::new_noteptr)
+               .addFunction ("note_list", ARDOUR::LuaAPI::note_list)
                .addCFunction ("sample_to_timecode", ARDOUR::LuaAPI::sample_to_timecode)
                .addCFunction ("timecode_to_sample", ARDOUR::LuaAPI::timecode_to_sample)