Class: Niki::Instrument
- Inherits:
-
Object
- Object
- Niki::Instrument
- Includes:
- Chords
- Defined in:
- lib/niki/instrument.rb
Instance Attribute Summary collapse
-
#channel_number ⇒ Object
readonly
Returns the value of attribute channel_number.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #channel(number) ⇒ Object
-
#initialize(name, song, &block) ⇒ Instrument
constructor
A new instance of Instrument.
- #note ⇒ Object
- #to_module ⇒ Object
Methods included from Chords
Constructor Details
#initialize(name, song, &block) ⇒ Instrument
Returns a new instance of Instrument.
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/niki/instrument.rb', line 7 def initialize(name, song, &block) @name = name @song = song @channel_number = nil @macros = {} self.instance_exec(&block) Part.send :include, self.to_module end |
Instance Attribute Details
#channel_number ⇒ Object (readonly)
Returns the value of attribute channel_number.
3 4 5 |
# File 'lib/niki/instrument.rb', line 3 def channel_number @channel_number end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/niki/instrument.rb', line 3 def name @name end |
Instance Method Details
#channel(number) ⇒ Object
18 19 20 |
# File 'lib/niki/instrument.rb', line 18 def channel(number) @channel_number = number - 1 end |
#note ⇒ Object
22 23 24 |
# File 'lib/niki/instrument.rb', line 22 def note @macros end |
#to_module ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/niki/instrument.rb', line 26 def to_module instrument_name = @name macros = @macros Module.new do define_method instrument_name do |*args| note = args.shift duration = args.shift || 1 = args.shift || {} velocity = [:v] || 100 if note.is_a?(Hash) && note[:from] copy_from_part(note[:from], instrument_name) return end note = [note].flatten.map do |n| if n.is_a?(Fixnum) n else # Try to fetch the note from the symbol macros[n] end end note.push [:base] if [:base] register_note(instrument_name, note, duration, velocity) end end end |