| View previous topic :: View next topic |
m1interactive
Joined: 04 May 2007 Posts: 18 Location: Chicago
|
Posted: Fri May 04, 2007 6:26 pm Post subject: Max/MSP communication? |
|
|
|
I've seen a couple posts relating to this, but seemingly no clear answer. Has anyone figured out an easy way to communicate data between Unity and Max/MSP? Perhaps OSC? The UDP method looks quite complicated-at least to me.
Thanks!
Brian |
|
| Back to top |
|
|
aNTeNNa trEE Unity Artist

Joined: 30 Oct 2005 Posts: 2778 Location: Unity HQ, Copenhagen
|
Posted: Sat May 05, 2007 6:28 am Post subject: |
|
|
|
Yep, there's a few people using Unity on this forum that would pee their pants with glee if an OSC or UDP plug would be written for Unity to talk with Max or SuperCollider.
Anyone holding out?  |
|
| Back to top |
|
|
jocphone
Joined: 26 Jun 2006 Posts: 32
|
Posted: Sun May 06, 2007 7:42 pm Post subject: |
|
|
|
Haven't persuaded myself to buy Max/MSP yet, but this quick example worked with Puredata.
Just stick the following code on an empty Gameobect and for the PD server wire up a 'netreceive' on port 32000 feeding out to an 'OSCroute'. (I used pd-extended don't know if the base version has this)
| Code: |
using UnityEngine;
using System.Collections;
using System.IO;
using System.Text;
using System.Net.Sockets;
public class PDCall : MonoBehaviour {
private TcpClient client;
private Stream stream;
private ASCIIEncoding asen;
void Start () {
client = new TcpClient();
client.Connect("127.0.0.1", 32000);
stream = client.GetStream();
asen= new ASCIIEncoding();
InvokeRepeating( "SoundUpdate", 1, 0.3f );
}
void SoundUpdate () {
string msg = "/note " + (60+(int)(Random.value * 20)) + ";";
byte[] ba = asen.GetBytes(msg);
stream.Write( ba, 0, ba.Length );
}
}
|
Only one way communication here but enough to get you started.
Joc |
|
| Back to top |
|
|
Bjerre
Joined: 08 Nov 2006 Posts: 99 Location: Kolding, Denmark
|
Posted: Fri May 18, 2007 8:35 am Post subject: |
|
|
|
thank you Joc. This was just what I needed to get started.
I had a lot of problems with the netreceive object crashing Max/Msp and had no luck using the mxj net.tcp.recv object.
But after a lot of trial and error I've managed to rewrite your code from using Tcp to Udp. I also changed your code from C# to javascript.
| Code: |
import System.Collections;
import System.IO;
import System.Text;
import System.Net.Sockets;
private var client;
private var asen;
private var msg : String;
function Start(){
client = new UdpClient();
client.Connect("127.0.0.1", 32000);
asen= new ASCIIEncoding();
InvokeRepeating( "SoundUpdate", 1, 0.5 );
}
function Update(){
//
}
function SoundUpdate(){
msg = "val0 " + Random.value * 20 + " : ";
msg += "val1 " + Random.Range(50,100) + " : ";
var ba : byte[] = asen.GetBytes(msg);
client.Send( ba, ba.Length );
}
|
If anybody is interested I have include Max/Msp code
| Code: |
max v2;
#N vpatcher 339 116 1081 609;
#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P newex 59 110 25 196617 iter;
#P newex 59 157 20 196617 t b;
#P newex 59 131 30 196617 sel :;
#P newex 59 185 61 196617 zl group 10;
#P number 105 244 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 59 244 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 59 215 102 196617 route val0 val1;
#P window linecount 2;
#P comment 412 112 171 196617 only one receiving object can be bound to any one port.;
#P window linecount 1;
#P newex 59 88 150 196617 mxj net.udp.recv @port 32000;
#P connect 0 0 8 0;
#P connect 8 0 6 0;
#P connect 6 0 7 0;
#P connect 7 0 5 0;
#P fasten 6 1 5 0 84 179 64 179;
#P connect 5 0 2 0;
#P connect 2 0 3 0;
#P connect 2 1 4 0;
#P pop;
|
Now I just need to make it receive data from Max. |
|
| Back to top |
|
|
m1interactive
Joined: 04 May 2007 Posts: 18 Location: Chicago
|
Posted: Tue May 29, 2007 6:26 pm Post subject: any more luck? |
|
|
|
Hi Guys,
Just wondering if you had any more luck communicating between Max and Unity. My specific purposes would be to send data from Max to control a Unity environment, most likely the POV of the world. Any thoughts or ideas?? I'm Max proficient, but not Java or C or anything else unfortunately.
By the way, here's what we're working on:
www.m1interactive.net
My goal is to add a full 3d game engine into this, with the ability to control it all without touching a control, just moving your body, etc. Any help would be much appreciated. As soon as I get this communication working, I'll be needing some guys/gals to help come up with cool new content for it as well.
Thanks!
Brian |
|
| Back to top |
|
|
Bjerre
Joined: 08 Nov 2006 Posts: 99 Location: Kolding, Denmark
|
Posted: Wed May 30, 2007 11:54 pm Post subject: |
|
|
|
Hi Brian
I found a server script on the wiki ( http://www.unifycommunity.com/wiki/index.php?title=Server ) It works ok for my current needs, which seems to be basically identically to yours. I use the mxj net.tcp.send object for sending data from Max -> Unity
Bjerre |
|
| Back to top |
|
|
m1interactive
Joined: 04 May 2007 Posts: 18 Location: Chicago
|
Posted: Thu May 31, 2007 6:45 pm Post subject: Thanks everyone, but help. |
|
|
|
| Thanks for the great comments and suggestions/help everyone. Bjerre, any chance you can talk me through how you made this work? The force is not strong with me in this stuff. Any help would be much appreciated! |
|
| Back to top |
|
|
Bjerre
Joined: 08 Nov 2006 Posts: 99 Location: Kolding, Denmark
|
Posted: Fri Jun 01, 2007 10:17 pm Post subject: |
|
|
|
Hi Brian
I have made this simple setup showing how i use the server script and Max/Msp
http://www.nonrelated.com/stuff/Max2Unity.unityPackage
Im not sure its the best way to do this, because im not exactly a Jedi when it comes to C# and .Net, im properly more of a Youngling. But it works for me. I have just finished a 10 weeks robot workshop at school where this setup was used and it worked like a dream.
the simplified Max/Msp patch.
| Code: | max v2;
#N vpatcher 6 47 660 696;
#P origin 53 -16;
#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P newex 240 144 27 196617 t b i;
#P number 240 122 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 201 144 27 196617 t b i;
#P number 201 122 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 164 144 27 196617 t b i;
#P number 164 122 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 127 144 27 196617 t b i;
#P number 127 122 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 89 144 27 196617 t b i;
#P number 89 122 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 89 181 180 196617 sprintf %i:%i:%i:%i:%i;
#P comment 220 251 123 196617 number of active packets;
#B frgb 157 157 157;
#P comment 172 268 125 196617 there is a bug somewhere;
#B frgb 157 157 157;
#P comment 104 288 160 196617 we successfully transmitted data;
#B frgb 157 157 157;
#P number 183 249 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 258 232 54 196617 print info;
#P newex 108 266 63 196617 print failure;
#P newex 33 286 69 196617 print success;
#P newex 33 210 236 196617 mxj net.tcp.send @address 127.0.0.1 @port 9349;
#P window setfont "Sans Serif" 24.;
#P comment 29 58 153 196632 net.tcp.send;
#P window setfont "Sans Serif" 9.;
#P comment 29 93 132 196617 sends TCP packets to Unity;
#P fasten 10 0 2 0 94 203 38 203;
#P connect 2 0 3 0;
#P connect 11 0 12 0;
#P fasten 12 0 10 0 94 171 94 171;
#P fasten 12 1 10 0 111 171 94 171;
#P fasten 14 0 10 0 132 171 94 171;
#P fasten 16 0 10 0 169 171 94 171;
#P fasten 18 0 10 0 206 171 94 171;
#P fasten 20 0 10 0 245 171 94 171;
#P connect 2 1 4 0;
#P connect 13 0 14 0;
#P fasten 14 1 10 1 149 171 136 171;
#P connect 15 0 16 0;
#P fasten 16 1 10 2 186 171 178 171;
#P connect 2 2 6 0;
#P connect 17 0 18 0;
#P fasten 18 1 10 3 223 171 220 171;
#P connect 19 0 20 0;
#P fasten 20 1 10 4 262 171 262 171;
#P connect 2 3 5 0;
#P pop;
|
btw. I just added to line of code to the server.cs script, well two if you count comments. Check line 274 to see and line 273 to read.
Bjerre
Last edited by Bjerre on Thu Apr 24, 2008 11:38 pm; edited 1 time in total |
|
| Back to top |
|
|
Bjerre
Joined: 08 Nov 2006 Posts: 99 Location: Kolding, Denmark
|
Posted: Fri Jun 01, 2007 11:14 pm Post subject: |
|
|
|
Hi again
Just updated the the unity package. This should be easier to understand and it is more well documented. The link is the same.
*Bjerre |
|
| Back to top |
|
|
m1interactive
Joined: 04 May 2007 Posts: 18 Location: Chicago
|
Posted: Thu Jun 28, 2007 4:09 pm Post subject: Thanks! |
|
|
|
Hey guys thanks so much for the help. Sorry for the lengthy wait to say that. I got sidetracked and haven't had much time to play lately. I'll keep reply when I have some news of some actual progress though.
Brian |
|
| Back to top |
|
|
m1interactive
Joined: 04 May 2007 Posts: 18 Location: Chicago
|
Posted: Mon Jul 23, 2007 5:50 pm Post subject: Using the variables from Max? |
|
|
|
OK so I got my max patch up and running, plus the Unity project package you provided. Sorry to be ill-informed here.
My goal is to send basically a start/stop message, plus x-y coordinates from Max. So if I send 3 variables from max, and they are received by Unity, how do I use the variables? Lets say I want an fps prefab to look left-right, up-down based on the x-y coords coming from max, and activate a particle system on the start/stop or whatever.
I'm confused as to what the scripts do or how I should use them. I spent all weekend on this and it's driving me batty.
Any help would be great!
Thanks!!
Brian |
|
| Back to top |
|
|
Bjerre
Joined: 08 Nov 2006 Posts: 99 Location: Kolding, Denmark
|
Posted: Mon Jul 23, 2007 9:34 pm Post subject: |
|
|
|
If you are using the Unity package I made, the way to access the variables is through the GetVariable function located in the ServerRead script.
Again if you use the above package find the GameObject named getVar. If you click on the attached script named GetVariables I have made an example where if you push the up key it will print the first value sent from Max/Msp, the line you are looking for is this:
script.GetVariable(0);
If you want the second value from Max you simply write something like script.GetVariable(1); and so on.
hope this information was useful, if not feel free to send an e-mail. |
|
| Back to top |
|
|
jbm
Joined: 26 Jul 2007 Posts: 2
|
Posted: Thu Jul 26, 2007 10:23 pm Post subject: |
|
|
|
Hello, All.
I've been working for a while on an interactive music composition app in java and max/msp. Lately I've been doing some interface work in Processing, but I'm kind of interested in something really immersive for the visual environment. It seems like a lot of the ideas I'm interested in would be a lot simpler to do in Unity than in Processing. Do any of you know whether Unity would be a good platform to create a visual environment from which to control a max/msp-based application?
I guess I'm just asking how much you think I could do in terms of two-way communication between Unity and Max. I'm guessing that, since it's just like any app that communicates with its gui over the network, that it's the same deal in Unity... But not being a Unity user, yet, I'm looking to find out whether this might an avenue worth pursuing.
Any and all thoughts appreciated.
cheers,
James. |
|
| Back to top |
|
|
m1interactive
Joined: 04 May 2007 Posts: 18 Location: Chicago
|
Posted: Thu Jul 26, 2007 10:30 pm Post subject: Interactive |
|
|
|
Sounds like you might be better using Jitter. Use it to get data from a camera or sensor, then apply it to a n MSP synth patch or something. Funny, I'm trying to go the other direction, sending motion data, extracted from camera movement to Unity. This way I can use Unity's graphic engine to build 3d worlds and have them controlled through Jitter (Max/MSP)
Now if we could only get motion tracking data directly through Unity itself... |
|
| Back to top |
|
|
jbm
Joined: 26 Jul 2007 Posts: 2
|
Posted: Fri Jul 27, 2007 12:10 am Post subject: |
|
|
|
Well, I'm using Processing right now, which can communicate with Max over the network. It's going okay this way, but it just sounds as though there would be a lot more "free" structure provided by Unity - everything has to be done basically by hand, from scratch, in Processing.
Besides that, I'm really interested in taking some of the general paradigms from game design and applying them to music representation and control. I think there's a lot of untapped potential there, but I just need to find the right platform for the job.
If anybody else has any comments or thoughts, I'd appreciate it. I think I'll download the trial anyway, but whatever info could help my decision would be great.
J. |
|
| Back to top |
|
|