-
Notifications
You must be signed in to change notification settings - Fork 3
Tutorial
Matthew R. Scott edited this page Aug 28, 2017
·
1 revision
...if you have it installed successfully already, try this from a Python console:
# Import the Project class, and the SunVox modules namespace:
from rv.api import Project, m
# Create a new Project instance
p = Project()
# Create and attach a new Generator module, with controller values and X/Y position
g = p.new_module(m.Generator, waveform='square', duty_cycle=256, x=p.output.x - 128, y=p.output.y)
# Connect the generator to the project's output module
g >> p.output
# Write the project to a file
with open('myproject.sunvox', 'wb') as f: p.write_to(f)
You should now be able to open myproject.sunvox inside SunVox itself, and see the generator configured and hooked up to output.
Note that the separate graphviz tool is required for doing automatic module layout. This is why we set the x/y position of the module manually in the above example. If graphviz is available, you can also call the "layout()" method of a project.
So I created a pattern, added a name and attached that pattern to the project, so far so good, but now I'd like to insert some notes in the pattern.
Here is an extension of the example we've been working with:
# Import the Project class, and the SunVox modules namespace:
from rv.api import Project, m, Pattern, NOTECMD
# Create a new Project instance
p = Project()
# Create and attach a new Generator module, with controller values and X/Y position
g = p.new_module(m.Generator, waveform='square', duty_cycle=256, x=p.output.x - 128, y=p.output.y)
# Connect the generator to the project's output module
g >> p.output
# Create a small pattern to emit a note every quarter note.
pat1 = Pattern(tracks=1, lines=4)
# Attach the pattern to the project.
p += pat1
# The 'data' property of a pattern is a 2-dimensional (row, track) array of Note objects.
# IMPORTANT: When setting "vel" and "module" of a Note, add +1 to it.
# This is because "0" is used by SunVox to mean "empty" for these attributes.
# Below are two different ways you can change notes in a pattern.
# Trigger the note at line 1, by modifying existing Note:
on = pat1.data[0][0]
on.note = NOTECMD.C4
on.vel = 128 + 1
on.module = g.index + 1
# Note off at line 2, by replacing with a different Note:
off = Note(note=NOTECMD.NOTE_OFF)
pat1.data[1][0] = off
# Write the project to a file
with open('myproject.sunvox', 'wb') as f:
p.write_to(f)