quantize

maelzel.scoring.quant.quantize(parts, struct=None, quantizationProfile=None, enharmonicOptions=None)[source]

Quantize and render unquantized notations organized into parts

Parameters:
  • parts (list[UnquantizedPart]) – a list of Parts, where each part represents a series of non-overlapping events which have not yet been quantized

  • struct (Optional[ScoreStruct]) – the structure of the resulting score. To create a simple score with an anitial time signature and tempo, use something like ScoreStructure.fromTimesig((4, 4), quarterTempo=52). If not given, defaults to a 4/4 score with tempo 60

  • quantizationProfile (Optional[QuantizationProfile]) – The quantization preset determines how events are quantized, which divisions of the beat are possible, how the best division is weighted and selected, etc. Not all options in a preset are supported by all backends (for example, the musicxml backend does not support nested tuplets). See quant.presetQuantizationProfiles, which is a dict with some predefined profiles

  • enharmonicOptions (Optional[EnharmonicOptions]) – if given, these are used to find the most suitable enharmonic representation

Return type:

QuantizedScore

Returns:

a QuantizedScore

Example

>>> from maelzel import scoring
>>> from maelzel.scorestruct import ScoreStruct
>>> scorestruct = ScoreStruct('''
... 4/4, 80
... 3/4
... 3/4
... 5/8, 60
... 7/8
... 4/4
... ...
... ''')
>>> scorestruct
=========== ======= ====================  =========
Meas. Index     Timesig Tempo (quarter note)    Label
=========== ======= ====================  =========
0           4/4     80
1           3/4
2           3/4
3           5/8     60
4           7/8
5           4/4
=========== ======= ====================  =========

>>> notes = [
... (0.5, "4C"),
... (1.5, "4C+"),
... (1/3, "4D-25"),
... (2/3, "4E+25"),
... (2+1/5, "4F#+"),
... (5.8, "4A-10")
... ]
>>> notations = [scoring.Notation(duration=dur, pitches=[p]) for dur, p in notes]
>>> part = scoring.UnquantizedPart(notations)
>>> qscore = scoring.quant.quantize([part], struct=scorestruct)
>>> qscore.parts[0].dump()

Timesig: 4/4 (quarter=80)
  Ratio (1, 1)
    «0.000:0.500 4C»
    «0.500:2.000 4C+»
  Ratio (3, 2)
    «2.000:2.333 3/2 4D-25»
    «2.333:3.000 3/2 4E+25»
  Ratio (1, 1)
    «3.000:4.000 tiedNext 4F#+»
Timesig: 3/4 (quarter=80)
  Ratio (1, 1)
    «0.000:1.000 tiedPrev tiedNext 4F#+»
  Ratio (5, 4)
    «1.000:1.200 5/4 tiedPrev 4F#+»
    «1.200:2.000 5/4 tiedNext 4A-10»
  Ratio (1, 1)
    «2.000:3.000 tiedPrev tiedNext 4A-10»
Timesig: 3/4 (quarter=80)
  Ratio (1, 1)
    «0.000:3.000 tiedPrev tiedNext 4A-10»
Timesig: 5/8 (quarter=60)
  Ratio (1, 1)
    «0.000:1.000 tiedPrev 4A-10»
  Ratio (1, 1)
    «1.000:2.500 rest»

>>> renderopts = scoring.render.RenderOptions(showCents=True)
>>> renderer = scoring.render.renderQuantizedScore(qscore, options=renderopts,
...                                                backend='lilypond')
>>> renderer.write("~/tmp/foo.pdf")
../_images/quantize-example.png