#compdef atonal-util
#
# ZSH completion for atonal-util. Install to a $fpath directory. Consult
# the perl module Music::AtonalUtil distribution for the related CLI
# program.

forte_numbers=(3-1 3-10 3-11 3-12 3-2 3-3 3-4 3-5 3-6 3-7 3-8 3-9 4-1 4-10 4-11 4-12 4-13 4-14 4-16 4-17 4-18 4-19 4-2 4-20 4-21 4-22 4-23 4-24 4-25 4-26 4-27 4-28 4-3 4-4 4-5 4-6 4-7 4-8 4-9 4-z15 4-z29 5-1 5-10 5-11 5-13 5-14 5-15 5-16 5-19 5-2 5-20 5-21 5-22 5-23 5-24 5-25 5-26 5-27 5-28 5-29 5-3 5-30 5-31 5-32 5-33 5-34 5-35 5-4 5-5 5-6 5-7 5-8 5-9 5-z12 5-z17 5-z18 5-z36 5-z37 5-z38 6-1 6-14 6-15 6-16 6-18 6-2 6-20 6-21 6-22 6-27 6-30 6-31 6-32 6-33 6-34 6-35 6-5 6-7 6-8 6-9 6-z10 6-z11 6-z12 6-z13 6-z17 6-z19 6-z23 6-z24 6-z25 6-z26 6-z28 6-z29 6-z3 6-z36 6-z37 6-z38 6-z39 6-z4 6-z40 6-z41 6-z42 6-z43 6-z44 6-z45 6-z46 6-z47 6-z48 6-z49 6-z50 6-z6 7-1 7-10 7-11 7-13 7-14 7-15 7-16 7-19 7-2 7-20 7-21 7-22 7-23 7-24 7-25 7-26 7-27 7-28 7-29 7-3 7-30 7-31 7-32 7-33 7-34 7-35 7-4 7-5 7-6 7-7 7-8 7-9 7-z12 7-z17 7-z18 7-z36 7-z37 7-z38 8-1 8-10 8-11 8-12 8-13 8-14 8-16 8-17 8-18 8-19 8-2 8-20 8-21 8-22 8-23 8-24 8-25 8-26 8-27 8-28 8-3 8-4 8-5 8-6 8-7 8-8 8-9 8-z15 8-z29 9-1 9-10 9-11 9-12 9-2 9-3 9-4 9-5 9-6 9-7 9-8 9-9)

# XXX --scaledegrees=anything is messing up subsequent completion
_atonal-util() {
  _arguments \
    '--flats[print notes as flats]' \
    '(- *)--help[display help]' \
    '--ly[emit notes not pitch numbers]' \
    '(- *)--listmodes[show available modes]' \
    '--scaledegrees=[degrees in the scale]:scaledegrees:' \
    '*::atonal-util command:_atonalutil_mode'
}

_atonalutil_mode() {
  _atonalutil_modes=(
    'basic:prime_form and interval_class_content info' \
    'circular_permute:all permutations of pitch set'
    'complement:complement of set'
    'equivs:Tn and TnI equivalents' \
    'findin:find pitch sets satisfying a base set' \
    'fnums:return all Forte Numbers and pitch sets' \
    'forte2pcs:return pitch set for Forte Number' \
    'interval_class_content:ICC'
    'invariance_matrix:invarience under TnI' \
    'invariants:list of invariants of a given pitch set' \
    'invert:inversion' \
    'multiply:multiplication' \
    'normal_form:normal_form' \
    'pcs2forte:return Forte Number for a given pitch set' \
    'pitch2intervalclass:pitch to interval class' \
    'prime_form:prime_form' \
    'recipe:list of methods to operate on a set with' \
    'retrograde:reverse' \
    'rotate:specific permutation' \
    'set_complex:2D pitch set to inversion chart' \
    'subsets:subsets of a given pitch set' \
    'tcis:transposition inversion common-tone structure' \
    'tcs:transposition common-tone structure' \
    'tension:tension values for given pitch set' \
    'transpose:Tn' \
    'transpose_invert:TnI' \
    'variances:intersection, difference, and union of two sets' \
    'zrelation:whether two sets share same ICC'
  )

  if (( CURRENT == 1 )); then
    _describe -t commands 'atonalutil command' _atonalutil_modes
  else
    local curcontext="$curcontext"

    cmd="${_atonalutil_modes[(r)$words[1]:*]%%:*}"
    if (( $#cmd )); then
      curcontext="${curcontext%:*:*}:atonalutil-${cmd}:"
      _call_function ret _atonalutil_$cmd || _message 'no more arguments'
    else
      _message "unknown atonalutil command: $words[1]"
    fi
    return ret
  fi
}

# XXX too much copy-n-paste hereafter
_atonalutil_basic() {
  _arguments -s \
    '--flats[print notes as flats]' \
    '--ly[emit notes not pitch numbers]'
}
_atonalutil_circular_permute() {
  _arguments -s \
    '--flats[print notes as flats]' \
    '--ly[emit notes not pitch numbers]'
}
_atonalutil_complement() {
  _arguments -s \
    '--flats[print notes as flats]' \
    '--ly[emit notes not pitch numbers]'
}
_atonalutil_equivs() {
  _arguments -s \
    '--flats[print notes as flats]' \
    '--ly[emit notes not pitch numbers]'
}
_atonalutil_fnums() { }
_atonalutil_findin() {
  _arguments -s \
    '--flats[print notes as flats]' \
    '--ly[emit notes not pitch numbers]' \
    '--pitchset=[base pitch set]:ps:'
}
_atonalutil_forte2pcs() {
  _arguments -s \
    '--flats[print notes as flats]' \
    '--ly[emit notes not pitch numbers]' \
    '1:fortenumber:_values "forte numbers" $forte_numbers'
}
_atonalutil_interval_class_content() { }
_atonalutil_invariance_matrix() { }
_atonalutil_invariants() {
  _arguments -s \
    '--flats[print notes as flats]' \
    '--ly[emit notes not pitch numbers]'
}
_atonalutil_invert() { 
  _arguments -s \
    '--axis=[inversion axis]:value:( )' \
    '--flats[print notes as flats]' \
    '--ly[emit notes not pitch numbers]'
}
_atonalutil_multiply() {
  _arguments -s \
    '--flats[print notes as flats]' \
    '--ly[emit notes not pitch numbers]'
}
_atonalutil_normal_form() {
  _arguments -s \
    '--flats[print notes as flats]' \
    '--ly[emit notes not pitch numbers]'
}
_atonalutil_pcs2forte() { }
_atonalutil_pitch2intervalclass() {
  _arguments -s \
    '--flats[print notes as flats]' \
    '--ly[emit notes not pitch numbers]'
}
_atonalutil_prime_form() {
  _arguments -s \
    '--flats[print notes as flats]' \
    '--ly[emit notes not pitch numbers]'
}
_atonalutil_recipe() {
  _arguments -s \
    '--flats[print notes as flats]' \
    '--ly[emit notes not pitch numbers]' \
    '--file=[recipe file]:filename:_files'
}
_atonalutil_retrograde() {
  _arguments -s \
    '--flats[print notes as flats]' \
    '--ly[emit notes not pitch numbers]'
}
_atonalutil_rotate() { 
  _arguments -s \
    '--rotate=[rotate by]:value:( )' \
    '--flats[print notes as flats]' \
    '--ly[emit notes not pitch numbers]'
}
_atonalutil_set_complex() {
  _arguments -s \
    '--flats[print notes as flats]' \
    '--ly[emit notes not pitch numbers]'
}
_atonalutil_set_complex() {
  _arguments -s \
    '--length=[length]:value:( )' \
    '--flats[print notes as flats]' \
    '--ly[emit notes not pitch numbers]'
}
_atonalutil_tcis() { }
_atonalutil_tcs() { }
_atonalutil_tension() { }
_atonalutil_transpose() {
  _arguments -s \
    '--transpose=[transposition value]:value:( )' \
    '--flats[print notes as flats]' \
    '--ly[emit notes not pitch numbers]'
}
_atonalutil_transpose_invert() {
  _arguments -s \
    '--axis=[inversion axis]:value:( )' \
    '--transpose=[transposition value]:value:( )' \
    '--flats[print notes as flats]' \
    '--ly[emit notes not pitch numbers]'
}
_atonalutil_variances() {
  _arguments -s \
    '--flats[print notes as flats]' \
    '--ly[emit notes not pitch numbers]'
}
_atonalutil_zrelation() { }
