制作一首歌曲

主声道

现在就来搞定旋律吧。为了避免一遍遍重复playsleep指令,我们有个简化指令:play_pattern_timed

如果你之前写成了:

play :c2
sleep 0.5
play :d2
sleep 0.25
play :e2
sleep 0.75
play :d2
sleep 0.5

那现在可以写成:

play_pattern_timed [:c2, :d2, :e2, :d2], [0.5, 0.25, 0.75, 0.5]

第一个列表[:c2, :d2, :e2, :d2]是一组音符,第二个列表[0.5, 0.25, 0.75, 0.5]是音符间的修止时间。

旋律

为你的歌曲创建一个名为:melodylive_loop图方便的话使用play_pattern_timedfunction功能来编写旋律。需要的话可以使用钢琴。 以下是例子:

live_loop :melody do
  play_pattern_timed [:c4, :e4, :f4, :g4, :f4, :e4, :f4, :g4, :f4, :e4, :f4], [0.25, 0.25, 0.25, 1.5, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25]
end

现在整首曲子听起来是这样的

use_bpm 120

live_loop :drums do
  sample :drum_heavy_kick
  sleep 1
  sample :drum_snare_hard
  sleep 1
  sample :drum_heavy_kick
  sleep 1
  sample :drum_snare_hard
  sleep 1
end

live_loop :hihat do
  sample :drum_cymbal_closed
  sleep 0.25
  sample :drum_cymbal_pedal
  sleep 1
end

live_loop :bass do
  use_synth :fm
  play :c2, attack: 0, release: 0.25
  sleep 0.25
  play :c2, attack: 0, release: 0.3
  sleep 2
  play :e2
  sleep 0.75
  play :f2
  sleep 1
end

live_loop :melody do
  play_pattern_timed [:c4, :e4, :f4, :g4, :f4, :e4, :f4, :g4, :f4, :e4, :f4], [0.25, 0.25, 0.25, 1.5, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25], attack: 0, release: 0.2
end

哈,真是个好的开端!快去试试不同旋律、合成以及attack:release: 的数值。