Classses Representing Basic Score Elements¶
from amads.core import *
Note: importing amads.core imports amads.core.basics, amads.core.distribution and amads.core.timemap.
Clef
¶
Clef(
parent: Optional[EventGroup] = None,
onset: float = 0.0,
clef: str = "treble",
)
Bases: Event
Clef is a zero-duration Event with clef information.
Parameters:
-
parent(Optional[EventGroup], default:None) –The containing object or None.
-
onset(float, default:0.0) –The onset (start) time. An initial value of None might be assigned when the Clef is inserted into an EventGroup.
-
clef(str, default:'treble') –The clef name, one of "treble", "bass", "alto", "tenor", "percussion", "treble8vb" (Other clefs may be added later.)
Attributes:
-
parent(Optional[EventGroup]) –The containing object or None.
-
_onset(float) –The onset (start) time.
-
duration(float) –Always zero for this subclass.
-
clef(str) –The clef name, one of "treble", "bass", "alto", "tenor", "percussion", "treble8vb" (Other clefs may be added later.)
Source code in amads/core/basics.py
1106 1107 1108 1109 1110 1111 1112 1113 | |
Attributes¶
units_are_seconds
property
¶
units_are_seconds: bool
Check if the times are in seconds.
This event must be in a Score (where _units_are_seconds is stored).
Returns:
-
bool–True iff the event's times are in seconds. If not in a score, False is returned.
units_are_quarters
property
¶
units_are_quarters: bool
Check if the times are in quarters.
This event must be in a Score (where _units_are_seconds is stored).
Returns:
-
bool–True iff the event's times are in quarters. If not in a score, False is returned.
part
property
¶
part: Optional[Part]
Retrieve the Part containing this event.
Returns:
-
Optional[Part]–The Part containing this event or None if not found.
score
property
¶
score: Optional[Score]
Retrieve the Score containing this event.
Returns:
-
Optional[Score]–The Score containing this event or None if not found.
measure
property
¶
measure: Optional[Measure]
Retrieve the Measure containing this event
Returns:
-
Optional[Measure]–The Measure containing this event or None if not found.
Functions¶
__repr__
¶
__repr__() -> str
All Event subclasses inherit this to use str().
Thus, a list of Events is printed using their str methods
Source code in amads/core/basics.py
120 121 122 123 124 125 | |
_event_times
¶
_event_times(dur: bool = True) -> str
produce onset and duration string for str
Source code in amads/core/basics.py
135 136 137 138 139 140 141 | |
time_shift
¶
time_shift(increment: float) -> Event
Change the onset by an increment.
Parameters:
-
increment(float) –The time increment (in quarters or seconds).
Returns:
-
Event–The object. This method modifies the
Event.
Source code in amads/core/basics.py
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 | |
insert_copy_into
¶
insert_copy_into(parent: Optional[EventGroup] = None) -> Event
Make a (mostly) deep copy of the Event and add to a new parent.
Pitch objects are considered immutable and are shared rather
than copied.
Parameters:
-
parent(Optional(EventGroup), default:None) –The copied
Eventwill be a child ofparentif notNone. The parent is modified by this operation.
Returns:
-
Event–A deep copy (except for parent and pitch) of the Event instance.
Source code in amads/core/basics.py
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 | |
_quantize
¶
_quantize(divisions: int) -> Event
Modify onset and offset to a multiple of divisions per quarter note.
This method modifies the Event in place. It also handles tied notes.
E.g., use divisions=4 for sixteenth notes. If a Note tied to or from other notes quantizes to a zero duration, reduce the chain of tied notes to eliminate zero-length notes. See Collection.quantize for additional details.
self.onset and self.duration must be non-None.
Parameters:
-
divisions(int) –The number of divisions per quarter note, e.g., 4 for sixteenths, to control quantization.
Returns:
-
Event–self, after quantization.
Source code in amads/core/basics.py
309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 | |
_convert_to_seconds
¶
_convert_to_seconds(time_map: TimeMap) -> None
Convert the event's duration and onset to seconds.
Parameters:
-
time_map(TimeMap) –The TimeMap object used for conversion.
Source code in amads/core/basics.py
428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 | |
_convert_to_quarters
¶
_convert_to_quarters(time_map: TimeMap) -> None
Convert the event's duration and onset to quarters.
Parameters:
-
time_map(TimeMap) –The TimeMap object used for conversion.
Source code in amads/core/basics.py
445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 | |
KeySignature
¶
KeySignature(
parent: Optional[EventGroup] = None,
onset: float = 0.0,
key_sig: int = 0,
)
Bases: Event
KeySignature is a zero-duration Event with key signature information.
Parameters:
-
parent(Optional[EventGroup], default:None) –The containing object or None.
-
onset(float, default:0.0) –The onset (start) time. An initial value of None might be assigned when the KeySignature is inserted into an EventGroup.
-
key_sig(int, default:0) –An integer representing the number of sharps (if positive) and flats (if negative), e.g., -3 for Eb major or C minor.
Attributes:
-
parent(Optional[EventGroup]) –The containing object or None.
-
_onset(float) –The onset (start) time.
-
duration(float) –Always zero for this subclass.
-
key_sig(int) –An integer representing the number of sharps and flats.
Source code in amads/core/basics.py
1168 1169 1170 1171 | |
Attributes¶
units_are_seconds
property
¶
units_are_seconds: bool
Check if the times are in seconds.
This event must be in a Score (where _units_are_seconds is stored).
Returns:
-
bool–True iff the event's times are in seconds. If not in a score, False is returned.
units_are_quarters
property
¶
units_are_quarters: bool
Check if the times are in quarters.
This event must be in a Score (where _units_are_seconds is stored).
Returns:
-
bool–True iff the event's times are in quarters. If not in a score, False is returned.
part
property
¶
part: Optional[Part]
Retrieve the Part containing this event.
Returns:
-
Optional[Part]–The Part containing this event or None if not found.
score
property
¶
score: Optional[Score]
Retrieve the Score containing this event.
Returns:
-
Optional[Score]–The Score containing this event or None if not found.
measure
property
¶
measure: Optional[Measure]
Retrieve the Measure containing this event
Returns:
-
Optional[Measure]–The Measure containing this event or None if not found.
Functions¶
__repr__
¶
__repr__() -> str
All Event subclasses inherit this to use str().
Thus, a list of Events is printed using their str methods
Source code in amads/core/basics.py
120 121 122 123 124 125 | |
_event_times
¶
_event_times(dur: bool = True) -> str
produce onset and duration string for str
Source code in amads/core/basics.py
135 136 137 138 139 140 141 | |
time_shift
¶
time_shift(increment: float) -> Event
Change the onset by an increment.
Parameters:
-
increment(float) –The time increment (in quarters or seconds).
Returns:
-
Event–The object. This method modifies the
Event.
Source code in amads/core/basics.py
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 | |
insert_copy_into
¶
insert_copy_into(parent: Optional[EventGroup] = None) -> Event
Make a (mostly) deep copy of the Event and add to a new parent.
Pitch objects are considered immutable and are shared rather
than copied.
Parameters:
-
parent(Optional(EventGroup), default:None) –The copied
Eventwill be a child ofparentif notNone. The parent is modified by this operation.
Returns:
-
Event–A deep copy (except for parent and pitch) of the Event instance.
Source code in amads/core/basics.py
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 | |
_quantize
¶
_quantize(divisions: int) -> Event
Modify onset and offset to a multiple of divisions per quarter note.
This method modifies the Event in place. It also handles tied notes.
E.g., use divisions=4 for sixteenth notes. If a Note tied to or from other notes quantizes to a zero duration, reduce the chain of tied notes to eliminate zero-length notes. See Collection.quantize for additional details.
self.onset and self.duration must be non-None.
Parameters:
-
divisions(int) –The number of divisions per quarter note, e.g., 4 for sixteenths, to control quantization.
Returns:
-
Event–self, after quantization.
Source code in amads/core/basics.py
309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 | |
_convert_to_seconds
¶
_convert_to_seconds(time_map: TimeMap) -> None
Convert the event's duration and onset to seconds.
Parameters:
-
time_map(TimeMap) –The TimeMap object used for conversion.
Source code in amads/core/basics.py
428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 | |
_convert_to_quarters
¶
_convert_to_quarters(time_map: TimeMap) -> None
Convert the event's duration and onset to quarters.
Parameters:
-
time_map(TimeMap) –The TimeMap object used for conversion.
Source code in amads/core/basics.py
445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 | |
EventGroup
¶
EventGroup(
parent: Optional[EventGroup],
onset: Optional[float],
duration: Optional[float],
content: Optional[list[Event]],
)
Bases: Event
A collection of Event objects. (An abstract class.)
Use one of the subclasses: Score, Part, Staff, Measure or Chord.
Normally, you create any EventGroup (Chord, Measure, Staff, Part,
Score) with no content, then add content. You can add content in
bulk by simply setting the content attribute to a list of Events
whose parent attributes have been set to the EventGroup. You can
also add one event at a time, by calling the EventGroup's insert
method. (This will change the event parent from None to the group.)
It is recommended to specify all onsets and durations explicitly,
including the onset of the group itself.
Alternatively, you can provide content when the group is
constructed. Chord, Measure, Staff, Part, and Score all have
*args parameters so that you can write something like:
Score(Part(Staff(Measure(Note(...), Note(...)),
Measure(Note(...), Note(...)))))
In this case, it is recommended that you leave the onsets of content and chord unknown (None, the default). Then, as each event or group becomes content for a parent, the onsets will be set automatically, organizing events sequentially (in Measures and Staves) or concurrently (in Chords, Parts, Scores).
The use of unknown (None) onsets is offered as a convenience for simple cases. The main risk is that onsets are considered to be relative to the group onset if the group onset is not known. E.g. if onsets are specified within the content of an EventGroup (Chord, Measure, Staff, Part, Score) but the group onset is unknown (None), and then you assign (or a parent assigns) an onset value to the group, the content onsets (even “known” ones) will all be shifted by the assigned onset. This happens only when changing an onset from None to a number. Subsequent changes to the group onset will not adjust the content onsets, which are considered absolute times once the group onset is known.
EventGroup is subclassed to form Concurrence and Sequence. A Concurrence defaults to placing all events at onset 0, while Sequence defaults to placing events sequentially such that event inter-onset intervals are their durations. The EventGroup behaves like Concurrence, so the Concurrence implementation is minimal, while the Sequence needs several methods to override EventGroup behavior to support sequential behavior.
Parameters:
-
parent(Optional[EventGroup]) –The containing object or None.
-
onset(float | None) –The onset (start) time.
-
duration(Optional[float]) –The duration in quarters or seconds.
-
content(Optional[list]) –A list of Event objects to be added to the group. The parent of each Event is set to this EventGroup, and it is an error if any Event already has a parent.
Attributes:
-
parent(Optional[EventGroup]) –The containing object or None.
-
_onset(Optional[float]) –The onset (start) time.
-
duration(float) –The duration in quarters or seconds.
-
content(list[Event]) –Elements contained within this collection.
Source code in amads/core/basics.py
1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 | |
Attributes¶
units_are_seconds
property
¶
units_are_seconds: bool
Check if the times are in seconds.
This event must be in a Score (where _units_are_seconds is stored).
Returns:
-
bool–True iff the event's times are in seconds. If not in a score, False is returned.
units_are_quarters
property
¶
units_are_quarters: bool
Check if the times are in quarters.
This event must be in a Score (where _units_are_seconds is stored).
Returns:
-
bool–True iff the event's times are in quarters. If not in a score, False is returned.
part
property
¶
part: Optional[Part]
Retrieve the Part containing this event.
Returns:
-
Optional[Part]–The Part containing this event or None if not found.
score
property
¶
score: Optional[Score]
Retrieve the Score containing this event.
Returns:
-
Optional[Score]–The Score containing this event or None if not found.
measure
property
¶
measure: Optional[Measure]
Retrieve the Measure containing this event
Returns:
-
Optional[Measure]–The Measure containing this event or None if not found.
Functions¶
__repr__
¶
__repr__() -> str
All Event subclasses inherit this to use str().
Thus, a list of Events is printed using their str methods
Source code in amads/core/basics.py
120 121 122 123 124 125 | |
_event_times
¶
_event_times(dur: bool = True) -> str
produce onset and duration string for str
Source code in amads/core/basics.py
135 136 137 138 139 140 141 | |
insert_copy_into
¶
insert_copy_into(parent: Optional[EventGroup] = None) -> Event
Make a (mostly) deep copy of the Event and add to a new parent.
Pitch objects are considered immutable and are shared rather
than copied.
Parameters:
-
parent(Optional(EventGroup), default:None) –The copied
Eventwill be a child ofparentif notNone. The parent is modified by this operation.
Returns:
-
Event–A deep copy (except for parent and pitch) of the Event instance.
Source code in amads/core/basics.py
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 | |
ismonophonic
¶
ismonophonic() -> bool
Determine if content is monophonic (non-overlapping notes).
A monophonic list of notes has no overlapping notes (e.g., chords).
Serves as a helper function for ismonophonic and
parts_are_monophonic.
Returns:
-
bool–True if the list of notes is monophonic, False otherwise.
Source code in amads/core/basics.py
1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 | |
time_shift
¶
time_shift(increment: float, content_only: bool = False) -> EventGroup
Change the onset by an increment, affecting all content.
Parameters:
-
increment(float) –The time increment (in quarters or seconds).
-
content_only(bool, default:False) –If true, preserves this container's time and shifts only the content.
Returns:
-
Event–The object. This method modifies the
EventGroup.
Source code in amads/core/basics.py
1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 | |
_convert_to_seconds
¶
_convert_to_seconds(time_map: TimeMap) -> None
Convert the event's duration and onset to seconds using the provided TimeMap. Convert content as well.
Parameters:
-
time_map(TimeMap) –The TimeMap object used for conversion.
Source code in amads/core/basics.py
1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 | |
_convert_to_quarters
¶
_convert_to_quarters(time_map: TimeMap) -> None
Convert the event's duration and onset to quarters using the provided TimeMap. Convert content as well.
Parameters:
-
time_map(TimeMap) –The TimeMap object used for conversion.
Source code in amads/core/basics.py
1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 | |
insert_emptycopy_into
¶
insert_emptycopy_into(
parent: Optional[EventGroup] = None,
) -> EventGroup
Create a deep copy of the EventGroup except for content.
A new parent is provided as an argument and the copy is inserted into this parent. This method is useful for copying an EventGroup without copying its content. See also insert_copy_into to copy an EventGroup with its content into a new parent.
Parameters:
-
parent(Optional[EventGroup], default:None) –The new parent to insert the copied Event into.
Returns:
-
EventGroup–A deep copy of the EventGroup instance with the new parent (if any) and no content.
Source code in amads/core/basics.py
1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 | |
expand_chords
¶
expand_chords(parent: Optional[EventGroup] = None) -> EventGroup
Replace chords with the multiple notes they contain.
Returns a deep copy with no parent unless parent is provided.
Normally, you will call score.expand_chords() which returns a deep
copy of Score with notes moved from each chord to the copy of the
chord's parent (a Measure or a Part). The parent parameter is
primarily for internal use when expand_chords is called recursively
on score content.
Parameters:
-
parent(EventGroup, default:None) –The new parent to insert the copied EventGroup into.
Returns:
-
EventGroup–A deep copy of the EventGroup instance with all Chord instances expanded.
Source code in amads/core/basics.py
1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 | |
find_all
¶
Find all instances of a specific type within the EventGroup.
Assumes that objects of type elem_type are not nested within
other objects of the same type. (The first elem_type encountered
in a depth-first enumeration is returned without looking at any
children in its content).
Parameters:
-
elem_type(Type[Event]) –The type of event to search for.
Yields:
-
Event–Instances of the specified type found within the EventGroup.
Source code in amads/core/basics.py
1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 | |
has_instanceof
¶
has_instanceof(the_class: Type[Event]) -> bool
Test if EventGroup contains any instances of the_class.
Parameters:
-
the_class(Type[Event]) –The class type to check for.
Returns:
-
bool–True iff the EventGroup contains an instance of the_class.
Source code in amads/core/basics.py
1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 | |
has_chords
¶
has_chords() -> bool
Test if EventGroup (e.g., Score, Part, ...) has any Chord objects.
Returns:
-
bool–True iff the EventGroup contains any Chord objects.
Source code in amads/core/basics.py
1608 1609 1610 1611 1612 1613 1614 1615 1616 | |
has_ties
¶
has_ties() -> bool
Test if EventGroup (e.g., Score, Part, ...) has any tied notes.
Returns:
-
bool–True iff the EventGroup contains any tied notes.
Source code in amads/core/basics.py
1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 | |
has_measures
¶
has_measures() -> bool
Test if EventGroup (e.g., Score, Part, ...) has any Measures.
Returns:
-
bool–True iff the EventGroup contains any Measure objects.
Source code in amads/core/basics.py
1634 1635 1636 1637 1638 1639 1640 1641 1642 | |
inherit_duration
¶
inherit_duration() -> EventGroup
Set the duration of this EventGroup according to maximum offset.
The duration is set to the maximum offset (end) time of the
children. If the EventGroup is empty, the duration is set to 0.
This method modifies this EventGroup instance.
Returns:
-
EventGroup–The EventGroup instance (self) with updated duration.
Source code in amads/core/basics.py
1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 | |
insert
¶
insert(event: Event) -> EventGroup
Insert an event.
Sets the parent of event to this EventGroup and makes event
be a member of this EventGroup.content. No changes are made to
event.onset or self.duration. Insert event in content just
before the first element with a greater onset. The method modifies
this object (self).
Parameters:
-
event(Event) –The event to be inserted.
Returns:
-
EventGroup–The EventGroup instance (self) with the event inserted.
Raises:
-
ValueError–If event._onset is None (it must be a number)
Source code in amads/core/basics.py
1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 | |
last
¶
last() -> Optional[Event]
Retrieve the last event in the content list.
Because the content list is sorted by onset, the returned
Event is simply the last element of content, but not
necessarily the event with the greatest offset.
Returns:
-
Optional[Event]–The last event in the content list or None if the list is empty.
Source code in amads/core/basics.py
1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 | |
list_all
¶
Find all instances of a specific type within the EventGroup.
Assumes that objects of type elem_type are not nested within
other objects of the same type. See also
find_all, which returns
a generator instead of a list.
Parameters:
-
elem_type(Type[Event]) –The type of event to search for.
Returns:
-
list[Event]–A list of all instances of the specified type found within the EventGroup.
Source code in amads/core/basics.py
1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 | |
merge_tied_notes
¶
merge_tied_notes(
parent: Optional[EventGroup] = None, ignore: list[Note] = []
) -> EventGroup
Create a new EventGroup with tied notes replaced by single notes.
If ties cross staffs, the replacement is placed in the staff of the
first note in the tied sequence. Insert the new EventGroup into
parent.
Ordinarily, this method is called on a Score with no parameters. The
parameters are used when Score.merge_tied_notes() calls this method
recursively on EventGroups within the Score such as Parts and
Staffs.
Parameters:
-
parent(Optional[EventGroup], default:None) –Where to insert the result.
-
ignore(list[Note], default:[]) –This parameter is used internally. Caller should not use this parameter.
Returns:
-
EventGroup–A copy with tied notes replaced by equivalent single notes.
Source code in amads/core/basics.py
1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 | |
pack
¶
pack(onset: float = 0.0, sequential: bool = False) -> float
Adjust the content to onsets starting with the onset parameter.
By default onsets are set to onset and the duration of self is set to
the maximum duration of the content. pack() works recursively on
elements that are EventGroups. Setting sequential to True implements
sequential packing, where events are placed one after another.
Parameters:
-
onset(float, default:0.0) –The onset (start) time for this object.
Returns:
-
float–duration of self
Source code in amads/core/basics.py
1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 | |
_quantize
¶
_quantize(divisions: int) -> EventGroup
"Since _quantize is called recursively on children, this method is
needed to redirect EventGroup._quantize to quantize
Source code in amads/core/basics.py
1844 1845 1846 1847 1848 | |
quantize
¶
quantize(divisions: int) -> EventGroup
Align onsets and durations to a rhythmic grid.
Assumes time units are quarters. (See Score.convert_to_quarters.)
Modify all times and durations to a multiple of divisions per quarter note, e.g., 4 for sixteenth notes. Onsets and offsets are moved to the nearest quantized time. Any resulting duration change is less than one quantum, but not necessarily less than 0.5 quantum, since the onset and offset can round in opposite directions by up to 0.5 quantum each. Any non-zero duration that would quantize to zero duration gets a duration of one quantum since zero duration is almost certainly going to cause notation and visualization problems.
Special cases for zero duration:
- If the original duration is zero as in metadata or possibly grace notes, we preserve that.
- If a tied note duration quantizes to zero, we remove the tied note entirely provided some other note in the tied sequence has non-zero duration. If all tied notes quantize to zero, we keep the first one and set its duration to one quantum.
This method modifies this EventGroup and all its content in place.
Note that there is no way to specify "sixteenths or eighth triplets" because 6 would not allow sixteenths and 12 would admit sixteenth triplets. Using tuples as in Music21, e.g., (4, 3) for this problem creates another problem: if quantization is to time points 1/4, 1/3, then the difference is 1/12 or a thirty-second triplet. If the quantization is applied to durations, then you could have 1/4 + 1/3 = 7/12, and the remaining duration in a single beat would be 5/12, which is not expressible as sixteenths, eighth triplets or any tied combination.
Parameters:
-
divisions(int) –The number of divisions per quarter note, e.g., 4 for sixteenths, to control quantization.
Returns:
-
EventGroup–The EventGroup instance (self) with (modified in place) quantized times.
Source code in amads/core/basics.py
1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 | |
Sequence
¶
Sequence(
parent: Optional[EventGroup],
onset: Optional[float] = None,
duration: Optional[float] = None,
content: Optional[list[Event]] = None,
)
Bases: EventGroup
Sequence (abstract class) represents a temporal sequence of music events.
Parameters:
-
parent(Optional[EventGroup]) –The containing object or None.
-
onset(Optional[float], default:None) –The onset (start) time. None means unknown, to be set when Sequence is added to a parent.
-
duration(Optional[float], default:None) –The duration in quarters or seconds. (If duration is omitted or None, the duration is set so that self.offset ends at the max offset in content, or 0 if there is no content.)
-
content(Optional[list[Event]], default:None) –A list of Event objects to be added to the group. Content events with onsets of None are set to the offset of the previous event in the sequence. The first event onset is the specified group onset, or zero if onset is None.
Attributes:
-
parent(Optional[EventGroup]) –The containing object or None.
-
_onset(Optional[float]) –The onset (start) time. None represents “unknown” and to be determined when this object is added to a parent.
-
duration(float) –The duration in quarters or seconds.
-
content(list[Event]) –Elements contained within this collection.
Source code in amads/core/basics.py
2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 | |
Attributes¶
units_are_seconds
property
¶
units_are_seconds: bool
Check if the times are in seconds.
This event must be in a Score (where _units_are_seconds is stored).
Returns:
-
bool–True iff the event's times are in seconds. If not in a score, False is returned.
units_are_quarters
property
¶
units_are_quarters: bool
Check if the times are in quarters.
This event must be in a Score (where _units_are_seconds is stored).
Returns:
-
bool–True iff the event's times are in quarters. If not in a score, False is returned.
part
property
¶
part: Optional[Part]
Retrieve the Part containing this event.
Returns:
-
Optional[Part]–The Part containing this event or None if not found.
score
property
¶
score: Optional[Score]
Retrieve the Score containing this event.
Returns:
-
Optional[Score]–The Score containing this event or None if not found.
measure
property
¶
measure: Optional[Measure]
Retrieve the Measure containing this event
Returns:
-
Optional[Measure]–The Measure containing this event or None if not found.
Functions¶
__repr__
¶
__repr__() -> str
All Event subclasses inherit this to use str().
Thus, a list of Events is printed using their str methods
Source code in amads/core/basics.py
120 121 122 123 124 125 | |
_event_times
¶
_event_times(dur: bool = True) -> str
produce onset and duration string for str
Source code in amads/core/basics.py
135 136 137 138 139 140 141 | |
time_shift
¶
time_shift(increment: float, content_only: bool = False) -> EventGroup
Change the onset by an increment, affecting all content.
Parameters:
-
increment(float) –The time increment (in quarters or seconds).
-
content_only(bool, default:False) –If true, preserves this container's time and shifts only the content.
Returns:
-
Event–The object. This method modifies the
EventGroup.
Source code in amads/core/basics.py
1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 | |
insert_copy_into
¶
insert_copy_into(parent: Optional[EventGroup] = None) -> Event
Make a (mostly) deep copy of the Event and add to a new parent.
Pitch objects are considered immutable and are shared rather
than copied.
Parameters:
-
parent(Optional(EventGroup), default:None) –The copied
Eventwill be a child ofparentif notNone. The parent is modified by this operation.
Returns:
-
Event–A deep copy (except for parent and pitch) of the Event instance.
Source code in amads/core/basics.py
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 | |
_quantize
¶
_quantize(divisions: int) -> EventGroup
"Since _quantize is called recursively on children, this method is
needed to redirect EventGroup._quantize to quantize
Source code in amads/core/basics.py
1844 1845 1846 1847 1848 | |
_convert_to_seconds
¶
_convert_to_seconds(time_map: TimeMap) -> None
Convert the event's duration and onset to seconds using the provided TimeMap. Convert content as well.
Parameters:
-
time_map(TimeMap) –The TimeMap object used for conversion.
Source code in amads/core/basics.py
1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 | |
_convert_to_quarters
¶
_convert_to_quarters(time_map: TimeMap) -> None
Convert the event's duration and onset to quarters using the provided TimeMap. Convert content as well.
Parameters:
-
time_map(TimeMap) –The TimeMap object used for conversion.
Source code in amads/core/basics.py
1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 | |
ismonophonic
¶
ismonophonic() -> bool
Determine if content is monophonic (non-overlapping notes).
A monophonic list of notes has no overlapping notes (e.g., chords).
Serves as a helper function for ismonophonic and
parts_are_monophonic.
Returns:
-
bool–True if the list of notes is monophonic, False otherwise.
Source code in amads/core/basics.py
1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 | |
insert_emptycopy_into
¶
insert_emptycopy_into(
parent: Optional[EventGroup] = None,
) -> EventGroup
Create a deep copy of the EventGroup except for content.
A new parent is provided as an argument and the copy is inserted into this parent. This method is useful for copying an EventGroup without copying its content. See also insert_copy_into to copy an EventGroup with its content into a new parent.
Parameters:
-
parent(Optional[EventGroup], default:None) –The new parent to insert the copied Event into.
Returns:
-
EventGroup–A deep copy of the EventGroup instance with the new parent (if any) and no content.
Source code in amads/core/basics.py
1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 | |
expand_chords
¶
expand_chords(parent: Optional[EventGroup] = None) -> EventGroup
Replace chords with the multiple notes they contain.
Returns a deep copy with no parent unless parent is provided.
Normally, you will call score.expand_chords() which returns a deep
copy of Score with notes moved from each chord to the copy of the
chord's parent (a Measure or a Part). The parent parameter is
primarily for internal use when expand_chords is called recursively
on score content.
Parameters:
-
parent(EventGroup, default:None) –The new parent to insert the copied EventGroup into.
Returns:
-
EventGroup–A deep copy of the EventGroup instance with all Chord instances expanded.
Source code in amads/core/basics.py
1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 | |
find_all
¶
Find all instances of a specific type within the EventGroup.
Assumes that objects of type elem_type are not nested within
other objects of the same type. (The first elem_type encountered
in a depth-first enumeration is returned without looking at any
children in its content).
Parameters:
-
elem_type(Type[Event]) –The type of event to search for.
Yields:
-
Event–Instances of the specified type found within the EventGroup.
Source code in amads/core/basics.py
1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 | |
has_instanceof
¶
has_instanceof(the_class: Type[Event]) -> bool
Test if EventGroup contains any instances of the_class.
Parameters:
-
the_class(Type[Event]) –The class type to check for.
Returns:
-
bool–True iff the EventGroup contains an instance of the_class.
Source code in amads/core/basics.py
1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 | |
has_chords
¶
has_chords() -> bool
Test if EventGroup (e.g., Score, Part, ...) has any Chord objects.
Returns:
-
bool–True iff the EventGroup contains any Chord objects.
Source code in amads/core/basics.py
1608 1609 1610 1611 1612 1613 1614 1615 1616 | |
has_ties
¶
has_ties() -> bool
Test if EventGroup (e.g., Score, Part, ...) has any tied notes.
Returns:
-
bool–True iff the EventGroup contains any tied notes.
Source code in amads/core/basics.py
1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 | |
has_measures
¶
has_measures() -> bool
Test if EventGroup (e.g., Score, Part, ...) has any Measures.
Returns:
-
bool–True iff the EventGroup contains any Measure objects.
Source code in amads/core/basics.py
1634 1635 1636 1637 1638 1639 1640 1641 1642 | |
inherit_duration
¶
inherit_duration() -> EventGroup
Set the duration of this EventGroup according to maximum offset.
The duration is set to the maximum offset (end) time of the
children. If the EventGroup is empty, the duration is set to 0.
This method modifies this EventGroup instance.
Returns:
-
EventGroup–The EventGroup instance (self) with updated duration.
Source code in amads/core/basics.py
1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 | |
insert
¶
insert(event: Event) -> EventGroup
Insert an event.
Sets the parent of event to this EventGroup and makes event
be a member of this EventGroup.content. No changes are made to
event.onset or self.duration. Insert event in content just
before the first element with a greater onset. The method modifies
this object (self).
Parameters:
-
event(Event) –The event to be inserted.
Returns:
-
EventGroup–The EventGroup instance (self) with the event inserted.
Raises:
-
ValueError–If event._onset is None (it must be a number)
Source code in amads/core/basics.py
1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 | |
last
¶
last() -> Optional[Event]
Retrieve the last event in the content list.
Because the content list is sorted by onset, the returned
Event is simply the last element of content, but not
necessarily the event with the greatest offset.
Returns:
-
Optional[Event]–The last event in the content list or None if the list is empty.
Source code in amads/core/basics.py
1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 | |
list_all
¶
Find all instances of a specific type within the EventGroup.
Assumes that objects of type elem_type are not nested within
other objects of the same type. See also
find_all, which returns
a generator instead of a list.
Parameters:
-
elem_type(Type[Event]) –The type of event to search for.
Returns:
-
list[Event]–A list of all instances of the specified type found within the EventGroup.
Source code in amads/core/basics.py
1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 | |
merge_tied_notes
¶
merge_tied_notes(
parent: Optional[EventGroup] = None, ignore: list[Note] = []
) -> EventGroup
Create a new EventGroup with tied notes replaced by single notes.
If ties cross staffs, the replacement is placed in the staff of the
first note in the tied sequence. Insert the new EventGroup into
parent.
Ordinarily, this method is called on a Score with no parameters. The
parameters are used when Score.merge_tied_notes() calls this method
recursively on EventGroups within the Score such as Parts and
Staffs.
Parameters:
-
parent(Optional[EventGroup], default:None) –Where to insert the result.
-
ignore(list[Note], default:[]) –This parameter is used internally. Caller should not use this parameter.
Returns:
-
EventGroup–A copy with tied notes replaced by equivalent single notes.
Source code in amads/core/basics.py
1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 | |
quantize
¶
quantize(divisions: int) -> EventGroup
Align onsets and durations to a rhythmic grid.
Assumes time units are quarters. (See Score.convert_to_quarters.)
Modify all times and durations to a multiple of divisions per quarter note, e.g., 4 for sixteenth notes. Onsets and offsets are moved to the nearest quantized time. Any resulting duration change is less than one quantum, but not necessarily less than 0.5 quantum, since the onset and offset can round in opposite directions by up to 0.5 quantum each. Any non-zero duration that would quantize to zero duration gets a duration of one quantum since zero duration is almost certainly going to cause notation and visualization problems.
Special cases for zero duration:
- If the original duration is zero as in metadata or possibly grace notes, we preserve that.
- If a tied note duration quantizes to zero, we remove the tied note entirely provided some other note in the tied sequence has non-zero duration. If all tied notes quantize to zero, we keep the first one and set its duration to one quantum.
This method modifies this EventGroup and all its content in place.
Note that there is no way to specify "sixteenths or eighth triplets" because 6 would not allow sixteenths and 12 would admit sixteenth triplets. Using tuples as in Music21, e.g., (4, 3) for this problem creates another problem: if quantization is to time points 1/4, 1/3, then the difference is 1/12 or a thirty-second triplet. If the quantization is applied to durations, then you could have 1/4 + 1/3 = 7/12, and the remaining duration in a single beat would be 5/12, which is not expressible as sixteenths, eighth triplets or any tied combination.
Parameters:
-
divisions(int) –The number of divisions per quarter note, e.g., 4 for sixteenths, to control quantization.
Returns:
-
EventGroup–The EventGroup instance (self) with (modified in place) quantized times.
Source code in amads/core/basics.py
1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 | |
pack
¶
pack(onset: float = 0.0, sequential: bool = True) -> float
Adjust the content to be sequential.
The resulting content will begin with the parameter onset
(defaults to 0), and each other object will get an onset equal
to the offset of the previous element. The duration of self is
set to the offset of the last element. This method essentially
arranges the content to eliminate gaps. pack() works recursively
on elements that are EventGroups.
Be careful not to pack Measures (directly or through
recursion) if the Measure's content durations do not add up to
the intended quarters per measure.
To override the sequential behavior, set the sequential
parameter to False. In that case, pack behaves like the
Concurrence.pack() method.
The pack method alters self and its content in place.
Parameters:
-
onset(float, default:0.0) –The onset (start) time for this object.
Returns:
-
float–duration of self
Source code in amads/core/basics.py
2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 | |
Concurrence
¶
Concurrence(
parent: Optional[EventGroup] = None,
onset: Optional[float] = None,
duration: Optional[float] = None,
content: Optional[list[Event]] = None,
)
Bases: EventGroup
Concurrence (abstract class) represents a group of simultaneous children.
However, children can have a non-zero onset to represent events organized in time). Thus, the main distinction between Concurrence and Sequence is that a Sequence can be constructed with pack=True to force sequential timing of the content. Note that a Sequence can have overlapping or entirely simultaneous Events as well.
Parameters:
-
parent(Optional[EventGroup], default:None) –The containing object or None.
-
onset(Optional[float], default:None) –The onset (start) time. None means unknown, to be set when Sequence is added to a parent.
-
duration(Optional[float], default:None) –The duration in quarters or seconds. (If duration is omitted or None, the duration is set so that self.offset ends at the max offset in content, or 0 if there is no content.)
-
content(Optional[list[Event]], default:None) –A list of Event objects to be added to the group. Content events with onsets of None are set to the offset of the concurrence, or zero if onset is None.
Attributes:
-
parent(Optional[EventGroup]) –The containing object or None.
-
_onset(Optional[float]) –The onset (start) time. None represents "unknown" and to be determined when this object is added to a parent.
-
duration(float) –The duration in quarters or seconds.
-
content(list[Event]) –Elements contained within this collection.
Source code in amads/core/basics.py
2161 2162 2163 2164 2165 | |
Attributes¶
units_are_seconds
property
¶
units_are_seconds: bool
Check if the times are in seconds.
This event must be in a Score (where _units_are_seconds is stored).
Returns:
-
bool–True iff the event's times are in seconds. If not in a score, False is returned.
units_are_quarters
property
¶
units_are_quarters: bool
Check if the times are in quarters.
This event must be in a Score (where _units_are_seconds is stored).
Returns:
-
bool–True iff the event's times are in quarters. If not in a score, False is returned.
part
property
¶
part: Optional[Part]
Retrieve the Part containing this event.
Returns:
-
Optional[Part]–The Part containing this event or None if not found.
score
property
¶
score: Optional[Score]
Retrieve the Score containing this event.
Returns:
-
Optional[Score]–The Score containing this event or None if not found.
measure
property
¶
measure: Optional[Measure]
Retrieve the Measure containing this event
Returns:
-
Optional[Measure]–The Measure containing this event or None if not found.
Functions¶
__repr__
¶
__repr__() -> str
All Event subclasses inherit this to use str().
Thus, a list of Events is printed using their str methods
Source code in amads/core/basics.py
120 121 122 123 124 125 | |
_event_times
¶
_event_times(dur: bool = True) -> str
produce onset and duration string for str
Source code in amads/core/basics.py
135 136 137 138 139 140 141 | |
time_shift
¶
time_shift(increment: float, content_only: bool = False) -> EventGroup
Change the onset by an increment, affecting all content.
Parameters:
-
increment(float) –The time increment (in quarters or seconds).
-
content_only(bool, default:False) –If true, preserves this container's time and shifts only the content.
Returns:
-
Event–The object. This method modifies the
EventGroup.
Source code in amads/core/basics.py
1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 | |
insert_copy_into
¶
insert_copy_into(parent: Optional[EventGroup] = None) -> Event
Make a (mostly) deep copy of the Event and add to a new parent.
Pitch objects are considered immutable and are shared rather
than copied.
Parameters:
-
parent(Optional(EventGroup), default:None) –The copied
Eventwill be a child ofparentif notNone. The parent is modified by this operation.
Returns:
-
Event–A deep copy (except for parent and pitch) of the Event instance.
Source code in amads/core/basics.py
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 | |
_quantize
¶
_quantize(divisions: int) -> EventGroup
"Since _quantize is called recursively on children, this method is
needed to redirect EventGroup._quantize to quantize
Source code in amads/core/basics.py
1844 1845 1846 1847 1848 | |
_convert_to_seconds
¶
_convert_to_seconds(time_map: TimeMap) -> None
Convert the event's duration and onset to seconds using the provided TimeMap. Convert content as well.
Parameters:
-
time_map(TimeMap) –The TimeMap object used for conversion.
Source code in amads/core/basics.py
1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 | |
_convert_to_quarters
¶
_convert_to_quarters(time_map: TimeMap) -> None
Convert the event's duration and onset to quarters using the provided TimeMap. Convert content as well.
Parameters:
-
time_map(TimeMap) –The TimeMap object used for conversion.
Source code in amads/core/basics.py
1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 | |
ismonophonic
¶
ismonophonic() -> bool
Determine if content is monophonic (non-overlapping notes).
A monophonic list of notes has no overlapping notes (e.g., chords).
Serves as a helper function for ismonophonic and
parts_are_monophonic.
Returns:
-
bool–True if the list of notes is monophonic, False otherwise.
Source code in amads/core/basics.py
1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 | |
insert_emptycopy_into
¶
insert_emptycopy_into(
parent: Optional[EventGroup] = None,
) -> EventGroup
Create a deep copy of the EventGroup except for content.
A new parent is provided as an argument and the copy is inserted into this parent. This method is useful for copying an EventGroup without copying its content. See also insert_copy_into to copy an EventGroup with its content into a new parent.
Parameters:
-
parent(Optional[EventGroup], default:None) –The new parent to insert the copied Event into.
Returns:
-
EventGroup–A deep copy of the EventGroup instance with the new parent (if any) and no content.
Source code in amads/core/basics.py
1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 | |
expand_chords
¶
expand_chords(parent: Optional[EventGroup] = None) -> EventGroup
Replace chords with the multiple notes they contain.
Returns a deep copy with no parent unless parent is provided.
Normally, you will call score.expand_chords() which returns a deep
copy of Score with notes moved from each chord to the copy of the
chord's parent (a Measure or a Part). The parent parameter is
primarily for internal use when expand_chords is called recursively
on score content.
Parameters:
-
parent(EventGroup, default:None) –The new parent to insert the copied EventGroup into.
Returns:
-
EventGroup–A deep copy of the EventGroup instance with all Chord instances expanded.
Source code in amads/core/basics.py
1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 | |
find_all
¶
Find all instances of a specific type within the EventGroup.
Assumes that objects of type elem_type are not nested within
other objects of the same type. (The first elem_type encountered
in a depth-first enumeration is returned without looking at any
children in its content).
Parameters:
-
elem_type(Type[Event]) –The type of event to search for.
Yields:
-
Event–Instances of the specified type found within the EventGroup.
Source code in amads/core/basics.py
1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 | |
has_instanceof
¶
has_instanceof(the_class: Type[Event]) -> bool
Test if EventGroup contains any instances of the_class.
Parameters:
-
the_class(Type[Event]) –The class type to check for.
Returns:
-
bool–True iff the EventGroup contains an instance of the_class.
Source code in amads/core/basics.py
1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 | |
has_chords
¶
has_chords() -> bool
Test if EventGroup (e.g., Score, Part, ...) has any Chord objects.
Returns:
-
bool–True iff the EventGroup contains any Chord objects.
Source code in amads/core/basics.py
1608 1609 1610 1611 1612 1613 1614 1615 1616 | |
has_ties
¶
has_ties() -> bool
Test if EventGroup (e.g., Score, Part, ...) has any tied notes.
Returns:
-
bool–True iff the EventGroup contains any tied notes.
Source code in amads/core/basics.py
1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 | |
has_measures
¶
has_measures() -> bool
Test if EventGroup (e.g., Score, Part, ...) has any Measures.
Returns:
-
bool–True iff the EventGroup contains any Measure objects.
Source code in amads/core/basics.py
1634 1635 1636 1637 1638 1639 1640 1641 1642 | |
inherit_duration
¶
inherit_duration() -> EventGroup
Set the duration of this EventGroup according to maximum offset.
The duration is set to the maximum offset (end) time of the
children. If the EventGroup is empty, the duration is set to 0.
This method modifies this EventGroup instance.
Returns:
-
EventGroup–The EventGroup instance (self) with updated duration.
Source code in amads/core/basics.py
1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 | |
insert
¶
insert(event: Event) -> EventGroup
Insert an event.
Sets the parent of event to this EventGroup and makes event
be a member of this EventGroup.content. No changes are made to
event.onset or self.duration. Insert event in content just
before the first element with a greater onset. The method modifies
this object (self).
Parameters:
-
event(Event) –The event to be inserted.
Returns:
-
EventGroup–The EventGroup instance (self) with the event inserted.
Raises:
-
ValueError–If event._onset is None (it must be a number)
Source code in amads/core/basics.py
1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 | |
last
¶
last() -> Optional[Event]
Retrieve the last event in the content list.
Because the content list is sorted by onset, the returned
Event is simply the last element of content, but not
necessarily the event with the greatest offset.
Returns:
-
Optional[Event]–The last event in the content list or None if the list is empty.
Source code in amads/core/basics.py
1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 | |
list_all
¶
Find all instances of a specific type within the EventGroup.
Assumes that objects of type elem_type are not nested within
other objects of the same type. See also
find_all, which returns
a generator instead of a list.
Parameters:
-
elem_type(Type[Event]) –The type of event to search for.
Returns:
-
list[Event]–A list of all instances of the specified type found within the EventGroup.
Source code in amads/core/basics.py
1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 | |
merge_tied_notes
¶
merge_tied_notes(
parent: Optional[EventGroup] = None, ignore: list[Note] = []
) -> EventGroup
Create a new EventGroup with tied notes replaced by single notes.
If ties cross staffs, the replacement is placed in the staff of the
first note in the tied sequence. Insert the new EventGroup into
parent.
Ordinarily, this method is called on a Score with no parameters. The
parameters are used when Score.merge_tied_notes() calls this method
recursively on EventGroups within the Score such as Parts and
Staffs.
Parameters:
-
parent(Optional[EventGroup], default:None) –Where to insert the result.
-
ignore(list[Note], default:[]) –This parameter is used internally. Caller should not use this parameter.
Returns:
-
EventGroup–A copy with tied notes replaced by equivalent single notes.
Source code in amads/core/basics.py
1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 | |
pack
¶
pack(onset: float = 0.0, sequential: bool = False) -> float
Adjust the content to onsets starting with the onset parameter.
By default onsets are set to onset and the duration of self is set to
the maximum duration of the content. pack() works recursively on
elements that are EventGroups. Setting sequential to True implements
sequential packing, where events are placed one after another.
Parameters:
-
onset(float, default:0.0) –The onset (start) time for this object.
Returns:
-
float–duration of self
Source code in amads/core/basics.py
1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 | |
quantize
¶
quantize(divisions: int) -> EventGroup
Align onsets and durations to a rhythmic grid.
Assumes time units are quarters. (See Score.convert_to_quarters.)
Modify all times and durations to a multiple of divisions per quarter note, e.g., 4 for sixteenth notes. Onsets and offsets are moved to the nearest quantized time. Any resulting duration change is less than one quantum, but not necessarily less than 0.5 quantum, since the onset and offset can round in opposite directions by up to 0.5 quantum each. Any non-zero duration that would quantize to zero duration gets a duration of one quantum since zero duration is almost certainly going to cause notation and visualization problems.
Special cases for zero duration:
- If the original duration is zero as in metadata or possibly grace notes, we preserve that.
- If a tied note duration quantizes to zero, we remove the tied note entirely provided some other note in the tied sequence has non-zero duration. If all tied notes quantize to zero, we keep the first one and set its duration to one quantum.
This method modifies this EventGroup and all its content in place.
Note that there is no way to specify "sixteenths or eighth triplets" because 6 would not allow sixteenths and 12 would admit sixteenth triplets. Using tuples as in Music21, e.g., (4, 3) for this problem creates another problem: if quantization is to time points 1/4, 1/3, then the difference is 1/12 or a thirty-second triplet. If the quantization is applied to durations, then you could have 1/4 + 1/3 = 7/12, and the remaining duration in a single beat would be 5/12, which is not expressible as sixteenths, eighth triplets or any tied combination.
Parameters:
-
divisions(int) –The number of divisions per quarter note, e.g., 4 for sixteenths, to control quantization.
Returns:
-
EventGroup–The EventGroup instance (self) with (modified in place) quantized times.
Source code in amads/core/basics.py
1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 | |
Chord
¶
Chord(
*args: Event,
parent: Optional[EventGroup] = None,
onset: Optional[float] = None,
duration: Optional[float] = None
)
Bases: Concurrence
A collection of notes played together.
Typically, chords represent notes that would share a stem, and note start times and durations match the start time and duration of the chord, but none of this is enforced. The order of notes is arbitrary.
Normally, a Chord is a member of a Measure. There is no requirement that simultaneous or overlapping notes be grouped into Chords, so the Chord class is merely an optional element of music structure representation.
See Constructor Details.
Representation note: An alternative representation would be to subclass Note and allow a list of pitches, which has the advantage of enforcing the shared onsets and durations. However, there can be ties connected differently to each note within the Chord, thus we use a Concurrence with Note objects as elements. Each Note.tie can be None (no tie) or tie to a Note in another Chord or Measure.
Parameters:
-
*args(Event, default:()) –The Event objects to be added to the group. Content events with onsets of None are set to the onset of the chord, or zero if onset is None.
-
parent(Optional[EventGroup], default:None) –The containing object or None. Must be passed as a keyword parameter due to
*args. -
onset(Optional[float], default:None) –The onset (start) time. None means unknown, to be set when Sequence is added to a parent. Must be passed as a keyword parameter due to
*args. -
duration(Optional[float], default:None) –The duration in quarters or seconds. (If duration is omitted or None, the duration is set so that self.offset ends at the max offset of args, or 0 if there is no content.) Must be passed as a keyword parameter due to
*args.
Attributes:
-
parent(Optional[EventGroup]) –The containing object or None.
-
_onset(Optional[float]) –The onset (start) time.
-
duration(float) –The duration in quarters or seconds.
-
content(list[Event]) –Elements contained within this collection.
Source code in amads/core/basics.py
2223 2224 2225 2226 2227 | |
Attributes¶
units_are_seconds
property
¶
units_are_seconds: bool
Check if the times are in seconds.
This event must be in a Score (where _units_are_seconds is stored).
Returns:
-
bool–True iff the event's times are in seconds. If not in a score, False is returned.
units_are_quarters
property
¶
units_are_quarters: bool
Check if the times are in quarters.
This event must be in a Score (where _units_are_seconds is stored).
Returns:
-
bool–True iff the event's times are in quarters. If not in a score, False is returned.
part
property
¶
part: Optional[Part]
Retrieve the Part containing this event.
Returns:
-
Optional[Part]–The Part containing this event or None if not found.
score
property
¶
score: Optional[Score]
Retrieve the Score containing this event.
Returns:
-
Optional[Score]–The Score containing this event or None if not found.
measure
property
¶
measure: Optional[Measure]
Retrieve the Measure containing this event
Returns:
-
Optional[Measure]–The Measure containing this event or None if not found.
Functions¶
__repr__
¶
__repr__() -> str
All Event subclasses inherit this to use str().
Thus, a list of Events is printed using their str methods
Source code in amads/core/basics.py
120 121 122 123 124 125 | |
_event_times
¶
_event_times(dur: bool = True) -> str
produce onset and duration string for str
Source code in amads/core/basics.py
135 136 137 138 139 140 141 | |
time_shift
¶
time_shift(increment: float, content_only: bool = False) -> EventGroup
Change the onset by an increment, affecting all content.
Parameters:
-
increment(float) –The time increment (in quarters or seconds).
-
content_only(bool, default:False) –If true, preserves this container's time and shifts only the content.
Returns:
-
Event–The object. This method modifies the
EventGroup.
Source code in amads/core/basics.py
1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 | |
insert_copy_into
¶
insert_copy_into(parent: Optional[EventGroup] = None) -> Event
Make a (mostly) deep copy of the Event and add to a new parent.
Pitch objects are considered immutable and are shared rather
than copied.
Parameters:
-
parent(Optional(EventGroup), default:None) –The copied
Eventwill be a child ofparentif notNone. The parent is modified by this operation.
Returns:
-
Event–A deep copy (except for parent and pitch) of the Event instance.
Source code in amads/core/basics.py
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 | |
_quantize
¶
_quantize(divisions: int) -> EventGroup
"Since _quantize is called recursively on children, this method is
needed to redirect EventGroup._quantize to quantize
Source code in amads/core/basics.py
1844 1845 1846 1847 1848 | |
_convert_to_seconds
¶
_convert_to_seconds(time_map: TimeMap) -> None
Convert the event's duration and onset to seconds using the provided TimeMap. Convert content as well.
Parameters:
-
time_map(TimeMap) –The TimeMap object used for conversion.
Source code in amads/core/basics.py
1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 | |
_convert_to_quarters
¶
_convert_to_quarters(time_map: TimeMap) -> None
Convert the event's duration and onset to quarters using the provided TimeMap. Convert content as well.
Parameters:
-
time_map(TimeMap) –The TimeMap object used for conversion.
Source code in amads/core/basics.py
1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 | |
ismonophonic
¶
ismonophonic() -> bool
Determine if content is monophonic (non-overlapping notes).
A monophonic list of notes has no overlapping notes (e.g., chords).
Serves as a helper function for ismonophonic and
parts_are_monophonic.
Returns:
-
bool–True if the list of notes is monophonic, False otherwise.
Source code in amads/core/basics.py
1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 | |
insert_emptycopy_into
¶
insert_emptycopy_into(
parent: Optional[EventGroup] = None,
) -> EventGroup
Create a deep copy of the EventGroup except for content.
A new parent is provided as an argument and the copy is inserted into this parent. This method is useful for copying an EventGroup without copying its content. See also insert_copy_into to copy an EventGroup with its content into a new parent.
Parameters:
-
parent(Optional[EventGroup], default:None) –The new parent to insert the copied Event into.
Returns:
-
EventGroup–A deep copy of the EventGroup instance with the new parent (if any) and no content.
Source code in amads/core/basics.py
1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 | |
expand_chords
¶
expand_chords(parent: Optional[EventGroup] = None) -> EventGroup
Replace chords with the multiple notes they contain.
Returns a deep copy with no parent unless parent is provided.
Normally, you will call score.expand_chords() which returns a deep
copy of Score with notes moved from each chord to the copy of the
chord's parent (a Measure or a Part). The parent parameter is
primarily for internal use when expand_chords is called recursively
on score content.
Parameters:
-
parent(EventGroup, default:None) –The new parent to insert the copied EventGroup into.
Returns:
-
EventGroup–A deep copy of the EventGroup instance with all Chord instances expanded.
Source code in amads/core/basics.py
1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 | |
find_all
¶
Find all instances of a specific type within the EventGroup.
Assumes that objects of type elem_type are not nested within
other objects of the same type. (The first elem_type encountered
in a depth-first enumeration is returned without looking at any
children in its content).
Parameters:
-
elem_type(Type[Event]) –The type of event to search for.
Yields:
-
Event–Instances of the specified type found within the EventGroup.
Source code in amads/core/basics.py
1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 | |
has_instanceof
¶
has_instanceof(the_class: Type[Event]) -> bool
Test if EventGroup contains any instances of the_class.
Parameters:
-
the_class(Type[Event]) –The class type to check for.
Returns:
-
bool–True iff the EventGroup contains an instance of the_class.
Source code in amads/core/basics.py
1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 | |
has_chords
¶
has_chords() -> bool
Test if EventGroup (e.g., Score, Part, ...) has any Chord objects.
Returns:
-
bool–True iff the EventGroup contains any Chord objects.
Source code in amads/core/basics.py
1608 1609 1610 1611 1612 1613 1614 1615 1616 | |
has_ties
¶
has_ties() -> bool
Test if EventGroup (e.g., Score, Part, ...) has any tied notes.
Returns:
-
bool–True iff the EventGroup contains any tied notes.
Source code in amads/core/basics.py
1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 | |
has_measures
¶
has_measures() -> bool
Test if EventGroup (e.g., Score, Part, ...) has any Measures.
Returns:
-
bool–True iff the EventGroup contains any Measure objects.
Source code in amads/core/basics.py
1634 1635 1636 1637 1638 1639 1640 1641 1642 | |
inherit_duration
¶
inherit_duration() -> EventGroup
Set the duration of this EventGroup according to maximum offset.
The duration is set to the maximum offset (end) time of the
children. If the EventGroup is empty, the duration is set to 0.
This method modifies this EventGroup instance.
Returns:
-
EventGroup–The EventGroup instance (self) with updated duration.
Source code in amads/core/basics.py
1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 | |
insert
¶
insert(event: Event) -> EventGroup
Insert an event.
Sets the parent of event to this EventGroup and makes event
be a member of this EventGroup.content. No changes are made to
event.onset or self.duration. Insert event in content just
before the first element with a greater onset. The method modifies
this object (self).
Parameters:
-
event(Event) –The event to be inserted.
Returns:
-
EventGroup–The EventGroup instance (self) with the event inserted.
Raises:
-
ValueError–If event._onset is None (it must be a number)
Source code in amads/core/basics.py
1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 | |
last
¶
last() -> Optional[Event]
Retrieve the last event in the content list.
Because the content list is sorted by onset, the returned
Event is simply the last element of content, but not
necessarily the event with the greatest offset.
Returns:
-
Optional[Event]–The last event in the content list or None if the list is empty.
Source code in amads/core/basics.py
1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 | |
list_all
¶
Find all instances of a specific type within the EventGroup.
Assumes that objects of type elem_type are not nested within
other objects of the same type. See also
find_all, which returns
a generator instead of a list.
Parameters:
-
elem_type(Type[Event]) –The type of event to search for.
Returns:
-
list[Event]–A list of all instances of the specified type found within the EventGroup.
Source code in amads/core/basics.py
1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 | |
merge_tied_notes
¶
merge_tied_notes(
parent: Optional[EventGroup] = None, ignore: list[Note] = []
) -> EventGroup
Create a new EventGroup with tied notes replaced by single notes.
If ties cross staffs, the replacement is placed in the staff of the
first note in the tied sequence. Insert the new EventGroup into
parent.
Ordinarily, this method is called on a Score with no parameters. The
parameters are used when Score.merge_tied_notes() calls this method
recursively on EventGroups within the Score such as Parts and
Staffs.
Parameters:
-
parent(Optional[EventGroup], default:None) –Where to insert the result.
-
ignore(list[Note], default:[]) –This parameter is used internally. Caller should not use this parameter.
Returns:
-
EventGroup–A copy with tied notes replaced by equivalent single notes.
Source code in amads/core/basics.py
1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 | |
pack
¶
pack(onset: float = 0.0, sequential: bool = False) -> float
Adjust the content to onsets starting with the onset parameter.
By default onsets are set to onset and the duration of self is set to
the maximum duration of the content. pack() works recursively on
elements that are EventGroups. Setting sequential to True implements
sequential packing, where events are placed one after another.
Parameters:
-
onset(float, default:0.0) –The onset (start) time for this object.
Returns:
-
float–duration of self
Source code in amads/core/basics.py
1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 | |
quantize
¶
quantize(divisions: int) -> EventGroup
Align onsets and durations to a rhythmic grid.
Assumes time units are quarters. (See Score.convert_to_quarters.)
Modify all times and durations to a multiple of divisions per quarter note, e.g., 4 for sixteenth notes. Onsets and offsets are moved to the nearest quantized time. Any resulting duration change is less than one quantum, but not necessarily less than 0.5 quantum, since the onset and offset can round in opposite directions by up to 0.5 quantum each. Any non-zero duration that would quantize to zero duration gets a duration of one quantum since zero duration is almost certainly going to cause notation and visualization problems.
Special cases for zero duration:
- If the original duration is zero as in metadata or possibly grace notes, we preserve that.
- If a tied note duration quantizes to zero, we remove the tied note entirely provided some other note in the tied sequence has non-zero duration. If all tied notes quantize to zero, we keep the first one and set its duration to one quantum.
This method modifies this EventGroup and all its content in place.
Note that there is no way to specify "sixteenths or eighth triplets" because 6 would not allow sixteenths and 12 would admit sixteenth triplets. Using tuples as in Music21, e.g., (4, 3) for this problem creates another problem: if quantization is to time points 1/4, 1/3, then the difference is 1/12 or a thirty-second triplet. If the quantization is applied to durations, then you could have 1/4 + 1/3 = 7/12, and the remaining duration in a single beat would be 5/12, which is not expressible as sixteenths, eighth triplets or any tied combination.
Parameters:
-
divisions(int) –The number of divisions per quarter note, e.g., 4 for sixteenths, to control quantization.
Returns:
-
EventGroup–The EventGroup instance (self) with (modified in place) quantized times.
Source code in amads/core/basics.py
1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 | |
_is_well_formed
¶
_is_well_formed()
Test if Chord conforms to strict hierarchy of Chord-Note
Source code in amads/core/basics.py
2230 2231 2232 2233 2234 2235 2236 2237 2238 | |
TimeMap
¶
TimeMap(qpm=100.0)
Implement the time_map attribute of Score class.
Every Score has a time_map attribute whose value is a
TimeMap that maintains a mapping between time in seconds
and beats in quarters. A TimeMap encodes the information
in a MIDI File tempo track as well as tempo information from
a Music XML score.
This class holds a list representing tempo changes as a list of (time, quarter) pairs, which you can think of as tempo changes. More mathematically, they are breakpoints in a piece-wise linear function that maps from time to quarter or from quarter to time.
Since tempo is not continuous, the tempo at a breakpoint is defined to be the tempo just after the breakpoint.
Parameters:
-
qpm(float, default:100.0) –Initial tempo in quarters per minute (default is 100.0).
Attributes:
-
changes(list of MapQuarter) –List of (time, quarter) breakpoints for piece-wise linear mapping.
-
last_tempo(float) –Final quarters per second (qps) for extrapolatation.
Examples:
>>> tm = TimeMap(qpm=120)
>>> tm.append_change(4.0, 60.0) # change to 60 qpm at quarter 4
>>> tm.quarter_to_time(5.0)
3.0
>>> tm.time_to_quarter(3.0)
5.0
Source code in amads/core/timemap.py
99 100 101 | |
Functions¶
deep_copy
¶
deep_copy() -> TimeMap
Make a full copy of this time map.
Returns:
-
TimeMap–A deep copy of this TimeMap instance.
Source code in amads/core/timemap.py
131 132 133 134 135 136 137 138 139 140 141 142 | |
append_change
¶
append_change(quarter: float, tempo: float) -> None
Append a tempo change at a given quarter.
Append a MapQuarter specifying a change to tempo at quarter.
quarter must be at least as great as last MapQuarter's quarter.
You cannot insert a tempo change before the end of the TimeMap.
The tempo will hold forever beginning at quarter unless you call
append_change again to change the tempo somewhere beyond
quarter.
Parameters:
-
quarter(float) –The quarter measured in quarters where the tempo changes
-
tempo(float) –The new tempo at quarter measured in quarters per minute. Typically, this is the same as beats per minute (BPM), but only when a beat lasts one quarter.
Returns:
-
None–
Source code in amads/core/timemap.py
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 | |
get_time_at
¶
get_time_at(index: int) -> float
Get the time in seconds at a given index in the changes list.
Parameters:
-
index(int) –The index in the changes list.
Returns:
-
float–The time in seconds at the specified index.
Source code in amads/core/timemap.py
176 177 178 179 180 181 182 183 184 185 186 187 188 189 | |
get_tempo_at
¶
get_tempo_at(index: int) -> float
Get the tempo at a given index in the changes list.
The tempo changes at each breakpoint. This method returns the tempo in QPM just after the breakpoint at the specified index.
Parameters:
-
index(int) –The index in the changes list.
Returns:
-
float–The tempo in quarters per minute immediately after the specified index.
-
The tempo at entry i is the tempo in effect JUST BEFORE entry i,–
Parameters:
-
index(int) –The index in the changes list.
Returns:
-
float–The tempo in quarters per minute (qpm) just after entry i.
Source code in amads/core/timemap.py
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 | |
_time_to_insert_index
¶
_time_to_insert_index(time: float) -> int
Find the insertion index for a given time in seconds.
Returns the index of the first MapQuarter whose time attribute
is greater than the specified time. If time is greater than
all entries, returns the length of self.changes.
This assumes that if you insert a tempo change at an existing time, the new change goes after the existing one. (But really, shouldn't you overwrite the existing one?)
Parameters:
-
time(float) –The time in seconds to locate.
Returns:
-
int–The insertion index for the given time.
Source code in amads/core/timemap.py
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 | |
_quarter_to_insert_index
¶
_quarter_to_insert_index(quarter: float) -> int
Find the insertion index for a given quarter in seconds.
Returns the index of the first MapQuarter whose quarter
attribute is greater than the specified
quarter. If quarter is greater than all entries, returns the
length of self.changes.
This assumes that if you insert a tempo change at an existing quarter, the new change goes after the existing one. (But really, shouldn't you overwrite the existing one?)
Parameters:
-
quarter(float) –The quarter note position to locate.
Returns:
-
int– -
The insertion index for the given quarter position.–
Source code in amads/core/timemap.py
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 | |
quarter_to_time
¶
quarter_to_time(quarter: float) -> float
Convert time in quarters to time to seconds.
Parameters:
-
quarter(float) –A score position in changes.
Returns:
-
float–The time in seconds corresponding to
quarter.
Source code in amads/core/timemap.py
335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 | |
quarter_to_tempo
¶
quarter_to_tempo(quarter: float) -> float
Get the tempo in qpm at a given quarter.
Parameters:
-
quarter(float) –A score position in changes.
Returns:
-
float–The tempo at
quarter. If there is a tempo change here, returns the tempo on the right (after the change).
Source code in amads/core/timemap.py
355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 | |
time_to_quarter
¶
time_to_quarter(time: float) -> float
Convert time in seconds to quarter position.
Parameters:
-
time(float) –A score time in seconds.
Returns:
-
float–The score position in changes corresponding to
time.
Source code in amads/core/timemap.py
410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 | |
time_to_tempo
¶
time_to_tempo(time: float) -> float
Get the tempo in qpm at a given time (in seconds).
Parameters:
-
time(float) –A score time in seconds.
Returns:
-
float–The tempo at
time. If there is a tempo change here, use the tempo on the right (aftr the change).
Source code in amads/core/timemap.py
433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 | |
MapQuarter
¶
MapQuarter(time: float, quarter: float)
Represents a (time, quarter) pair in a piece-wise linear mapping.
Parameters:
-
time(float) –The time in seconds.
-
quarter(float) –The corresponding quarter note position.
Attributes:
-
time(float) –The time in seconds.
-
quarter(float) –The corresponding quarter note position.
Methods:
-
copy–Return a copy of the MapQuarter instance.
Source code in amads/core/timemap.py
40 41 42 | |
Functions¶
copy
¶
copy() -> MapQuarter
return a copy of this MapQuarter
Returns:
-
MapQuarter–A copy of this MapQuarter instance.
Source code in amads/core/timemap.py
44 45 46 47 48 49 50 51 52 | |