Class: Zgomot::Midi::CC

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

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.ccsObject (readonly)

Returns the value of attribute ccs.



9
10
11
# File 'lib/zgomot/midi/cc.rb', line 9

def ccs
  @ccs
end

.paramsObject (readonly)

Returns the value of attribute params.



9
10
11
# File 'lib/zgomot/midi/cc.rb', line 9

def params
  @params
end

Class Method Details

.add_cc(name, cc, args, &blk) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/zgomot/midi/cc.rb', line 11

def add_cc(name, cc, args, &blk)
  channel = args[:channel].nil? ? 1 : args[:channel]
  min = args[:min].nil? ? 0.0 : args[:min]
  max = args[:max].nil? ? 1.0 : args[:max]
  type = args[:type] || :cont
  init = args[:init].nil? ? (type == :cont ? 0.0 : false) : args[:init]
  @ccs[cc] = name.to_sym
  (@params[name] ||= {})[channel] = {:min         => min,
                                     :max         => max,
                                     :value       => init,
                                     :type        => type,
                                     :updated_at  => ::Time.now,
                                     :cc          => cc,
                                     :blk         => blk}
  Zgomot.logger.info "ADDED CC #{cc}:#{name}:#{init}:#{channel}"
end

.apply(cc_num, value, channel) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/zgomot/midi/cc.rb', line 50

def apply(cc_num, value, channel)
  name = @ccs[cc_num]
  unless name.nil?
    Zgomot.logger.info "UPDATED CC #{cc_num}:#{name}:#{value}:#{channel}"
    p = @params[name][channel]
    unless p.nil?
      p[:updated_at] = ::Time.now
      min = p[:min]
      max = p[:max]
      if p[:type] == :cont
        p[:value] = min + (max - min)*value.to_f/127.0
      else
        p[:value] = value == 127 ? true : false
      end
      if p[:blk]
        p[:blk].call(p)
      end
    end
  end
end

.cc(name, channel = 1) ⇒ Object

Raises:



29
30
31
32
# File 'lib/zgomot/midi/cc.rb', line 29

def cc(name, channel = 1)
  raise(Zgomot::Error, " CC '#{name}' for channel '#{channel}' not found") if @params[name].nil? or @params[name][channel].nil?
  @params[name][channel][:value]
end

.cc_namesObject



41
42
43
# File 'lib/zgomot/midi/cc.rb', line 41

def cc_names
  params.keys
end

.channel_info(name, channel, config) ⇒ Object



33
34
35
36
37
38
39
40
# File 'lib/zgomot/midi/cc.rb', line 33

def channel_info(name, channel, config)
  val, max, min = if config[:type] == :cont
                    ["%3.2f" % config[:value], "%3.2f" % config[:max], "%3.2f" % config[:min]]
                  else
                    [config[:value].to_s, '-', '-']
                  end
  [name, val, config[:cc].to_s, channel.to_s, config[:type].to_s, max, min]
end

.info(name) ⇒ Object



44
45
46
# File 'lib/zgomot/midi/cc.rb', line 44

def info(name)
  params[name].map{|(ch, config)| channel_info(name, ch, config)}
end

.learn_cc(name, cc, args) ⇒ Object



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

def learn_cc(name, cc, args)
end

.update_at(name, ch) ⇒ Object



47
48
49
# File 'lib/zgomot/midi/cc.rb', line 47

def update_at(name, ch)
  params[name.to_sym][ch.to_i][:updated_at]
end