Ignore:
Timestamp:
Oct 31, 2018, 5:37:35 PM (5 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/pydocstrings, feature/timestretch, fix/ffmpeg5, master
Children:
7a54b37
Parents:
9b23815e (diff), 78561f7 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'feature/docstrings' (see #73)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • python/lib/aubio/midiconv.py

    r9b23815e r07382d8  
    1616
    1717def note2midi(note):
    18     " convert note name to midi note number, e.g. [C-1, G9] -> [0, 127] "
     18    """Convert note name to midi note number.
     19
     20    Input string `note` should be composed of one note root
     21    and one octave, with optionally one modifier in between.
     22
     23    List of valid components:
     24
     25    - note roots: `C`, `D`, `E`, `F`, `G`, `A`, `B`,
     26    - modifiers: `b`, `#`, as well as unicode characters
     27      `𝄫`, `♭`, `♮`, `♯` and `𝄪`,
     28    - octave numbers: `-1` -> `11`.
     29
     30    Parameters
     31    ----------
     32    note : str
     33        note name
     34
     35    Returns
     36    -------
     37    int
     38        corresponding midi note number
     39
     40    Examples
     41    --------
     42    >>> aubio.note2midi('C#4')
     43    61
     44    >>> aubio.note2midi('B♭5')
     45    82
     46
     47    Raises
     48    ------
     49    TypeError
     50        If `note` was not a string.
     51    ValueError
     52        If an error was found while converting `note`.
     53
     54    See Also
     55    --------
     56    midi2note, freqtomidi, miditofreq
     57    """
    1958    _valid_notenames = {'C': 0, 'D': 2, 'E': 4, 'F': 5, 'G': 7, 'A': 9, 'B': 11}
    2059    _valid_modifiers = {
     
    62101
    63102def midi2note(midi):
    64     " convert midi note number to note name, e.g. [0, 127] -> [C-1, G9] "
     103    """Convert midi note number to note name.
     104
     105    Parameters
     106    ----------
     107    midi : int [0, 128]
     108        input midi note number
     109
     110    Returns
     111    -------
     112    str
     113        note name
     114
     115    Examples
     116    --------
     117    >>> aubio.midi2note(70)
     118    'A#4'
     119    >>> aubio.midi2note(59)
     120    'B3'
     121
     122    Raises
     123    ------
     124    TypeError
     125        If `midi` was not an integer.
     126    ValueError
     127        If `midi` is out of the range `[0, 128]`.
     128
     129    See Also
     130    --------
     131    note2midi, miditofreq, freqtomidi
     132    """
    65133    if not isinstance(midi, int_instances):
    66134        raise TypeError("an integer is required, got %s" % midi)
     
    73141
    74142def freq2note(freq):
    75     " convert frequency in Hz to nearest note name, e.g. [0, 22050.] -> [C-1, G9] "
     143    """Convert frequency in Hz to nearest note name.
     144
     145    Parameters
     146    ----------
     147    freq : float [0, 23000[
     148        input frequency, in Hz
     149
     150    Returns
     151    -------
     152    str
     153        name of the nearest note
     154
     155    Example
     156    -------
     157    >>> aubio.freq2note(440)
     158    'A4'
     159    >>> aubio.freq2note(220.1)
     160    'A3'
     161    """
    76162    nearest_note = int(freqtomidi(freq) + .5)
    77163    return midi2note(nearest_note)
Note: See TracChangeset for help on using the changeset viewer.