Duration Distributions
duration_distribution_1
¶
duration_distribution_1(
score: Score,
name: str = "Duration Distribution",
bin_centers: Union[list[float], None] = None,
ignore_extrema: Union[bool, str] = "unspecified",
miditoolbox_compatible: bool = False,
) -> Distribution
Returns the distribution of note durations in a Score.
Each duration is assigned to a bin according to its value.
The default centers of the bins are on a logarithmic scale as follows:
| component | bin center (in units of quarters) |
|---|---|
| 0 | 1/4 (sixteenth) |
| 1 | sqrt(2)/4 |
| 2 | 1/2 (eighth) |
| 3 | sqrt(2)/2 |
| 4 | 1 (quarter) |
| 5 | sqrt(2) |
| 6 | 2 (half) |
| 7 | 2*sqrt(2) |
| 8 | 4 (whole) |
These centers can be overridden by providing a list of bin centers.
If midi_toolbox_compatible is True, the behavior is the same as in
the Midi Toolbox durdist1 function, with each bin count increased by
1e-12 to avoid division by zero, and values below $sqrt(2)/8$ quarters
(just above a sixteenth triplet) and greater than $sqrt(2) \cdot 4$ quarters
(about 5.65685) are ignored. Also, an error is raised if either
bin_centers or ignore_extrema are specified.
If midi_toolbox_compatible is False (default), the normal behavior
is as follows. If bin_centers is not provided, the default centers
listed above are used. Values below the lowest or above the highest
bins are assigned to those bins appropriately.
One remaining case is where you want to ignore values outside the
range of the bins. This can be done by setting ignore_extrema to
True. If bin_centers is not provided, the default bins are used,
and the extreme boundaries are set to $sqrt(2)/8$ quarters and
$sqrt(2) \cdot 4$ quarters respectively. If bin_centers is provided,
they must include an additional lower bin and upper bin center value
so that upper and lower boundaries can be computed as
$sqrt(bin\_centers[0] \cdot bin\_centers[1])$ and
$sqrt(bin\_centers[-2] \cdot bin\_centers[-1])$ respectively. Since values
beyond the boundaries are ignored, the result will have
$len(bin\_centers) - 2$ bins.
Authors: Yiming Huang, Roger B. Dannenberg
Parameters:
-
score(Score) –The musical score to analyze.
-
name(str, default:'Duration Distribution') –A name for the distribution and plot title.
-
bin_centers(Union[list[float], None]), default:None) –bin centers (optional) (see description for details).
-
ignore_extrema(bool, default:'unspecified') –If True, values outside the range of the bins are ignored (see description for details).
-
miditoolbox_compatible(bool, default:False) –Matlab MIDI Toolbox avoids zero division by dividing counts by the total count plus 1e-12 times the number of counts. True enables this behavior as well as ignoring extreme values and setting the bins as described above. Default is False. If True,
bin_centersandignore_extremamust not be set.
Returns:
-
Distribution–containing and describing the distribution of note durations.
Raises:
-
ValueError: If the score is not monophonic (e.g. contains chords) or–if the miditoolbox is True and either
bin_centersorignore_extremaoptional parameters are set.
Source code in amads/time/durdist1.py
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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 | |
duration_distribution_2
¶
duration_distribution_2(
score: Score,
name: str = "Duration Pairs Distribution",
bin_centers: Optional[list[float]] = None,
ignore_extrema: Union[bool, str] = "unspecified",
miditoolbox_compatible: bool = False,
) -> Distribution
Returns the 2nd-order duration distribution of a musical score.
Each duration is assigned to one of 9 bins. The default centers of the bins are on a logarithmic scale as follows:
| component | bin center (in units of quarters) |
|---|---|
| 0 | 1/4 (sixteenth) |
| 1 | sqrt(2)/4 |
| 2 | 1/2 (eighth) |
| 3 | sqrt(2)/2 |
| 4 | 1 (quarter) |
| 5 | sqrt(2) |
| 6 | 2 (half) |
| 7 | 2*sqrt(2) |
| 8 | 4 (whole) |
These centers can be overridden by providing a list of bin centers.
If midi_toolbox_compatible is True, the behavior is the same as in
the Midi Toolbox durdist1 function, with each bin count increased by
1e-12 to avoid division by zero, and values below $sqrt(2)/8$ quarters
(just above a sixteenth triplet) and greater than $sqrt(2) \cdot 4$ quarters
(about 5.65685) are ignored. Also, an error is raised if either
bin_centers or ignore_extrema are specified.
If midi_toolbox_compatible is False (default), the normal behavior
is as follows. If bin_centers is not provided, the default centers
listed above are used. Values below the lowest or above the highest
bins are assigned to those bins appropriately.
One remaining case is where you want to ignore values outside the
range of the bins. This can be done by setting ignore_extrema to
True. If bin_centers is not provided, the default bins are used,
and the extreme boundaries are set to $sqrt(2)/8$ quarters and
$sqrt(2) \cdot 4$ quarters respectively. If bin_centers is provided,
they must include an additional lower bin and upper bin center value
so that upper and lower boundaries can be computed as
$sqrt(bin\_centers[0] * bin\_centers[1])$ and
$sqrt(bin\_centers[-2] * bin\_centers[-1])$ respectively. Since values
beyond the boundaries are ignored, the result will have
$len(bin\_centers) - 2$ bins.
Authors: Yiming Huang, Roger B. Dannenberg
Parameters:
-
score(Score) –The musical score to analyze.
-
name(str, default:'Duration Pairs Distribution') –A name for the distribution and plot title.
-
bin_centers(Union[list[float], None]), default:None) –bin centers (optional) (see description for details).
-
ignore_extrema(bool, default:'unspecified') –If True, values outside the range of the bins are ignored (see description for details).
-
miditoolbox_compatible(bool, default:False) –Matlab MIDI Toolbox avoids zero division by dividing counts by the total count plus 1e-12 times the number of counts. True enables this behavior as well as ignoring extreme values and setting the bins as described above. Default is False. If True,
bin_centersandignore_extremamust not be set.
Returns:
-
Distribution–containing and describing the distribution of note durations.
Raises:
-
ValueError: If the score is not monophonic (e.g. contains chords) or–if the miditoolbox is True and either
bin_centersorignore_extremaoptional parameters are set orignore_extremais true and less than 3 bin centers are provided.
Source code in amads/time/durdist2.py
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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 | |