Squeak
  links to this page:    
View this PageEdit this PageUploads to this PageHistory of this PageTop of the SwikiRecent ChangesSearch the SwikiHelp Guide
Playing chords with Musical Objects
Last updated at 2:02 pm UTC on 25 July 2022
This code on this page works in the Musical objects for Squeak image.

A MusicalNote object

  Mode major c inspect

gives a MusicalNote object.


Combining MusicalNote objects


Concatenation applies. Five chords:
 ((Mode major c | Mode major e | Mode major g),
 (Mode major c | Mode major f | Mode major a),
 (Mode major c | Mode major e | Mode major g),
 (Mode major b | Mode major d | Mode major g),
 (Mode major C | Mode major e | Mode major g)) play

This notation may be simplified by using the #readPhrase method

 Mode major readPhrase: 'c e g,c f a,c e g,d g b,c e g'    **** How is this notation called?

Now since these are all major chords, you could also do

 Mode major readPhrase: 'c:maj, f, c, g, c'

but this one will give you two notes in the upper octave, so to get
exactly the same phrase you would need to transpose and invert two chords:

  Mode major readPhrase: 'c:maj, {/down;inv2/ f}, c, {/down;inv2/ g}, c'

The expression above gives back a MusicalPhrase object

         (Mode major readPhrase: 'c:maj, {/down;inv2/ f}, c, {/down;inv2/ g}, c') class  
             MusicalPhrase

It may be played:
         (Mode major readPhrase: 'c:maj, {/down;inv2/ f}, c, {/down;inv2/ g}, c') play


How do I choose an instrument?


If you output to a MIDI synth where channels are already assigned to
instruments, just set the channel

        (Mode major readPhrase: 'c e g,c f a,c e g,d g b,c e g')
                channel: 3; play

If you want to send a Program Change event to a General MIDI synth, use
the class ProgramChange

        ph := Mode major readPhrase: 'c e g,c f a,c e g,d g b,c e g'.
        ProgramChange xylophon play.
        ph play.

If you want to use a Squeak synthesizer instance, use #playPhrase:

        Clarinet new asSqueakSynthesizer playPhrase: (Mode major readPhrase: 'c e g,c f a,c e g,d g b,c e g')

You can find the available synthesizers by looking for implementors of
 #asSqueakSynthesizer 
notably the full AbstractSound hierarchy, and also the Instrument one.