public
Description: QuartzComposer Custom Plugin for Gainer I/O module.
Homepage: http://deadbeaf.org/
Clone URL: git://github.com/mootoh/qc_gainer.git
qc_gainer / qc_gainer.rb
100644 66 lines (56 sloc) 1.578 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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
58
59
60
61
62
63
64
65
66
#
# qc_gainer.rb
#
# Created by mootoh on 6/6/08.
# Copyright (c) 2008 deadbeaf.org. All rights reserved.
#
require 'osx/cocoa'
OSX.require_framework 'QuartzComposer'
require 'funnel'
 
class QCGainer < OSX::QCPlugIn
  def self.executionMode
    2
  end
 
  def self.timeMode
    1
  end
 
  def initialize
    @initialized = false
    @gio = Funnel::Gainer.new(Funnel::Gainer::MODE1)
 
    @ain = [0,0,0,0]
    @din = [0,0,0,0]
    @aot = [0,0,0,0]
    @dot = [0,0,0,0]
  end
 
  def startExecution(context)
    Thread.new do
      sleep 0.1
      4.times { |i| addInputPortWithType_forKey_withAttributes(OSX::QCPortTypeNumber, "aot_" + i.to_s, nil) }
      4.times { |i| addInputPortWithType_forKey_withAttributes(OSX::QCPortTypeNumber, "dot_" + i.to_s, nil) }
      4.times { |i| addOutputPortWithType_forKey_withAttributes(OSX::QCPortTypeNumber, "ain_" + i.to_s, nil) }
      4.times { |i| addOutputPortWithType_forKey_withAttributes(OSX::QCPortTypeNumber, "din_" + i.to_s, nil) }
    end
    true
  end
 
  def execute_atTime_withArguments(context, time, args)
    unless @initialized
      4.times do |i|
        @gio.ain(i).on Funnel::PortEvent::CHANGE do |event|
          @ain[i] = event.target.value
        end
        @gio.din(i).on Funnel::PortEvent::CHANGE do |event|
          @din[i] = event.target.value
        end
      end
      @initialized = false
    end
 
    4.times do |i|
      setValue_forOutputKey(@ain[i], "ain_" + i.to_s)
      setValue_forOutputKey(@din[i], "din_" + i.to_s)
    end
 
    true
  end
 
  def stopExecution(context)
    true
  end
end