pxt-calliope/docs/reference/music/making-melodies.md
Amerlander 918af4f3ac
Bump V3.0.22 (#110)
* change simulator svg

* change radio image

* Remove google fonts cdn

* change color of 'advanced' button

* font fix

* font fix 2

* display fix

* change fullsceen simulator bg

* Continuous servo

* handle continuous state

* adding shims

* update rendering for continuous servos

* fixing sim

* fix sig

* typo

* fix sim

* bump pxt

* bump pxt

* rerun travis

* Input blocks revision

- add Button and Pin event types
- merge onPinPressed & onPinReleased in new onPinEvent function
- create new onButtonEvent function

* update input blocks in docs and tests

* remove device_pin_release block

* Hide DAL.x behind Enum

* bring back deprecated blocks, but hide them

* shims and locales files

* fix input.input. typing

* remove buildpr

* bump V3

* update simulator aspect ratio

* add Loudness Block

* revoke loudness block

* Adds soundLevel

To be replaced by pxt-common-packages when DAL is updated.

* Remove P0 & P3 from AnalogPin

Co-authored-by: Juri <gitkraken@juriwolf.de>
2020-09-08 02:04:25 -07:00

3.8 KiB

Making melodies

Composing some sound, or maybe some music, is done by putting tones to together, one after another. A melody is a sequence of these tones each played, for some short amount of time, one after the other until all notes have played.

Musical notes

A note is a tone that is recognized as part of music. A note has a name like 'C'. A note is played for an amount of time called its duration.

On your @boardname@, a note is played on the speaker by sending a signal to it with a certain frequency called Hertz. Frequency is how fast something vibrates during one second. If you ring a bell that was made to play an 'A' note, the bell will vibrate at 440 Hertz (440 times per second). So, notes are just certain frequencies that have special names.

~ hint

Listen to music with headphones

Watch this video to see how speakers and headphones make sound when connected to your @boardname@.

https://www.youtube.com/watch?v=cxfPNc4Wefo

~

In history, music came from tones that seemed nice to hear. The tones were played on wood, strings, metal, and skins. These tones were given names and they became what we know today as musical notes. Notes were named so we could write them down and remember how to play them again later.

How are notes named?

Basic notes have names that use one of the first nine letters of the alphabet. They are:

|A|, |B|, |C|, |D|, |E|, |F|, |G|

There are other notes named like the basic notes but have extra parts to the name called sharp and flat. These other notes are just a bit different from the basic notes and have frequencies a little higher or lower than the basic note. This makes music a little more complicated but much more interesting!

Some of these other notes look like:

|C#|, |Eb|

When a small amount music or even a song is written down it is called sheet music.

~ hint

Note names in different languages

Many languages other than English use different names for some or all of the musical notes. MakeCode uses English for names in code.

~

Sounds and music in code

Of course, we can't use written music in our code. We can make music another way. The way to do it is to put names of notes in strings. We make our notes using letters, symbols, and numbers. The notes of a melody are put together in an array like:

let melody = ['E3:3', 'R:1', 'D#:3', 'R:1', 'D:4', 'R:1', 'C#:8']

In JavaScript code, it looks like this:

let melody = ['E3:3', 'R:1', 'D#:3', 'R:1', 'D:4', 'R:1', 'C#:8']

What you see here is not some alien language but a bunch of notes with their duration. The form of a single note is note : duration or 'C:2'. This means play the 'C' note for 2 beats of time. The notes are placed one after the other, in an array, with a comma between them, like 'B:2', 'C#:6'. If you want a note to play for 4 beats, you don't need to use any duration number (a note with 4 beats is called a whole note). Just say something like 'E' with no colon (leave out the ':') and no duration number.

You might notice that the sound string has an 'R:1' in it. The 'R` means rest and to rest for one beat. A rest is a pause, or a time of silence, in the sound.

~ hint

Duration

The amount of time a note is played (duration) is measured as beats. The standard number beats per minute (bpm) in music is 120 bpm which is one-half of a second of time. A whole note lasts for 4 beats and a quarter note takes just one beat.

~

Example

Compose the first few notes of Beethoven's 5th symphony.

let beet5 = ['G:1', 'G:1', 'G:1', 'Eb', 'F:1', 'F:1', 'F:1', 'D']

See also

begin melody

Tempo