Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add silence and velocity options

  • Loading branch information...
commit f7aa157984472ff47b669bdf579a000513805393 1 parent c085440
@txus authored
View
10 examples/my_song.rb
@@ -38,7 +38,7 @@
drums [:kick, :hh], 8
drums :hh, 16
- drums :hh, 16
+ drums silence, 16
drums :hh, 16
drums :hh, 16
drums [:snare, :hh], 8
@@ -228,15 +228,15 @@
# Drums
7.times do
- drums [:kick, :hh], 8
+ drums [:kick, :hh], 8, :velocity => 127
drums :hh, 8
- drums [:snare, :kick, :hh], 8
+ drums [:snare, :kick, :hh], 8, :velocity => 127
drums :hh, 8
end
- drums :kick, 8
+ drums :kick, 8, :velocity => 127
drums :hh, 16
drums :hh, 16
- drums [:snare, :kick], 16
+ drums [:snare, :kick], 16, :velocity => 127
drums :snare, 16
drums [:kick, :ohh], 8
View
4 lib/niki/chords.rb
@@ -41,5 +41,9 @@ module Chords
end
+ def silence
+ 0
+ end
+
end
end
View
4 lib/niki/instrument.rb
@@ -33,6 +33,8 @@ def to_module
duration = args.shift || 1
options = args.shift || {}
+ velocity = options[:v] || 100
+
if note.is_a?(Hash) && note[:from]
copy_from_part(note[:from], instrument_name)
return
@@ -49,7 +51,7 @@ def to_module
note.push options[:base]
- register_note(instrument_name, note, duration)
+ register_note(instrument_name, note, duration, velocity)
end
end
end
View
4 lib/niki/part.rb
@@ -22,9 +22,9 @@ def copy_from_part(name, type)
@notes[type] = part.send(type)
end
- def register_note(instrument_name, note, duration)
+ def register_note(instrument_name, note, duration, velocity)
@notes[instrument_name] ||= []
- @notes[instrument_name] << [note, calculate_duration(duration)]
+ @notes[instrument_name] << [note, calculate_duration(duration), velocity]
end
def calculate_duration(duration)
View
10 lib/niki/song.rb
@@ -52,14 +52,18 @@ def play_part(part, instrument)
channel = instrument.channel_number
@midi.open do |out|
- part.for_instrument(instrument.name).each do |notes, duration|
+ part.for_instrument(instrument.name).each do |notes, duration, velocity|
notes = [notes].flatten.compact
notes.each do |note|
- out.puts NOTE_ON + channel, note, 100
+ if note == 0 # Silence
+ out.puts NOTE_OFF + channel, last_note, velocity
+ end
+ out.puts NOTE_ON + channel, note, velocity
+ last_note = note
end
sleep(duration)
notes.each do |note|
- out.puts NOTE_OFF + channel, note, 100
+ out.puts NOTE_OFF + channel, note, velocity
end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.