Primitive management

What is the purpose of this code :

@bpm.setter
    def bpm(self, new_bpm):
        '''
        Permits to change the beat rate while the motion is performing
        '''
        self._bpm = new_bpm
        self.frequency = self._bpm / 60.0

I understand that it is to change the bpm, but why not just make a :

instance_primitive._bpm = 70

to change the attribute _bpm to 70 ?

If you change the bpm with self._bpm it will not update the frequency self.frequency = self._bpm / 60.0.

Right, so I can do :

self._bpm = 70
self.frequency = 70/60

and forget the method def bpm

What is :
@bpm.setter

It means that when you do yourinstance.bpm = 70, it will do exactly what you said (set _bpm and frequency appropriately, following the bpm function). It is a way to hide some complexity for the user that he should not have to deal with. And to also not have to change the interface all the time.

1 Like

Ok thanks, I knew @classmethod, @property and now I know @function.setter… Learn the decorators with Poppy :slight_smile: