nortikin / sverchok

Sverchok
http://nortikin.github.io/sverchok/
GNU General Public License v3.0
2.25k stars 233 forks source link

SV OSC ChucK and Sonic Pi, but ChucK for now #1311

Closed enzyme69 closed 7 years ago

enzyme69 commented 7 years ago

While experimenting with the idea of Sverchok connecting to SOUND GENERATOR like Sonic Pi, I stumbled into Python ChucK module.

https://github.com/Calysto/chuck/blob/master/docs/API.md

Currently I am testing this ChucK module with Sverchok Script Node Lite. I manage to make sound, although the refresh rate is too low, I wonder if I am doing it right.

My issue is often with the idea of realtime and update. I don't know exactly how Blender or Sverchok "update" apart from update when time changed or parameter changed.

Is this thing slow because of the ChucK module itself is slow? Or because the environment was not really made for it (realtime)?

Maybe we can somewhat make it to work? 👍

"""
in trigger      s   d=1     n=2
in note        s   d=440.0    n=2
"""
import bpy
#from psonic import *
from chuck import *

init()

s = SineWave()
s.connect()

if(trigger):
    s.setFrequency(note)

else:
    s.disconnect()
enzyme69 commented 7 years ago

For below, I am getting 2 fps:

"""
in trigger      s   d=1     n=2
in note        s   d=440.0    n=2
"""
import bpy
#from psonic import *
from chuck import *

init()

m = Mandolin()
m.connect()
m.setFrequency(note)

if(trigger):
    m.noteOn(0.8)

else:
    m.noteOff(0.2) 
enzyme69 commented 7 years ago

Sverchok and Sonic Pi python module are reasonably fast, with a slight latency. Sonic Pi python module does not have the interaction smoothness of ChucK.

I realized one thing:
For all my programming experience, whether it is using Processing, ChucK, my biggest issue is the lack of UI and Interaction. Well, apart from weird syntax of many languages, and not program talks with each other. Nodes and sliders facilitate the learning process. This is why using Sverchok, Animation Nodes to control python modules from Blender feels amazing. Jupyter NoteBook and iPython helps too actually. Especially when one can use the interactive sliders to control parameters in near real-time.

But I realise there is such thing as real-time and thread etc. It's alien to me that a program is continuously running while parameters are changing, but that happens in games as well. The concept of a server is also a surprise for me.

Even more strange is that in node based and time based programming, everything happens at the same time, or not always in full speed.

Ideally every program can talk with each other without issue. As easy as connecting digital musical instruments.

zeffii commented 7 years ago
  1. ChucK does have an osx UI library built on cocoa (iirc). I don't know if the python module for ChucK exposes it.

  2. OSC over udp/tcp has some latency, latency is generated by several contributing factors and i feel i've explained this in the past. Anyway.. external modules (like python chuck) to sverchok are beyond the scope of this issue tracker (even tho it's interesting)..

One thing that will have a big influence on the chuck/python latency using SN1 is the fact that you are repeatedly doing this:

"""
in trigger      s   d=1     n=2
in note        s   d=440.0    n=2
"""
init()

m = Mandolin()
m.connect()

means each time you trigger the node.. it does something in init() and instancing Mandolin() and m.connect() probably also take up time. The only thing you should be doing on a SN update is

m.setFrequency(note)

if(trigger):
    m.noteOn(0.8)

else:
    m.noteOff(0.2) 

SNlite is "stateless" and isn't equipped to handle this, but SN MK1 is.

# psuedo

init()

m = Mandolin()
m.connect()

svmain

    m.setFrequency(note)

    if(trigger):
        m.noteOn(0.8)

    else:
        m.noteOff(0.2) 

Making SNLite work with state is definitely something I want to add, it's even noted somewhere in the first commits of SNLite to master. but no ETA.

enzyme69 commented 7 years ago

Thanks @zeffii for explanation I will keep this egg as pending wishlist.

zeffii commented 7 years ago

@enzyme69 can you please use _underscores_ to emphasise words, instead of CAPITALS. caps are for acronyms. please please please.

enzyme69 commented 7 years ago

@zeffii I will try to remember this. I got used to CAPITALIZE... yeeks. I will emphaize like this.