More examples and some minor fixes

This commit is contained in:
2023-06-29 00:03:45 +03:00
parent 7d6ba407bd
commit 9bd4ec0ff0
14 changed files with 336 additions and 66 deletions

View File

@ -1,3 +1,4 @@
"""Example of using ziffers with Csound score."""
try:
import ctcsound
except (ImportError,TypeError):
@ -5,30 +6,35 @@ except (ImportError,TypeError):
from ziffers import *
# Csound numeric score is very versatile so it is hard to do generic tranformer
# See http://www.csounds.com/manual/html/ScoreTop.html and http://www.csounds.com/manual/html/ScoreStatements.html
# There is a simple converter implemented that uses format:
# i {instrument} {start time} {duration} {amplitude} {frequency}
# See ziffers_to_csound_score in ziffers/converters.py
if(csound_imported):
# Parse ziffers notation
parsed = zparse("w 0 1 q 0 1 2 3 r e 5 3 9 2 q r 0")
# Parse ziffers notation, scale in SCALA format
parsed = zparse("w 0 024 q 0 1 2 346 r e (5 3 9 2 -605)+(0 -3 6) q 0h24e67s9^s1^e3^5^7", key="D4", scale="100. 200. 250. 400. 560.")
# Convert to csound score
score = to_csound_score(parsed, 180, 1500, "Meep")
# Outputs: i {instrument} {start time} {duration} {amplitude} {pitch}
score = ziffers_to_csound_score(parsed, 180, 1500, "FooBar") # 180 bpm, 1500 amplitude, FooBar instrument
print("Generated score:")
print(score)
# Define FooBar Csound instrument
orc = """
instr Meep
instr FooBar
out(linen(oscili(p4,p5),0.1,p3,0.1))
endin
"""
# Run score with Csound
c = ctcsound.Csound()
c.setOption("-odac") # Using SetOption() to configure Csound
c.setOption("-odac")
c.compileOrc(orc)
c.readScore(score)
c.start()
c.perform()
c.stop()