chaosprint / glicol

Graph-oriented live coding language and music/audio DSP library written in Rust
https://glicol.org
MIT License
2.22k stars 74 forks source link

Panic with this variation #150

Closed chaosprint closed 5 months ago

chaosprint commented 7 months ago
~gate: speed 2.2
>> seq ~a _~a _~a 72;
~a: choose 48 69 67 72 0 0 0
~amp: ~gate >> envperc 0.001 0.1

~pit: ~gate >> mul 261.63 >> mul 1.0

~lead: saw ~pit >> mul ~amp >> lpf ~mod 1.0
>> meta `
    output = input.map(|x| x* sin(PI) );
    output
`
~mod: sin 0.2 >> mul 1300 >> add 1500;
out: ~lead >> add ~drum >> plate 0.1 // optional semicolon
~drum: speed 4.4 >> seq 60 >> sp \808bd;
// live drag and drop your sample  ^^^
chaosprint commented 7 months ago

guess there is sth wrong with sin(PI)

Jengamon commented 5 months ago

It's the PI as replacing PI with 0.1 doesn't crash the engine

Jengamon commented 5 months ago

Yup, with the current features rhai is used, using this code:

use rhai::{Engine, EvalAltResult};

pub fn main() -> Result<(), Box<EvalAltResult>> {
    let engine = Engine::new();
    let result = engine.eval::<f32>("PI")?;
    println!("Answer: {result}");
    Ok(())
}

I get Error: ErrorVariableNotFound("PI", 1:1)

EDIT: To fix it, you have to call it like a function:

use rhai::{Engine, EvalAltResult};

pub fn main() -> Result<(), Box<EvalAltResult>> {
    let engine = Engine::new();
    let result = engine.eval::<f32>("PI()")?;
    println!("Answer: {result}");
    Ok(())
}

and I've verified that this works in glicol today.