Do Python scripts drive everybody crazy or is it just me?

Discuss music production with Ableton Live.
Post Reply
RegD
Posts: 46
Joined: Sat Nov 30, 2013 4:54 pm

Do Python scripts drive everybody crazy or is it just me?

Post by RegD » Tue Jul 08, 2014 9:19 am

Hello,
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)
It should be feasible to monitor each button and get the associated function to run without having to set a specific listener and function for each, right?

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

TomViolenz
Posts: 6854
Joined: Mon Dec 13, 2010 6:19 pm

Re: Do Python scripts drive everybody crazy or is it just me?

Post by TomViolenz » Tue Jul 08, 2014 9:35 am

Well, almost no one ever answering your questions in this regard could be an indication ;-)

Every time I read another thread from you I think "this could be done with clyphx and/or Bomes MT, but hell, I don't know how to write a phyton script to do that...."

ST8
Posts: 259
Joined: Mon Jan 26, 2009 12:55 pm

Re: Do Python scripts drive everybody crazy or is it just me?

Post by ST8 » Tue Jul 08, 2014 4:23 pm

Your overwriting your button in the loop so only the last one exists, hence you always get the id of the last one. You need to make an array of buttons.

Code: Select all


def _setup(self):
    self._buttons = []
    for index in range(72): 
        button = ConfigurableButtonElement(True, MIDI_NOTE_TYPE, 0, index)) #using the Launchpad's module here
        button.name = ((str(index)) + "_Button")
        button.set_on_off_values(75, 73)
        button.turn_off()
        // tell the listener you want to be notified who is triggering the callback
        button.add_value_listener(self._do_stuff_value, identify_sender=True) 
        self._buttons.append(button)

// sender is now the button triggering the callback
def _do_stuff_value(self, value, sender):
    moo


RegD
Posts: 46
Joined: Sat Nov 30, 2013 4:54 pm

Re: Do Python scripts drive everybody crazy or is it just me?

Post by RegD » Wed Jul 09, 2014 8:24 am

Thank you ST8 it works great!
@TomViolenz
I am challenging myself with Python - if I give up I'll switch to clyphx and/or Bomes MT

TomViolenz
Posts: 6854
Joined: Mon Dec 13, 2010 6:19 pm

Re: Do Python scripts drive everybody crazy or is it just me?

Post by TomViolenz » Wed Jul 09, 2014 8:38 am

Skyter wrote:Thank you ST8 it works great!
@TomViolenz
I am challenging myself with Python - if I give up I'll switch to clyphx and/or Bomes MT
Fair enough and god speed :-)

Btw, while scripting can potentially do everything clyphx does, I think (from how I understand it for now, but I'm also only just beginning) Bomes MT can give you posibilities that even scripting can't, because it is outside of Live and can thus circumvent a few of the limitations Live imposes.

So it's not necessarily an either/or proposition

Oh and clyphx is open source, this means you can look into its well documented (in the code and the clyphx manual) source code (which is in phyton of course) and take a look at how he implemented some function.
And I don't think there are many more talented Phyton coders in the Live community than Stray. 8)

RegD
Posts: 46
Joined: Sat Nov 30, 2013 4:54 pm

Re: Do Python scripts drive everybody crazy or is it just me?

Post by RegD » Thu Jul 10, 2014 2:31 pm

Thanks! that's good to know and I will definitely keep this mind !

Post Reply