DasEtwas / enginesound

Procedural engine sound generator controlled via GUI or CLI
MIT License
309 stars 15 forks source link

New Feature #5

Closed matchild closed 3 years ago

matchild commented 3 years ago

Hi, It would be awesome to change the rpms in real-time through stdin (and not only the slider in the GUI). This would help a lot in interfacing the simulator with other scripts!

DasEtwas commented 3 years ago

I'm hesitant to add this feature, as the crate exposes the generator struct as a library already. A C FFI would make more sense, as it can be accessed easily using python.

matchild commented 3 years ago

I agree, that would probably be a better approach (though it would also be more complicated if you are not familiar with Rust).

Anyway, in case someone else is wondering, I eventually managed to do it by adding this to main.rs:

let mut generator = generator.clone();
        loop {
            let n = get_input().trim().parse::<i64>().unwrap();
        let flt = n as f32;
        generator.write().engine.rpm=flt    
        }

Where get_input() is defined as:

fn get_input() -> String {
    let mut buffer = String::new();
    std::io::stdin().read_line(&mut buffer).expect("Failed");
    buffer
}

(Thank you again for this awesome library)