Class: Patch::IO::OSC::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/patch/io/osc/server.rb

Overview

OSC server

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, port, options = {}) ⇒ Server

Returns a new instance of Server.

Parameters:

  • id (Fixnum)
  • port (Fixnum)
  • options (Hash) (defaults to: {})

Options Hash (options):

  • :echo (Hash)
  • :log (Log)


17
18
19
20
21
22
23
24
25
# File 'lib/patch/io/osc/server.rb', line 17

def initialize(id, port, options = {})
  @log = options[:log]
  @server = nil
  @active = false
  @id = id
  @is_failsafe = true

  configure(port, options)
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



10
11
12
# File 'lib/patch/io/osc/server.rb', line 10

def id
  @id
end

Instance Method Details

#active?Boolean

Is the server active?

Returns:

  • (Boolean)


29
30
31
# File 'lib/patch/io/osc/server.rb', line 29

def active?
  @active
end

#disable(patch) ⇒ Boolean

Disable the message handlers

Returns:

  • (Boolean)


50
51
52
53
# File 'lib/patch/io/osc/server.rb', line 50

def disable(patch)
  addresses = get_addresses(patch)
  addresses.select { |address| @server.remove_method(address) }.any?
end

#listen(patch, &callback) ⇒ Boolean

Listen for messages

Parameters:

  • patch (::Patch::Patch)

    The patch to use for context

  • callback (Proc)

    A callback to fire when messages are received

Returns:

  • (Boolean)

    Whether any actions were configured



59
60
61
62
# File 'lib/patch/io/osc/server.rb', line 59

def listen(patch, &callback)
  addresses = get_addresses(patch)
  addresses.select { |address| listen_for(address, patch, &callback) }.any?
end

#startBoolean

Start the server

Returns:

  • (Boolean)

    Whether the server was started



35
36
37
38
39
# File 'lib/patch/io/osc/server.rb', line 35

def start
  @active = true
  @connection = @server.run
  true
end

#stopBoolean

Stop the server

Returns:

  • (Boolean)


43
44
45
46
# File 'lib/patch/io/osc/server.rb', line 43

def stop
  @active = false
  true
end