Skip to content

Instantly share code, notes, and snippets.

@gkthiruvathukal
Created December 28, 2013 20:00
Show Gist options
  • Save gkthiruvathukal/8163503 to your computer and use it in GitHub Desktop.
Save gkthiruvathukal/8163503 to your computer and use it in GitHub Desktop.
First attempt at a simple jazz pattern using Abjad
import sys
from abjad import *
# 0=C, 2=D, 3=E, 4=F, 5=F#, 6=G
# How to organize a pattern
# Write it in C-whatever first.
#(C E G)/4 (CC G E)/4 C/2
notetools = scoretools
def respell_as_flats(notes):
for note in notes:
written_pitch = note.written_pitch
accidental_name = written_pitch.accidental.name
if accidental_name == 'sharp':
note.written_pitch = written_pitch.respell_with_flats()
def pattern1(pitch_delta=0):
eighth = Duration(1, 8)
quarter = Duration(1, 4)
half = Duration(1, 2)
transpose = lambda x : x + pitch_delta
pitches = map(transpose, [0, 4, 7, 12, 7, 4, 0])
durations = [eighth] * 3 + [eighth] * 3 + [half]
notes = notetools.make_notes(pitches, durations)
accidentals = set([note.written_pitch.accidental.name for note in notes])
print(notes)
print(accidentals)
if set(['sharp', 'flat']).issubset(accidentals):
print("respelling this pattern's key")
respell_as_flats(notes)
print(notes)
t1_notes = notes[0:3]
t2_notes = notes[3:6]
landing_note = notes[6:]
t1 = Tuplet(Fraction(2, 3), t1_notes)
t2 = Tuplet(Fraction(2, 3), t2_notes)
return [t1, t2] + landing_note
def pattern1_chord(pitch_delta=0):
whole = Duration(4, 4)
transpose = lambda x : x + pitch_delta
pitches = map(transpose, [0, 4, 7])
durations = [whole] * len(pitches)
notes = notetools.make_notes(pitches, durations)
accidentals = set([note.written_pitch.accidental.name for note in notes])
if set(['sharp', 'flat']).issubset(accidentals):
print("respelling this pattern's key")
respell_as_flats(notes)
print(notes)
written_pitches = [note.written_pitch for note in notes]
c = Chord(written_pitches, whole)
print("created chord", str(c))
return c
notes = []
chords = []
for i in range(0, 12):
pattern = pattern1(i)
notes = notes + pattern
chords.append( str(pattern1_chord(i)))
input_string = ' '.join(chords)
# NB: I have the logic to generate these chords but am ending up with some "ugly" sus chords because the
# the Lilypond chord cannot be inferred when the written pitches of the chord are not as expected!
input_string = """<c' e' g'>1
<df' f' af'>1
<d' fs' a'>1
<ef' g' bf'>1
<e' gs' b'>1
<f' a' c''>1
<gf' bf' df''>1
<g' b' d''>1
<af' c'' ef''>1
<a' cs'' e''>1
<bf' d'' f''>1
<b' ds'' fs''>1
"""
print(input_string)
staff = Staff(notes)
chords = Staff(input_string, context_name='ChordNames')
score = Score([chords, staff])
show(score)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment