pytakt.score module

This module defines the Score class and its subclasses.

class Score

Bases: object

This class is an abstract class for scores. A score is either an event list (an instance of the EventList class), an event stream (an instance of the EventStream class), or a Tracks container. An event list is a list of zero or more events, with an attribute called duration (see below) added. An event stream is an object that uses Python’s generator mechanism to generate events in sequence, allowing for the representation of infinite-length scores. A Tracks container is a list of zero or more event lists or other Tracks containers as elements, representing a structure in which all elements are played concurrently.

Duration

Scores have the concept of duration, which represents the length of the performance in ticks. In sequential concatenation of scores, the start time of the performance of a score is set to the start time of its previous score plus the duration of the score. The duration of an EventList is equal to the value of its duration attribute. The duration of a Tracks is the maximum duration among its components. The duration of an EventStream is the value attribute of the StopIteration exception raised when the end of the stream is reached. The duration is non-negative and is not necessarily equal to the maximum time of the events in the score; it may be greater or even less.

Arithmetic Rules

  • The ‘+’ operator: If s1 and s2 are Score objects, then s1 + s2 implies a sequential concatenation and returns a new score that plays the two scores in sequence. The result is an EventStream if s2 is an EventStream, otherwise an EventList. s1 must not be an EventStream. Each event in s2 is copied and its time is shifted by the duraion of s1. The resulting score’s duration is the sum of the durations of the two scores.

  • The ‘+=’ operator: In s1 += s2, if s1 is an EventList and s2 is a score other than an EventStream, then the copied events of s2 are added in-place to s1. Otherwise, it is equivalent to s1 = s1 + s2.

  • The ‘&’ operator: If s1 and s2 are Score objects, then s1 & s2 implies parallel merging and returns a new score that plays the two scores simultaneously. The result is an EventStream if one or both of s1 and s2 are EventStream, otherwise an EventList. No copying of events is performed. The duration of the resulting score will be either the durations of the two scores, whichever is greater.

  • The ‘&=’ operator: In s1 &= s2, if s1 is an EventList and s2 is a score other than an EventStream, then the events in s2 are added in-place to s1. Otherwise, it is equivalent to s1 = s1 & s2.

  • The ‘*’ operator: The product of a Score object and an integer is a score that repeats the original score by the integer value. s1 must not be an EventStream. The result will always be an EventList.

Examples

(note(C4) + note(D4) + note(E4)).play()

(note(C4) & note(E4) & note(G4)).play()

(note(C4) * 16).play()


tostr(timereprfunc=<function std_time_repr>) str

Returns a string representation of the score.

Parameters:

timereprfunc (function) – Function to convert a value of time to a string. By default, it assumes a function that returns a representation rounded to 5 decimal places.

get_duration() Union[int, float, Fraction]

Returns the duration of the score. Not available for EventStream.

tee() Score

If the score is an EventStream, returns a new equivalent generator that can be read independently without changing the read state of the original generator. For scores of any other type, returns self as is.

count() int

Returns the number of events in the score. Not available for EventStream.

mapev(func, durfunc=None) Score

Calls the function func for each event in the score and returns a new score where each event is replaced by the return value of func. The type of the score and the order of events in the score remain the same.

The function func is called in the order of appearance of events in the score, not necessarily in chronological order.

The function func can return not only a single event, but also None or a list of events, which allows insertion or deletion of events.

Remark: For an EventStream, func must not change the value of the t attribute in such a way that the time order of the events is changed.

Parameters:
  • func (function) – For each event ev, this function is called in the form func(ev). The return value of this function must be of type Event, None, or an iterable of Event.

  • durfunc (function, optional) – Specifies the function to convert the duration. The function is called in the form durfunc(d) for the duration d of the original score, and the return value will be the duration of the new score. By default, the original score’s duration is used in the new score.

Examples

score.mapev(lambda ev: ev.update(tk=0))

Returns a score of all events with the track number set to 0. The original events are overwritten.

score.mapev(lambda ev: ev.copy().update(ch=3)) if hasattr(ev, 'ch') else ev)

Returns a score with the channel number changed to 3. (This is equivalent to Modify('ch=3') using Modify.)

score.mapev(lambda ev: None if hasattr(ev, 'ch') and ev.ch==2 else ev)

Returns a score where events with channel number 2 are removed.

score.mapev(lambda ev: ev.copy().update(t=ev.t * 2), durfunc=lambda d: d*2)

Returns a score with time stretched by a factor of 2.

chord_mapev(func, time_tolerance=None) Union[EventList, EventStream]

For each event in the score, it calls the function func with additional information about the number of notes being played simultaneously and pitch position within those, and returns a new score where each event is replaced by the return value of func. If the original score is Tracks, the result is an EventList. For other types of scores, the type remains the same.

The function func is called in the order of time of the events (i.e., ascending order of the t attribute values). If they occur at the same time, they are called in the order of their appearance in the score.

The function func can return not only a single event, but also None or a list of events, which allows insertion or deletion of events.

Parameters:
  • func (function) – For each event ev, this function is called in the form func(i, m, ev), where i is the ranking number in terms of pitch among the notes being played at the same time (0 <= i < m and 0 representing the lowest note) and m is the number of notes being played at the same time. Events not belonging to NoteEventClass will have both i and m equal to 0. The return value of this function must be of type Event, None, or an iterable of Event.

  • time_tolerance (float, optional) – See chord_iterator() argument of the same name.

Examples

score.chord_mapev(lambda i, m, ev: ev.copy().update(v=ev.v + (i==m-1)*10) if hasattr(ev, 'v') else ev)

Returns a score with the velocity of the highest note of each chord increased by 10.

mapstream(func) Score

For each event list or event stream in the score, it calls the transforming function func on the stream, and returns a new score replaced by the event stream that the function generates. The type of the score does not change (an event list is converted to an event stream, func is applied, and then it is converted back to an event list again). Each event is not copied unless explicitly done within the transforming function.

Parameters:

func (function) – A generator function to transform an event sequence. The function is called on the input stream stream in the form func(stream). The stream is the one converted by stream() in the case of an event list, or itself in the case of an event stream. The ‘value’ attribute of the StopIteration raised at the end of stream contains the duration of the score. The generator function func should return an iterator of events such that StopIteratoin has the converted duration (such a function can be implemented by outputting converted events with ‘yield’ and returning the converted duration with ‘return’).

stream(copy=False, *, limit=None) EventStream

Converts a score to an event stream. The returned EventStream object yields the events in the score in chronological order (ascending order of the t attribute values). Events that occur at the same time are yielded in the order of their appearance in the score. The returned EventStream will raise a StopIteration exception when the end of the score is reached, and the ‘value’ attribute of this exception object will contain the duration of the score (or the value of limit if the limit is reached).

Parameters:
  • copy (bool, optional) – If True, copied events are yielded.

  • limit (ticks, optional) – If given, limits the length of the score if self is an EventStream, and will warn and raise a StopIteration exception when it sees an event with a time greater than this value (the observed event will not be yielded). It has no effect on scores other than EventStream.

chord_iterator(time_sequence=None, *, cont_notes=True, copy=False, time_tolerance=None, limit=None) Generator[EventList, None, Union[int, float, Fraction]]

This ia a generator function that yields the information for each time span of the score in chronological order. Each yielded object is an EventList that contains the events that exist in the span and, optionally, the events for notes that have been continued since the previous span. The EventList has an additional attribute named ‘start’, which contains the start time of the span. The end time of the span is stored in the duration attribute. The order of events in the EventList follows that of stream().

Parameters:
  • time_sequence (None, ticks, or iterable of ticks, optional) – Specifies how to delimit the spans; if None (default), the span boundaries are time positions where one or more note-ons or note-offs (including note-off implied by NoteEvent, that is, the time at the sum of its t and L attributes) exist. If it is an int or a float, spans are formed with a constant interval of that value. If it is an int or float iterable, each element of the iterable is the time of the span boundary. Each span is defined to be greater than or equal to the time of a boundary and less than or equal to the time of the next boundary.

  • cont_notes (bool, optional) – If True, an additional reference to the NoteEvent or NoteOnEvent is inserted into EventList for notes that have been continued since the previous span. Note that whether or not events are such additional references can be determined by comparing the time of the event and the start time of the span: an event ev is an additional reference if ev.t < evlist.start where evlist is the event list yielded.

  • copy (bool, optional) – If True, the event list to be yielded will contain the copied events. If cont_notes is True, additional references are to the copy.

  • time_tolerance (float, optional) – This is meaningful only when time_sequence is None. Note-ons and note-offs within this value of time difference are considered to be the same time and have a single span boundary. If omitted, it is set to 50 ticks if self is a RealTimeStream; otherwise it is set to 10-6.

  • limit (ticks, optional) – Has the same meaning as the ‘limit’ argument of stream().

Yields:

EventList

Raises:

StopIteration – Raised when the end of the score is reached. The ‘value’ attribute of this exception object contains the duration of the score. It is also raised when the limit is reached, in which case the value attribute will contain the value of the limit.

Tip

From the output sequence of chord_iterator(), you can get the score of the same performance as the original (but the duration may be different) by the following:

par(EventList((ev for ev in evlist if ev.t >= evlist.start),
              evlist.duration)
    for evlist in score.chord_iterator())

or

par(score.chord_iterator(cont_notes=False))

Examples

The program below calculates the maximum number of simultaneous played notes for a non-empty score s:

max(sum(isinstance(ev, (NoteEvent, NoteOnEvent)) for ev in evlist)
    for evlist in s.chord_iterator())

The program below displays a list of sounding pitches for each sixteenth-note span:

for evlist in s.chord_iterator(L16):
    print(evlist.start,
          [ev.n for ev in evlist if isinstance(ev, (NoteEvent, NoteOnEvent))])

The program below prints an event list for each measure:

tm = TimeMap(s)
for m, evlist in enumerate(s.chord_iterator(tm.iterator())):
    print(f'Measure {m + tm.ticks2mbt(0)[0]}:', evlist)
active_events_at(time, event_type=<class 'pytakt.event.Event'>, cache=True) List[Event]

Returns a list of events that are active (or effective) at time. Active events are specifically the following events.

  • NoteEvent or NoteOnEvent for the note sounding at time, not including a note that has just ended at time. NoteEvent or NoteOnEvent events for notes that start sounding at time are included, unless they have zero duration (NoteEvent with the L attribute of 0, or NoteOnEvent with a note-off at the same time).

  • KeySignatureEvent representing the key at time, including those present at exactly time.

  • TimeSignatureEvent representing the time signature at time, including those that exist at exactly time.

  • TempoEvent representing the tempo at time, including those that exist at exactly time.

  • The last CtrlEvent before time for each controller number, each track number, and each MIDI channel number, except the mode changes (controller numbers 124-127). For RPCs, CtrlEvent’s needed to set each parameter value are included.

  • The last KeyPressureEvent before time for each track number, each MIDI channel number, and each MIDI note number.

The active events are computed based on notated time (i.e., without regard to the dt and du attributes). If you want to use the played time as a reference, apply the Render effector before calling.

Parameters:
  • time (ticks) – Time of interest

  • event_type (class, int, or tuple of class or int) – If a class is specified, the type of events examined is limited to events of that class or its subclasses (in this argument, NoteEvent, NoteOnEvent, and NoteOffEvent all have the same meaning as NoteEventClass). If an integer is specified, events are limited to CtrlEvent’s of that controller number. In the case of a tuple of classes and/or integers, events corresponding to any of them are targetted. Note that when specifying RPC-related controller numbers (6,38,98-101), all of these must be specified at the same time.

  • cache (bool) – If True (default), caching is enabled to speed up multiple queries against the same score. However, if the score is rewritten after using this method, it will not return correct results thereafter, so use False in such a case.

Returns:

List of active events, which are references to events in the score. The events are ordered by time. For events present at the same time, they are ordered by their appearance in the socre.

Return type:

list of Event

Notes

Without caching, the computational complexity of M queries for a score with N events is O(NM). With caching, it is reduced to O(N+MlogN) for ordinary scores, although the worst-case complexity remains O(MN).

show(*args, **kwargs) None

Call pianoroll.show() with the given arguments to display a pianoroll window.

showtext(*args, **kwargs) None

text.showtext() is called with the given arguments to convert this score into a descriptive text that can be evaluated by Python and output it.

summary(*args, **kwargs) None

Call text.showsummary() with the given arguments to output statistics of the score.

play(*args, **kwargs) None

midiio.play() is called with the given arguments to play this score.

writesmf(*args, **kwargs) None

Call smf.writesmf() with the given arguments to write this score to a standard MIDI file.

writepyfile(*args, **kwargs) None

Call text.writepyfile() with the given arguments to convert this score to a descriptive text that can be evaluated by Python and output it to a file.

writejson(*args, **kwargs) None

Call text.writejson() with the given arguments to convert this score to JSON format and output it to a file.

music21(min_note=60, bar0len=None, *, allow_tuplet=True, limit=500000.0) music21.stream.Score

Converts a Pytakt Score object to a music21 Score object. In the conversion, each track in Pytakt, except track 0, is assigned a music21 part (one stave).

The following information that the Pytakt score has is not output to the music21 score.

  • Played time information (dt and du attributes)

  • MIDI channel information (ch attribute)

  • Note-off velocity (nv attribute)

  • Information contained in CtrlEvent (and its subclasses) and SysExEvent

  • Meta events other than key signature events, time signature events, tempo events, copyright information events, track name events, instrument name events, and marker events (The generic text event (mtype=1) is output as a song title if it exists on track 0.)

In the conversion, if NoteEvent has the following attributes, it has the meaning written below.

  • voice (int): Specifies a voice number, an integer greater than or equal to 1, indicating how the music21 Voice streams will be constructed if multiple voices are present. If this attribute is not specified, the voice number is automatically selected from the voice numbers that are not used at the same time.

  • mark (str or tuple of str): Specifies a string of symbols (staccato, accents, finger numbers, trills, etc.) to be added to each note. Multiple markers can be specified by tuples. A list of available strings can be found at the beginning of the pytakt.m21conv source code.

Currently, lyrics and spanners such as slurs are not supported.

Parameters:
  • min_note (ticks, optional) – The duration (note value) of the shortest possible note to be used in the converted score. The smaller this value, the more accurately the Pytakt score is represented, but it may result in a score that is difficult to read when converted to staff notation.

  • bar0len (ticks, optional) – specifies the length of the bar with bar number 0.

  • allow_tuplet (bool, optional) – By default, up to tredecuplets (13-tuplets) are automatically recognized, but setting this argument to False disables the use of tuplets altogether.

  • limit (ticks, optional) – Limits the length of the score (see Score.stream() for details).

pretty_midi(render=True, limit=2000000.0) pretty_midi.PrettyMIDI

Converts a Pytakt Score object to pretty_midi’s PrettyMIDI object. Information on notes, pitch-bends, control-changes, tempo, time signatures, key signatures, program numbers (via program change), track names, lyrics, and text events is output. In the pretty_midi object, a new Instrument is allocated if any of the track number, MIDI channel number, or program number is different. On the other hand, information of track numbers and channel numbers themselves will be lost.

Parameters:
  • render (bool, optional) – If True (default), the played time is used. Otherwise, the notated time is used.

  • limit (ticks, optional) – Limits the length of the score (see Score.stream() for details).

static from_music21(m21score) Tracks

Converts a music21 score object (an object of the music21.stream.Stream class) to a Pytakt Score object. In the conversion, a Pytakt track is assigned to each part of music21, and the MIDI channel number is always 1. If the music21 score uses the Voice structure, the ‘voice’ attribute will be set to each NoteEvent.

Currently, lyrics and spanners such as slurs are not supported.

static from_pretty_midi(pmscore) Tracks

Converts a pretty_midi score object (an object of the pretty_midi.PrettyMIDI class) to a Pytakt Score object. Each instrument in pretty_midi is allocated from Track 1 sequentially. MIDI channels 1-16 except 10 are cyclically assigned to each track. MIDI channel 10 is assigned to instruments flagged as drums.

dump() None
EventEffector: Callable[[...], Score] = None
CompositeEffector: Callable[[...], Score] = None
Transpose: Callable[[...], Score] = None
Invert: Callable[[...], Score] = None
ApplyScale: Callable[[...], Score] = None
ConvertScale: Callable[[...], Score] = None
ScaleVelocity: Callable[[...], Score] = None
Repeat: Callable[[...], Score] = None
TimeStretch: Callable[[...], Score] = None
Retrograde: Callable[[...], Score] = None
Quantize: Callable[[...], Score] = None
TimeDeform: Callable[[...], Score] = None
Swing: Callable[[...], Score] = None
ToMilliseconds: Callable[[...], Score] = None
Randomize: Callable[[...], Score] = None
Clip: Callable[[...], Score] = None
Arpeggio: Callable[[...], Score] = None
Filter: Callable[[...], Score] = None
Reject: Callable[[...], Score] = None
Cond: Callable[[...], Score] = None
Modify: Callable[[...], Score] = None
Product: Callable[[...], Score] = None
Apply: Callable[[...], Score] = None
ToTracks: Callable[[...], Score] = None
Render: Callable[[...], Score] = None
Tie: Callable[[...], Score] = None
EndTie: Callable[[...], Score] = None
ConnectTies: Callable[[...], Score] = None
Dump: Callable[[...], Score] = None
Voice: Callable[[...], Score] = None
Mark: Callable[[...], Score] = None
PairNoteEvents: Callable[[...], Score] = None
UnpairNoteEvents: Callable[[...], Score] = None
RetriggerNotes: Callable[[...], Score] = None
class EventList(events=[], duration=None, *, limit=2000000.0, **kwargs)

Bases: Score, list

EventList is a class for event lists and inherits from both the Score and ‘list’ classes. An event list is a list of zero or more events, with an attribute called duration added, which represents the length of the performance. The events in the list are not necessarily ordered by time.

Attributes

duration

Duration in ticks. Must not be a negative value.

Type:

ticks

Arithmetic Rules

  • The bool value is False if the number of elements is 0, as in the normal list. Note that an empty event list with a non-zero duration will also be false.

  • The equivalence comparison (‘==’) between event lists results in True if and only if the classes match, the list lengths match, all list elements are equivalent, and all attribute values of the event list are equivalent.

  • If the ‘|’ operator is used with the left operand being a string and the right operand being an event list, the left operand is ignored and the result is the value of the event list itself. This is used in showtext() to ignore measure numbers, etc. to the left of the ‘|’.

Constructor

Parameters:
  • events (Score or iterable of Event) –

    • If it is a Score (including the case of an EventList), the score is converted (or ‘flattened’) to an event list where the events therein are sorted by time. Each event is not copied. The value of the duration attribute is set to the value of the duration argument, if any, otherwise the duration of the source score (or the value of limit if the EventStream is terminated by the limit feature below).

    • If it is an Event iterable (but not an EventList or EventStream), the event list is created with keeping the order of events as it is. Each event is not copied. The value of the duration attribute is determined in the following order: (1) the value of the duration argument, if any, (2) the value owned by StopIteration if events is an iterator and has the value attribute in its StopIteration, or (3) 0 for an empty iterable. An exception is raised if none of these apply.

  • duration (ticks, optional) – Specifies the value of the duration attribute.

  • limit (ticks, optional) – If events is an EventStream, it limits the length of the score. See the limit argument of Score.stream() for details.

  • kwargs – Specifies additional attributes for the event list.


tostr(timereprfunc=<function std_time_repr>) str

Returns a string representation of the score.

Parameters:

timereprfunc (function) – Function to convert a value of time to a string. By default, it assumes a function that returns a representation rounded to 5 decimal places.

copy() EventList

Returns a duplicated event list (shallow copy).

deepcopy() EventList

Returns a new event list with each event duplicated.

sort(*, key=None) None

Sorts the events (by default, in ascending order of the t attribute value). Uses the stable sorting algorithm same as list.sort().

Args: key(function, optional)
key(function, optional): has the same meaning as the ‘key’

argument of list.sort().

sorted(*, key=None) EventList

Returns a new list of events sorted (by default, in ascending order of the t attribute value). Uses the stable sorting algorithm same as list.sort().

Args: key(function, optional)
key(function, optional): has the same meaning as the ‘key’

argument of list.sort().

add(ev) None

Add an event ev to the end of the event list. In addition, it updates the duration attribute of the event list by the greater of that value and the t attribute value of ev (or the sum of the t and L attribute values in the case of a NoteEvent).

Args: Args

ev(Event): event to add

merge(other, time=0) None

Adds all events in the event list other to the end of the event list self. The resulting duration attribute value of event list self will be the greater of that value and the duration attribute value of other plus time.

Caution: If time is non-zero, events in other are destroyed by default. To avoid this, deepcopy other before calling this method.

Parameters:
  • other (EventList) – list of events to merge

  • time (ticks, optional) – add value of time

get_duration() Union[int, float, Fraction]

Returns the value of the duration attribute.

tee() EventList

Returns self as is.

count() int

Returns the number of events in the score.

class Tracks(elms=[], **kwargs)

Bases: Score, list

Container class for representing a concurrently played structure. It inherits from both the Score and list classes. Elements are limited to EventList or other Tracks containers; EventStreams cannot be the elements. The overall duration is the maximum of the elements’ duration.

Arithmetic Rules

  • The equivalence comparison (‘==’) between Tracks objects results in true if and only if the classes match, the list lengths match, all list elements are equivalent, and all attribute values of the Tracks object are equivalent.

Constructor

Parameters:
  • elms (iterable of Score) – element scores

  • kwargs – additional attributes for the Tracks object.


tostr(timereprfunc=<function std_time_repr>) str

Returns a string representation of the score.

Parameters:

timereprfunc (function) – Function to convert a value of time to a string. By default, it assumes a function that returns a representation rounded to 5 decimal places.

copy() Tracks

Returns a duplicated object (shallow copy).

get_duration() Union[int, float, Fraction]

Returns the maximum of the elements’ duration as the duration of the score.

tee() Tracks

Returns self as is.

count() int

Returns the number of events in the score.

sort(*, key=None) None

Applies the sort() method to all the elements.

Parameters:

key (function, optional) – has the same meaning as the ‘key’ argument of list.sort().

class EventStream(iterator, **kwargs)

Bases: Score

Class for generators (generator iterators) that yield events in chronological order. This makes it possible to construct scores of infinite length.

Constructor

Parameters:
  • iterator (iterator of Event) – The iterator from which a sequence of events are generated. The order of events generated must be in ascending order of time (the t attribute values). In addition, the StopIteration object raised at the end of the event sequence must have the ‘value’ attribute with the score duration as its value. This duration may be less than the time of the last event.

  • kwargs – Additional attributes for the EventStream object.


is_consumed()

Returns True if next() has been executed on this stream in the past, or False otherwise.

tostr(timereprfunc=<function std_time_repr>) str

Returns a string representation of the score.

Parameters:

timereprfunc (function) – Function to convert a value of time to a string. By default, it assumes a function that returns a representation rounded to 5 decimal places.

get_duration() Union[int, float, Fraction]

Raises an exception.

count() int

Raises an exception.

tee() EventStream

Returns a new equivalent generator that can be read independently without changing the read state of the original generator.

merged(other, time=0) EventStream

Returns a new EventStream that merges the two event streams self and other.

The duration of the returned EventStream will be the greater of self’s duration or other’s duration plus time.

Parameters:
  • other (EventStream) – Event stream to be merged.

  • time (ticks, optional) – This value is added to the time of the events output by other. At that time, the original events are rewritten without copying the events.

noteoff_inserted() EventStream

Returns a new EventStream with a NoteOffEvent inserted for each NoteEvent in the event stream. The t attribute value of the added NoteOffEvent is set to the sum of the NoteEvent’s t and L attribute values and inserted at the appropriate position in the stream. The attribute ‘noteon’ is added to that NoteOffEvent, whose value is the original NoteEvent. This method is mainly used for the return value of stream() and is useful when some processing needs to be done at the time of note-off.

class RealTimeStream(iterator, starttime, **kwargs)

Bases: EventStream

A subclass of EventStream that represents an event stream from an input device.


queue_event(ev, time=None, devnum=None)
seq(elms=[], **kwargs) EventList

Returns an EventList that is a sequential concatenation of all scores given in elms. For example, seq([note(C4), note(D4), note(E4)]) is equivalent to EvenList() + note(C4) + note(D4) + note(E4). It cannot be used for infinite-length scores.

Parameters:
  • elms (iterable of Score) – scores to concatenate

  • kwargs – additional attributes for the resulting EventList.

Examples

seq(note(i) for i in range(C4, C5)).show()

par(elms=[], **kwargs) EventList

Returns an EventList that merges all the scores given in elms. For example, par([note(C4), note(D4), note(E4)]) is equivalent to note(C4) & note(D4) & note(E4).

Parameters:
  • elms (iterable of Score) – scores to merge

  • kwargs – additional attributes for the resulting EventList.

Examples

par(note(i) for i in range(C4, C5, 2)).show()

genseq(elms=[], **kwargs) EventStream

Returns an EventStream that is a sequential concatenation of all the scores given in elms. elms can be a generator that generates an infinite number of scores.

Parameters:
  • elms (iterable of Score) – Sequence of scores to be combined. Each score must be an EventList or Tracks.

  • kwargs – Additional attributes for the resulting EventStream.

Examples

>>> from itertools import count
>>> genseq(note(C4) for i in count()).play()
>>> genseq(note(C4 + (i % 4)) for i in count()).play()
>>> from random import randrange
>>> genseq(note(randrange(C4, C5)) for i in count()).play()