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

[FR] Shorthand for mapping event input values #47

Closed
agdsat134 opened this issue Nov 28, 2020 · 1 comment
Closed

[FR] Shorthand for mapping event input values #47

agdsat134 opened this issue Nov 28, 2020 · 1 comment

Comments

@agdsat134
Copy link

agdsat134 commented Nov 28, 2020

I wasn't sure if this is the right place to put a feature request, if not let me know.

Since processors can potentially have a lot of event inputs, I thought there may be a way we could reduce boilerplate. From my understanding this is the current best practice for adding an input and mapping it to a value:

processor Synth
{
	input event float inputOne;

	float inputOneValue = 0.0f;

	event inputOne(float v)
	{
		inputOneValue = v;
	}
}

When you add a lot of different inputs, this requires a lot more code and reduces clarity. What if we could map the value in two lines:

float inputOneValue;
input event float inputOne => inputOneValue;

Or add a getter function (.getValue()) to the event identifier so you don't have to create a separate variable:

processor Gain
{
	input stream float in;
	output stream float out;
	input event float gain = 1.0f; // initial value

	void run()
	{
		loop
		{
			out << in * gain.getValue();
			
			advance();
		}
	}
}
@julianstorer
Copy link
Contributor

Thanks - this is a good idea, and we'd been thinking along the same lines!

It's on the to-do-list.. My current thoughts are that we can implement it without any new syntax: if you don't provide an event function, then any uses of the endpoint name will simply return the last value that was received.

(And if you do provide a callback function, then it'll work the same as it does now, and won't allowed the name to be used as an expression)

Good point about it needing an initial value - the syntax you suggested is probably the best for that (and I guess that if you do provide an initial value, it means you're not allowed to also provide an event function)

Cheers - will implement this soon!

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

No branches or pull requests

2 participants