change LFO type dynamically from OSC data

28 views
Skip to first unread message

fabio bottarelli

unread,
Sep 19, 2021, 9:29:08 AM9/19/21
to pyo-discuss
hello, i am building a class that is supposed to simulate a theremin.
i implemented one slider for changing the main LFO type and it works.
the problem rises when i am trying to modify the type through some OSC data (i have a potentiometer on my arduino).
when i insert in LFO type the OSC variable it brakes, so i tried wrapping that variable inside a Sig(). this method already worked for the frequency, but in this case it didn't.
is here something that i am missing?
LFO can be modified through a slider and function but cannot accept a stream in input?

here is some super simple code to explain:
sig = Sig(0)
lf = LFO(200, type=sig)
sig.ctrl()

>>>error: (integer expected, got <class 'pyo.lib._core.Sig'>)

and here is how i recieve OSC data:
scpar = OscReceive(port=port, address= ["theremin/pitch", "theremin/brightness", "theremin/wave"])
pitch = oscpar["theremin/pitch"]
brightness = oscpar["theremin/brightness"]
wave = oscpar["theremin/wave"]
amp = 1
t = Theremin(freq=pitch, mul=amp, brightness=brightness, wavetype=wave)
mix = t.mix(2).out()
t.ctrl().

if you can show me a way out of this i would really
appreciate, thank you

Alexandros

unread,
Sep 19, 2021, 9:39:33 AM9/19/21
to pyo-d...@googlegroups.com

The LFO type can only be set via an integer as the error message states. You can pass your OSC data through a chain of Change() -> Select() -> TrigFunc() -> function that gets the OSC stream as an int (e.g. int(wave.get()) or something like that).

--
You received this message because you are subscribed to the Google Groups "pyo-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyo-discuss...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pyo-discuss/c64869de-7bb9-4c89-b247-6b4b7ada4ef2n%40googlegroups.com.

Olivier Bélanger

unread,
Sep 19, 2021, 10:03:50 AM9/19/21
to pyo-d...@googlegroups.com
Here is a sketch to start with!

def wave_changed():
    
lfo.type = int(wave.get())

oscpar = OscReceive(port=port, address= ["theremin/pitch", "theremin/brightness", "theremin/wave"])
lfo = LFO()
wave = oscpar["theremin/wave"]

tf = TrigFunc(Change(Round(wave)), wave_changed)

Olivier


Message has been deleted
Message has been deleted

Olivier Bélanger

unread,
Sep 21, 2021, 8:27:02 AM9/21/21
to pyo-d...@googlegroups.com
Excellent!

You can override the ctrl() of a PyoObject to show only the relevant sliders... See the example in this tutorial:


Olivier
 

On Tue, Sep 21, 2021 at 8:09 AM fabio bottarelli <f.bo...@gmail.com> wrote:
Ok it works well but i had to twist the code a bit since i get an error saying that wave does not have a get() method (maybe because i am running pyo 1.0.1?)
anyway the twist is:
oscpar = OscReceive(port=port, address= ["theremin/pitch", "theremin/brightness", "theremin/wave"])
pitch = oscpar["theremin/pitch"]
brightness = oscpar["theremin/brightness"]
wave = oscpar["theremin/wave"]
amp = 1#= oscpar["theremin/amp"]

t = Theremin(freq=pitch, mul=amp, brightness=brightness)
def wave_changed():
       t.waveType = int(oscpar.get("theremin/wave"))
tf = TrigFunc(Change(Round(wave)), wave_changed)

this technique works but the slider in crtl() of the theremin class does not follow OSC values and is not hided, but i think i can live with it.
thank you very much Olivier.
Reply all
Reply to author
Forward
0 new messages