Skip to content

Instantly share code, notes, and snippets.

@pcorey
Created August 15, 2018 23:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pcorey/0101a9861370f5c566762f3c83e69da8 to your computer and use it in GitHub Desktop.
Save pcorey/0101a9861370f5c566762f3c83e69da8 to your computer and use it in GitHub Desktop.
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