Circle of 5ths fixes and tests#25
Conversation
scale.lua
Outdated
| return self:rotate(4) | ||
| :add_alteration(4, -1) | ||
| :to_the_left_on_circle_of_5ths(iterations -1) | ||
| out = self:clone() |
There was a problem hiding this comment.
Sorry I don't get it.
return self:rotate(4)
:add_alteration(4, -1)
:to_the_left_on_circle_of_5ths(iterations -1)
is strictly equivalent to
out = self:clone()
for i = 1, iterations do
out = out:rotate(4):add_alteration(4, -1)
end
So we could probably keep the recursive implementation even with the fix.
What I don't get is
if out:count_alterations() < -7 then
out = out:to_the_right_on_circle_of_5ths(12)
end
I guess you need it somehow because it makes your tests pass but I don't know what it does and if it is that generic. For instance what happens if someone calls to_the_left_on_circle_of_5ths(123) ?
There was a problem hiding this comment.
What it does : If there are more than seven alterations on the scale (sharp of flat), there is an equivalent scale with only one of the other alteration (flat or sharp). To get it you have to rotate 12 on the opposite way.
If you want to allow double sharp or double flats, then the criterion would be out:count_alterations() < -14 . Would that would satisfy your need of generality ?
Although I agree that a recursive version is more elegant, it is also less efficient because the check would be done at each iteration. With a for loop, the check is done only at the end of the requested rotation.
to_the_left_on_circle_of_5ths(123) works with the proposed implementation. It will first add that many alterations, and then recursively call ten times to_the_right_on_circle_of_5ths(12). The result would be to_the_left_on_circle_of_5ths(3).
scale.lua
Outdated
| return self:rotate(5) | ||
| :add_alteration(7, 1) | ||
| :to_the_right_on_circle_of_5ths(iterations -1) | ||
| out = self:clone() |
No description provided.