One fix.
[ardour.git] / libs / ardour / lv2_plugin.cc
index 16ea4c57f75f0cb4789e2fbb79f431665f49a101..a163b879c72c2a96e7099ec90b82ef7d3d83d7ba 100644 (file)
@@ -1318,6 +1318,8 @@ LV2Plugin::add_state(XMLNode* root) const
        if (_has_state_interface) {
                // Provisionally increment state version and create directory
                const std::string new_dir = state_dir(++_state_version);
+               // and keep track of it (for templates & archive)
+               unsigned int saved_state = _state_version;;
                g_mkdir_with_parents(new_dir.c_str(), 0744);
 
                LilvState* state = lilv_state_new_from_instance(
@@ -1363,9 +1365,10 @@ LV2Plugin::add_state(XMLNode* root) const
                        lilv_state_free(state);
                        PBD::remove_directory(new_dir);
                        --_state_version;
+                       saved_state = _state_version;
                }
 
-               root->add_property("state-dir", string_compose("state%1", _state_version));
+               root->add_property("state-dir", string_compose("state%1", saved_state));
        }
 }
 
@@ -2194,27 +2197,34 @@ LV2Plugin::describe_io_port (ARDOUR::DataType dt, bool input, uint32_t id) const
        Plugin::IOPortDescription iod (lilv_node_as_string (name));
        lilv_node_free(name);
 
+       /* get the port's pg:group */
        LilvNodes* groups = lilv_port_get_value (_impl->plugin, pport, _world.groups_group);
        if (lilv_nodes_size (groups) > 0) {
                const LilvNode* group = lilv_nodes_get_first (groups);
                LilvNodes* grouplabel = lilv_world_find_nodes (_world.world, group, _world.rdfs_label, NULL);
 
+               /* get the name of the port-group */
                if (lilv_nodes_size (grouplabel) > 0) {
                        const LilvNode* grpname = lilv_nodes_get_first (grouplabel);
                        iod.group_name = lilv_node_as_string (grpname);
                }
                lilv_nodes_free (grouplabel);
 
+               /* get all port designations.
+                * we're interested in e.g. lv2:designation pg:right */
                LilvNodes* designations = lilv_port_get_value (_impl->plugin, pport, _world.lv2_designation);
-               if (group && lilv_nodes_size (designations) > 0) {
+               if (lilv_nodes_size (designations) > 0) {
+                       /* get all pg:elements of the pg:group */
                        LilvNodes* group_childs = lilv_world_find_nodes (_world.world, group, _world.groups_element, NULL);
                        if (lilv_nodes_size (group_childs) > 0) {
+                               /* iterate over all port designations .. */
                                LILV_FOREACH (nodes, i, designations) {
                                        const LilvNode* designation = lilv_nodes_get (designations, i);
+                                       /* match the lv2:designation's element against the port-group's element */
                                        LILV_FOREACH (nodes, j, group_childs) {
                                                const LilvNode* group_element = lilv_nodes_get (group_childs, j);
                                                LilvNodes* elem = lilv_world_find_nodes (_world.world, group_element, _world.lv2_designation, designation);
-
+                                               /* found it. Now look up the index (channel-number) of the pg:Element */
                                                if (lilv_nodes_size (elem) > 0) {
                                                        LilvNodes* idx = lilv_world_find_nodes (_world.world, lilv_nodes_get_first (elem), _world.lv2_index, NULL);
                                                        if (lilv_node_is_int (lilv_nodes_get_first (idx))) {
@@ -2487,7 +2497,7 @@ LV2Plugin::connect_and_run(BufferSet& bufs,
        }
 
        if (_bpm_control_port) {
-               *_bpm_control_port = tmap.tempo_at_frame (start).beats_per_minute();
+               *_bpm_control_port = tmap.tempo_at_frame (start).note_types_per_minute();
        }
 
 #ifdef LV2_EXTENDED
@@ -2559,7 +2569,7 @@ LV2Plugin::connect_and_run(BufferSet& bufs,
                        if (valid && (flags & PORT_INPUT)) {
                                if ((flags & PORT_POSITION)) {
                                        Timecode::BBT_Time bbt (tmap.bbt_at_frame (start));
-                                       double bpm = tmap.tempo_at_frame (start).beats_per_minute();
+                                       double bpm = tmap.tempo_at_frame (start).note_types_per_minute();
                                        double beatpos = (bbt.bars - 1) * tmetric.meter().divisions_per_bar()
                                                       + (bbt.beats - 1)
                                                       + (bbt.ticks / Timecode::BBT_Time::ticks_per_beat);
@@ -2600,8 +2610,8 @@ LV2Plugin::connect_and_run(BufferSet& bufs,
                                        } else {
                                                tmetric.set_metric(metric);
                                                Timecode::BBT_Time bbt;
-                                               bbt = tmap.bbt_at_pulse (metric->pulse());
-                                               double bpm = tmap.tempo_at_frame (start/*XXX*/).beats_per_minute();
+                                               bbt = tmap.bbt_at_frame (metric->frame());
+                                               double bpm = tmap.tempo_at_frame (start/*XXX*/).note_types_per_minute();
                                                write_position(&_impl->forge, _ev_buffers[port_index],
                                                               tmetric, bbt, speed, bpm,
                                                               metric->frame(),
@@ -2874,7 +2884,7 @@ LV2Plugin::connect_and_run(BufferSet& bufs,
                 * so it needs to be realative to that.
                 */
                TempoMetric t = tmap.metric_at(start);
-               _current_bpm = tmap.tempo_at_frame (start).beats_per_minute();
+               _current_bpm = tmap.tempo_at_frame (start).note_types_per_minute();
                Timecode::BBT_Time bbt (tmap.bbt_at_frame (start));
                double beatpos = (bbt.bars - 1) * t.meter().divisions_per_bar()
                               + (bbt.beats - 1)