sorting_lists
Utilities for standardizing, extracting, and ordering pitch and interval
strings. These are used internally throughout main_objs.py to keep note
names and ngram tuples in a consistent, sortable form.
sort_pitch_values sorts against a reference ordering passed as its order
parameter. The module defines these options:
pitch_order(default): full chromatic gamut across octaves 2-6, e.g. 'C2', 'C#2', 'D-2', ... 'C6'.recta_order: the same range restricted to musica recta pitches, omitting a handful of chromatic alterations found inpitch_order(e.g. 'C2', 'G-2', 'A#2').pitch_class_order: pitch classes without octave, plus 'Rest', e.g. 'C', 'C#', 'D-', ... 'B#', 'Rest'.pitch_class_order_no_rests:pitch_class_orderwith 'Rest' removed.pitch_class_order_with_rests: alias forpitch_class_order, kept for symmetry withpitch_class_order_no_rests.
standardize_note
standardize_note(note)
Source code in crim_intervals/sorting_lists.py
150 151 152 153 154 155 | |
extract_letter
extract_letter(value, include_rests=True)
Extract pitch class from a note string.
Returns 'Rest' for rest tokens (if include_rests=True), None for rest tokens (if include_rests=False), or the pitch class letter+accidental for pitched notes.
Source code in crim_intervals/sorting_lists.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 | |
tuple_to_list
tuple_to_list(value, separator=None, cast=None)
Convert tuple-like values to a Python list.
cast, if given, is applied to each element (e.g. cast=int to parse a
string of the form "1, -2, 1, -2" into [1, -2, 1, -2]).
Source code in crim_intervals/sorting_lists.py
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 | |
tuple_to_string
tuple_to_string(value, separator=', ')
Convert tuple-like values to a delimited string.
Source code in crim_intervals/sorting_lists.py
203 204 205 206 207 208 209 210 211 212 213 | |
sort_pitch_values
sort_pitch_values(values, order=None, include_rests=True)
Return a list of pitch values sorted according to a supplied order.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
list, tuple, set, pandas.Series, or scalar
|
The pitch values to sort. |
required |
order
|
list
|
The reference ordering to sort
|
None
|
include_rests
|
bool, optional (default True)
|
Whether rest tokens ('Rest', 'r', '-', etc.) sort in place (True) or are pushed after all pitched values (False). |
True
|
Returns:
| Type | Description |
|---|---|
list
|
|
Source code in crim_intervals/sorting_lists.py
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 | |