mò TæBc@sÒdklZlZdklZdklZdklZd„Z d„Z d„Z d„Z d„Z d „Zd „Zd „Zd „Zd d„Zd„Zdfd„ƒYZd„Zd„Zd„ZdS((sfloorslog(sgcd(s generators(ssplitcCs d||S(sdcents_et(degree,division) returns the cents value of a given pitch degree in a given octave divison.f1200.0N(tdivisiontdegree(RR((t microtonal.pytcents_etscCst|dƒ\}}|djo|d}|d}nt|ƒ}dtt|dƒƒ}|djo d}n||fS( s©note_and_bend(cents) returns a tuple containing a standard 12-equal keyboard MIDI note number, plus a pitch bend value required to hit the target parameter's cents valuef100.0i2iidi f40.960000000000001iŠi‰N(tdivmodtcentstnotetremaintinttroundtbend(RRRR ((Rt note_and_bend s     cCs||d}|djp |djo t‚n|djo7|}xr|djo|d}||d}qHWnE|djo7|}x.|djo|d}||d}qŒWnt||ƒ}t|d|ƒtdƒd}|||||fS(sji_space(numerator,denominator) returns an octave-reduced and simplified numerator, denominator, and cents value as a 3-tuple. The numerator and denominator themselves can be passed as arithmetic expressions to be evaluated, so that in effect, fractions can be multiplied, etc.f0.0iiii°N( t numeratort denominatortdec_valtZeroDivisionErrort new_dec_valtgcdtfactortlogR(R R RRRR((Rtji_spaces&       "cCs‰|dg}d}xo|dD]c}t|dƒ}tt|dƒt|dƒƒd}|i tt ||ƒƒƒ|d7}qW|S(s#make_offsets(scale_array) returns a cents-offset from 12-equal temperament array based on an inputted array of string representations of a Just Intonation scale as fractions, e.g. ['1/1','16/15', etc.]. Since this is designed to give 12-member sets, the input scale must be 12-members large.iit/iidN( t scale_arraytoutt step_of_12tfractsplittfractionRRt cents_valuetappendR (RRRRRR((Rt make_offsets0s  'cCs,||d}dtt|ƒtdƒƒS(soctave_of_fraction(numerator,denominator) returns the MIDI octave\ that a given just intonation ratio will lie in, with middle C equal to 5.f0.0iiN(R R RtfloorR(R R R((Rtoctave_of_fraction?scCs·tt|dƒƒ}g}g}x@t|ƒD]2}||d}||jo|i |ƒq/q/W|i dƒ|}|i ƒx$|D]}|i |i |ƒƒqŠW|||fS(Nièi€O(RR tfifthtvaluestindexestrangetlengthtxtnewRtunsorted_valuestsorttitemtindex(R!R%R#R*R"R'R(R&((Rt make_meantoneEs    cCs€g}xTtdt|ƒdƒD]:}||||d}||jo|i|ƒqqWt|ƒdjodSndSdS(Niii(tdiffsR$tlentarrayR&tdiffR(R/R-R&R0((Rtis_mosTs cCsXg}xKtd|dƒD]7}t||ƒ}t|dƒo|i|ƒqqW|S(Niii( tmos_setR$tlimitR&R,R!tscaleR1R(R!R3R4R2R&((Rt find_mos_a_scCs+g}t|ƒD]}||iƒq~S(N(t_[1]R$tnR&tgtnext(R7R8R6R&((Rtfirsthsiccsµ|d}t|ƒ}d\}}xŒt||ƒdjotd||}t|ƒ}|o||||}}|Vq%||}}x"t|ƒD]}||7}|Vq”Wq%WdS(Nf1200.0iif9.9999999999999995e-07(ii( R!tratioRtitmPrevtmtabst mustBeProperR$R7(R!R@R;R<R>R7R=((Rtfind_mosks       c Cs‹g}g}xrt||ddƒD]Z}xQt|ƒD]C}tt ||ƒƒ\}}|i |d|ƒ|i |ƒq6Wq#W||fS(Nii ( tnotestbendsR$t octave_mint octave_maxtoctRtstepR RRR R( RRDRERCRBRGRR RF((Rtmicrotonal_chromatic_scale~s t microtonalcBstZd„ZRS(NcCsªtttddƒd|dƒƒ|_tttddƒd|dƒƒ|_tttddƒd|dƒƒ|_tttdd ƒd|dƒƒ|_tttd d ƒd|dƒƒ|_ tttd d ƒd|dƒƒ|_ tttd dƒd|dƒƒ|_ tttdd ƒd|dƒƒ|_ ttd |dƒƒ|_ tttd dƒd|dƒƒ|_tttdd ƒd|dƒƒ|_tttddƒd|dƒƒ|_tttd d ƒd|dƒƒ|_tttdd ƒd|dƒƒ|_tttddƒd|dƒƒ|_tttddƒd|dƒƒ|_d|i|i |i |i|i|ig|_d|i|i|i |i|i|ig|_d|i|i|i |i|i|ig|_d|i|i|i |i|i|ig|_d|i|i |i |i|i|ig|_d|i|i |i |i|i|ig|_d|i|i|i |i |i|ig|_d|i|i|i |i |i|i|ig|_d|i|i |i |i|ig|_d|i|i |i|ig|_d|i|i |i |i|i|ig|_t |ƒ|_!dS(Niiii°i iiiiiii f696.57799999999997i i("RR RRtselft minor_secondt major_secondtseptimal_minor_thirdt minor_thirdt major_thirdtfourththarmonic_eleventhttritonetmeantone_fifthR!t minor_sixththarmonic_thirteentht major_sixththarmonic_seventht minor_seventht major_seventhtmajortminortdoriantphrygiantlydiant mixolydiantlocriant octatonict whole_tonet pentatonictgypsyR$t chromatic(RJR((Rt__init__‰s8***************00000006*$0(t__name__t __module__Rf(((RRIˆscCsZg}xMt||ƒD]<}x3td||fƒD]}|i |||ƒq3WqW|S(Nsmicrotonal(%i).%s( R4R$toct_mintoct_maxtoctavetevalRttypeRR(RRmRiRjR4RRk((Rtmicrotonal_scaleèsc Cs­g}g}x\t||ƒD]K}xB|D]:}t|ƒ\}}|i |d|ƒ|i |ƒq)WqWt|dƒ\}}|i |d|ƒ|i |ƒ||fS(Ni i( RBRCR$RiRjRktlistRR RR R( RoRiRjRCRRR RkRB((Rtcreate_scale_from_centsïs c Csg}g}x@td|ddƒD](}||djo|i|ƒq#q#WxMtd|ddƒD]5} || djo| |jo|i| ƒqfqfW|iƒdt |ƒGHt |ƒ}|ddjo|i|dƒd} nd} |i|ƒ|d}xc|D][}t||dƒtdƒ}|tdt|ƒƒ}||jo|i|ƒqqW|iƒ|S(Niis scale is %sif0.0(R4t out_scaleR$R&taRtytbR)tstrtmaxtmax_notetscaling_factorR*RRtpowRtanswer( R&RsRrR4RwRRzRqR*RtRx((Rtdudonüs6       N(tmathRRt math_stuffRt __future__t generatorststringRRR RRR R,R1R5R:RARHRIRnRpR{(R1R RIRRHRR{RRnR:RARR,RRR R5RRpR((Rt?s$            `