Class: Zgomot::Midi::Channel

Inherits:
Object
  • Object
show all
Defined in:
lib/zgomot/midi/channel.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

.channelsObject (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

#clockObject (readonly)

Returns the value of attribute clock.



27
28
29
# File 'lib/zgomot/midi/channel.rb', line 27

def clock
  @clock
end

#length_to_secObject (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

#numberObject (readonly)

Returns the value of attribute number.



27
28
29
# File 'lib/zgomot/midi/channel.rb', line 27

def number
  @number
end

#offsetObject

Returns the value of attribute offset.



27
28
29
# File 'lib/zgomot/midi/channel.rb', line 27

def offset
  @offset
end

#patternObject (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

#set_clockObject



52
53
54
# File 'lib/zgomot/midi/channel.rb', line 52

def set_clock
  @offset, @clock = nil, Clock.new
end