Clip

class maelzel.core.clip.Clip(source, dur=None, pitch=None, amp=1.0, offset=None, startsecs=0.0, endsecs=0.0, channel=None, loop=False, speed=Fraction(1, 1), label='', dynamic='', tied=False, noteheadShape=None)[source]

Bases: MEvent

A Clip represent an audio sample in time

It is possible to select a fragment from the source

Parameters:
  • source (str | Sample | tuple[ndarray, int]) – the source of the clip (a filename, audiosample, samples as numpy array)

  • dur (Union[float, Rational, Fraction, None]) – the duration of the clip, in quarternotes. If not given, the duration will be the duration of the source. If loop==True, then the duration needs to be given

  • pitch (Union[int, float, str, None]) – the pitch representation of this clip. It has no influence in the playback itself, it is only for notation purposes

  • amp (float) – the playback gain

  • offset (Union[float, Rational, Fraction, None]) – the time offset of this clip. Like in a Note, if not given, the start time depends on the context (previous events) where this clip is evaluated

  • startsecs (float | Fraction) – selection start time (in seconds)

  • endsecs (float | Fraction) – selection end time (in seconds). If 0., play until the end of the source

  • loop – if True, playback of this Clip should be looped

  • label (str) – a label str to identify this clip

  • speed (Fraction | float) – playback speed of the clip

  • dynamic (str) – allows to attach a dynamic expression to this Clip. This is only for notation purposes, it does not modify playback

  • tied – this clip should be tied to the next one. This is only valid if the clips share the same source (same soundfile or samples) and allows to automate parameters such as playback speed or amplitude.

  • noteheadShape (Optional[str]) – the notehead shape to use for notation, one of ‘normal’, ‘cross’, ‘harmonic’, ‘triangle’, ‘xcircle’, ‘rhombus’, ‘square’, ‘rectangle’, ‘slash’, ‘cluster’. (see config[‘show.clipNoteheadShape’])

Attributes Summary

amp

An amplitude (gain) applied to this clip

channel

Which channel to load from soundfile.

dur

The duration of this Clip, in quarter notes

dynamic

A dynamic expression attached to the score representation of this clip

loop

Should this clip loop?

name

A string representing this event

noteheadShape

The shape to use as notehead

numChannels

The number of channels of this Clip

pitch

The pitch representation of this clip.

selectionEndSecs

The end time of the selected fragment of the source media (in seconds)

selectionStartSecs

The start time of the selected fragment of the source media (in seconds)

soundfile

The soundfile holding the audio data (if any)

source

The source of this clip

sourceDurSecs

The duration in seconds of the source of this Clip

speed

The playback speed

sr

Methods Summary

asSample()

Return a maelzel.snd.audiosample.Sample with the audio data of this Clip

chordAt(time[, resolution, channel, mindb, ...])

Analyze the spectrum at the given time and extract the most relevant partials

copy()

Returns a copy of this object

durSecs()

Returns the duration in seconds according to the active score

isRest()

Is this a rest?

pitchRange()

The pitch range of this object, if applicable

scoringEvents([groupid, config, parentOffset])

Returns its notated form as scoring.Notations

Attributes Documentation

amp: float

An amplitude (gain) applied to this clip

channel

Which channel to load from soundfile. If None, all channels are loaded

dur

The duration of this Clip, in quarter notes

dynamic: str

A dynamic expression attached to the score representation of this clip

loop

Should this clip loop?

name
noteheadShape

The shape to use as notehead

numChannels

The number of channels of this Clip

pitch: float

The pitch representation of this clip. This is used for notation purposes, it has no influence on the playback of this clip

selectionEndSecs: F

The end time of the selected fragment of the source media (in seconds)

selectionStartSecs: F

The start time of the selected fragment of the source media (in seconds)

soundfile

The soundfile holding the audio data (if any)

source: str | audiosample.Sample

The source of this clip

sourceDurSecs: F

The duration in seconds of the source of this Clip

speed

The playback speed

sr

Methods Documentation

asSample()[source]

Return a maelzel.snd.audiosample.Sample with the audio data of this Clip

Return type:

Sample

Returns:

a Sample with the audio data of this Clip. The returned Sample is read-only.

Example

TODO

chordAt(time, resolution=50, channel=0, mindb=-90, dur=None, maxcount=0, ampfactor=1.0, maxfreq=20000, minfreq=None)[source]

Analyze the spectrum at the given time and extract the most relevant partials

A small fragment of the clip is analyzed and the most relevant sinusoidal components at the given time are extracted and returned in the form of a chord

See

Parameters:
  • time (Union[float, Rational, Fraction]) – the time to analyze. This is a time within the clip, in seconds

  • resolution (float) – the resolution of the analysis, in Hz

  • channel – which channel to analyze, for multichannel clips

  • mindb – the min. amplitude (in dB) for a component to be included

  • dur (Union[float, Rational, Fraction, None]) – the duration of the returned chord

  • maxcount – the max. number of components in the chord

  • ampfactor – an amplitude factor to apply to each component.

  • maxfreq – the max. frequency for a component to be included

  • minfreq (Optional[int]) – the min. frequency for a component to be included

Return type:

Chord | None

Returns:

a Chord representing the spectrum of the clip at the given time, or None if no components were found following the given restraints. None if no components found which would satisfy the given conditions at the given time

copy()[source]

Returns a copy of this object

Return type:

Clip

durSecs()[source]

Returns the duration in seconds according to the active score

Return type:

Fraction

Returns:

the duration of self in seconds

isRest()[source]

Is this a rest?

Return type:

bool

pitchRange()[source]

The pitch range of this object, if applicable

This is useful in order to assign this object to a proper Voice when distributing objects among voices

Return type:

tuple[float, float]

Returns:

either None or a tuple (lowest pitch, highest pitch)

scoringEvents(groupid='', config=None, parentOffset=None)[source]

Returns its notated form as scoring.Notations

These can then be converted into notation via some of the available backends: musicxml or lilypond

Parameters:
  • groupid – passed by an object higher in the hierarchy to mark this objects as belonging to a group

  • config (Optional[CoreConfig]) – a configuration to customize rendering

  • parentOffset (Optional[Fraction]) – if given this should be the absolute offset of this object’s parent

Return type:

list[Notation]

Returns:

A list of scoring.Notation which best represent this object as notation