a monkey patch for osc-ruby 1.1.5 (2025-07-28 ver)
The snippet can be accessed without any authentication.
Authored by
cleemy desu wayo
This is a monkey patch to handle OSC messages whose OSC Type Tag String is "T", "F", or "N".
これは OSC Type Tag String が "T" や "F" や "N" であるOSCメッセージに対応するためのモンキーパッチです。
It supports both sending and receiving.
送信側にも受信側にも対応しています。
And it is for osc-ruby 1.1.5.
osc-ruby 1.1.5 のためのものです。
osc_ruby_monkey_patch.rb 3.50 KiB
# a monkey patch for osc-ruby 1.1.5
# by cleemy desu wayo
# 2025-07-28
#
# this is NOT CC0.
#
# this code came from the osc-ruby project (MIT License).
#
# see:
# https://github.com/aberant/osc-ruby/blob/3b4b589d888396f031b01e6a2289a56db1aa933e/lib/osc-ruby/osc_types.rb
# https://github.com/aberant/osc-ruby/blob/a173bccbcd74e223d433bfbd44dd07b7a596a56a/lib/osc-ruby/osc_packet.rb#L46-L56
# https://github.com/aberant/osc-ruby/blob/a173bccbcd74e223d433bfbd44dd07b7a596a56a/lib/osc-ruby/osc_packet.rb#L106-L130
# https://github.com/aberant/osc-ruby/blob/3b4b589d888396f031b01e6a2289a56db1aa933e/lib/osc-ruby/message.rb#L8-L26
#
# ----
#
# an old version of this monkey patch:
# https://gitlab.com/cleemy-desu-wayo/outvoke/-/snippets/4875484
#
# ----
#
# This is a monkey patch to handle OSC messages whose OSC Type Tag String is
# "T", "F", or "N".
#
# It supports both sending and receiving.
#
# And it is for osc-ruby 1.1.5.
#
# To use this monkey patch with Outvoke, for example, save this file as
# `osc_ruby_monkey_patch.rb` in the current directory and require it in
# `outvoke.conf.rb` with `require "./osc_ruby_monkey_patch.rb"`.
#
#
# これは OSC Type Tag String が "T" や "F" や "N" であるOSCメッセージに対応
# するためのモンキーパッチです。
#
# 送信側にも受信側にも対応しています。
#
# osc-ruby 1.1.5 のためのものです。
#
# Outvokeでこのモンキーパッチを利用する場合、例えばこのファイルを
# osc_ruby_monkey_patch.rb でカレントディレクトリに保存し、outvoke.conf.rb から
# require "./osc_ruby_monkey_patch.rb" する、といった方法があります。
#
require 'osc-ruby'
require 'osc-ruby/em_server'
module OSC
class OSCTrue < OSCArgument
def tag
'T'
end
def encode
"".force_encoding("BINARY")
end
end
class OSCFalse < OSCArgument
def tag
'F'
end
def encode
"".force_encoding("BINARY")
end
end
class OSCNull < OSCArgument
def tag
'N'
end
def encode
"".force_encoding("BINARY")
end
end
class OSCPacket
def initialize(string)
@packet = NetworkPacket.new(string)
@types = {
"i" => lambda{OSCInt32.new(get_int32)},
"f" => lambda{ OSCFloat32.new(get_float32)},
"d" => lambda{ OSCDouble64.new(get_double64)},
"s" => lambda{ OSCString.new(get_string)},
"b" => lambda{ OSCBlob.new(get_blob)},
"T" => lambda{OSCTrue.new(get_true)},
"F" => lambda{OSCFalse.new(get_false)},
"N" => lambda{OSCNull.new(get_null)},
}
end
def get_true
@packet.skip_padding
true
end
def get_false
@packet.skip_padding
false
end
def get_null
@packet.skip_padding
nil
end
end
class Message
def self.new_with_time(address, time, tags=nil, *args)
message = new(address, *args) # maybe in osc-ruby 1.1.5, an unnecessary argument is being passed at this line
message.time = time
message
end
def initialize(address, *args)
@address = address
@args = []
args.each do |arg|
case arg
when Integer; @args << OSCInt32.new(arg)
when Float; @args << OSCFloat32.new(arg)
when String; @args << OSCString.new(arg)
when TrueClass; @args << OSCTrue.new(arg)
when FalseClass; @args << OSCFalse.new(arg)
when NilClass; @args << OSCNull.new(arg)
when OSCArgument; @args << arg
end
end
end
end
end-
I've opened an issue in GitHub aberant/osc-ruby repo:
https://github.com/aberant/osc-ruby/issues/21
Please register or sign in to comment