concept harmony in category chuck

This is an excerpt from Manning's book Programming for Musicians and Digital Artists: Creating music with ChucK.
Once you’ve swept the pitch upward, you begin playing your melody and harmony (listing 1.20c) by turning on the sine oscillator
, setting the frequency to 110.0
, and playing two notes on the triangle oscillator using a for loop
. To play these notes, you turn on the triangle oscillator (set gain to a non-zero value)
, wait for a time
, and then turn it off
and wait again
. This plays the first “Twinkle” of the song.
To wrap up this chapter, we want to give you a more fleshed-out example of how to make a whole composition using all the things we’ve talked about so far. You’ll make a much longer version of “Twinkle,” using two MIDI note arrays for melody and harmony. You’ll use a float array to hold the note durations. You’ll also use an array of strings to print out the words as the song plays! And you’ll pan the melody randomly, using the Math library. So let’s get to it!
In listing 3.8, you first declare and add panning to your melody oscillator using the Pan2 object
. Next, you make another oscillator for harmony and connect it to the dac
. As you’ve learned, the dac takes care of mixing these sources together automatically. Then you make some gain variables to use for turning your notes on and off
.
Next, you have the same melody array that you’ve been working with
, and you make another array to control another oscillator for harmony
. You make an array of floats that you’ll use for durations
and yet another array of type string that holds your words
.
, setting the frequency to
, and playing two notes on the triangle oscillator using a
. To play these notes, you turn on the triangle oscillator (set gain to a non-zero value)
, wait for a time
, and then turn it off
and wait again
. This plays the first “Twinkle” of the song.
. Next, you make another oscillator for harmony and connect it to the
. As you’ve learned, the
.
, and you make another array to control another oscillator for harmony
. You make an array of floats that you’ll use for durations
and yet another array of type
.