original_docstring: Computes elements of cost between two chords: contrary motion, etc.
docstring: Computes elements of cost between two chords: contrary motion, etc.
docstring_tokens: Computes elements of cost between two chords : contrary motion etc .
code: def progressionCost(key, chord1, chord2):
      """Computes elements of cost between two chords: contrary motion, etc."""
      cost = 0
  
      # Overlapping voices
      if (
          chord2[0] > chord1[1]
          or chord2[1] < chord1[0]
          or chord2[1] > chord1[2]
          or chord2[2] < chord1[1]
          or chord2[2] > chord1[3]
          or chord2[3] < chord1[2]
      ):
          cost += 40
  
      # Avoid big jumps
      diff = [abs(chord1.pitches[i].midi - chord2.pitches[i].midi) for i in range(4)]
      cost += (diff[3] // 3) ** 2 if diff[3] else 1
      cost += diff[2] ** 2 // 3
      cost += diff[1] ** 2 // 3
      cost += diff[0] ** 2 // 50 if diff[0] != 12 else 0
  
      # Contrary motion is good, parallel fifths are bad
      for i in range(4):
          for j in range(i + 1, 4):
              t1, t2 = chord1.pitches[j], chord2.pitches[j]
              b1, b2 = chord1.pitches[i], chord2.pitches[i]
              if t1 == t2 and b1 == b2:  # No motion
                  continue
              i1, i2 = t1.midi - b1.midi, t2.midi - b2.midi
              if i1 % 12 == i2 % 12 == 7:  # Parallel fifth
                  cost += 60
              if i1 % 12 == i2 % 12 == 0:  # Parallel octave
                  cost += 100
              if i == 0 and j == 3:  # Soprano and bass not contrary
                  if (t2 > t1 and b2 > b1) or (t2 < t1 and b2 < b1):
                      cost += 2
  
      # Chordal 7th should resolve downward or stay
      if chord1.seventh:
          seventhVoice = chord1.pitches.index(chord1.seventh)
          delta = chord2.pitches[seventhVoice].midi - chord1.seventh.midi
          if delta < -2 or delta > 0:
              cost += 100
  
      # V->I means ti->do or ti->sol
      pitches = key.getPitches()
      pitches[6] = key.getLeadingTone()
      if (
          chord1.root().name
          in (
              pitches[4].name,
              pitches[6].name,
          )
          and chord2.root().name in (pitches[0].name, pitches[5].name)
          and pitches[6].name in chord1.pitchNames
      ):
          voice = chord1.pitchNames.index(pitches[6].name)
          delta = chord2.pitches[voice].midi - chord1.pitches[voice].midi
          if not (delta == 1 or (delta == -4 and voice >= 1 and voice <= 2)):
              cost += 100
  
      return cost
code_tokens: def progressionCost ( key , chord1 , chord2 ) : cost = 0 if ( chord2 [ 0 ] > chord1 [ 1 ] or chord2 [ 1 ] < chord1 [ 0 ] or chord2 [ 1 ] > chord1 [ 2 ] or chord2 [ 2 ] < chord1 [ 1 ] or chord2 [ 2 ] > chord1 [ 3 ] or chord2 [ 3 ] < chord1 [ 2 ] ) : cost += 40 diff = [ abs ( chord1 . pitches [ i ] . midi - chord2 . pitches [ i ] . midi ) for i in range ( 4 ) ] cost += ( diff [ 3 ] // 3 ) ** 2 if diff [ 3 ] else 1 cost += diff [ 2 ] ** 2 // 3 cost += diff [ 1 ] ** 2 // 3 cost += diff [ 0 ] ** 2 // 50 if diff [ 0 ] != 12 else 0 for i in range ( 4 ) : for j in range ( i + 1 , 4 ) : t1 , t2 = chord1 . pitches [ j ] , chord2 . pitches [ j ] b1 , b2 = chord1 . pitches [ i ] , chord2 . pitches [ i ] if t1 == t2 and b1 == b2 : continue i1 , i2 = t1 . midi - b1 . midi , t2 . midi - b2 . midi if i1 % 12 == i2 % 12 == 7 : cost += 60 if i1 % 12 == i2 % 12 == 0 : cost += 100 if i == 0 and j == 3 : if ( t2 > t1 and b2 > b1 ) or ( t2 < t1 and b2 < b1 ) : cost += 2 if chord1 . seventh : seventhVoice = chord1 . pitches . index ( chord1 . seventh ) delta = chord2 . pitches [ seventhVoice ] . midi - chord1 . seventh . midi if delta < - 2 or delta > 0 : cost += 100 pitches = key . getPitches ( ) pitches [ 6 ] = key . getLeadingTone ( ) if ( chord1 . root ( ) . name in ( pitches [ 4 ] . name , pitches [ 6 ] . name , ) and chord2 . root ( ) . name in ( pitches [ 0 ] . name , pitches [ 5 ] . name ) and pitches [ 6 ] . name in chord1 . pitchNames ) : voice = chord1 . pitchNames . index ( pitches [ 6 ] . name ) delta = chord2 . pitches [ voice ] . midi - chord1 . pitches [ voice ] . midi if not ( delta == 1 or ( delta == - 4 and voice >= 1 and voice <= 2 ) ) : cost += 100 return cost
short_docstring: Computes elements of cost between two chords: contrary motion, etc.
short_docstring_tokens: Computes elements of cost between two chords : contrary motion etc .
comment: """Computes elements of cost between two chords: contrary motion, etc."""$SEP$# Overlapping voices$SEP$# Avoid big jumps$SEP$# Contrary motion is good, parallel fifths are bad$SEP$# No motion$SEP$# Parallel fifth$SEP$# Parallel octave$SEP$# Soprano and bass not contrary$SEP$# Chordal 7th should resolve downward or stay$SEP$# V->I means ti->do or ti->sol