Skip to content

Nnotes

nnotes

nnotes(score: Score, merge_ties: bool = False) -> int

Returns the number of notes in a musical score.

Parameters:

  • score (Score) –

    The musical score to analyze

  • merge_ties (bool, default: False ) –

    Count tied sequences of notes as a single note.

Returns:

  • int

    The number of notes in the score

Examples:

>>> from amads.music import example
>>> from amads.io.readscore import read_score
>>> import contextlib
>>> # Load example score while suppressing output:
>>> with contextlib.redirect_stdout(None):
...     score = read_score(example.fullpath("musicxml/ex3.xml"))
>>> nnotes(score)
2
>>> nnotes(score, merge_ties=True)
1
Source code in amads/algorithms/nnotes.py
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
def nnotes(score: Score, merge_ties: bool = False) -> int:
    """
    Returns the number of notes in a musical score.

    Parameters
    ----------
    score : Score
        The musical score to analyze

    merge_ties : bool
        Count tied sequences of notes as a single note.


    Returns
    -------
    int
        The number of notes in the score

    Examples
    --------
    >>> from amads.music import example
    >>> from amads.io.readscore import read_score
    >>> import contextlib
    >>> # Load example score while suppressing output:
    >>> with contextlib.redirect_stdout(None):
    ...     score = read_score(example.fullpath("musicxml/ex3.xml"))
    >>> nnotes(score)
    2
    >>> nnotes(score, merge_ties=True)
    1
    """

    if merge_ties:
        score = score.merge_tied_notes()  # type: ignore
    total = 0
    for _ in score.find_all(Note):
        total += 1
    return total