comparison Example VamPy plugins/PyZeroCrossing.py @ 24:7d28bed0864e

* Rearrange Python plugin construction. Formerly, the PyPluginAdapter has retained a single plugin instance pointer for each plugin found, and its createPlugin method has simply returned a new PyPlugin object wrapping the same instance pointer. This has a couple of negative consequences: - Because construction of the actual Python instance occurred before the wrapper was constructed, it was not possible to pass arguments (i.e. the sample rate) from the wrapper constructor to the Python plugin instance constructor -- they had to be passed later, to initialise, disadvantaging those plugins that would like to use the sample rate for parameter & step/block size calculations etc - Because there was only a single Python plugin instance, it was not possible to run more than one instance at once with any isolation This rework instead stores the Python class pointer (rather than instance pointer) in the PyPluginAdapter, and each PyPlugin wrapper instance creates its own Python plugin instance. What could possibly go wrong?
author cannam
date Mon, 17 Aug 2009 15:22:06 +0000
parents 535d559300dc
children ba3686eb697c
comparison
equal deleted inserted replaced
23:535d559300dc 24:7d28bed0864e
1 '''PyZeroCrossing.py - Example plugin demonstrates''' 1 '''PyZeroCrossing.py - Example plugin demonstrates'''
2 '''how to call a python class using the VamPy Vamp plugin''' 2 '''how to call a python class using the VamPy Vamp plugin'''
3 3
4 from random import *
5
4 class PyZeroCrossing: 6 class PyZeroCrossing:
5 7
6 def __init__(self): 8 def __init__(self,inputSampleRate):
7 self.m_imputSampleRate = 0.0 9 self.m_inputSampleRate = inputSampleRate
8 self.m_stepSize = 0 10 self.m_stepSize = 0
9 self.m_blockSize = 0 11 self.m_blockSize = 0
10 self.m_channels = 0 12 self.m_channels = 0
11 self.previousSample = 0.0 13 self.previousSample = 0.0
12 self.threshold = 0.005 14 self.threshold = 0.005
15 self.identity = random()
16 self.counter = 0
13 17
14 def initialise(self,channels,stepSize,blockSize,inputSampleRate): 18 def initialise(self,channels,stepSize,blockSize):
15 self.m_channels = channels 19 self.m_channels = channels
16 self.m_stepSize = stepSize 20 self.m_stepSize = stepSize
17 self.m_blockSize = blockSize 21 self.m_blockSize = blockSize
18 self.m_inputSampleRate = inputSampleRate
19 return True 22 return True
20 23
21 def getMaker(self): 24 def getMaker(self):
22 return 'VamPy Example Plugins' 25 return 'VamPy Example Plugins'
23 26
68 return [output0,output1] 71 return [output0,output1]
69 72
70 def getParameterDescriptors(self): 73 def getParameterDescriptors(self):
71 paramlist1={ 74 paramlist1={
72 'identifier':'threshold', 75 'identifier':'threshold',
73 'name':'Noise threshold: ', 76 'name':'Noise threshold',
74 'description':'Return null or delete this function if not needed.', 77 'description':'',
75 'unit':'v', 78 'unit':'v',
76 'minValue':0.0, 79 'minValue':0.0,
77 'maxValue':0.5, 80 'maxValue':0.5,
78 'defaultValue':0.005, 81 'defaultValue':0.005,
79 'isQuantized':False 82 'isQuantized':False
94 def process(self,inbuf,timestamp): 97 def process(self,inbuf,timestamp):
95 crossing = False 98 crossing = False
96 prev = self.previousSample 99 prev = self.previousSample
97 count = 0.0; 100 count = 0.0;
98 channel = inbuf[0] 101 channel = inbuf[0]
102
103 print "Identity ", self.identity, ", counter ", self.counter
104 self.counter = self.counter + 1
99 105
100 #we have two outputs defined thus we have to declare 106 #we have two outputs defined thus we have to declare
101 #them as empty dictionaries in our output list 107 #them as empty dictionaries in our output list
102 #in order to be able to return variable rate outputs 108 #in order to be able to return variable rate outputs
103 output0=[] 109 output0=[]