Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possibility for meta node manipulation #51

Closed
1 of 2 tasks
chaosprint opened this issue Feb 15, 2022 · 1 comment
Closed
1 of 2 tasks

Possibility for meta node manipulation #51

chaosprint opened this issue Feb 15, 2022 · 1 comment
Labels
enhancement New feature or request

Comments

@chaosprint
Copy link
Owner

chaosprint commented Feb 15, 2022

It would also be great to support dynamic node.

o: sin 440 >> dnode "for i in range(128): output[0][i] = input[0][i] * 0.5"

grame-cncm/faust#685 (comment)

Edit:

I have been looking for options for this embedding language and finally landed on rhai.

the syntax of rhai is really intuitive and I think it has merged the syntax sugar of js and rust.

embedding Rhai in Glicol is a very straightforward experience thanks to its well-designed api and docs (rhai.rs)

now, users can write:

a: script `
    output.pad(128, 0.0);
    for i in 0..128 {
        output[i] = sin(2*PI()*phase) ;
        phase += 440.0 / sr;
    };
    while phase > 1.0 { phase -= 1.0 };
    output
` >> script `
    output = input.map(|i|i*0.2);
    output
`

see the interactive example on https://glicol.org/guide#rhai2

from my current testing, for this real-time audio scripting, creating new variables, especially arrays should be avoided.

for now the script node provides outout, input (if there is one), sr and phase to the Scope of rhai, as well as variables from a to z. x0, x1, x2, y0, y1, y2.

I am still exploring the possibility to share a ringbuf in rhai Scope; some functions such as random can also be useful.


Add an example:

// a sawtooth osc chained with a onepole filter
a: meta `
	f = 220.;
	output.pad(128, 0.0);
	if phase == 0 {
		p = 0.0;
	}
	for i in 0..128 {
		output[i] = p * 2. - 1.;
		p += f / sr;
	};
	if p > 1.0 { p -= 1.0 };
	output
` >> meta `
	r = 1./2000.;
	if phase == 0.0 {
		z = 0.0
	}
	output.pad(128, 0.0);
	b = (-2.0 * PI() * r).exp();
	a = 1.0 - b;
	for i in 0..128 {
		y = input[i] * a + b * z;
		output[i] = y;
		z = y;
	};
	output
`

TODOs:

  • Solve the popping during update
  • Improve the performance
@chaosprint chaosprint changed the title Missing the mechanism to add large scales of oscillators at once Dynamic node manipulation Feb 15, 2022
@chaosprint chaosprint changed the title Dynamic node manipulation Possibility for dynamic node manipulation Feb 15, 2022
@chaosprint chaosprint added the enhancement New feature or request label Feb 15, 2022
@chaosprint chaosprint pinned this issue Feb 19, 2022
@chaosprint chaosprint added this to the v1.0.0 milestone Feb 21, 2022
@chaosprint chaosprint changed the title Possibility for dynamic node manipulation Possibility for dynamic (meta) node manipulation Mar 16, 2022
@chaosprint chaosprint changed the title Possibility for dynamic (meta) node manipulation Possibility for meta node manipulation Mar 18, 2022
@chaosprint chaosprint unpinned this issue Apr 18, 2022
@chaosprint chaosprint removed this from the v1.0.0 milestone Nov 15, 2022
@chaosprint
Copy link
Owner Author

done with expr and eval; will finalise them right away.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant