Class: Zgomot::Midi::Channel
Class Attribute Summary collapse
-
.channels ⇒ Object
readonly
Returns the value of attribute channels.
Instance Attribute Summary collapse
-
#clock ⇒ Object
readonly
Returns the value of attribute clock.
-
#length_to_sec ⇒ Object
readonly
Returns the value of attribute length_to_sec.
-
#number ⇒ Object
readonly
Returns the value of attribute number.
-
#offset ⇒ Object
Returns the value of attribute offset.
-
#pattern ⇒ Object
readonly
Returns the value of attribute pattern.
Class Method Summary collapse
Instance Method Summary collapse
- #<<(pat) ⇒ Object
-
#initialize(num) ⇒ Channel
constructor
A new instance of Channel.
- #method_missing(meth, *args, &blk) ⇒ Object
- #set_clock ⇒ Object
Constructor Details
#initialize(num) ⇒ Channel
Returns a new instance of Channel.
29 30 31 32 |
# File 'lib/zgomot/midi/channel.rb', line 29 def initialize(num) @number, @pattern, @offset = num, [], nil set_clock end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &blk) ⇒ Object
48 49 50 |
# File 'lib/zgomot/midi/channel.rb', line 48 def method_missing(meth, *args, &blk ) pattern.send(meth, *args, &blk); reset_pattern_time;self end |
Class Attribute Details
.channels ⇒ Object (readonly)
Returns the value of attribute channels.
9 10 11 |
# File 'lib/zgomot/midi/channel.rb', line 9 def channels @channels end |
Instance Attribute Details
#clock ⇒ Object (readonly)
Returns the value of attribute clock.
27 28 29 |
# File 'lib/zgomot/midi/channel.rb', line 27 def clock @clock end |
#length_to_sec ⇒ Object (readonly)
Returns the value of attribute length_to_sec.
27 28 29 |
# File 'lib/zgomot/midi/channel.rb', line 27 def length_to_sec @length_to_sec end |
#number ⇒ Object (readonly)
Returns the value of attribute number.
27 28 29 |
# File 'lib/zgomot/midi/channel.rb', line 27 def number @number end |
#offset ⇒ Object
Returns the value of attribute offset.
27 28 29 |
# File 'lib/zgomot/midi/channel.rb', line 27 def offset @offset end |
#pattern ⇒ Object (readonly)
Returns the value of attribute pattern.
27 28 29 |
# File 'lib/zgomot/midi/channel.rb', line 27 def pattern @pattern end |
Class Method Details
.ch(num = 0) ⇒ Object
11 12 13 |
# File 'lib/zgomot/midi/channel.rb', line 11 def ch(num=0) (channels << new(is_valid(num))).last end |
.is_valid(num) ⇒ Object
15 16 17 18 19 |
# File 'lib/zgomot/midi/channel.rb', line 15 def is_valid(num) nums = [num].flatten valid = nums.select{|n| 0 <= n and n <= 15} valid.length.eql?(nums.length) ? num : raise(Zgomot::Error, "channel number invalid: 1<= channel <= 16") end |
.release(chan) ⇒ Object
21 22 23 |
# File 'lib/zgomot/midi/channel.rb', line 21 def release(chan) channels.delete_if{|c| c.eql?(chan)} end |
Instance Method Details
#<<(pat) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/zgomot/midi/channel.rb', line 34 def <<(pat) @pattern.clear @length_to_sec = 0.0 pat = Zgomot::Comp::Pattern.new(pat) unless pat.kind_of?(Zgomot::Comp::Pattern) pat.seq.each do |p| p.time = clock.current_time p_sec = p.length_to_sec p.channel = number @length_to_sec += p_sec clock.update(p_sec) @pattern << Marshal.load(Marshal.dump(p)) end; self end |