
    3j                       d dl mZ d dlZd dlZd dlZd dlmZ d dlmZ d dlmZ d dlm	Z	 d dlm
Z
 d dlmZ d d	lmZ e
j                  e
j                   e
j"                  e
j$                  e
j&                  d
Z G d d      Z G d dej,                        Z G d dej0                        Zedk(  rd dlZ ej6                  e       yy)    )annotationsN)exceptions21)note)pitch)key)scale)notation)convertToPitch)majorminordorianphrygianhypophrygianc                  L    e Zd ZU dZdddZded<   ddZdd	Zdd
ZddZ	d Z
y)FiguredBassScalea  
    Acts as a wrapper for :class:`~music21.scale.Scale`. Used to represent the
    concept of a figured bass scale, with a scale value and mode.

    Accepted scale types: major, minor, dorian, phrygian, and hypophrygian.
    A FiguredBassScaleException is raised if an invalid scale type is provided.

    >>> from music21.figuredBass import realizerScale
    >>> fbScale = realizerScale.FiguredBassScale()
    >>> fbScale.realizerScale
    <music21.scale.MajorScale C major>
    >>> fbScale.keySig
    <music21.key.KeySignature of no sharps or flats>

    >>> fbScale = realizerScale.FiguredBassScale('d', 'minor')
    >>> fbScale.realizerScale
    <music21.scale.MinorScale D minor>
    >>> fbScale.keySig
    <music21.key.KeySignature of 1 flat>
    zj
            A :class:`~music21.scale.Scale` based on the
            desired value and mode.
            zu
            A :class:`~music21.key.KeySignature` corresponding to
            the scale value and mode.
            )realizerScalekeySigzdict[str, str]	_DOC_ATTRc                    	 t         |   } ||      | _        t        j                  t        j                  ||            | _        y # t        $ r t        d|z         w xY w)NzUnsupported scale type-> )
scaleModesr   r   KeySignaturepitchToSharpsr   KeyErrorFiguredBassScaleException)self
scaleValue	scaleMode
scaleClasss       N/DATA/.local/lib/python3.12/site-packages/music21/figuredBass/realizerScale.py__init__zFiguredBassScale.__init__@   s`    	U#I.J!+J!7D**3+<+<Z+STDK 	U+,G),STT	Us   AA ANc                   t        |      }| j                  j                  |      }t        j                  |      }|t        j                  |      }t        j                  |      }| j                  j                  |j                  j                        |j                  j                  k7  r>| j                  j                  |j                  j                        |j                  _        | j                  j                  |j                        }g }t        t        |j                               D ]n  }||j                   |   z   dz
  dz  }	| j                  j#                  |	      }
|j$                  |   j'                  |
j(                        }|j+                  |       p |j+                  |j(                         |j-                          |S )ax  
        Takes a bassPitch and notationString and returns a list of corresponding
        pitch names based on the scale value and mode above and inclusive of the
        bassPitch name.

        >>> from music21.figuredBass import realizerScale
        >>> fbScale = realizerScale.FiguredBassScale()
        >>> fbScale.getPitchNames('D3', '6')
        ['D', 'F', 'B']
        >>> fbScale.getPitchNames('G3')
        ['G', 'B', 'D']
        >>> fbScale.getPitchNames('B3', '6,#5')
        ['B', 'D', 'F#', 'G']
        >>> fbScale.getPitchNames('C#3', '-7')  # Fully diminished seventh chord
        ['C#', 'E', 'G', 'B-']
              )r
   r   getScaleDegreeFromPitchr	   Notationcopydeepcopyr   Noter   accidentalByStepr   step
accidentalrangelennumberspitchFromDegree	modifiersmodifyPitchNamenameappendreverse)r   	bassPitchnotationStringbassSDntbassPitchCopybassNote
pitchNamesipitchSDsamplePitch	pitchNames               r   getPitchNameszFiguredBassScale.getPitchNamesH   sb   " #9-	##;;IF~.> MM)4Myy/H,,X^^-@-@A~~001,0KK,H,HI\I\,])''??OF
s2::'A

1-1Q6G,,<<WEKQ778H8HIIi(	 ( 	)..)    c                d    t        |      }|j                  d      }| j                  |||      }|S )a  
        Returns all pitches for a bassPitch and notationString within
        an octave of the bassPitch, inclusive of the bassPitch but
        exclusive at the upper bound. In other words, this method
        returns the most compact complete chord implied by the bassPitch
        and its figures.

        >>> from music21.figuredBass import realizerScale
        >>> fbScale = realizerScale.FiguredBassScale()

        >>> fbScale.getSamplePitches('D3', '6')  # First inversion triad
        [<music21.pitch.Pitch D3>, <music21.pitch.Pitch F3>, <music21.pitch.Pitch B3>]

        Root position triad

        >>> [str(p) for p in fbScale.getSamplePitches('G3') ]
        ['G3', 'B3', 'D4']

        First inversion seventh chord

        >>> [str(p) for p in fbScale.getSamplePitches('B3', '6,5') ]
        ['B3', 'D4', 'F4', 'G4']

        Neapolitan chord

        >>> [str(p) for p in fbScale.getSamplePitches('F3', '-6,-') ]
        ['F3', 'A-3', 'D-4']

        Second inversion seventh chord

        >>> [str(p) for p in fbScale.getSamplePitches('C5', '4,3') ]
        ['C5', 'E5', 'F5', 'A5']

        Fully diminished seventh chord

        >>> [str(p) for p in fbScale.getSamplePitches('C#3', '-7') ]
        ['C#3', 'E3', 'G3', 'B-3']
        d8)r
   	transpose
getPitches)r   r5   r6   maxPitchsamplePitchess        r   getSamplePitchesz!FiguredBassScale.getSamplePitchesp   s7    N #9-	&&t,	>8LrA   c                   t        j                  d      t              t              | j                  |      }t	        j
                  |t        j                  dz               }t        d |      }t	        j                  fd|      }t	        j                  fd|      }t        |      }	|	j                          |	S )a$  
        Takes in a bassPitch, a notationString, and a maxPitch representing the highest
        possible pitch that can be returned. Returns a sorted list of pitches which
        correspond to the pitches of each specific pitch name found through getPitchNames
        that fall between the bassPitch and the maxPitch, inclusive of both.

        if maxPitch is None, then B5 s used instead.

        >>> from music21.figuredBass import realizerScale
        >>> fbScale = realizerScale.FiguredBassScale()

        Root position triad

        >>> [str(p) for p in fbScale.getPitches('C3') ]
        ['C3', 'E3', 'G3', 'C4', 'E4', 'G4', 'C5', 'E5', 'G5']

        First inversion triad

        >>> [str(p) for p in fbScale.getPitches('D3', '6') ]
        ['D3', 'F3', 'B3', 'D4', 'F4', 'B4', 'D5', 'F5', 'B5']

        Root position seventh chord, showing MaxPitch

        >>> fbScale.getPitches(pitch.Pitch('G3'), '7', 'F4')
        [<music21.pitch.Pitch G3>, <music21.pitch.Pitch B3>,
         <music21.pitch.Pitch D4>, <music21.pitch.Pitch F4>]
        B5r"   c                P    t        j                  | d   t        | d         z         S )Nr   r"   )r   Pitchstr)xs    r   <lambda>z-FiguredBassScale.getPitches.<locals>.<lambda>   s    ekk!A$QqT*:;rA   c                    | kD  S N )r>   r5   s    r   rO   z-FiguredBassScale.getPitches.<locals>.<lambda>   s
    )k:QrA   c                    | kD  S rQ   rR   )r>   rF   s    r   rO   z-FiguredBassScale.getPitches.<locals>.<lambda>   s
    +:PrA   )r   rL   r
   r@   	itertoolsproductr,   octavemapfilterfalselistsort)
r   r5   r6   rF   r;   iter1iter2iter3iter4
allPitchess
    ` `      r   rE   zFiguredBassScale.getPitches   s    8 {{4(H"9-	!(+''	>B
!!*eHOOa4G.HI;UC%%&QSXY%%&PRWX%[
rA   c                    | j                   S rQ   )r   )r   s    r   _reprInternalzFiguredBassScale._reprInternal   s    $$'(rA   )Cr   rQ   )NN)__name__
__module____qualname____doc__r   __annotations__r    r@   rH   rE   ra   rR   rA   r   r   r       s<    *	!I~ 	U&P+Z(T)rA   r   c                      e Zd Zy)r   Nrc   rd   re   rR   rA   r   r   r          rA   r   c                      e Zd Zy)TestNri   rR   rA   r   rl   rl      rj   rA   rl   __main__)
__future__r   r&   rT   unittestmusic21r   r   r   r   r   music21.figuredBassr	   music21.figuredBass.notationr
   
MajorScale
MinorScaleDorianScalePhrygianScaleHypophrygianScaler   r   Music21Exceptionr   TestCaserl   rc   mainTestrR   rA   r   <module>r{      s    #          ( 7''''))--#55	7
h) h)V	 = = 		8 	 zGT rA   