call IO::prepare_for_reset() on BOTH IO nodes of a PortInsert's XML state, not just...
[ardour.git] / libs / ardour / lua_api.cc
index 080ba128416faf645ca067561ec427e839aafd2b..59d27493998925a445366ce80b64755f28455614 100644 (file)
@@ -103,6 +103,30 @@ ARDOUR::LuaAPI::new_luaproc (Session *s, const string& name)
        return boost::shared_ptr<Processor> (new PluginInsert (*s, p));
 }
 
+PluginInfoList
+ARDOUR::LuaAPI::list_plugins ()
+{
+       PluginManager& manager = PluginManager::instance ();
+       PluginInfoList all_plugs;
+       all_plugs.insert (all_plugs.end (), manager.ladspa_plugin_info ().begin (), manager.ladspa_plugin_info ().end ());
+       all_plugs.insert (all_plugs.end (), manager.lua_plugin_info ().begin (), manager.lua_plugin_info ().end ());
+#ifdef WINDOWS_VST_SUPPORT
+       all_plugs.insert (all_plugs.end (), manager.windows_vst_plugin_info ().begin (), manager.windows_vst_plugin_info ().end ());
+#endif
+#ifdef LXVST_SUPPORT
+       all_plugs.insert (all_plugs.end (), manager.lxvst_plugin_info ().begin (), manager.lxvst_plugin_info ().end ());
+#endif
+#ifdef AUDIOUNIT_SUPPORT
+       all_plugs.insert (all_plugs.end (), manager.au_plugin_info ().begin (), manager.au_plugin_info ().end ());
+#endif
+#ifdef LV2_SUPPORT
+       all_plugs.insert (all_plugs.end (), manager.lv2_plugin_info ().begin (), manager.lv2_plugin_info ().end ());
+#endif
+       all_plugs.insert (all_plugs.end (), manager.lua_plugin_info ().begin (), manager.lua_plugin_info ().end ());
+
+       return all_plugs;
+}
+
 PluginInfoPtr
 ARDOUR::LuaAPI::new_plugin_info (const string& name, ARDOUR::PluginType type)
 {
@@ -122,6 +146,7 @@ ARDOUR::LuaAPI::new_plugin_info (const string& name, ARDOUR::PluginType type)
 #ifdef LV2_SUPPORT
        all_plugs.insert (all_plugs.end (), manager.lv2_plugin_info ().begin (), manager.lv2_plugin_info ().end ());
 #endif
+       all_plugs.insert (all_plugs.end (), manager.lua_plugin_info ().begin (), manager.lua_plugin_info ().end ());
 
        for (PluginInfoList::const_iterator i = all_plugs.begin (); i != all_plugs.end (); ++i) {
                if (((*i)->name == name || (*i)->unique_id == name) && (*i)->type == type) {
@@ -342,7 +367,7 @@ ARDOUR::LuaAPI::sample_to_timecode_lua (lua_State *L)
                        sample, timecode, false, false,
                        s->timecode_frames_per_second (),
                        s->timecode_drop_frames (),
-                       s->frame_rate (),
+                       s->sample_rate (),
                        0, false, 0);
 
        luabridge::Stack<uint32_t>::push (L, timecode.hours);
@@ -378,7 +403,7 @@ ARDOUR::LuaAPI::timecode_to_sample_lua (lua_State *L)
 
        Timecode::timecode_to_sample (
                        timecode, sample, false, false,
-                       s->frame_rate (),
+                       s->sample_rate (),
                        0, false, 0);
 
        luabridge::Stack<int64_t>::push (L, sample);
@@ -485,7 +510,7 @@ ARDOUR::LuaAPI::hsla_to_rgba (lua_State *L)
                a = luabridge::Stack<double>::get (L, 4);
        }
 
-       // we can't use ArdourCanvas::hsva_to_color here
+       // we can't use Gtkmm2ext::hsva_to_color here
        // besides we want HSL not HSV and without intermediate
        // color_to_rgba (rgba_to_color ())
        double r, g, b;
@@ -502,6 +527,32 @@ ARDOUR::LuaAPI::hsla_to_rgba (lua_State *L)
        return 4;
 }
 
+int
+ARDOUR::LuaAPI::color_to_rgba (lua_State *L)
+{
+       int top = lua_gettop (L);
+       if (top < 1) {
+               return luaL_argerror (L, 1, "invalid number of arguments, color_to_rgba (uint32_t)");
+       }
+       uint32_t color = luabridge::Stack<uint32_t>::get (L, 1);
+       double r, g, b, a;
+
+       /* libardour is no user of libcanvas, otherwise
+        * we could just call
+        * Gtkmm2ext::color_to_rgba (color, r, g, b, a);
+        */
+       r = ((color >> 24) & 0xff) / 255.0;
+       g = ((color >> 16) & 0xff) / 255.0;
+       b = ((color >>  8) & 0xff) / 255.0;
+       a = ((color >>  0) & 0xff) / 255.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;
+}
+
 int
 ARDOUR::LuaAPI::build_filename (lua_State *L)
 {
@@ -702,7 +753,7 @@ LuaAPI::Vamp::Vamp (const std::string& key, float sample_rate)
 
        if (bs > 0 && ss > 0 && bs <= 8192 && ss <= 8192) {
                _bufsize = bs;
-               _stepsize = bs;
+               _stepsize = ss;
        }
 }
 
@@ -747,12 +798,12 @@ LuaAPI::Vamp::analyze (boost::shared_ptr<ARDOUR::Readable> r, uint32_t channel,
        float* data = new float[_bufsize];
        float* bufs[1] = { data };
 
-       framecnt_t len = r->readable_length();
-       framepos_t pos = 0;
+       samplecnt_t len = r->readable_length();
+       samplepos_t pos = 0;
 
        int rv = 0;
        while (1) {
-               framecnt_t to_read = std::min ((len - pos), _bufsize);
+               samplecnt_t to_read = std::min ((len - pos), _bufsize);
                if (r->read (data, pos, to_read, channel) != to_read) {
                        rv = -1;
                        break;
@@ -788,8 +839,22 @@ LuaAPI::Vamp::process (const std::vector<float*>& d, ::Vamp::RealTime rt)
        return _plugin->process (bufs, rt);
 }
 
-boost::shared_ptr<Evoral::Note<Evoral::Beats> >
-LuaAPI::new_noteptr (uint8_t chan, Evoral::Beats beat_time, Evoral::Beats length, uint8_t note, uint8_t velocity)
+boost::shared_ptr<Evoral::Note<Temporal::Beats> >
+LuaAPI::new_noteptr (uint8_t chan, Temporal::Beats beat_time, Temporal::Beats length, uint8_t note, uint8_t velocity)
+{
+       return boost::shared_ptr<Evoral::Note<Temporal::Beats> > (new Evoral::Note<Temporal::Beats>(chan, beat_time, length, note, velocity));
+}
+
+std::list<boost::shared_ptr<Evoral::Note<Temporal::Beats> > >
+LuaAPI::note_list (boost::shared_ptr<MidiModel> mm)
 {
-       return boost::shared_ptr<Evoral::Note<Evoral::Beats> > (new Evoral::Note<Evoral::Beats>(chan, beat_time, length, note, velocity));
+       typedef boost::shared_ptr<Evoral::Note<Temporal::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;
 }