Skip to content

Simpler value() function #125

@tobx

Description

@tobx

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...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions