Skip to content

Instantly share code, notes, and snippets.

@pcorey pcorey/fourths.exs

Created Aug 15, 2018
Embed
What would you like to do?
Diatonic fourths in C using the Chord project. https://github.com/pcorey/chord/
# 0 1 2 3 4 5 6 7 8 9 10 11
# C D E F G A B
f_maj7 = [5, 9, 0, 4]
b_m7b5 = [11, 2, 5, 9]
e_m7 = [4, 7, 11, 2]
a_m7 = [9, 0, 4, 7]
d_m7 = [2, 5, 9, 0]
g_7 = [7, 11, 2, 5]
c_maj7 = [0, 4, 7, 11]
get_next_chord = fn previous_chord, next_chord ->
next_chord
|> Chord.voicings(4)
|> Enum.map(
&{Chord.Distance.Semitone.distance(
&1,
previous_chord
|> Enum.map(fn
nil -> nil
{fret, _} -> fret
end)
), &1}
)
|> Enum.sort()
|> Enum.chunk_by(&elem(&1, 0))
|> List.first()
|> Enum.map(&elem(&1, 1))
|> Enum.map(fn chord ->
chord
|> Chord.fingerings()
|> Enum.uniq()
|> Enum.map(&{Chord.Distance.Fingering.distance(&1, previous_chord), &1})
end)
|> List.flatten()
|> Enum.sort()
|> Enum.map(&elem(&1, 1))
|> List.first()
end
get_progression = fn starting_chord, progression ->
progression
|> Enum.reduce([starting_chord], fn next_chord, chords = [previous_chord | _] ->
get_next_chord.(previous_chord, next_chord)
|> (&[&1 | chords]).()
end)
|> Enum.reverse()
end
get_progression.([nil, {10, 2}, {10, 3}, {9, 1}, {12, 4}, nil], [
f_maj7,
b_m7b5,
e_m7,
a_m7,
d_m7,
g_7,
c_maj7
])
|> Enum.map(&Chord.to_string/1)
|> Enum.join("\n\n")
|> IO.puts()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.