Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Raspberry Pi Projects for Kids (Second Edition)

You're reading from  Raspberry Pi Projects for Kids (Second Edition)

Product type Book
Published in Apr 2015
Publisher
ISBN-13 9781785281525
Pages 146 pages
Edition 1st Edition
Languages
Author (1):
Daniel Leonard Bates Daniel Leonard Bates
Profile icon Daniel Leonard Bates

Code listing


This section gives a complete listing of the code used in this chapter. You can refer to it if your code is not working to see what changes need to be made. Some of the code blocks have been moved around within the program to keep similar parts of the program together. This can make things easier to read, but it is completely optional. The following is the complete code used in the chapter:

pace = 0.8

define :play_notes do |notes, durations|
  together = notes.zip(durations)
  together.each do |note, duration|
    if one_in(2)
      speaker = -1
    else
      speaker = 1
    end
    play note, release: pace * duration, pan: speaker
    sleep pace * duration
  end
end

define :drum do
  sample :drum_tom_lo_hard, attack: 0, sustain: 0, release: 0.2
end

define :play_beat do |beat|
  beat.each do |pause|
    drum
    sleep pace * pause
  end
end

rhythm = [1, 1, 1, 0.75, 0.25, 1, 0.75, 0.25, 2]
line1 = [:G3, :G3, :G3, :Eb3, :Bb3, :G3, :Eb3, :Bb3, :G3]
line2 = [:D4, :D4, :D4, ...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}