@martin @jhh The problem would be that you will still be using unique ids! And the issue of maintaining ids will prevail. What about you delete an control? is the ID repeated? Do you have a list to keep the order of used numbers?..
A Solution: using a Repository call. Sample Code:
cRep = {}
-- Returns control or nil, without errors
cRep.getById = function(id)
local control
if pcall(function () control = controls.get(id) end) then
return control
else
return nil
end
end
-- Returns first control found with name
cRep.getFirstWithName = function(self, name)
local control
local nameToFind = string.upper(name)
for i=1,432 do
control = cRep.getById(i)
if (control ~= nil and control:getName() == nameToFind) then
return control
end
end
return nil
end
-- Returns first control found using the parameter number
cRep.getFirstWithParameterNumber = function(self, number)
local control
for i=1,432 do
control = cRep.getById(i)
if (control ~= nil and control:getValue(0):getMessage():getParameterNumber() == number) then
print("found "..i)
return control
end
end
return nil
end
-- Sample Usage
local superFader = cRep:getFirstWithName("Super Fader 1")
local panning = cRep:getFirstWithParameterNumber(3)
It should work, but will not be really optimized (however, I would prefer to use processor than memory for this things.)
the first day I played with the E1 I thought the same: I need to move the Ids! And even tried ways to figure it out. However, E1 Strength is that every control can be moved, and have code tied to those controls, by its action or its parameter. this other way of working turned out way cleaner, easier and organized.
I usually have calls like pan = cRep:getControlFromTopOfControl(fader)
because I know they will always be next to each other. Or maybe I never repeat parameter number for ANY control, so I can call them that way and move them all around! You can build your repository with cache on a table (controlId, CCNumber, name, other field, etc), and search for them no matter where they are. I think parameterNumber is pretty much never repeated, so its a good match for most calls.
This decoupling of code from interface is ideal, and coupling it will only give you more problems on the long run.
Of course, this is just MY opinion. An extra ID in the controls could be used, sure. But I wouldn’t recommend using it unless there is no other way.
------- EDIT -------
Thinking it over, if the identifier is a STRING, then it would be welcome! Event oriented programming will take you only so far in such a limited environment.