复习:鼓和拍子 5 分钟
- Music 积木按拍子来数,不按秒。
- 速度决定一拍有多长。
rest for (1) beats是安静的一拍。
快问快答
速度是 120。一个鼓敲 4 次,每次 0.5 拍。一共要几秒?
看答案
1 秒。四个半拍是 2 拍。速度 120 时,每一拍是半秒。
今天的主题 3 分钟
play note (60) for (0.5) beats:音符有编号set instrument to [(1) Piano v]- 一块叫
sing的自制积木,它会弹一个音符,还会把音符显示出来 - 旋律里的休止
学习目标
上完这节课,你能够:
- 找到一个音符的编号,让它弹几拍。
- 改变一个角色用的乐器。
- 用一块自制积木弹完一整段带休止的旋律。
学一学:音符和乐器 28 分钟
1 · 弹一个音符
- 打开 Music,拖出
play note (60) for (0.25) beats。 - 点写着 60 的白色圆圈。会弹出一个小钢琴。
- 点一个琴键。数字会变成这个键的编号。
- 点一下积木,听听这个音符。
每个琴键都有一个编号。60 是中央 C。往右每一个键,编号就多 1。下面是我们用的白键:
| 字母 | C | D | E | F | G | A | B | C |
|---|---|---|---|---|---|---|---|---|
| 编号 | 60 | 62 | 64 | 65 | 67 | 69 | 71 | 72 |
加 12,你会得到同一个字母,高一个八度。72 是高音 C。
2 · 一个音符有多长?
play note (60) for (1) beats
play note (60) for (0.5) beats
这块积木会等音符结束。所以一块接一块叠起来的音符,会一个接一个地弹,就像鼓那样。
3 · 选一个乐器
set instrument to [(1) Piano v] 会改变这个角色在它后面弹的每个音符的声音。一共有 21 种可以试。
| 编号 | 乐器 |
|---|---|
| 1 | Piano |
| 4 | Guitar |
| 6 | Bass |
| 12 | Flute |
| 16 | Vibraphone |
| 18 | Steel Drum |
怎么用: 点绿旗。别的都不用按。四个音符,弹四遍,用四种乐器。
4 · 一块会唱歌、还会显示音符的积木
输入 60、64 和 67 很容易。能看到它们更好。我们做一块叫 sing 的自制积木。它会弹一个音符,还会在和音符相配的高度显示它的字母。
- 加一个角色,用字母
CDEFGAB当它的造型。角色库里的 Glow 字母正好合适。 - 建一个叫
letters的列表。放进 12 项,从 C 往上,每个键一项:C C D D E F F G G A A B。黑键显示它下面那个白键的字母。 - 做一块叫
sing的积木,有两个数字输入:note和beats。 - 搭出下面的定义。
define sing (note) (beats)
switch costume to (item (((note) mod (12)) + (1)) of [letters v])
set y to ((((note) - (60)) * (6)) - (20))
show
play note (note) for (beats) beats
((note) mod (12)) 找出这个键在它的八度里是第几个,从 0 到 11。每往上一个键,字母就升高 6 步。怎么用: 点绿旗。别的都不用按。字母沿着音阶往上爬,再走下来。
5 · 旋律里的休止
音乐需要空当。要休止,就把字母隐藏起来,用 rest for (0.5) beats。下一次 sing 会再把它显示出来。
基础任务:Studio Theme 24 分钟
你要弹一段为这门课写的短旋律。它有 8 拍长,有一个休止。
第 1 步:歌手
- 按照“学一学”,做出字母角色、letters 列表和 sing 积木。
- 试一试:用一次
sing (67) (1) :: custom,应该显示一个 G。
第 2 步:设置音乐
when flag clickedset tempo to (120)set instrument to [(1) Piano v]
第 3 步:旋律
按照顺序,表里每个音符加一块 sing。除了最后一个,每个音符都是 0.5 拍。
| 小节 | 音符 |
|---|---|
| 1 | C 60 · E 64 · G 67 · E 64 |
| 2 | F 65 · A 69 · G 67 · 休止 |
| 3 | E 64 · G 67 · C 72 · G 67 |
| 4 | F 65 · D 62 · C 60(1 拍) |
第 4 步:休止和结尾
- 表里写着休止的地方:先
hide,再rest for (0.5) beats。 - 最后:
say [Studio Theme!] for (2) seconds。
when flag clicked
set tempo to (120)
set instrument to [(1) Piano v]
sing (60) (0.5) :: custom
sing (64) (0.5) :: custom
sing (67) (0.5) :: custom
sing (64) (0.5) :: custom
sing (65) (0.5) :: custom
sing (69) (0.5) :: custom
sing (67) (0.5) :: custom
hide
rest for (0.5) beats
sing (64) (0.5) :: custom
sing (67) (0.5) :: custom
sing (72) (0.5) :: custom
sing (67) (0.5) :: custom
sing (65) (0.5) :: custom
sing (62) (0.5) :: custom
sing (60) (1) :: custom
say [Studio Theme!] for (2) seconds
怎么用: 点绿旗。别的都不用按。字母弹旋律的时候,眼睛跟着它。
字母一直是 C。
检查列表是不是正好有 12 项,顺序对不对。还要检查造型的名字是不是一个大写字母:是 C,不是 Glow-C。
字母从来不上下移动。
set y to (0) 这一行用的是一个数字,而不是算式。把 note 输入从 define 帽子积木里拖出来,放进算式里。
休止以后字母不见了,再也没回来。
sing 积木里少了 show。只有 sing 积木会把字母带回来。
高一个八度
把旋律弹两遍。第二遍,每个音符都高 12 个键。
- 建一个叫
shift的变量。 - 只改 sing 积木,让它弹
note + shift。 - 两遍的旋律是一样的。你不用再输入第二段旋律。
怎么用: 点绿旗。别的都不用按。旋律弹一遍,然后在更高的地方再弹一遍。
Teacher reveal
define sing (note) (beats)
switch costume to (item ((((note) + (shift)) mod (12)) + (1)) of [letters v])
set y to (((((note) + (shift)) - (60)) * (6)) - (20))
show
play note ((note) + (shift)) for (beats) beats
The script sets shift to 0, plays the tune, sets it to 12, plays it again. Adding 12 keeps every letter the same, because of the mod 12.
两只手
弹钢琴的人用两只手。给旋律加一条低音线。
- 复制字母角色,把它叫作
Bass。它用 6 号乐器 Bass。 - 它弹:C 48 弹 2 拍,F 53 弹 2 拍,C 48 弹 2 拍,G 43 弹 1 拍,C 48 弹 1 拍。
- 舞台先设置速度,然后广播
go。两个角色都在收到go时开始。 - 两个声部一起结束。
怎么用: 点绿旗。别的都不用按。旋律走得快,看低处的字母慢慢地动。
Teacher reveal
when I receive [go v]
set [color v] effect to (120)
set instrument to [(6) Bass v]
sing (48) (2) :: custom
sing (53) (2) :: custom
sing (48) (2) :: custom
sing (43) (1) :: custom
sing (48) (1) :: custom
The bass adds up to 8 beats, the same as the tune — that is why they end together. The colour effect just makes the two letters easy to tell apart.
电脑键盘变钢琴
把电脑的按键变成钢琴的琴键。
- 按键
A S D F G H J K弹 C D E F G A B C,也就是从 60 到 72。 - 每个键把它的音符弹半拍,并显示它的字母。
- 点绿旗的时候,字母告诉玩家要按哪些键。
怎么用: 点绿旗,然后点一下舞台,按 A、S、D、F、G、H、J 或 K 弹一个音符。
Teacher reveal
when [a v] key pressed
say []
sing (60) (0.5) :: custom
when [s v] key pressed
say []
sing (62) (0.5) :: custom
Eight scripts like these, one per key. Pupils can play the Studio Theme from the table by ear — a good test that their numbers are right.
整个乐队
把上周的鼓和舞者带回来,在节拍上面弹旋律。
- 舞台把 bpm 设为 120,然后广播 go。
- 旋律弹两遍。底鼓和军鼓在下面敲 16 拍。
- Ballerina 每一拍都跳一步。
- 所有东西一起停下。
怎么用: 点绿旗。别的都不用按。旋律在节拍上弹两遍,Ballerina 跟着跳舞。
Teacher reveal
when flag clicked
set [bpm v] to (120)
set tempo to (bpm)
broadcast [go v]
when I receive [go v]
repeat (8)
rest for (1) beats
switch costume to [drum-snare-b v]
play drum [(1) Snare Drum v] for (0.25) beats
switch costume to [drum-snare-a v]
rest for (0.75) beats
end
The Stage, then the Snare. The Kick loops 8 times through a hit and a rest, sending beat twice per loop for the dancer, as in Lesson 9. The tune is the Basic stack under when I receive [go v], played twice.
总结 5 分钟
- 每个琴键都有一个编号。60 是中央 C;每往上一个键,就多 1。
- 加 12,就是高一个八度的同一个字母。
play note (60) for (0.5) beats会等音符结束。- 每个角色有自己的乐器。所有角色共用速度。
- sing 自制积木会弹音符,也会把它显示出来,所以你能看到旋律。
- 音符编号
- 一个琴键的编号。60 是中央 C。
- 八度
- 十二个键。同一个字母,更高或更低。
- 乐器
- 角色弹音符时用的声音。
- 旋律
- 曲调,就是你能哼出来的那些音符。
- 低音线
- 在旋律下面弹的又低又慢的音符。
交作业
保存你的旋律。下节课,音符会从脚本里搬出来,放进两个列表。然后一个循环就能弹出你放进去的任何歌。