Permalink
Browse files

support for reusable riffs

  • Loading branch information...
1 parent 442deac commit 7717384063c21a437a08078c108e3933ec9cee17 @txus committed Aug 19, 2011
Showing with 100 additions and 67 deletions.
  1. +1 −1 Gemfile.lock
  2. +13 −3 Readme.md
  3. +37 −59 examples/my_song.rb
  4. +13 −3 lib/niki.rb
  5. +7 −0 lib/niki/part.rb
  6. +19 −0 lib/niki/riff.rb
  7. +9 −0 lib/niki/song.rb
  8. +1 −1 lib/niki/version.rb
View
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
- niki (0.1.1)
+ niki (0.2.1)
unimidi
GEM
View
@@ -68,6 +68,15 @@ A Niki Song is represented this way:
note[:hh] = e1 # And the hh will be e1
end
+ # You can define reusable riffs that you will be able to play with
+ # different instruments:
+ riff :simple_break do
+ note g3, 8
+ note f3, 8
+ note e3, 8
+ note d3, 8
+ end
+
# Define your song parts like this:
part :intro do
# Notes are defined like this:
@@ -112,9 +121,9 @@ A Niki Song is represented this way:
piano f2MAJ, 4
piano a2MIN, 4, :base => f2
piano silence, 4
- piano a2MIN, 4 :base => f2
- piano a2MIN, 8
- piano a2MIN, 8
+
+ # Play the previously defined riff with the piano.
+ riff :simple_break, :piano
end
# You can repeat any part!
@@ -137,3 +146,4 @@ A Niki Song is represented this way:
# Play the song!!!
song.play
+
View
@@ -24,6 +24,39 @@
note[:ohh] = +g1
end
+ # Define reusable riffs with this snippet
+ riff :simple_notes do
+ note f2, 4
+
+ note f2, 8
+ note e2, 8
+ note f2, 8
+ note e2, 8
+ note f2, 8
+
+ note e3, 4
+ note c3, 4
+ note b2, 8
+ note c2, 8
+ note c2, 8
+ note g2, 4
+
+ note a2, 4
+
+ note a2, 8
+ note g2, 8
+ note a2, 8
+ note g2, 8
+ note a2, 8
+
+ note e3, 4
+ note c3, 4
+ note b2, 8
+ note c2, 8
+ note c2, 8
+ note g2, 4
+ end
+
part :intro do
# Drums
2.times do
@@ -50,36 +83,8 @@
drums :ohh, 8
end
- # Bass
- bass f2, 4
-
- bass f2, 8
- bass e2, 8
- bass f2, 8
- bass e2, 8
- bass f2, 8
-
- bass e3, 4
- bass c3, 4
- bass b2, 8
- bass c2, 8
- bass c2, 8
- bass g2, 4
-
- bass a2, 4
-
- bass a2, 8
- bass g2, 8
- bass a2, 8
- bass g2, 8
- bass a2, 8
-
- bass e3, 4
- bass c3, 4
- bass b2, 8
- bass c2, 8
- bass c2, 8
- bass g2, 4
+ # Play the simple notes riff with bass
+ riff :simple_notes, :bass
end
part :intro_ending do
@@ -127,35 +132,8 @@
drums [:snare, :ohh], 16
drums :snare, 16
- # Bass
- bass f2, 4
-
- bass f2, 8
- bass e2, 8
- bass f2, 8
- bass e2, 8
- bass f2, 8
-
- bass e3, 4
- bass c3, 4
- bass b2, 8
- bass c2, 8
- bass c2, 8
- bass g2, 4
-
- bass a2, 4
- bass a2, 4
- bass a2, 4
- bass a2, 4
-
- bass b2, 8
- bass b2, 8
- bass b2, 8
- bass c2, 8
- bass c2, 8
- bass c2, 8
- bass d3, 8
- bass e3, 8
+ # Play the simple notes riff with bass
+ riff :simple_notes, :bass
end
part :pre_chorus do
View
@@ -2,6 +2,7 @@
require 'core_ext/array'
require 'niki/chords'
require 'niki/part'
+require 'niki/riff'
require 'niki/song'
require 'niki/instrument'
@@ -30,6 +31,15 @@
# note[:hh] = e1 # And the hh will be e1
# end
#
+# # You can define reusable riffs that you will be able to play with
+# # different instruments:
+# riff :simple_break do
+# note g3, 8
+# note f3, 8
+# note e3, 8
+# note d3, 8
+# end
+#
# # Define your song parts like this:
# part :intro do
# # Notes are defined like this:
@@ -75,9 +85,9 @@
# piano f2MAJ, 4
# piano a2MIN, 4, :base => f2
# piano silence, 4
-# piano a2MIN, 4 :base => f2
-# piano a2MIN, 8
-# piano a2MIN, 8
+#
+# # Play the previously defined riff with the piano.
+# riff :simple_break, :piano
# end
#
# # You can repeat any part!
View
@@ -15,6 +15,13 @@ def for_instrument(instrument_name)
@notes[instrument_name] || []
end
+ def riff(name, instrument_name, &blk)
+ riff = @song.get_riff(name)
+ riff.notes.each do |args|
+ send(instrument_name, *args)
+ end
+ end
+
private
def copy_from_part(name, type)
View
@@ -0,0 +1,19 @@
+module Niki
+ class Riff
+ attr_reader :name, :notes
+
+ include Niki::Chords
+
+ def initialize(name, song, &block)
+ @name = name
+ @song = song
+
+ @notes = []
+ self.instance_exec(&block)
+ end
+
+ def note(*args)
+ @notes << args
+ end
+ end
+end
View
@@ -13,6 +13,7 @@ def initialize(options, &block)
@midi = UniMIDI::Output.first
@parts = []
@instruments = []
+ @riffs = []
@channel = {}
@tempo = options[:tempo]
self.instance_eval &block
@@ -27,6 +28,10 @@ def instrument(name, &block)
@instruments << Instrument.new(name, self, &block)
end
+ def riff(name, &block)
+ @riffs << Riff.new(name, self, &block)
+ end
+
def repeat(name, options = {})
(options[:times] || 1).times do
@parts << get_part(name)
@@ -76,6 +81,10 @@ def get_part(name)
@parts.detect {|p| p.name == name }
end
+ def get_riff(name)
+ @riffs.detect {|p| p.name == name }
+ end
+
private
def has_part?(name)
View
@@ -1,3 +1,3 @@
module Niki
- VERSION = "0.2.0"
+ VERSION = "0.2.1"
end

0 comments on commit 7717384

Please sign in to comment.