É, oficialmente, meu novo hobby. Sonic Pi é uma ferramenta para criação de música ao vivo através de programação Ruby.
É divertidíssimo! Olha só, um exemplo do Sonic Pi tocando um Dó-Ré-Mi-Fá:
# Do-Re-Mi-Fa
use_synth :pluck
melody = [ :C, :D, :E, :F, 0, :F, :F, 0,
:C, :D, :C, :D, 0, :D, :D, 0,
:C, :G, :F, :E, 0, :E, :E, 0,
:C, :D, :E, :F, 0, :F, :F, 0 ]
melody.each do |note|
if note != 0 then
play note
end
sleep 0.3
end
Numa tarde de domingo, escrevi o seguinte programa:
# Cyber Piano Blues #1
# Author: Elcio Ferreira
# https://elcio.com.br/
beat = 0.45
chords = [ chord(:A3, :minor7), chord(:D4, :minor7), chord(:A3, :minor7), chord(:A3, :minor7),
chord(:D4, :minor7), chord(:D4, :minor7), chord(:A3, :minor7), chord(:A3, :minor7),
chord(:E4, :minor7), chord(:D4, :minor7), chord(:A3, :minor7), chord(:E4, :major7),
]
basses = [ :A2, :C3, :E3, :A2, :D3, :F3, :E3, :C3, :E3, :D3, :C3, :E3,
:A2, :C3, :A2, :C3, :D3, :F3, :A2, :C3, :E3, :A2, :E3, :A2 ]
melody = [[ :A4, :B4, :C5, :E5, :B4, :C5, :E5, :Fs5, :A4, :B4, :C5, :E5, :B4, :C5, :E5, :Fs5,
:E5, :B4, :C5, :E5, :B4, :C5, :E5, :C5, :E5, :B4, :C5, :E5, :B4, :C5, :E5, :C5,
:C5, :E5, :G5, :E5, :C5, :A4, :F4, :C5, :C5, :E5, :G5, :E5, :C5, :A4, :F4, :C5,
:A4, :B4, :C5, :E5, :B4, :C5, :E5, :C5, :A4, :B4, :C5, :E5, :B4, :C5, :E5, :C5,
:B4, :G4, :B4, :D5, :F5, :D5, :F5, :D5, :B4, :G4, :B4, :D5, :F5, :D5, :F5, :D5,
:B4, :C5, :E5, :Fs5,:E5, :Gs5,:E5, :D5, :B4, :C5, :E5, :Fs5,:E5, :Gs5,:E5, :D5,
],
[ :B4, :C5, :A4, :E5, :C5, :E5, :B4, :Fs5,
:B4, :C5, :E5, :E5, :C5, :E5, :B4, :C5,
:E5, :G5, :C5, :E5, :A4, :F4, :C5, :C5,
:B4, :C5, :A4, :E5, :C5, :E5, :B4, :C5,
:G4, :B4, :B4, :D5, :D5, :F5, :F5, :D5,
:C5, :E5, :B4, :Fs5,:Gs5,:E5, :E5, :D5,
]
]
live_loop :melody do
use_synth :piano
idx = 0
2.times do |melodyidx|
4.times do |time|
if time == 1 or time == 3 then
melody[melodyidx].each do |tune|
play tune
sleep beat * (idx % 2 + 0.5)
idx+=1
end
elsif time == 2 then
melody[melodyidx].each do |tune|
2.times do
play tune
if idx % 2 == 1 then
sleep beat * 1
play tune, pan: 0.5
end
sleep beat * 0.5
play tune, pan: -0.5
idx+=1
end
end
else
play :A5
play_chord chord(:A4, :major7)
play_chord chord(:A5, :major7)
sleep beat * 6 * 8
melody[1].each do |tune|
play tune
sleep beat/2
play tune
sleep beat/2
end
end
end
end
end
live_loop :chimes do
sleep 12 * 4 * 4 * beat
(12 * 4 * 4).times do
sample :drum_cymbal_pedal
sleep beat
end
end
counter = 0
live_loop :drums do
if counter % 4 == 0 and counter > 23 and counter < 48 then
sample :drum_cymbal_open
end
sleep beat
sample :drum_tom_hi_soft, pan: 0.4
sleep beat * 1.5
if counter > 23 then
sample :drum_tom_hi_soft, pan: 0.4
end
sleep beat / 2
if counter > 47 then
sample :drum_tom_hi_soft, pan: 0.4
end
sleep beat
sample :drum_snare_soft
if counter % 24 == 0 then
sample :drum_cymbal_closed, pan: 0.4
end
counter += 1
if counter > 71 then
counter = 0
end
end
live_loop :progression_chords do
use_synth :piano
4.times do |variation|
if variation > 0 then
chords.each do |thechord|
sleep beat
play thechord, pan: -0.4
sleep beat * 4
play thechord, pan: -0.4
sleep beat * 3
end
else
chords.each do |thechord|
sleep beat/2
play thechord, pan: -0.4
sleep beat * 2
play thechord, pan: -0.2
sleep beat * 1.5
sleep beat/2
play thechord, pan: 0
sleep beat * 2
play thechord, pan: 0.2
sleep beat * 1.5
end
end
end
end
live_loop :basses do
use_synth :piano
3.times do
basses.each do |bass|
2.times do
play bass, amp: 1, pan: -0.7
sleep beat/2
play bass, amp: 1, pan: -0.7
sleep beat * 3.5
end
end
end
4.times do
basses.each do |bass|
2.times do
play bass, amp: 1, pan: -0.7
sleep beat/2
play bass, amp: 1, pan: -0.7
sleep beat * 2.5
play bass, amp: 1, pan: -0.7
sleep beat
end
end
end
end
live_loop :progression_melody do
use_synth :piano
5.times do |round|
chords.each do |thechord|
if round == 0 then
play_pattern_timed thechord, beat/2, amp: 1, pan: 0.7
sleep beat * 2
play_pattern_timed thechord, beat/2, amp: 1, pan: 0.7
sleep beat * 2
elsif round == 1 then
play_pattern_timed thechord, beat, amp: 0.6, pan: 0.7
play_pattern_timed thechord, beat/2, amp: 0.6, pan: 0.7
sleep beat * 2
elsif round == 2 then
play_pattern_timed thechord, beat, amp: 0.6, pan: 0.7
play_pattern_timed thechord, beat, amp: 0.6, pan: 0.7
else
play_pattern_timed thechord, beat/2, amp: 0.6, pan: 0.7
play_pattern_timed thechord, beat/2, amp: 0.6, pan: 0.7
sleep beat * 4
end
end
end
end
Se você não estiver afim de instalar o Sonic Pi para testar, e quiser saber como ficou meu blues:
Recomendo! Instala, testa, é divertido!