mootoh / qcplugin_rb

An Example QuartzComposer Custom Plugin by RubyCocoa on Leopard.

This URL has Read+Write access

qcplugin_rb / qc_plugin.rb
100644 74 lines (60 sloc) 1.49 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
67
68
69
70
71
72
73
74
#
# Created by mootoh on 6/3/08.
# Copyright (c) 2008 deadbeaf.org. All rights reserved.
#
require 'logger'
require 'osx/cocoa'
OSX.require_framework 'QuartzComposer'
 
class QCRubyPlugin < OSX::QCPlugIn
=begin
def self.attributes
 
{OSX::QCPlugInAttributeNameKey => "Example RubyPlugin",
OSX::QCPlugInAttributeDescriptionKey => "by RubyCocoa."
}
end
 
def self.attributesForPropertyPortWithKey(key)
end
=end
 
  def self.executionMode
    2
  end
 
  def self.timeMode
    0
  end
 
  def initialize
    @logger = Logger.new('/tmp/qc_ruby_plugin.log')
    @logger.level = Logger::DEBUG
  end
 
 
  def startExecution(context)
@logger.debug("startExecution")
 
    Thread.new {
      sleep 0.1
      5.times do |i|
        begin
          addInputPortWithType_forKey_withAttributes(OSX::QCPortTypeString, "input_" + i.to_s, nil)
          addOutputPortWithType_forKey_withAttributes(OSX::QCPortTypeString, "out_" + i.to_s, nil)
@logger.debug("ports added")
        rescue => e
          @logger.error(e.message)
        end
      end
    }
    true
  end
 
  def execute_atTime_withArguments(context, time, args)
@logger.debug("execute !")
begin
      @logger.debug(valueForInputKey("input_0"))
      setValue_forOutputKey(
[valueForInputKey("input_0"), "Ruby", valueForInputKey("input_1")].join(' '),
"out_0")
    rescue => e
      @logger.error(e.message)
    end
 
    true
  end
 
  def stopExecution(context)
@logger.debug("stopExecution")
    true
  end
end