Examples Playing Melodies

Playing Melodies

Music often makes use of scales, or predetermined pitch sets, to create melodic movement. In western musical traditions pitches are given letter names like ‘A’ and ‘C#.’

There are many different types of scales from all of over the world. You can learn more about different kinds of scales here, and here.

This sketch demonstrates how one might use the ‘D Minor Pentatonic’ scale by providing the frequency values for each note. It also shows how you can provide a scale as an array of note names.

Valid note names are C, C#/Db, D, D#/Eb, E, F, F#/Gb, G, G#/Ab, A, A#/Bb, and B. There is a 10 octave range which you can specify after the note name using values 1-10. For example, ‘middle’ or ‘concert C’ can be denoted by the note name, C4.

Valid frequency values are 0 - 22,000, measured in Hertz (Hz), where 20 - 22,000 represents the range of human hearing (though keep in mind not many people can hear that high 😅). Values lower than 20 are usually used as ‘control values’ for other audio parameters.

Creative Commons BY-NC-SA license badge

Playing Melodies: Edited and maintained by p5.js Contributors and Processing Foundation. Licensed under CC BY-NC-SA 4.0.