MIDI over TCP / IP / UDP to receive inUnity3D with C # /. NET

I work in Unity3D Standard Edition. For those who don't know this, this is a 3D game engine that supports C # /. NET scripts (so it has access to the .NET 2.0 API).

I created my own synthesizer. (He is currently responding to Note-ON events that are generated by a MIDI sequencer chewing on a MIDI file.)

Now I want to catch Note-ON events from a MIDI keyboard.

I'm going to deploy my application on iOS, at least hope other operating systems follow. Thus, the target scenarios are:

  • someone runs my application on iPhone, they have a MIDI keyboard that connects to their windows machine.
  • someone runs my application on an Android tablet, they have a MIDI keyboard plugged into their Linux machine.
  • someone runs my application on OS X, they have a MIDI keyboard connected to OS X

The latter is the situation I am in, so if someone has a solution for one that is not distributed, I am still very interested in this - this will at least allow me to get a functional prototype together.

There is one asset, MIDI Unified , that will connect to a MIDI device. However, this requires a PRO version. This is due to the fact that the PRO version allows you to create your own plugins.

I believe it should be possible to get MIDI in Unity without using its own plugins, but instead over a network connection.

(Note that I'm not talking about Internet connectivity, Ethernet, TCP / IP, UDP, HTTP, as I'm not quite sure what to use the correct term.)

A utility appears for sending MIDI signals over networks: ipMIDI will do this for Windows and OS X. There may be something for this on Linux.

OSX has a โ€œ Audio MIDI setup, โ€ which I mentioned in order to transfer MIDI signals from the device to the local host. (Perhaps that is why ipMIDI for OS X is free?)

EDIT: I just found that Audio MIDI tuning implements RTP MIDI , which seems to be the best standard for simulating MIDI over a network (it handles lossy networks).

So, I'm sure the challenge will be: how to implement RTP MIDI in C # /. NET?

But perhaps there is a slightly lighter (but less powerful) solution, for example, some solution that only works and receives Note-ON MIDI messages from localhost to OSX.

I would be very happy if I could get a basic solution for the first generation of my application, and then replace it with a reliable component when I have the tools.

So, as far as I got, can anyone take it all away to steer it forward?

ฯ€

EDIT: http://u3d.as/content/sta-blockhead/websocket-sharp-for-unity/4X4 Did this help?

+2
networking unity3d midi
source share
2 answers

Python is truly wonderful!

This script sends a UDP packet when turning on / off MIDI notes. I can catch 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() 
0
source share

I have done something similar in the past. What can you do:

Install the Midi loopback device (driver) on your computer. There are many, for example: http://www.tobias-erichsen.de/software/loopmidi.html

Then develop a simple application that listens on a virtual MIDI port with a Loopback device and converts anything received from the virtual MIDI port to a packet of data sent over a TCP / IP connection. A TCP / IP connection will end with your Unity Script or something else that supports TCP / IP and the ability to play MIDI. The protocol is pretty simple 3 bytes - Note On, Note Number, Volume. (usually volume 0 means note). This is about how you could implement this.

Hope this helps ...

0
source share

All Articles