Quantization Comparison
Example script (scamp): examples/Notation & engraving/Quantization/quantization.py
Download: quantization.py
Records a loose piano improvisation against a metronome, then plays back the quantized version.
Topics: Notation & engraving › Quantization
from scamp import *
import random
s = Session()
drum = s.new_part("metronome", (0, 116))
piano = s.new_part("piano")
s.start_transcribing()
recording = True
random.seed(4)
def piano_part():
while recording:
if random.random() < 0.5:
piano.play_note(50 + random.random()*20, 0.5, random.random() * 1.5)
else:
piano.play_chord([50 + random.random()*20, 50 + random.random()*20], 0.5, random.random() * 1.5)
s.fork(piano_part)
print("Making Recording...", end="")
for _ in range(8):
drum.play_note(80, 1, 1)
recording = False
performance = s.stop_transcribing()
quantized_performance = performance.quantized(
QuantizationScheme([
MeasureQuantizationScheme.from_time_signature("4/4", max_divisor=5, max_divisor_indigestibility=3)
])
)
print("Done")
while True:
print("Replaying recording with quantization")
wait(1)
quantized_performance.play()
print("Replaying recording without quantization")
wait(1)
performance.play()