An Introduction to Collective Algorithmic Music Composition

Melody

A melody can simply be described as a sequence of notes. Melodies are made up of pitches, durations and intensities (volume).

In MIDI we can use numbers and map them to specific notes. Scripthica allows to use note symbols which makes it easier to compose as it may be easier for some musicians to work with notes rather than numbers. We can then use predifined functions to convert the notes to numbers and create MIDI events.

Jesusita en Chihuahua

First, lets set the tempo to 150 and use pizzicato strings as our instrument which is defined by number 45 according to the MIDI standard.

;; jesusita en chihuahua

(set-tempo '((0 0 150)))
(set-instruments '((1 0 45)))

We can now define a list for the pitches and another list for the durations of each corresponding note.

(define violin-pitches '(R B4 C5 E5 D5 C#5 D5 G5 D5 C#5 D5 F#5 E5 D#5 E5 A5 G5 E5 G5 F#5 D5 F#5 C5 B4 C5 E5 D5 C#5 C5 B4 C5 E5 D5 C#5 D5 B5 G5 F#5 G5 A5 E5 E5 F#5 A5 G5 F#5 E5 G5 D5 C#5 D5 E5 G5 F#5 A5 (B4 G5) r (B4 G5)))

(define violin-lengths '(H Q E E Q E E E E E E E E E E Q E E Q E E E E E E E E E E Q E E Q. S S E E E E E Q S S E E E E E E E E E E E E (E E) E (Q Q)))

Finally, lets convert the symbols to numbers by using the pitches->numbers and lengths->numbers procedures and then create the events so we can save to a MIDI file.

(define v1p (pitches->numbers violin-pitches))
(define v1l (lengths->numbers violin-lengths))
(define v1v (create-constant-velocities v1p 96))
(define violin (create-events 0 v1p v1l v1v 1))

(save-midi violin)

Our result should lok something like this depending on the sheemusic editor that your using.

The complete code:

;; jesusita en chihuahua

(set-tempo '((0 0 150)))
(set-instruments '((1 0 45)))

(define violin-pitches '(R B4 C5 E5 D5 C#5 D5 G5 D5 C#5 D5 F#5 E5 D#5 E5 A5 G5 E5 G5 F#5 D5 F#5 C5 B4 C5 E5 D5 C#5 C5 B4 C5 E5 D5 C#5 D5 B5 G5 F#5 G5 A5 E5 E5 F#5 A5 G5 F#5 E5 G5 D5 C#5 D5 E5 G5 F#5 A5 (B4 G5) r (B4 G5)))

(define violin-lengths '(H Q E E Q E E E E E E E E E E Q E E Q E E E E E E E E E E Q E E Q. S S E E E E E Q S S E E E E E E E E E E E E (E E) E (Q Q)))

(define v1p (pitches->numbers violin-pitches))
(define v1l (lengths->numbers violin-lengths))
(define v1v (create-constant-velocities v1p 96))
(define violin (create-events 0 v1p v1l v1v 1))

(save-midi violin)