Giter Club home page Giter Club logo

Comments (8)

rumblesan avatar rumblesan commented on August 9, 2024 1

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

  • make all the functions/values on Math globally available
  • create a math variable that is just Math so casing doesn't make any difference.
    Both are fine, though the bigger issue really is that the undefined variable crashes everything. I think a better fix would be to catch the error and handle it gracefully with a warning so users can fix the casing.

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 ๐Ÿ˜‚

from hydra.

zachkrall avatar zachkrall commented on August 9, 2024

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()

from hydra.

rfpuyana avatar rfpuyana commented on August 9, 2024

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

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

from hydra.

zachkrall avatar zachkrall commented on August 9, 2024

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();

from hydra.

zachkrall avatar zachkrall commented on August 9, 2024

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

from hydra.

rumblesan avatar rumblesan commented on August 9, 2024

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

from hydra.

ojack avatar ojack commented on August 9, 2024

@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

from hydra.

rumblesan avatar rumblesan commented on August 9, 2024

hah, glad to be of use :D

from hydra.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.