通过C#/.NET在Unity3D中接收基于TCP/IP/UDP的MIDI [英] MIDI over TCP/IP/UDP to be received inUnity3D with C#/.NET
问题描述
我正在使用Unity3D Standard Edition.对于那些不知道的人,它是一个3D游戏引擎,支持C#/.NET脚本(因此可以访问.NET 2.0 API).
I am working in Unity3D Standard Edition. For those that don't know, it is a 3D games engine which supports C#/.NET scripting (so it has access to the .NET 2.0 API).
我创建了自己的合成器. (当前它正在响应由MIDI音序器通过MIDI文件压缩产生的note-ON事件.)
I have created my own synthesiser. (Currently it is responding to note-ON events which are generated by a MIDI sequencer munching through a MIDI file.)
现在,我希望从MIDI键盘捕获音符打开事件.
Now I wish to catch note-ON events from a MIDI keyboard.
我打算至少将我的应用程序部署到iOS,希望可以跟随其他操作系统.因此目标场景是:
I'm intending to deploy my app to iOS at the very least, hopefully other operating systems to follow. So target scenarios are:
- 有人在iPhone上运行我的应用程序,他们的MIDI键盘已连接到Windows计算机
- 有人在android平板电脑上运行我的应用程序,他们的MIDI键盘已连接到Linux机器
- 有人在OS X上运行我的应用程序,他们有一个MIDI键盘连接到OS X
最后一个是我所处的情况,因此,如果有人对不扩展的解决方案有兴趣,那么我仍然对此很感兴趣-至少可以让我一起获得一个功能原型
The last one is the situation I'm in, so if anyone has a solution for that one that doesn't extend, I am still very interested in it -- that would at least allow me to get a functional prototype together.
存在一种资产 MIDI Unified ,它将与MIDI设备连接.但是,它需要PRO版本.这是因为PRO版本允许使用本机插件.
There exists one asset, MIDI Unified, which will connect with a MIDI device. However, it requires the PRO version. This is because PRO version allows native plug-ins.
我相信应该可以在不使用本机插件的情况下,而是通过网络连接将MIDI集成到Unity中.
I believe it should be possible to get MIDI into Unity without using native plug-ins, but instead over the network connection.
(请注意,我并不是在说Internet连接,以太网连接,TCP/IP,UDP,HTTP,因为我不确定要使用的正确术语是什么.)
(Note that I'm not saying Internet connection, Ethernet connection, TCP/IP, UDP, HTTP, as I'm not completely sure what the right term to use would be.)
似乎有一些实用程序可以通过网络发送MIDI信号: ipMIDI 可以做到这一点适用于Windows和OSX.在Linux中可能需要这样做.
It appears there are utilities for sending MIDI signals over networks: ipMIDI will do this for Windows and OS X. There is probably something for doing it in Linux.
OSX具有一个"音频MIDI设置实用程序,我被告知允许MIDI信号从设备引导到本地主机. (也许这就是为什么OS X的ipMIDI是免费的吗?)
OSX has an "Audio MIDI setup" utility which I have been told allow MIDI signals to be channelled from the device to localhost. (maybe this is why ipMIDI for OS X is free?)
我刚刚发现音频MIDI设置实现了 RTP MIDI ,这似乎是通过网络传送MIDI的最佳标准(它可以应对有损网络).
I've just discovered that Audio MIDI setup implements RTP MIDI, which appears to be the best standard for beaming MIDI over a network (it copes with lossy networks).
所以我很确定任务会变成:如何在C#/.NET中实现RTP MIDI?
So I'm pretty sure the task becomes: how to implement RTP MIDI in C#/.NET?
但是也许有一些更简单(但功能不那么强大)的解决方案,例如,某些解决方案仅适用于OSX上的localhost并从其接收Note-ON MIDI消息.
But maybe there is some easier (but less powerful) solution, for example, some solution that only works for and receiving Note-ON MIDI messages from localhost on OSX.
如果能够为我的第一代应用程序获得一个基本的解决方案,然后在我有能力的情况下,随后将其替换为健壮的组件,我将感到非常高兴.
I would be very happy if I could get a basic solution for of the first generation of my app, and then subsequently replaced this with a robust component when I have the means.
据我所知,任何人都可以整理一下这一切吗?
So that is as far as I have got, can anyone tidy this up all push it forwards?
π
http://u3d.as/content/sta-blockhead/websocket-sharp-for-unity/4X4 这能帮上忙吗?
推荐答案
Python确实很棒!
Python is truly wonderful!
每当MIDI音符打开/关闭时,此脚本都会发送UDP数据包.我可以在Unity3D中捕获UDP数据包.
This script sends a UDP packet whenever a MIDI note on/off occurs. I can catch the UDP packets in Unity3D.
#!/usr/bin/python
# https://github.com/superquadratic/rtmidi-python/
import rtmidi_python as rtmidi
import time
import socket
def callback( data, time_stamp ):
event, note, vel = data
if event == 144: # note on/off
endpoint = ( "127.0.0.1", 6500 )
MESSAGE = "%d, %f" % ( note, float(vel) / 127.0 )
print MESSAGE
udp_socket = socket.socket( socket.AF_INET, socket.SOCK_DGRAM )
udp_socket.sendto(
MESSAGE,
endpoint
)
def main( ):
midi_in = rtmidi.MidiIn( )
midi_in.callback = callback
midi_in.open_port( 0 )
# do something else here (but don't quit)
while True:
time.sleep( 0.001 )
if __name__ == '__main__':
main()
这篇关于通过C#/.NET在Unity3D中接收基于TCP/IP/UDP的MIDI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!