amads.algorithms.slice.window#
Sliding window algorithm.
The algorithm segments a musical score into fixed-size windows that can optionally overlap. Each window contains all notes that are sounding within its time boundaries.
- class amads.algorithms.slice.window.Window(time, size, align, candidate_notes, skip=0)[source]#
A fixed-size window of a musical score.
- Parameters:
time (float) – The reference time for this window
size (float) – The size of the window in time units
align (str) – How to align the window relative to the reference time: - “left”: window starts at reference time - “center”: reference time is at window center - “right”: window ends at reference time
candidate_notes (Iterable[Note]) – Notes to consider for inclusion in this window, sorted by onset time and pitch
skip (int, default=0) – Index to start searching from in candidate_notes. This is used to optimize performance when iterating through multiple windows - each window can tell the next window which notes it can safely skip because they end before the window starts.
- amads.algorithms.slice.window.sliding_window(passage, size, step=1.0, align='right', onset=0.0, offset=None, times=None) Iterator[Window] [source]#
Slice a score into (possibly overlapping) windows of a given size.
- Parameters:
passage (Score or Iterable[Note]) – The musical passage to be windowed
size (float) – The size (duration) of each window (time units)
step (float, default=1.0) – The step size to take between windows (time units). For example, if step is 0.1, then a given slice will start 0.1 time units after the previous slice started. Note that if step is smaller than size, successive windows will overlap
align (str, default="right") – Each generated window has a time property that points to a particular timepoint in the musical passage. The align parameter determines how the window is aligned to this timepoint: - “left”: the window starts at
window.time
- “center”:window.time
corresponds to the midpoint of the window - “right”: the window finishes atwindow.time
onset (float, default=0.0) – The desired time of the first window
offset (float, optional) – If set, the windowing will stop once the offset time is reached. Following the behaviour of Python’s built-in range function,
offset
is not treated inclusively, i.e. the last window will not includeoffset
times (Iterable[float], optional) – Optional iterable of times to generate windows for. If provided, onset and offset are ignored
- Returns:
Iterator over the windows
- Return type:
Iterator[Window]