Ducking and diving in Python atm.....
If anyone with some deeper knowledge than me could take a look at this script:
Currently I can get the value of the ButtonElement, the required function is to observe changes to it also;
Code: Select all
#qManager.py
import Live
import time
from _Framework.ControlSurface import ControlSurface
from _Framework.MyObserver import MyObserver # Class the same as ButtonElement class
class qManager(ControlSurface):
pplisten = {}
typeIndex = 0
qmButton1 = 0
def __init__(self, c_instance):
ControlSurface.__init__(self, c_instance)
self.qmButton1 = MyObserver(True, 0, 0, 14)
self.qmButton1.name = 'PP Changed Value Output'
self.qmButton1.value = 0.
cb = lambda :self.parent_changestate(self.qmButton1)
self.qmButton1.add_value_listener(cb)
# Here I get an error in log.txt : 'NoneType' object has no attribute 'add_value_listener'
def pp(self, pid):
# Here I add a couple of value listeners from M4L world to the pplisten dictionary
cb = lambda :self.param_changestate(pid)
if self.pplisten.has_key(pid) != 1:
pid.add_value_listener(cb)
self.pplisten[pid] = cb
return self.typeIndex
# self.typeIndex is for future use
return 1
# These returns pass successfully to an assigned live.object
def param_changestate(self,pid):
# Here I pass a value from any pplistener to my ButtonElement(MyOberver)
self.qmButton1.value = pid.value
def parent_changestate(self,pid):
pass # Should I do something here?
def pp_type(self, ppType):
self.typeIndex = ppType
Code: Select all
# emacs-mode: -*- python-*-
# -*- coding: utf-8 -*-
import Live
from InputControlElement import *
ON_VALUE = int(127)
OFF_VALUE = int(0)
value = 0.
class MyObserver(InputControlElement):
' Class representing a button a the controller '
def __init__(self, is_momentary, msg_type, channel, identifier):
InputControlElement.__init__(self, msg_type, channel, identifier)
assert isinstance(is_momentary, type(False))
self._MyObserver__is_momentary = is_momentary
def is_momentary(self):
' returns true if the buttons sends a message on being released '
return self._MyObserver__is_momentary
def message_map_mode(self):
assert (self.message_type() is MIDI_CC_TYPE)
return Live.MidiMap.MapMode.absolute
def turn_on(self):
self.send_value(value)
def turn_off(self):
self.send_value(value)
def value(self, value2):
value = value2
return value
# local variables:
# tab-width: 4
FYI - a live.observer object succesfully connects to id of the ButtonElement, it is only that it doesn't 'observe' the value, it can only 'get' the value.
I wondering if it is possible to 'observe' the values of Control Surface elements as they change within a script?
Thanks in advance,
Leigh