Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tutorials on how to use the snippets #2

Open
wants to merge 8 commits into
base: design-patterns
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@ Linux/Mac OS/Raspberry Pi
Windows

load_snippets('c:/dir/of/your/choice/sonic-pi-snippets')

From that point snippets should be loaded automagically when Sonic Pi starts.

----
13 changes: 13 additions & 0 deletions dp/desc_fm.sps
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# key: desc fm
# point_line: 0
# point_index: 0
# --

puts "| -------------------------------------------------------------------|"
puts "| FACTORY METHOD (Metoda Fabrykująca): |"
puts "| -------------------------------------------------------------------|"
puts "| Wzorzec ten definiuje interfejs la tworzenia obiektu, ale pozwala |"
puts "| klasom implementującym na podjęcie decyzji o tym jakiej konkretnej |"
puts "| klasy obiekt utworzyć. Metoda fabrykująca powala oddelegować tę |"
puts "| czynność to klas implementujących jej interfejs. |"
puts "| -------------------------------------------------------------------|"
12 changes: 12 additions & 0 deletions dp/desc_strategy.sps
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# key: desc strategy
# point_line: 0
# point_index: 0
# --
puts "| -------------------------------------------------------------------|"
puts "| STRATEGIA (Strategy): |"
puts "| -------------------------------------------------------------------|"
puts "| Wzorzec strategia definiuje rodzinę algorytmów, hermetyzuje każdy |"
puts "| z nich w postaci klas. Ponadto jego zastosowanie sprawia, |"
puts "| że poczególne algorywmy mogą być używane zamiennie, niezależnie od |"
puts "| klas/klientów, którzy korzystają z tych algorytmów. |"
puts "| -------------------------------------------------------------------|"
4 changes: 3 additions & 1 deletion dp/dp_fac_1.sps
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
# point_line: 0
# point_index: 0
# --
# DP FAC 1: Our current beat loop isn't so flexible if we'd like to introduce different beat patterns
# DP FAC 1:
# Current beat sampling loop isn't so flexible if we'd like
# to introduce different beat patterns
set_volume! 1

live_loop :beat do
Expand Down
3 changes: 2 additions & 1 deletion dp/dp_fac_2_a.sps
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
# point_index: 0
# --
# DP FAC 2 A
# This is a little bit more flexible solution, let's try add second beat...
# This is a little bit more flexible solution.
# Let's try add second beat...
set_volume! 1

use_bpm 96
Expand Down
2 changes: 1 addition & 1 deletion dp/dp_fac_2_b.sps
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# That looks nice, but the code on the screen starts getting to much space on our screen... Let's add another one...
set_volume! 1

use_bpm 94
use_bpm 96

# Impeach the president: https://www.youtube.com/watch?v=wqbEsS5kFb8
# beat_loop = {
Expand Down
7 changes: 4 additions & 3 deletions dp/dp_fac_2_c.sps
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
# point_index: 0
# --
# DP FAC 2 C
# OK. This is the point, when we'd like to extract below beats to a separate configuration scripts.
# Apart of that it would be nice to have the possibility to store our beat patterns for later performances
# and make them easy to use. And You've probably noticed, that the BPM had changed.
# OK. This is the point, we'd like to extract below beats
# to a separate configuration scripts as it would be nice
# to have the possibility make them easy to reuse.
# And You've probably noticed, that the BPM had changed.
set_volume! 1

use_bpm 127
Expand Down
4 changes: 3 additions & 1 deletion dp/dp_fac_3.sps
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ set_volume! 1
beat = ImpeachThePresident.new(ext_samples_path)
# beat = FunkyDrummer.new(ext_samples_path)
# beat = BigBeat.new(ext_samples_path)
# beat = HouseBeat.new(ext_samples_path)

live_loop :beat do
use_bpm beat.bpm
beat.steps.times do |step|
Expand All @@ -17,4 +19,4 @@ live_loop :beat do
end
sleep 0.25
end
end
end
73 changes: 73 additions & 0 deletions dp/dp_fac_3_bit.sps
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# key: dp fac 3 bit
# point_line: 0
# point_index: 0
# --
# DP FAC 3 BIT
# Our simple break bit wrapped into class

# Base class
class BeatLoop
attr_reader :steps # amount of beats in pattern
attr_accessor :bpm
attr_reader :loop # pattern
def initialize(samples_path)
raise 'Use subclasses'
end
end

# https://www.youtube.com/watch?v=dNP8tbDMZNE
class ImpeachThePresident < BeatLoop
def initialize(samples_path)
@steps = 16
@bpm = 96
@loop = {
:drum_bass_hard => [0, 7, 8, 14], # KICK (stopa)
:drum_snare_hard => [4, 12], # SNARE (werbel)
:drum_cymbal_closed => [0, 2, 4, 6, 7, 8, 12, 14], # CLOSED HI-HAT
:drum_cymbal_open => [10] # OPEN HI-HAT
}
end
end

# https://www.youtube.com/watch?v=dNP8tbDMZNE
class FunkyDrummer < BeatLoop
def initialize(samples_path)
@steps = 16
@bpm = 96
@loop = {
:drum_bass_hard => [1, 3, 7, 11, 14], # KICK (stopa)
:drum_snare_hard => [5, 8, 10, 12, 13, 16], # SNARE (werbel)
:drum_cymbal_closed => [0, 1, 2, 3, 4, 5, 6, 7, 9, 10, 11, 12, 13, 15, 16], # CLOSED HI-HAT
:drum_cymbal_open => [8, 14] # OPEN HI-HAT
}
end
end

# https://www.youtube.com/watch?v=sVysHOfV8CI&t=5
class BigBeat < BeatLoop
def initialize(samples_path)
@steps = 16
@bpm = 127
@loop = {
:drum_bass_hard => [1, 4, 7, 9], # KICK (stopa)
:drum_snare_hard => [5, 13], # SNARE (werbel)
"#{samples_path}/clap/clap707.wav" => [5, 13], # CLAP
}
end
end


# https://www.attackmagazine.com/technique/beat-dissected/rolling-deep-house/
class HouseBeat < BeatLoop
def initialize(samples_path)
@steps = 16
@bpm = 127
@loop = {
:drum_tom_lo_soft => [3, 11], # TOM
:drum_cymbal_closed => [2, 6, 9, 10, 14], # OPEN HI-HAT
:drum_heavy_kick => [0, 4, 8, 12], # KICK
:perc_swash => [3, 11] # SHAKER
}
end
end

17 changes: 0 additions & 17 deletions dp/dp_fac_3_bit_a.sps

This file was deleted.

19 changes: 0 additions & 19 deletions dp/dp_fac_3_bit_b.sps

This file was deleted.

18 changes: 0 additions & 18 deletions dp/dp_fac_3_bit_c.sps

This file was deleted.

18 changes: 0 additions & 18 deletions dp/dp_fac_3_bit_d.sps

This file was deleted.

19 changes: 0 additions & 19 deletions dp/dp_fac_3_bit_e.sps

This file was deleted.

20 changes: 16 additions & 4 deletions dp/dp_fac_4.sps
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,26 @@
# point_line: 0
# point_index: 0
# --
# DP FAC 4: Let's try to convert this simple loop
# into the the some kind'a more OOP loop
# DP FAC 4: In regular application You'll
# probably will have something like this:
set_volume! 1

use_bpm 96 # 127
arg = 'Funky Drummer'

if arg == 'Impeach The President'
beat = ImpeachThePresident.new(ext_samples_path)
elsif arg == 'Funky Drummer'
beat = FunkyDrummer.new(ext_samples_path)
elsif arg == 'Big Beat'
beat = BigBeat.new(ext_samples_path)
elsif arg == 'House Beat'
beat = HouseBeat.new(ext_samples_path)
else
beat = nil
end

beat = BigBeat.new
live_loop :beat do
use_bpm beat.bpm
beat.steps.times do |step|
beat.loop.each do |s, pattern|
sample s, amp: 0.5 if pattern.include? step
Expand Down
40 changes: 0 additions & 40 deletions dp/dp_fac_4_bit_a.sps

This file was deleted.

26 changes: 26 additions & 0 deletions dp/dp_fac_5.sps
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# key: dp fac 5
# point_line: 0
# point_index: 0
# --
# DP FAC 5:
# Let's try to extract the logic of creating Beats
# to simple factory
set_volume! 1

arg = 'Impeach The President'
# arg = 'Funky Drummer'
# arg = 'Big Beat'
# arg = 'House Beat'

beat_factory = SimpleBeatFactory.new(ext_samples_path)
beat = beat_factory.createBeat(arg)

live_loop :beat do
use_bpm beat.bpm
beat.steps.times do |step|
beat.loop.each do |s, pattern|
sample s, amp: 0.5 if pattern.include? step
end
sleep 0.25
end
end
27 changes: 27 additions & 0 deletions dp/dp_fac_5_a.sps
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# key: dp fac 5 a
# point_line: 0
# point_index: 0
# --
# DP FAC 5 A: Simple Beat Factory implementation

class SimpleBeatFactory

def initialize(samples_path)
@samples_path = samples_path

end

def createBeat(beat_name)
if beat_name == 'Impeach The President'
ImpeachThePresident.new(@samples_path)
elsif beat_name == 'Funky Drummer'
FunkyDrummer.new(@samples_path)
elsif beat_name == 'Big Beat'
BigBeat.new(@samples_path)
elsif beat_name == 'House Beat'
HouseBeat.new(@samples_path)
else
nil
end
end
end
Loading