Advertisement
KRITSADA

Sonic Pi Mario

Nov 21st, 2016
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. comment do
  2.   # transcribed from the MML notation here: http://www.mmlshare.com/tracks/view/403
  3.   #
  4.   # Sonic Pi currently has a size limit of about 9k which is a known issue (#102).
  5.   # I've kept the comments up here to get around that as comment blocks don't get
  6.   # sent to the interpreter. Some of the layout here is an exercise in reducing bytes.
  7.   # I'm using Ruby's stabby lambda syntax ( -> { ... } ) in case you want to google it :)
  8.   #
  9.   # THIS HAS ONLY BEEN TESTED ON A MAC - on an RaspberryPi you might want to change it to
  10.   # use_bpm 60
  11.   #
  12.   # Regarding the choice of an FM synth for drums:
  13.   # You could use a noise synth here, but I think the NES sound
  14.   # chip would have used something like this FM as the character
  15.   # of the noise would change with different notes which I'm making
  16.  # use of in drum_pattern_b
  17. end
  18. use_debug false # help RPi performance
  19. use_bpm 100
  20. use_synth :pulse
  21. use_synth_defaults release: 0.2, mod_rate: 5, amp: 0.6
  22. define :structure do |i,a,b,c,d|
  23.  1.times { i.call }
  24.  loop do
  25.    2.times { a.call }
  26.    2.times { b.call }
  27.    1.times { c.call }
  28.    2.times { a.call }
  29.    2.times { d.call }
  30.    1.times { c.call }
  31.    1.times { d.call }
  32.  end
  33. end
  34.  
  35. in_thread do
  36.  intro = -> { play_pattern_timed([:e5,:e5,nil,:e5,nil,:c5,:e5,nil,
  37.                                   :g5,nil,nil,nil,nil,nil,nil,nil], [0.25]) }
  38.  theme_a = -> {
  39.    play_pattern_timed([:c5,nil,nil,:g4,nil,nil,:e4,nil,
  40.                        nil,:a4,nil,:b4,nil,:Bb4,:a4,nil], [0.25])
  41.    play_pattern_timed([:g4,:e5,:g5], [1/3.0]) # minim triplets
  42.    play_pattern_timed([:a5,nil,:f5,:g5,
  43.                        nil,:e5,nil,:c5,
  44.                        :d5,:b4,nil,nil], [0.25]) }
  45.  theme_b = -> {
  46.    play_pattern_timed([nil,nil,:g5,:fs5,:f5,:ds5,nil,:e5,
  47.                        nil,:gs4,:a4,:c5,nil,:a4,:c5,:d5,
  48.                        nil,nil,:g5,:fs5,:f5,:ds5,nil,:e5,
  49.                        nil,:c6,nil,:c6,:c6,nil,nil,nil,
  50.                        nil,nil,:g5,:fs5,:f5,:ds5,nil,:e5,
  51.                        nil,:gs4,:a4,:c5,nil,:a4,:c5,:d5,
  52.                        nil,nil,:ds5,nil,nil,:d5,nil,nil,
  53.                        :c5,nil,nil,nil,nil,nil,nil,nil], [0.25]) }
  54.  theme_c = -> {
  55.    play_pattern_timed([:c5,:c5,nil,:c5,nil,:c5,:d5,nil,
  56.                        :e5,:c5,nil,:a4,:g4,nil,nil,nil,
  57.                        :c5,:c5,nil,:c5,nil,:c5,:d5,:e5,
  58.                        nil,nil,nil,nil,nil,nil,nil,nil,
  59.                        :c5,:c5,nil,:c5,nil,:c5,:d5,nil,
  60.                        :e5,:c5,nil,:a4,:g4,nil,nil,nil,
  61.                        :e5,:e5,nil,:e5,nil,:c5,:e5,nil,
  62.                        :g5,nil,nil,nil,nil,nil,nil,nil], [0.25]) }
  63.  theme_d = -> {
  64.    play_pattern_timed([:e5,:c5,nil,:g4,nil,nil,:gs4,nil,
  65.                        :a4,:f5,nil,:f5,:a4,nil,nil,nil], [0.25])
  66.    play_pattern_timed([:b4,:a5,:a5,
  67.                        :a5,:g5,:f5], [1/3.0])
  68.    play_pattern_timed([:e5,:c5,nil,:a4,:g4,nil,nil,nil], [0.25])
  69.    play_pattern_timed([:e5,:c5,nil,:g4,nil,nil,:gs4,nil,
  70.                        :a4,:f5,nil,:f5,:a4,nil,nil,nil,
  71.                        :b4,:f5,nil,:f5], [0.25])
  72.    play_pattern_timed([:f5,:e5,:d5], [1/3.0])
  73.  play_pattern_timed([:g5,:e5,nil,:e5,:c5,nil,nil,nil], [0.25]) }
  74.  
  75.  structure(intro, theme_a, theme_b, theme_c, theme_d)
  76. end
  77.  
  78. in_thread do
  79.  intro = -> { play_pattern_timed([:fs4,:fs4,nil,:fs4,nil,:fs4,:fs4,nil,
  80.                                   :b4,nil,nil,nil,:g4,nil,nil,nil], [0.25]) }
  81.  theme_a = -> {
  82.    play_pattern_timed([:e4,nil,nil,:c4,nil,nil,:g3,nil,
  83.                        nil,:c4,nil,:d4,nil,:Db4,:c4,nil], [0.25])
  84.    play_pattern_timed([:c4,:g4,:b4], [1/3.0])
  85.    play_pattern_timed([:c5,nil,:a4,:b4,
  86.                        nil,:a4,nil,:e4,
  87.                        :f4,:d4,nil,nil], [0.25]) }
  88.  theme_b = -> {
  89.    play_pattern_timed([nil,nil,:e5,:ds5,:d5,:b4,nil,:c5,
  90.                        nil,:e4,:f4,:g4,nil,:c4,:e4,:f4,
  91.                        nil,nil,:e5,:ds5,:d5,:b4,nil,:c5,
  92.                        nil,:f5,nil,:f5,:f5,nil,nil,nil,
  93.                        nil,nil,:e5,:ds5,:d5,:b4,nil,:c5,
  94.                        nil,:e4,:f4,:g4,nil,:c4,:e4,:f4,
  95.                        nil,nil,:gs4,nil,nil,:f4,nil,nil,
  96.                        :e4,nil,nil,nil,nil,nil,nil,nil], [0.25]) }
  97.  theme_c = -> {
  98.    play_pattern_timed([:gs4,:gs4,nil,:gs4,nil,:gs4,:as4,nil,
  99.                        :g4,:e4,nil,:e4,:c4,nil,nil,nil,
  100.                        :gs4,:gs4,nil,:gs4,nil,:gs4,:as4,:g4,
  101.                        nil,nil,nil,nil,nil,nil,nil,nil,
  102.                        :gs4,:gs4,nil,:gs4,nil,:gs4,:as4,nil,
  103.                        :g4,:e4,nil,:e4,:c4,nil,nil,nil,
  104.                        :fs4,:fs4,nil,:fs4,nil,:fs4,:fs4,nil,
  105.                        :b4,nil,nil,nil,:g4,nil,nil,nil], [0.25]) }
  106.  theme_d = -> {
  107.    play_pattern_timed([:c5,:a4,nil,:e4,nil,nil,:e4,nil,
  108.                        :f4,:c5,nil,:c5,:f4,nil,nil,nil], [0.25])
  109.    play_pattern_timed([:g4,:f5,:f5,
  110.                        :f5,:e5,:d5], [1/3.0])
  111.    play_pattern_timed([:c5,:a4,nil,:f4,:e4,nil,nil,nil], [0.25])
  112.    play_pattern_timed([:c5,:a4,nil,:e4,nil,nil,:e4,nil,
  113.                        :f4,:c5,nil,:c5,:f4,nil,nil,nil,
  114.                        :g4,:d5,nil,:d5], [0.25])
  115.    play_pattern_timed([:d5,:c5,:b4], [1/3.0])
  116.  play_pattern_timed([:c5,nil,nil,nil,nil,nil,nil,nil], [0.25]) }
  117.  
  118.  structure(intro, theme_a, theme_b, theme_c, theme_d)
  119. end
  120.  
  121. in_thread do
  122.  use_synth :tri
  123.  use_synth_defaults attack: 0, sustain: 0.1, decay: 0.1, release: 0.1, amp: 0.4
  124.  
  125.  intro = -> { play_pattern_timed([:D4,:D4,nil,:D4,nil,:D4,:D4,nil,
  126.                                   :G3,nil,nil,nil,:G4,nil,nil,nil], [0.25]) }
  127.  theme_a = -> {
  128.    play_pattern_timed([:G4,nil,nil,:E4,nil,nil,:C4,nil,
  129.                        nil,:F4,nil,:G4,nil,:Gb4,:F4,nil], [0.25])
  130.    play_pattern_timed([:E4,:C4,:E4], [1/3.0])
  131.    play_pattern_timed([:F4,nil,:D4,:E4,
  132.                        nil,:C4,nil,:A3,
  133.                        :B3,:G3,nil,nil], [0.25]) }
  134.  theme_b = -> {
  135.    play_pattern_timed([:C3,nil,nil,:G3,nil,nil,:C3,nil,
  136.                        :F3,nil,nil,:C3,:C3,nil,:F3,nil,
  137.                        :C3,nil,nil,:E3,nil,nil,:G3,:C3,
  138.                        nil,:G2,nil,:G2,:G2,nil,:G4,nil,
  139.                        :C3,nil,nil,:G3,nil,nil,:C3,nil,
  140.                        :F3,nil,nil,:C3,:C3,nil,:F3,nil,
  141.                        :C3,nil,:Ab3,nil,nil,:Bb3,nil,nil,
  142.                        :C3,nil,nil,:G2,:G2,nil,:C3,nil], [0.25]) }
  143.  theme_c = -> {
  144.    3.times {
  145.      play_pattern_timed([:gs4,nil,nil,:ds4,nil,nil,:gs4,nil,
  146.                          :g4,nil,nil,:c4,nil,nil,:g4,nil], [0.25])
  147.    }
  148.    play_pattern_timed([:D4,:D4,nil,:D4,nil,:D4,:D4,nil,
  149.                        :G3,nil,nil,nil,:G4,nil,nil,nil], [0.25]) }
  150.  theme_d = -> {
  151.    play_pattern_timed([:C3,nil,nil,:fs3,:g3,nil,:C3,nil,
  152.                        :F3,nil,:F3,nil,:C3,:C3,:F3,nil,
  153.                        :D3,nil,nil,:F3,:G3,nil,:B3,nil,
  154.                        :G3,nil,:G3,nil,:C3,:C3,:G3,nil,
  155.                        :C3,nil,nil,:fs3,:g3,nil,:C3,nil,
  156.                        :F3,nil,:F3,nil,:C3,:C3,:F3,nil,
  157.                        :G3,nil,nil,:G3], [0.25])
  158.    play_pattern_timed([:G3,:A3,:B3], [1/3.0])
  159.  play_pattern_timed([:C4,nil,:G3,nil,:C4,nil,nil,nil], [0.25]) }
  160.  
  161.  structure(intro, theme_a, theme_b, theme_c, theme_d)
  162. end
  163.  
  164. in_thread do
  165.  use_synth :fm
  166.  use_synth_defaults divisor: 1.6666, attack: 0.0, depth: 1500, sustain: 0.05, release: 0.0
  167.  
  168.  ll = -> { play :a, sustain: 0.1; sleep 0.75 }
  169.  l = -> { play :a, sustain: 0.1; sleep 0.5 }
  170.  s = -> { play :a; sleep 0.25 }
  171.  
  172.  define :drum_pattern_a do
  173.    [l,s,l,s,l,ll,l,s,s,s].map(&:call)
  174.  end
  175.  
  176.  define :drum_pattern_b do
  177.    play :b
  178.    sleep 0.5
  179.    play :a6
  180.    sleep 0.3
  181.    play :a7
  182.    sleep 0.2
  183.    play :a, sustain: 0.1
  184.    sleep 0.5
  185.    play :a6
  186.    sleep 0.3
  187.    play :a7
  188.    sleep 0.2
  189.  end
  190.  
  191.  define :drum_pattern_c do
  192.    [ll,s,l,l].map(&:call)
  193.  end
  194.  
  195.  with_fx :level, amp: 1.2 do
  196.    1.times  { drum_pattern_a }
  197.    loop do
  198.      24.times { drum_pattern_b }
  199.      4.times  { drum_pattern_a }
  200.      8.times  { drum_pattern_b }
  201.      16.times { drum_pattern_c }
  202.      4.times  { drum_pattern_a }
  203.      8.times  { drum_pattern_b }
  204.    end
  205.  end
  206. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement