Again, I a have face difficulties in Python programming.
This time the issue relates to the method add_value_listener().
I have a series of buttons that I would like each to do their own thing when pressed but they all behave as the last button set up.
So far my script looks like this:
Code: Select all
[imports]
class MyController(ControlSurface):
" INITALIZE "
def __init__(self, c_instance):
ControlSurface.__init__(self, c_instance)
self.set_suppress_rebuild_requests(True)
self._suppress_send_midi = True
self.note_button = None
self._setup()
self.set_suppress_rebuild_requests(False)
self._suppress_receive_midi = False
" SETUP BUTTONS "
def _setup(self):
for index in range(72):
self.note_button = ConfigurableButtonElement(True, MIDI_NOTE_TYPE, 0, index)) #using the Launchpad's module here
self.note_button.name = ((str(index)) + "_Button")
self.note_button.set_on_off_values(75, 73)
self.note_button.turn_off()
self.note_button.add_value_listener(self._do_stuff_value)
"DO STUFF ON PRESS"
def _do_stuff_value(self, value):
assert (self.note_button != None)
assert isinstance(value, int)
identifier = self.note_button.message_identifier() #<----- this is wrong (it's always 71)
if ((value != 0) or (not self.note_button.is_momentary())):
ControlSurface._some_function(self, identifier)
I tried using note_button as a list of buttons ( note_button[index] ) but then I am not managing to carry the index over to the _do_stuff_value() method... is it possible somehow?
Thanks for any help!
R