Class: Shmidi::Socket
Constant Summary collapse
- @@controllers =
{}
Constants included from Base
Instance Attribute Summary collapse
-
#in ⇒ Object
readonly
Returns the value of attribute in.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#out ⇒ Object
readonly
Returns the value of attribute out.
Attributes included from Base
#_attachments, #_deleted, #_id, #_rev, #version
Class Method Summary collapse
Instance Method Summary collapse
- #init ⇒ Object
-
#initialize(name, in_id, out_id) ⇒ Socket
constructor
A new instance of Socket.
- #on_event(channel = nil, message = nil, note = nil, value = nil, &block) ⇒ Object
- #push(events) ⇒ Object
Methods included from Base
#[], #[]=, #clone, #dump, #etag, included, #inspect, #reset, #to_hash, #to_s
Constructor Details
#initialize(name, in_id, out_id) ⇒ Socket
Returns a new instance of Socket.
13 14 15 16 17 18 |
# File 'lib/shmidi/socket.rb', line 13 def initialize(name, in_id, out_id) @name = name @in = in_id @out = out_id init end |
Instance Attribute Details
#in ⇒ Object (readonly)
Returns the value of attribute in.
11 12 13 |
# File 'lib/shmidi/socket.rb', line 11 def in @in end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
11 12 13 |
# File 'lib/shmidi/socket.rb', line 11 def name @name end |
#out ⇒ Object (readonly)
Returns the value of attribute out.
11 12 13 |
# File 'lib/shmidi/socket.rb', line 11 def out @out end |
Class Method Details
.[](name) ⇒ Object
7 8 9 |
# File 'lib/shmidi/socket.rb', line 7 def self.[](name) @@controllers[name] end |
.print_device_list ⇒ Object
71 72 73 74 75 76 |
# File 'lib/shmidi/socket.rb', line 71 def self.print_device_list $stdout.puts('Inputs:') UniMIDI::Input.list $stdout.puts('Outputs:') UniMIDI::Output.list end |
Instance Method Details
#init ⇒ Object
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 |
# File 'lib/shmidi/socket.rb', line 20 def init @__in_dev = UniMIDI::Input.all.find { |d| d.name == @in } @__out_dev = UniMIDI::Output.all.find { |d| d.name == @out } @@controllers[@name] = self @__queue = Queue.new @__on_event = [] # @__sync_threads = Hash.new { |hash, key| hash[key] = Clock.new(key, self) } @__listener = Thread.new do loop do break unless @__in_dev begin @__in_dev.gets.each do |event| event[:source] = @name event = Event.new(event) Shmidi.TRACE_INTERNAL("> #{@name}\t#{event}") @__queue.push(event) @__on_event.each do |rule| next if (channel = rule[:channel]) && channel != event.channel next if ( = rule[:message]) && != event. next if (note = rule[:note]) && note != event.note next if (value = rule[:value]) && value != event.value rule[:block].call(event) rescue Shmidi.ON_EXCEPTION end end rescue Shmidi.ON_EXCEPTION end end end end |
#on_event(channel = nil, message = nil, note = nil, value = nil, &block) ⇒ Object
53 54 55 56 57 58 59 60 |
# File 'lib/shmidi/socket.rb', line 53 def on_event(channel = nil, = nil, note = nil, value = nil, &block) @__on_event << { :block => block, :channel => channel, :message => , :note => note } end |
#push(events) ⇒ Object
62 63 64 65 66 67 68 69 |
# File 'lib/shmidi/socket.rb', line 62 def push(events) events = Array(events).reduce([]) do |array, event| Shmidi.TRACE_EXTERNAL("< #{@name}\t#{event}") array << event.data array end @__out_dev.puts(*events) end |