Skip to content

Concur

concur

concur(score: Score, threshold: float = 0.2) -> float

Calculates the number of distinct onset "groups," where group boundaries are the inter-onset interval greater than threshold (in beats or seconds, depending on the current units in the score).

Equivalently, counts the number of distinct onset "groups", where groups are consecutive IOIs less than or equal to threshold. Note that the time span of a group is arbitrary since there can be any number of consecutive IOIs less than threshold.

This algorithm and its results are not an exact replication of the Matlab MIDI Toolbox concur function.

Parameters:

  • score (Score) –

    The score to analyze.

  • threshold (float, default: 0.2 ) –

    IOI in beats greater than this value starts a new group. Default value is 0.2.

Returns:

  • float

    The number of distinct onset groups divided by the total number of notes.

Source code in amads/algorithms/concur.py
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
48
49
50
51
52
def concur(score: Score, threshold: float = 0.2) -> float:
    """
    Calculates the number of distinct onset "groups," where group
    boundaries are the inter-onset interval greater than threshold
    (in beats or seconds, depending on the current units in the score).

    Equivalently, counts the number of distinct onset "groups", where
    groups are consecutive IOIs less than or equal to threshold. Note
    that the time span of a group is arbitrary since there can be any
    number of consecutive IOIs less than threshold.

    This algorithm and its results are not an exact replication of the
    Matlab MIDI Toolbox concur function.

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

    threshold : float
        IOI in beats greater than this value starts a new group.
        Default value is 0.2.

    Returns
    -------
    float
        The number of distinct onset groups divided by the total number
        of notes.
    """
    # 1. Get all the notes in the score
    notes = score.get_sorted_notes()
    prev_onset = -999  # effectively -infinity so first note starts a group
    count = 0

    # 2. Iterate through the notes and count distinct onset groups
    for note in notes:
        if note.onset - prev_onset > threshold:
            count += 1
        prev_onset = note.onset

    # 3. Calculate the ratio of distinct groups to total notes
    return count / len(notes)