Files
loustique-home/venv/lib/python3.11/site-packages/gpiozero/__pycache__/tones.cpython-311.pyc

114 lines
11 KiB
Plaintext
Raw Normal View History

2026-03-21 10:53:02 +01:00
<EFBFBD>
?<3F><>i<EFBFBD>!<00><00>J<00>ddlZddlZddlmZddlmZGd<05>de<06><00>ZdS)<07>N)<01>log2<67>)<01> AmbiguousTonec<00>V<00><00>eZdZdZdZddddddd<06>Zejdd<08>e<05> <00><00><00><00><00>d <09><03><00>Z
dd
d
d
d <0B>d <0C>Z d <0A>Z d<0E>Z ed<0F><00><00>Zed<10><00><00>Ze<0E>fd<11><08><00>Zed<12><00><00>Zed<13><00><00>Zed<14><00><00>Zdd<15>Zdd<16>Z<17>xZS)<19>Tonea<65>
Represents a frequency of sound in a variety of musical notations.
:class:`Tone` class can be used with the :class:`~gpiozero.TonalBuzzer`
class to easily represent musical tones. The class can be constructed in a
variety of ways. For example as a straight frequency in `Hz`_ (which is the
internal storage format), as an integer MIDI note, or as a string
representation of a musical note.
All the following constructors are equivalent ways to construct the typical
tuning note, `concert A`_ at 440Hz, which is MIDI note #69:
>>> from gpiozero.tones import Tone
>>> Tone(440.0)
>>> Tone(69)
>>> Tone('A4')
If you do not want the constructor to guess which format you are using
(there is some ambiguity between frequencies and MIDI notes at the bottom
end of the frequencies, from 128Hz down), you can use one of the explicit
constructors, :meth:`from_frequency`, :meth:`from_midi`, or
:meth:`from_note`, or you can specify a keyword argument when
constructing::
>>> Tone.from_frequency(440)
>>> Tone.from_midi(69)
>>> Tone.from_note('A4')
>>> Tone(frequency=440)
>>> Tone(midi=69)
>>> Tone(note='A4')
Several attributes are provided to permit conversion to any of the
supported construction formats: :attr:`frequency`, :attr:`midi`, and
:attr:`note`. Methods are provided to step :meth:`up` or :meth:`down` to
adjacent MIDI notes.
.. warning::
Currently :class:`Tone` derives from :class:`float` and can be used as
a floating point number in most circumstances (addition, subtraction,
etc). This part of the API is not yet considered "stable"; i.e. we may
decide to enhance / change this behaviour in future versions.
.. _Hz: https://en.wikipedia.org/wiki/Hertz
.. _concert A: https://en.wikipedia.org/wiki/Concert_pitch
<20> CCDDEFFGGAAB<41><42><EFBFBD><EFBFBD><EFBFBD>rr)u<>bu<>u<>#z(?P<note>[A-G])(?P<semi>[r z]?)(?P<octave>[0-9])N)<03> frequency<63>midi<64>notec<00>v<00>td<01>||||fD<00><00><00><00>}|dkrtd<03><00><00>|<04>|<00>|<04><00>S|<03>|<00>|<03><00>S|<02>|<00>|<02><00>St |t tf<02><00>rad|cxkrdkr?nn<|dkr!tj td<06><00><00><00>|<00>|<01><00>S|<00>|<01><00>St |ttf<02><00>r|<00>|<01><00>S|<00>|<01><00>S)Nc3<00>K<00>|]}|<01>dV<00><00> dS)Nr<00>)<02>.0<EFBFBD>args <20>Z/home/maxime/Documents/loustiques-home/venv/lib/python3.11/site-packages/gpiozero/tones.py<70> <genexpr>zTone.__new__.<locals>.<genexpr>Qs"<00><00><00><00>O<>O<>c<EFBFBD>s<EFBFBD><EFBFBD><01><EFBFBD><EFBFBD><EFBFBD><EFBFBD>O<>O<>rz5must specify a value, frequency, midi number, or noter<00><>z<>Ambiguous tone specification; assuming you want a MIDI note. To suppress this warning use, e.g. Tone(midi=60), or to obtain a frequency instead use, e.g. Tone(frequency=60)) <0A>sum<75> TypeError<6F> from_note<74> from_midi<64>from_frequency<63>
isinstance<EFBFBD>int<6E>float<61>warnings<67>warnr<00>bytes<65>str)<06>cls<6C>valuer rr<00>ns r<00>__new__z Tone.__new__Ps\<00><00> <0F>O<>O<>e<EFBFBD>Y<EFBFBD><04>d<EFBFBD>;<3B>O<>O<>O<> O<> O<><01> <0C><01>6<EFBFBD>6<EFBFBD><1B>&<26>'<27>'<27> '<27> <0F> <1B><16>=<3D>=<3D><14>&<26>&<26> &<26> <11> <1D><16>=<3D>=<3D><14>&<26>&<26> &<26> <16> "<22><16>%<25>%<25>i<EFBFBD>0<>0<> 0<><19>%<25>#<23>u<EFBFBD><1C>.<2E>.<2E> 1<><14><05>#<23>#<23>#<23>#<23><03>#<23>#<23>#<23>#<23>#<23><1C>q<EFBFBD>y<EFBFBD>y<EFBFBD> <20> <0A>)<29>!&<26>'<27>'<27>(<28>(<28>(<28><1F>=<3D>=<3D><15>/<2F>/<2F>/<2F><1E>-<2D>-<2D>e<EFBFBD>4<>4<>4<><1B>E<EFBFBD>E<EFBFBD>3<EFBFBD><<3C>0<>0<> 1<><1A>}<7D>}<7D>U<EFBFBD>+<2B>+<2B>+<2B><1A>)<29>)<29>%<25>0<>0<>0rc<00><00>|jS<00>N)r<00><01>selfs r<00>__str__z Tone.__str__ns
<00><00><13>y<EFBFBD>rc<00><><00> |j}d|<01><02>}n#t$rd}YnwxYw |j}d|<02><02>}n#t$rd}YnwxYwd|<02>|<01>d|jd<06>d<07>S)Nz midi=r z note=z<Tonez frequency=<3D>.2fzHz>)r<00>
ValueErrorrr )r,rrs r<00>__repr__z Tone.__repr__qs<><00><00> %<25><17>9<EFBFBD>D<EFBFBD>%<25>D<EFBFBD>$<24>$<24>D<EFBFBD>D<EFBFBD><44><1A> <16> <16> <16><15>D<EFBFBD>D<EFBFBD>D<EFBFBD> <16><><EFBFBD><EFBFBD> %<25><17>9<EFBFBD>D<EFBFBD>%<25>D<EFBFBD>$<24>$<24>D<EFBFBD>D<EFBFBD><44><1A> <16> <16> <16><15>D<EFBFBD>D<EFBFBD>D<EFBFBD> <16><><EFBFBD><EFBFBD>F<01>t<EFBFBD>E<>T<EFBFBD>E<>E<>d<EFBFBD>n<EFBFBD>E<>E<>E<>E<>Es<00><00> <03><03>/<00> ><03>>c<00><><00>t|<01><00>}d|cxkrdkr(nn%d}d}|<00>|d||z
dz zz<00><00>Std|<02><02><02><00><00>)a
Construct a :class:`Tone` from a MIDI note, which must be an integer
in the range 0 to 127. For reference, A4 (`concert A`_ typically used
for tuning) is MIDI note #69.
.. _concert A: https://en.wikipedia.org/wiki/Concert_pitch
rr<00>E<00><><00><00> zinvalid MIDI note: )rrr0)r%<00> midi_noter<00>A4_midi<64>A4_freqs rrzTone.from_midi<64>sy<00><00><13>9<EFBFBD>~<7E>~<7E><04> <0C> <09> <1F> <1F> <1F> <1F>C<EFBFBD> <1F> <1F> <1F> <1F> <1F><18>G<EFBFBD><19>G<EFBFBD><16>%<25>%<25>g<EFBFBD><01>t<EFBFBD>g<EFBFBD>~<7E><12>6K<36>0L<30>&L<>M<>M<> M<><18>7<>t<EFBFBD>7<>7<>8<>8<>8rc<00><00>t|t<00><00>r|<01>d<01><00>}t|t<00><00>r<>tj<00>|<01><00>}|r<>t|<02>d<02><00><00><00>dz}|<00> tj
<00> |<02>d<04><00><00><00>tj |<02>d<05><00>z|dzz<00><00>Std|<01><02><02><00><00>)a[
Construct a :class:`Tone` from a musical note which must consist of
a capital letter A through G, followed by an optional semi-tone
modifier ("b" for flat, "#" for sharp, or their Unicode equivalents),
followed by an octave number (0 through 9).
For example `concert A`_, the typical tuning note at 440Hz, would be
represented as "A4". One semi-tone above this would be "A#4" or
alternatively "Bb4". Unicode representations of sharp and flat are also
accepted.
.. _concert A: https://en.wikipedia.org/wiki/Concert_pitch
<20>ascii<69>octaverr<00>semir6zinvalid note specification: )rr#<00>decoder$r<00>regex<65>matchr<00>groupr<00>tones<65>index<65> semitonesr0)r%rr@r<s rrzTone.from_note<74>s<><00><00> <16>d<EFBFBD>E<EFBFBD> "<22> "<22> (<28><17>;<3B>;<3B>w<EFBFBD>'<27>'<27>D<EFBFBD> <15>d<EFBFBD>C<EFBFBD> <20> <20> !<21><18>J<EFBFBD>$<24>$<24>T<EFBFBD>*<2A>*<2A>E<EFBFBD><14> !<21><1C>U<EFBFBD>[<5B>[<5B><18>2<>2<>3<>3<>a<EFBFBD>7<><06><1A>}<7D>}<7D><18>J<EFBFBD>$<24>$<24>U<EFBFBD>[<5B>[<5B><16>%8<>%8<>9<>9<><18>N<EFBFBD>5<EFBFBD>;<3B>;<3B>v<EFBFBD>#6<>#6<>7<>8<><1A>R<EFBFBD>K<EFBFBD> <20>!<21>!<21>!<21><19>@<40><04>@<40>@<40>A<>A<>Arc<00><><00><01>d|cxkrdkr%nn"t<00><00><00>||<01><00>Std|d<04><04><02><00><00>)z<>
Construct a :class:`Tone` from a frequency specified in `Hz`_ which
must be a positive floating-point value in the range 0 < freq <= 20000.
.. _Hz: https://en.wikipedia.org/wiki/Hertz
ri Nzinvalid frequency: r/)<03>superr(r0)r%<00>freq<65> __class__s <20>rrzTone.from_frequency<63>sY<00><><00> <0A>t<EFBFBD> <1C> <1C> <1C> <1C>u<EFBFBD> <1C> <1C> <1C> <1C> <1C><18>7<EFBFBD>7<EFBFBD>?<3F>?<3F>3<EFBFBD><04>-<2D>-<2D> -<2D><18>9<>t<EFBFBD>9<>9<>9<>:<3A>:<3A>:rc<00> <00>t|<00><00>S)zq
Return the frequency of the tone in `Hz`_.
.. _Hz: https://en.wikipedia.org/wiki/Hertz
)r r+s rr zTone.frequency<63>s<00><00><15>T<EFBFBD>{<7B>{<7B>rc <00><><00>ttdt|jdz <00><00>zdz<00><00><00><00>}d|cxkrdkrnn|St |jd<06>d<07><02><00><00>)a+
Return the (nearest) MIDI note to the tone's frequency. This will be an
integer number in the range 0 to 127. If the frequency is outside the
range represented by MIDI notes (which is approximately 8Hz to 12.5KHz)
:exc:`ValueError` exception will be raised.
r6r4r3rr<00>fz is outside the MIDI note range)r<00>roundrr r0)r,<00>results rrz Tone.midi<64>su<00><00><15>U<EFBFBD>2<EFBFBD><04>T<EFBFBD>^<5E>c<EFBFBD>%9<> :<3A> :<3A>:<3A>R<EFBFBD>?<3F>@<40>@<40>A<>A<><06> <0C><06> <1C> <1C> <1C> <1C><13> <1C> <1C> <1C> <1C> <1C><19>M<EFBFBD><18>D<EFBFBD>N<EFBFBD>M<>M<>M<>M<>N<>N<>Nrc<00> <00>|jdz
}|dz}d|dzz}d|cxkrdkrSnnPtj|tj|tj|dz
krdndzt|<03><00>zSt |jd <09>d
<EFBFBD><02><00><00>) aV
Return the (nearest) note to the tone's frequency. This will be a
string in the form accepted by :meth:`from_note`. If the frequency is
outside the range represented by this format ("A0" is approximately
27.5Hz, and "G9" is approximately 12.5Khz) a :exc:`ValueError`
exception will be raised.
<20><r6<00>r<00> rr r rKz is outside the notation range)rrrBr$r0r )r,<00>offsetrCr<s rrz Tone.note<74>s<><00><00><16><19>R<EFBFBD><1E><06><16><12> <0B><05><12>V<EFBFBD>r<EFBFBD>\<5C>!<21><06> <0C><06> <1B> <1B> <1B> <1B>!<21> <1B> <1B> <1B> <1B> <1B><14>
<EFBFBD>5<EFBFBD>!<21><1C>
<EFBFBD>5<EFBFBD>)<29>T<EFBFBD>Z<EFBFBD><05><01> <09>-B<>B<>B<><13><13><02>L<01><13>F<EFBFBD> <0B> <0B><1C> <0E>
<19>D<EFBFBD>N<EFBFBD>L<>L<>L<>L<>M<>M<>Mrc<00>F<00>t<00>|j|z<00><00>S)zk
Return the :class:`Tone` *n* semi-tones above this frequency (*n*
defaults to 1).
<20>rrr<00>r,r's r<00>upzTone.up<75><00><00><00>
<14>~<7E>~<7E>d<EFBFBD>i<EFBFBD>!<21>m<EFBFBD>,<2C>,<2C>,rc<00>F<00>t<00>|j|z
<00><00>S)zk
Return the :class:`Tone` *n* semi-tones below this frequency (*n*
defaults to 1).
rTrUs r<00>downz Tone.down<77>rWrr*)r)<19>__name__<5F>
__module__<EFBFBD> __qualname__<5F>__doc__rBrD<00>re<72>compile<6C>join<69>keysr?r(r-r1<00> classmethodrrr<00>propertyr rrrVrY<00> __classcell__)rHs@rrrs<><00><><00><00><00><00><00>-<08>-<08>^ <1B>E<EFBFBD><11> <0F><10> <0E><10> <0E> <06><06>I<EFBFBD> <17>B<EFBFBD>J<EFBFBD> <1E><18>g<EFBFBD>g<EFBFBD>i<EFBFBD>n<EFBFBD>n<EFBFBD>.<2E>.<2E>/<2F>/<2F> <1E> <1E> <1E> <1F> <1F>E<EFBFBD>
1<>d<EFBFBD><14>D<EFBFBD>1<>1<>1<>1<>1<><<19><19><19> F<01> F<01> F<01><11> 9<> 9<><11>[<5B> 9<><11>B<01>B<01><11>[<5B>B<01>4<11> ;<3B> ;<3B> ;<3B> ;<3B><11>[<5B> ;<3B><0E><1B><1B><0E>X<EFBFBD><1B><0E>
O<01>
O<01><0E>X<EFBFBD>
O<01><0E>N<01>N<01><0E>X<EFBFBD>N<01>&-<2D>-<2D>-<2D>-<2D>-<2D>-<2D>-<2D>-<2D>-<2D>-<2D>-<2D>-rr)r^r!<00>mathr<00>excrr rrrr<00><module>rgs{<00><01>
<EFBFBD> <09> <09> <09><0F><0F><0F><0F><15><15><15><15><15><15><1E><1E><1E><1E><1E><1E>[-<2D>[-<2D>[-<2D>[-<2D>[-<2D>5<EFBFBD>[-<2D>[-<2D>[-<2D>[-<2D>[-r