Programming with Music Blocks

Content:

  1. Chunks
  2. Music Transformation
    1. Step Pitch Block
    2. Sharps and Flats
    3. Adjust-Transposition Block
    4. Dotted Notes
    5. Speeding Up and Slowing Down Notes via Mathematical Operations
    6. Repeating Notes
    7. Swinging Notes and Tied Notes
    8. Set Volume, Crescendo, Staccato, and Slur Blocks
    9. Intervals and Set Relative Volume
    10. Absolute Intervals
    11. Inversion
    12. Backwards
    13. Setting Voice and Keys
    14. Vibrato
  3. Voices
  4. Interactions


1. Chunks


Every time you create a new Action stack, Music Blocks creates a new block specific to, and linked with, that stack. (The new block is found at the top of the Block palette, found on the left edge of the screen.) Clicking on and running this block is the same as clicking on your stack. By default, the new blocks are named chunk, chunk1, chunk2... but you can rename them by editing the labels on the Action blocks.
An Action block contains a sequence of actions that will only be executed when the block is referred to by something else, such as a start block. This is useful in orchestrating more complex programs of music.
A Start Block is a chunk that will automatically be executed once the start button is pressed. This is where most of your programs will begin at. There are many ways to Run a program: you can click on the Run button at the upper-left corner of the screen (the "rabbit") to run the music at a fast speed; click on the Run Slow button (the "turtle") to run it slower; and the Step button (the "snail"), to step through the program one block per button press.
In the example above, the Chunk block is inside of a Start block, which means that when any of the start buttons is pressed, the code inside the Start block (the Chunk block) will be executed. You can add more chunks after this one inside the Start block to execute them sequentially.



You can repeat chunks either by using multiple Chunk blocks or using a Repeat block.



You can also mix and match chunks. Here we play the action block with name "chunk", followed by "chunk1" twice, and then "chunk" again.



A few more chunks and we can make a song. (Can you read the block notation well enough to guess the outcome? Are you familiar with the song we created?)


2. Music Transformation

There are many ways to transform pitch, rhythm, and other sonic qualities.


2.a. Step Pitch Block

The Step Pitch block will move up or down notes in a scale from the last played note. In the example above, Step Pitch blocks are used inside of Repeat blocks to repeat the code 7 times, playing up and down a scale.

Open in Music Blocks


Another way to move up and down notes in a scale is to use the Consonant Step Up and Consonant Step Down blocks. These blocks calculate the number of half-steps to the next note in the current mode. (You can read more about Musical Modes below.)

Note:

The Mouse Pitch Number block returns the pitch number of the most recent note played.


2.b. Sharps and Flats


The Sharp and Flat blocks can be wrapped around Pitch blocks, Note value blocks, or chunks. A sharp will raise the pitch by one half step. A flat will lower by one half step. In the example, on the left, just the Pitch block Mi is lowered by one half step; on the right, both Pitch blocks are raised by one half step.


2.c. Adjust-Transposition Block


The Adjust-transposition block can be used to make larger shifts in pitch in half step units. A positive number shifts the pitch up and a negative number shifts the pitch down. The input must be a whole number. To shift an entire octave, transpose by 12 half-steps up. -12 will shift an octave down.


In the example above, we take the song we programmed previously and raise it by one octave.


2.d. Dotted Notes


You can "dot" notes using the Dot block. A dotted note extends the rhythmic duration of a note by 50%. E.g., a dotted quarter note will play for 3/8 (1/4 + 1/8) of a beat. A dotted eighth note will play for 3/16 (1/8 + 1/16) of a beat.
You can also simply change the note value to mimic a dotted note, for example indicating 3/8 instead of 1/4, for a dotted quarter note.


2.e. Speeding Up and Slowing Down Notes via Mathematical Operations

You can also multiply (or divide) the beat value, which will speed up or slowdown the notes. Multiplying the beat value of an 1/8 note by 2 is the equivalent of playing a 1/16 note. Dividing the beat value of an 1/8 note by '2' is the equivalent of playing a 1/4 note.


2.f. Repeating Notes

There are several ways to repeat notes. The Repeat block will play a sequence of notes multiple times; the Duplicate block will repeat each note in a sequence.
In the example, on the left, the result would be Sol, Re, Sol, Sol, Re, Sol, Sol, Re, Sol, Sol, Re, Sol; on the right the result would be Sol, Sol, Sol, Sol, Re, Re, Re, Re, Sol, Sol, Sol, Sol.


2.g. Swinging Notes and Tied Notes

The Swing block works on pairs of notes (specified by note value), adding some duration (specified by swing value) to the first note and taking the same amount from the second note. Notes that do not match note value are unchanged.
In the example, re5 would be played as a 1/6 note and mi5 would be played as a 1/12 note (1/8 + 1/24 === 1/6 and 1/8 - 1/24 === 1/12). Observe that the total duration of the pair of notes is unchanged.
Tie also works on pairs of notes, combining them into one note. (The notes must be identical in pitch, but can vary in rhythm.)


2.h. Set Volume, Crescendo, Staccato, and Slur Blocks

The Set volume block will change the volume of the notes. The default is 50; the range is 0 (silence) to 100 (full volume).
The Crescendo block will increase (or decrease) the volume of the contained notes by a specified amount for every note played. For example, if you have 3 notes in sequence contained in a Crescendo block with a value of 5, the final note will be at 15% more than the original value for volume.
The Staccato block shortens the length of the actual note—making them tighter bursts—while maintaining the specified rhythmic value of the notes.
The Slur block lengthens the sustain of notes—running longer than the noted duration and blending it into the next note—while maintaining the specified rhythmic value of the notes.


2.i. Intervals and Set Relative Volume

The Interval block calculates a relative interval, e.g., a fifth, and adds the additional pitches to a note's playback. In the figure, we add La to Re and Ti to Mi.
The Set Relative Volume block modifies the clamped note's volume according to the input value of the block in an added (or subtracted when negative) percentage with respect to the original volume.For example,100 would mean doubling the current volume.


2.j. Absolute Intervals

The Augmented block calculates an absolute interval, e.g., an augmented fifth, and adds the additional pitches to a note. Similarly, the Minor block calculates an absolute interval, e.g., a minor third. Other absolute intervals include Perfect, Diminished, and Major.
In the augmented fifth example above, a chord of D5 and A5 are played, followed by a chord of E5 and C5. In the minor third example, which includes a shift of one octave, first a chord of D5 and F5 is played, followed by chord of E5 and G6.


2.k. Inversion

The Invert block will invert a series of notes around a target note. There are two different modes of the Invert block: odd and even, the latter shifts the point of rotation up by a 1/4 step, enabling rotation around a point between two notes.
In the invert (even) example, D4 is inverted aroundG4, resulting in a C5. In the invert (odd) example, D4 is inverted around a point midway between G4 and G♯4 resulting in a C♯5.


2.l. Backwards


The Backward block will play the contained notes in reverse order (retrograde). In the example above, the notes in Chunk are played as Sol, Ti, La, Sol, i.e., from the bottom to the top of the stack.

Open in Music Blocks


Note that all of the blocks inside a Backward block are reverse, so use this feature with caution if you include logic intermixed with notes.


2.m. Setting Voice and Keys


The Set Voice block selects a voice for the synthesizer for any contained blocks, e.g., violin or cello.



The Set Key block will change the key and mode of the mapping between solfege, e.g., Do, Re, Mi, to note names, e.g., C, D, E, when in C Major. Modes include Major and Minor, Chromatic, and a number of more exotic modes, such as Bebop, Geez, Maqam, etc. This block allows users to access "movable Do" within Music Blocks, where the mapping of solfege to particular pitch changes depending on the user's specified tonality.


In the above example, the sequence of drum beats is increased over time.

Open in Music Blocks


2.n. Vibrato


The Vibrato Block adds a rapid variation in pitch to any contained notes. The intensity of the variation ranges from 1 to 100 (cents), e.g. plus or minus up to one half step. The rate argument determines the rate of the variation.


3. Voices

Each Start block runs as a separate voice in Music Blocks. (When you click on the Run button, all of the Start blocks are run concurrently.)


If we put our song into an action...


...we can run it from multiple Start blocks.



It gets more interesting if we shift up and down octaves.



It gets more interesting if we shift up and down octaves.


Open in Music Blocks


A special "drum" version of the Start block is available for laying down a drum track. Any Pitch blocks encounted while starting from a drum will be played as C2 with the default drum sample. In the example above, all of the notes in chunk will be played with a kick drum.


4. Interactions

There are many ways to interactive with Music Blocks, including tracking the mouse position to impact some aspect of the music.


For example, we can launch the phrases (chunks) interactively. When the mouse is in the lower-left quadrant, chunk is played; lower-right quadrant, chunk1; upper-left quadrant, chunk2; and upper-right quadrant, chunk3.


Open in Music Blocks



In the example above, a simple two-key piano is created by associating click events on two different turtles with individual notes. Can you make an 8-key piano?.


Open in Music Blocks



You can also add a bit of randomness to your music. In the top example above, the One-of block is used to randomly assign either Do or Re each time the Note value block is played. In the bottom example above, the One-of block is used to randomly select between chunk1 and chunk2.