hydra-synth / hydra

Livecoding networked visuals in the browser
https://hydra.ojack.xyz
GNU Affero General Public License v3.0
2.13k stars 255 forks source link

Pass midi values into p5 Draw function #206

Closed staus closed 1 year ago

staus commented 1 year ago

Maybe I'm doing something wrong, but it doesn't seem like it's possible to use midi controllers inside the draw function of p5. I've tried a bunch of things, but none of it seems to work

Writing the cc() inside the draw call

p5.draw = () => {
  p5.background(0, 0, 0, 0)
  p5.torus(180, cc(0).range(10,80) )
}

Passing it in

radius = cc(0).range(10,80) 
p5.draw = (r = radius) => {
  p5.background(0, 0, 0, 0)
  p5.torus(180, r )
}
geikha commented 1 year ago

Hydra doesn't have any pre-defined functions for MIDI such as cc as you're writing there. If there's a library you're trying to use please clarify! You can also look here for a basic WebMIDI setup: https://github.com/ojack/hydra/blob/master/docs/midi.md

micuat commented 1 year ago

I think cc is an array (if you follow this guide) so you need to use it such as p5.background(cc[8] * 256) (note that cc ranges from 0 to 1).

I close the issue but if the problem persists feel free to reopen :)