Class: Cyclotone::Backends::OSCBackend
- Inherits:
-
Object
- Object
- Cyclotone::Backends::OSCBackend
- Defined in:
- lib/cyclotone/backends/osc_backend.rb
Defined Under Namespace
Instance Attribute Summary collapse
-
#address ⇒ Object
readonly
Returns the value of attribute address.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
Class Method Summary collapse
Instance Method Summary collapse
- #build_bundle(events, at:, cps: nil, timetag: at) ⇒ Object
- #build_message(event, at:, cps: nil) ⇒ Object
- #close ⇒ Object
- #flush ⇒ Object
-
#initialize(host: "127.0.0.1", port: 57_120, address: "/dirt/play", socket: nil, socket_factory: nil, retries: 1) ⇒ OSCBackend
constructor
A new instance of OSCBackend.
- #panic ⇒ Object
- #payload_for(event, at:, cps: nil) ⇒ Object
- #send_event(event, at: Time.now.to_f, cps: nil, **_options) ⇒ Object
Constructor Details
#initialize(host: "127.0.0.1", port: 57_120, address: "/dirt/play", socket: nil, socket_factory: nil, retries: 1) ⇒ OSCBackend
Returns a new instance of OSCBackend.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/cyclotone/backends/osc_backend.rb', line 23 def initialize( host: "127.0.0.1", port: 57_120, address: "/dirt/play", socket: nil, socket_factory: nil, retries: 1 ) @host = host @port = port @address = address @socket_factory = socket_factory || proc { UDPSocket.new } @retries = retries.to_i @socket = socket || build_socket @closed = false rescue StandardError => error raise ConnectionError, error. end |
Instance Attribute Details
#address ⇒ Object (readonly)
Returns the value of attribute address.
11 12 13 |
# File 'lib/cyclotone/backends/osc_backend.rb', line 11 def address @address end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
11 12 13 |
# File 'lib/cyclotone/backends/osc_backend.rb', line 11 def host @host end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
11 12 13 |
# File 'lib/cyclotone/backends/osc_backend.rb', line 11 def port @port end |
Class Method Details
Instance Method Details
#build_bundle(events, at:, cps: nil, timetag: at) ⇒ Object
56 57 58 59 |
# File 'lib/cyclotone/backends/osc_backend.rb', line 56 def build_bundle(events, at:, cps: nil, timetag: at) = Array(events).map { |event| (event, at: at, cps: cps) } encode_bundle(, timetag: ) end |
#build_message(event, at:, cps: nil) ⇒ Object
52 53 54 |
# File 'lib/cyclotone/backends/osc_backend.rb', line 52 def (event, at:, cps: nil) (address, payload_for(event, at: at, cps: cps)) end |
#close ⇒ Object
78 79 80 81 82 |
# File 'lib/cyclotone/backends/osc_backend.rb', line 78 def close close_socket @closed = true self end |
#flush ⇒ Object
70 71 72 |
# File 'lib/cyclotone/backends/osc_backend.rb', line 70 def flush self end |
#panic ⇒ Object
74 75 76 |
# File 'lib/cyclotone/backends/osc_backend.rb', line 74 def panic self end |
#payload_for(event, at:, cps: nil) ⇒ Object
42 43 44 45 46 47 48 49 50 |
# File 'lib/cyclotone/backends/osc_backend.rb', line 42 def payload_for(event, at:, cps: nil) values = event.value.is_a?(Hash) ? event.value : { value: event.value } [ "when", at.to_f, "onset", absolute_onset(event, at), "offset", absolute_offset(event, at, cps) ].compact + flatten_hash(values) end |
#send_event(event, at: Time.now.to_f, cps: nil, **_options) ⇒ Object
61 62 63 64 65 66 67 68 |
# File 'lib/cyclotone/backends/osc_backend.rb', line 61 def send_event(event, at: Time.now.to_f, cps: nil, **) reopen_if_closed! with_retry do @socket.send((event, at: at, cps: cps), 0, host, port) end rescue StandardError => error raise ConnectionError, error. end |