Thank you Thomas and Frank. Your solution, Frank, would have too much impact on too many other aspects of my project .... I found another solution .... Best, Michael
Frank Barknecht wrote:
Hallo, Frank Barknecht hat gesagt: // Frank Barknecht wrote:
I think, for Michael's code it would be better to make "orchestra" a real list of "Instrument"s like:
orchestra1 = [ ['x1','a',1], ['x2','c',11] ] # changed! orchestra = []
for i in orchestra1: tmp = Instrument(i[0], i[1], i[2]) orchestra.append(tmp)
Then in the pyext class use in float_1 something like:
orchestra[index].setVal(f)
I forgot to say: In this case, orchestra should be a class member like:
class whatever(pyext._class):
def __init__(self, archestra): self.orchestra = [] for i in archestra: tmp = Instrument(i[0], i[1], i[2]) self.orchestra.append(tmp)
def float_1(self,f): if f > 10: self.orchestra[0].setVal = f else: self.orchestra[1].setVal = f
Ciao
try: import pyext except: print "ERROR: This script must be loaded by the PD/Max pyext external" from testclass import *
orchestra1 = [['x1',['a',1]],['x2',['c',11]]] orchestra2 = [['y1',['e',2]],['y2',['g',22]]] orchestra = [] namespace = {}
class Test(pyext._class): _inlets=1 _outlets=1
def __init__(self, *args):
global namespace, orchestra
print str(args[0])
orchestra = eval(str(args[0]))
for i in orchestra:
j = (i[0], i[1][0], i[1][1])
exec str(i[0])+' = Instrument'+str(j)
exec str(i[0])+'.getInfo()'
namespace = locals()
def float_1(self,f):
global namespace, orchestra
if f > 10:
exec str(orchestra[0][0])+'.setVal('+str(f)+')' in namespace
else:
exec str(orchestra[1][0])+'.setVal('+str(f)+')'in namespace