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

Simpler value() function #125

Open
tobx opened this issue Feb 9, 2019 · 0 comments
Open

Simpler value() function #125

tobx opened this issue Feb 9, 2019 · 0 comments

Comments

@tobx
Copy link

tobx commented Feb 9, 2019

Hey, I love your project and try to understand how things work (just for fun).

I think the Interval.prototype.value() function can be a lot simplified. An octave has 7 key steps, a fifths has 4. So why not simplify the function like this:

let steps = vector.sum(vector.mul(this.coord, [7, 4]));
return steps + (steps < 0 ? -1 : 1);

I tried it with a small test and it seems to work:

['P1', 'M3', 'm13', 'P15', 'd12', 'AA3', 'AA-1', 'M-14', 'm-6', 'P-15', 'd-12', 'AA-10'].forEach((name) => {
	let interval = teoria.interval(name);
	let steps = interval.coord[0] * 7 + interval.coord[1] * 4;
	let value = steps + (steps < 0 ? -1 : 1);
	console.log(name, value === interval.value());
});

I hope I have not overlooked something...

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

1 participant