hydra-synth / hydra

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

using math. (lowercase) as opposed to Math. is freezing Hydra #51

Closed rfpuyana closed 5 years ago

rfpuyana commented 5 years ago

There's something about this sine function freezing Hydra and not showing any error. Hydra web needs to be reloaded in the browser.

This chain works well

osc(10,0.1)
  .thresh(0.1).scale(3)
.out()

This one freezes Hydra. No error messages

osc(10,0.1)
  .thresh(0.1).scale(()=>math.sin(time))
.out()

OS:Mac OSX - High Sierra Browser: Chrome Version 75.0.3770.100 (Official Build) (64-bit) Hydra: Web

zachkrall commented 5 years ago

Hi @rfpuyana I think the error might be because math isn't capitalized in your code. The name of the math object in javascript is capitalized: Math. (Source: MDN web docs)

Try the following code:

osc(10,0.1)
  .thresh(0.1).scale(()=>Math.sin(time))
.out()
rfpuyana commented 5 years ago

Zach you are correct. My Bad. It's now working.

However, Hydra shouldn't freeze. An error message should notify about this particular case.

zachkrall commented 5 years ago

Maybe a solution is allowing sin to be a globally accessible function to prevent calling Math object directly.

Example (hydra-editor)

sin = (x) => Math.sin(x);

shape(3)
.scale(
    ()=>sin(time)
).out();

Ideally, it wouldn't require an anonymous function to pass the value but I am not sure how that could be accomplished. Maybe @ojack @rumblesan @echophon @brucelane have ideas on that? Example:

shape(3)
.scale(
    sin(time)
).out();
rumblesan commented 5 years ago

so there's a couple of immediate solutions I guess.

I've not had a look at the hydra code for a while now, but I've not got anything else happening with my Friday night so I'll start digging 😂

zachkrall commented 5 years ago

setting sin( ) matches how p5.js (source code, line 188) has approached this too

rumblesan commented 5 years ago

right, think I've figured out what's going on and opened that PR, but not had a chance to fully check. will get back to it a bit later when I have a moment

ojack commented 5 years ago

@rumblesan's commit fixed the function crashing issue, yay! And also fixes https://github.com/ojack/hydra/issues/35

As far as globally defining certain functions as @zachkrall mentions, that is part of a much larger conversation at https://github.com/ojack/hydra/issues/8 so let's continue it there.

Opened a new issue about providing user log info about what happens in hydra synth at: https://github.com/ojack/hydra/issues/53

rumblesan commented 5 years ago

hah, glad to be of use :D