Before you start with D♭, please keep in mind that all tutorials assume that you know general programming concepts and basic C# syntax. Only additions and changes with respect to D♭ will be discussed.
A D♭ program consists of a set of functions, we will look at them in detail in the next tutorial.
Each program must contain a single function Main
that is the entry point to the program.
The Main
function creates the first default entity which is also called the axiom.
Even if you take just an empty Main
function, the axiom entity that was created in
the background will sound according to its default parameters.
It will be a C4
played by a piano for 1s
.
Try it out here. Press the left-most button to execute the program, then press play to hear the result.
Each entity has some attributes. The most distinctive feature of D♭ is how entites and their attributes are accessed. For now we have just a single entity in the working set, but in later tutorials there will be a lot of them. They are internally kept in a working set. D♭ always works with the whole set at once, processing all of its entites at once (notice the similarity to L-Systems).
In order to read or write attributes of the entities in the current working set,
use the @
prefix. It denotes a batch operation that get applied to all
entities of the working set at once. D♭ overrides its original C# meaning for this purpose.
The previous snippets use velocity
and octave
which are native
attributes available for each entity. Note that the musical meaning of
velocity
is how hard the instrument is hit. Achieving a higher
velocity requires more power, which implies not only a louder tone, but
also its quality changes accross different velocities. Please remember that
velocity
is associated with dynamics, not with tempo.
You can add custom attributes to the entities anytime. They can be of any type and D♭ should be able handle them properly in the background without explicit typing. With just a single entity, it is impossible to come up with a meaningful custom attribute use case. So the following example is just a teaser for what will be frequently used in later tutorials and examples.
Custom attributes are globally compiled into the common entity class.
Once a type is associated with an attribute name, like in the above example
it was string composer
, it is not possible to use a different type for
the attribute elsewhere in the program. The following example illustrates a
situation that will fail even when a type collision during execution is not possible.
The compiler will complain that it can not assign an int
to a string
for composer
.
This was the most boring tutorial. It is great that you managed to read so far. In the next one we will learn how to divide the axiom entity into several entities so that we can actually start doing music.