Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions chord.lua
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,20 @@ function ChordBuilder:clone()
return b
end

-- extensions is a table of 4 elements, each element being either 0 or 1 or false or true
-- the first element is the seventh,
-- the second is the ninth,
-- the third is the eleventh,
-- the fourth is the thirteenth
function ChordBuilder:extend(extensions)
local b = self:clone()
b.seventh = (extensions[1]==1 or extensions[1]==true)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I don't get why we would express boolean with either an int or an actual bool value

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea is to allow to pass argument array defining extensions as eg. {false,true,false,false} or {0,1,0,0} for lazy people. If it is not a canonical way to write this, I won't complain imposing strict boolean arguments.

b.ninth = (extensions[2]==1 or extensions[2]==true)
b.eleventh = (extensions[3]==1 or extensions[3]==true)
b.thirteenth = (extensions[4]==1 or extensions[4]==true)
return b
end

function ChordBuilder:withSeventh()
local b = self:clone()
b.seventh = true
Expand Down
2 changes: 1 addition & 1 deletion run_utests.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ require('test/tracks/test_clip_array')
require('test/tracks/test_event')
require('test/tracks/test_event_array')

os.exit( lu.LuaUnit.run() )
os.exit( lu.LuaUnit.run() )
16 changes: 16 additions & 0 deletions scale.lua
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,22 @@ function Scale:to_the_right_on_circle_of_5ths(iterations)
:to_the_right_on_circle_of_5ths(iterations -1)
end

--[[
Warning: only works for ionian scales
]]
function Scale:circle_of_5ths_rotate(iterations)
if(iterations == 0) then
return self
elseif(iterations < 0) then
return self:to_the_left_on_circle_of_5ths(-iterations)
elseif(iterations > 0) then
return self:to_the_right_on_circle_of_5ths(iterations)
else
return "Error"
end
end


--[[
Returns a new scale based on self, rotated from note_offset
note_offset:
Expand Down
24 changes: 23 additions & 1 deletion test/test_scale.lua
Original file line number Diff line number Diff line change
Expand Up @@ -359,4 +359,26 @@ function TestScale:testGetDistance()
luaunit.assertEquals(f_sharp_maj:get_distance(g_flat_min), 2)
luaunit.assertEquals(f_sharp_maj:get_distance(d_sharp_min), 0)
luaunit.assertEquals(f_sharp_maj:get_distance(d_sharp_min_harm), 1)
end
end

function TestScale:test_c5ths_totheleft()
local c_major = Scale.c_major()
local next = c_major:to_the_left_on_circle_of_5ths(1)
-- print(next:tostring())
for i=1,11 do
next = next:to_the_left_on_circle_of_5ths(1)
-- print(next:tostring())
end
luaunit.assertEquals(next, Scale.c_major())
end

function TestScale:test_c5ths_totheright()
local c_major = Scale.c_major()
local next = c_major:to_the_right_on_circle_of_5ths(1)
-- print(next:tostring())
for i=1,11 do
next = next:to_the_right_on_circle_of_5ths(1)
-- print(next:tostring())
end
luaunit.assertEquals(next, Scale.c_major())
end
Loading