通过udp消息格式将max/msp转换为ruby [英] max/msp to ruby via udp message format

查看:125
本文介绍了通过udp消息格式将max/msp转换为ruby的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为ruby项目使用max/msp构建一个小的GUI 我找不到一种方法来正确转换我从max接收到的数据.

I'm trying to build a little GUI with max/msp for a ruby project I can't find a way to properly convert the data i receive form max.

这是我从ruby的max中收到的消息的几个示例(我先发送2,然后发送1 0 -1 -2):

here is several examples of message that i've received from max in ruby (i've send 2 first then 1 0 -1 -2):

["int\x00,i\x00\x00\x00\x00\x00\x02", ["AF_INET", 53802, "127.0.0.1", "127.0.0.1"]]
["int\x00,i\x00\x00\x00\x00\x00\x01", ["AF_INET", 53802, "127.0.0.1", "127.0.0.1"]]
["int\x00,i\x00\x00\x00\x00\x00\x00", ["AF_INET", 53802, "127.0.0.1", "127.0.0.1"]]
["int\x00,i\x00\x00\xFF\xFF\xFF\xFF", ["AF_INET", 53802, "127.0.0.1", "127.0.0.1"]]
["int\x00,i\x00\x00\xFF\xFF\xFF\xFE", ["AF_INET", 53802, "127.0.0.1", "127.0.0.1"]]

到目前为止,我已经能够通过String#ord或String#unpack将正值转换为整数,但是使用这些方法,负整数给我0值

so far i've been able to convert positive values to integer via String#ord or String#unpack but with those methods negative integers gives me 0 value

推荐答案

您可以轻松地使用#unpack,使用偏移量('@ 8')和32位带符号的bigendian int('l>')

You can easily do it with #unpack, using offset ('@8'), and 32-bit signed bigendian int ('l>')

str.unpack('@8l>')

我不确定字符串的起始部分是什么意思("int \ x00,i \ x00 \ x00"),我只是忽略了它的偏移量.如果有重要数据,则可能需要额外摆弄.

I'm not sure what initial part of string means ("int\x00,i\x00\x00") and I have just ignored it with offset. It might need additional fiddling, if there is any important data.

这篇关于通过udp消息格式将max/msp转换为ruby的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆