The Selected Parameter In Automation Editor

I’m working on a script that alters automation data. I want it to work on the parameter that is currently selected in the automation editor, but I can’t get this to work. The problem is that I don’t know how to uniquely identify the currently selected parameter. I can get its name and some other values, but if there are two identical devices in the track, then both will have a parameter that matches the currently selected parameter’s properties.

so far, this is what I have:

  
  
target_parameter = renoise.song().selected_parameter  
  
ta = renoise.song().selected_pattern_track.automation  
  
for a in pairs(ta) do  
 if (ta[a].dest_parameter.name == target_parameter.name) then print("yay!")end  
end  

I thought I could use renoise.song().selected_device, but this only works for the device selected in the device chain view, not in the automation editor.

So what I need is a way to identify the device to which the selected parameter in the automation editor belongs. Is there a way to do this?

  
local selected_parameter = renoise.song().selected_parameter  
local selected_pattern_track = renoise.song().selected_pattern_track  
  
-- there might be no parameter selected...  
if (selected_parameter) then  
 local selected_parameters_automation = selected_pattern_track:find_automation(  
 selected_parameter)  
  
 if (not selected_parameters_automation) then  
 -- create a new automation in the selected pattern/track  
 selected_parameters_automation = selected_pattern_track:create_automation(  
 selected_parameter)  
 end  
  
 -- do something with the automation...  
 selected_parameters_automation.points = {} -- clear all points  
 selected_parameters_automation:add_point_at(1, 0.5) -- insert a new one at the pattern start  
end  
  

should do the job…

It does, thanks!

Heres a snippet how to integrate this in a tool, adding entries to the track automation:

  
--------------------------------------------------------------------------------  
-- tool registration  
--------------------------------------------------------------------------------  
  
renoise.tool():add_menu_entry {  
 name = "Track Automation:Do Something With Automation",  
 invoke = function() do_something_with_current_automation() end,  
 active = function() return (renoise.song().selected_parameter ~= nil) end   
}  
  
renoise.tool():add_menu_entry {  
 name = "Track Automation List:Do Something With Automation",  
 invoke = function() do_something_with_current_automation() end,   
 active = function() return (renoise.song().selected_parameter ~= nil) end   
}  
  
-- could also check   
-- selected_pattern_track:find_automation(renoise.song().selected_parameter)   
-- in the "active" callbacks to only allow modifying existing automation  
  
  
--------------------------------------------------------------------------------  
-- process  
--------------------------------------------------------------------------------  
  
function do_something_with_current_automation()  
 local selected_parameter = renoise.song().selected_parameter  
 --- ... selected_parameter is never nil here  
end