-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
got templating working to the point of swapping out all of the 16th n…
…otes for the same given probability
- Loading branch information
Greg Borenstein
committed
Feb 1, 2009
1 parent
125f284
commit 669417c
Showing
2 changed files
with
63 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
$clock.bpm = 175 | ||
$mutation = L{|measure| 0 == (measure - 1) % 2} | ||
$measures = 4 | ||
|
||
probabilities = {} | ||
|
||
<% probabilities.each do |k,v| %> | ||
probabilities[<%= 36 + k %>] = <%= v.sort.collect{|a| a.last}.inspect %> | ||
<% end %> | ||
|
||
def note(midi_note_number) | ||
Note.create(:channel => 2, | ||
:number => midi_note_number, | ||
:duration => 0.25, | ||
:velocity => 100 + rand(27)) | ||
end | ||
|
||
static = L{1.0} | ||
dynamic = L{rand} | ||
check_every_drum = L{|queue| queue[queue.size - 1]} | ||
check_random_drums = L{|queue| queue[rand(queue.size)]} | ||
|
||
notes = [] | ||
(36..45).each do |midi_note_number| | ||
notes << Drum.new(:note => note(midi_note_number), | ||
:when => L{|beat| false}, | ||
# :number_generator => static, | ||
:number_generator => dynamic, | ||
# :next => check_every_drum, | ||
:next => check_random_drums, | ||
:probabilities => probabilities[midi_note_number]) | ||
end | ||
notes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,31 @@ | ||
class Templarx | ||
require 'erb' | ||
|
||
class Templarx | ||
TEMPLATE_PATH = File.expand_path(File.dirname(__FILE__)) + "/drum_definition.erb" | ||
|
||
attr_accessor :probabilities | ||
attr_accessor :default_probability | ||
|
||
def initialize opts={} | ||
@ddpath = opts[:definition_path] | ||
@default_probability = opts[:probability] | ||
end | ||
|
||
# 10x16 hash of 0.0-1.0 | ||
# rows represent midi channels, columns sixteenth notes | ||
def initialize_probabilities | ||
@probabilities = {} | ||
(0..9).each{|i| @probabilities[i] = {}} | ||
(0..9).each{|i| k={}; (0..15).each{|j| k[j] = @default_probability || 0.5}; @probabilities[i] = k } | ||
end | ||
|
||
def template | ||
@template ||= open(TEMPLATE_PATH).read | ||
end | ||
|
||
def rewrite_drum_definition | ||
initialize_probabilities | ||
e = ERB.new template | ||
File.open(@ddpath, "w"){|f| f << e.result(binding)} | ||
end | ||
end |