playMaker

Author Topic: Can playmaker support OSC? like touchosc?  (Read 17327 times)

kyy921

  • Junior Playmaker
  • **
  • Posts: 50
    • View Profile
    • 上海杉蔓数字科技
Can playmaker support OSC? like touchosc?
« on: February 12, 2012, 10:05:48 PM »
some times I wanne control my game in a wifi environment , I like to use touchosc  http://hexler.net/software/touchosc , it can control like vj  vvvv, Can playmaker make some action to connect playmaker with osc?? 

kyy921

  • Junior Playmaker
  • **
  • Posts: 50
    • View Profile
    • 上海杉蔓数字科技
Re: Can playmaker support OSC? like touchosc?
« Reply #1 on: February 12, 2012, 10:08:29 PM »
http://uscript.net/forum/viewtopic.php?f=21&t=1089  uscript have some thing like this

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 13638
  • Official Playmaker Support
    • View Profile
Re: Can playmaker support OSC? like touchosc?
« Reply #2 on: February 12, 2012, 11:27:23 PM »
Hi,

 Since PLaymaker use c# for each of its actions, it is possible to implement custom actions to support OSC messages.

 I haven't seen any such action on the forum yet tho. But you can definitely write some. I looked a some of the code involved to work with OSC and it looks completely feasible.

 I have unfortunatly no time to play around with this. If you can't get anywhere, and no one stepped in with some custom actions. Just post on this thread again when playmaker will be out of beta.

 Bye,

 Jean

elbows

  • Playmaker Newbie
  • *
  • Posts: 15
    • View Profile
Re: Can playmaker support OSC? like touchosc?
« Reply #3 on: February 18, 2012, 01:45:35 PM »
I would be very happy to see OSC done properly in PlayMaker. Im not really good enough at programming to do this stuff nicely yet. I have managed to tie PlayMaker together with incoming OSC messages using one of the existing Unity OSC scripts, but my method is very basic. I am simply using a script to detect specific OSC messages and use floats or booleans from OSC to set the values of specific Playmaker variables. I can then use PlayMaker logic to check for these values changing, and use the values to control other things using PlayMaker actions in the normal way. But I still have to go into my script file and code all of the OSC messages I want to listen for, and tell it what FSM & variable to target. A proper solution would enable you to do all of that within PlayMaker, and could even feature a learn mode so the PlayMaker action could be told what OSC message to use by listening to incoming OSC messages in edit mode rather than the user having to type in the OSC message manually. Im not sure we'd need support for every possible variable type that OSC can send, floats and booleans would probably be enough for most uses, although the ability to handle OSC messages that contain more than one variable would be useful (e.g. a message like /xypad/1/ 123.4 13.1 )

If an additional incentive for someone to write this is required then I would be prepared to put up a bounty of around £100 for a nice solution, but I've no idea if this will be enough to encourage someone to do this.

elbows

  • Playmaker Newbie
  • *
  • Posts: 15
    • View Profile
Re: Can playmaker support OSC? like touchosc?
« Reply #4 on: February 18, 2012, 02:03:37 PM »
Actually having now seen how easy it was for someone to get it working with uscript Im probably going to have a little attempt at doing it properly myself now. First version is likely to be limited in some key ways but should still be a useful start. Wish me luck and I'll post later if I get anywhere :)

elbows

  • Playmaker Newbie
  • *
  • Posts: 15
    • View Profile
Re: Can playmaker support OSC? like touchosc?
« Reply #5 on: February 18, 2012, 02:09:14 PM »
Oh and by the way, to get the most out of OSC on something like the iPad I recommend the Lemur app rather than touchosc. Its not a cheap iOS app but its got plenty of features and is certainly cheap compared to the Jazzmutant Lemur OSC hardware version of a few years ago.

elbows

  • Playmaker Newbie
  • *
  • Posts: 15
    • View Profile
Re: Can playmaker support OSC? like touchosc?
« Reply #6 on: February 19, 2012, 09:59:43 AM »
I got it working :D

My approach so far involves having a GameObject with three scripts attached to it. The only thing the user needs to do with these scripts is to set the port variable on one of them to the port that you want to listen to OSC messages on.

Then in PlayMaker I have created an action where you set a string to the OSC Address Pattern you want that Action to work with (e.g. /slider1 ), and when a matching OSC message arrives its value will be used to set a FSM float variable. This will happen for as long as that state is active. A FSM event is triggered when a message is received, so you can move to another state as soon as a message with a matching address pattern is received if you want to.

It seems to work quite well. I can have as many of these OSC Actions active as I want, listening to many different OSC messages and updating many variables continuously or as triggers to change state. Limitations at this point, which I probably won't get round to fixing myself at the moment, are:

It will only listen to one port (but this is fairly normal for OSC apps)
A game object with scripts on is also required rather than being a pure PlayMaker solution (a purer way would involve moving more script code to another PlayMaker action that you would use just once to start the OSC port listening stuff)
You have to be careful not to have more than one active OSC Action listening for the same OSC Address Pattern at once (its fine to have more than one action within a single FSM listening for the same OSC Address Pattern, so long as they are not both active at the same time, e.g. if they are attached to different states. But if you were listening for the same Address Pattern in several different FSMs where both actions could be active at the same time, there will probably be problems with my system).

Anyway my initial test OSC Action only uses the first OSC message value, and treats it as a float, so I should probably try to add a bit more functionality to this before sharing it. But I will still try to post it later today :)


kyy921

  • Junior Playmaker
  • **
  • Posts: 50
    • View Profile
    • 上海杉蔓数字科技
Re: Can playmaker support OSC? like touchosc?
« Reply #7 on: February 28, 2012, 10:59:18 AM »
hope to see your action :)

elbows

  • Playmaker Newbie
  • *
  • Posts: 15
    • View Profile
Re: Can playmaker support OSC? like touchosc?
« Reply #8 on: February 29, 2012, 12:43:23 PM »
Sorry for the delay, I got distracted by other things and I tend to need to motivation of others responding to get me to keep going!

I'm not sure when I will get the time to polish this thing as much as I would really like, so I'll probably end up sharing it in a less than completed state, as its better than nothing and won't take much work by someone else to improve if necessary.

elbows

  • Playmaker Newbie
  • *
  • Posts: 15
    • View Profile
Re: Can playmaker support OSC? like touchosc?
« Reply #9 on: February 29, 2012, 02:30:12 PM »
OK here is the unpolished version. I post it here for someone to check before drawing more attention to it, in case someone knows a way to quickly make it better or spots some other issue. All the detail I gave in my post from a while ago still applies, i.e. the major flaw in this version is that you can only listen for a particular OSC address pattern (such as /slider1 or slider/1/) in one active state at a time. This flaw will not matter for some scenarios, but is a pain in other situations and probably breaks part of the ethos of PlayMaker. The simplest way to avoid getting into trouble due to this issue is to stick to the following rule:

Keep your listening for a specific address pattern to a single FSM. You can have it on multiple states within that FSM, just not different FSMS where more than one of the states listening for a particular address may be active at once.

So it would be fine to have a FSM listening for /slider1 and another FSM listening for /slider2
It would be fine to have multiple states within a single FSM listening for /slider1
But do not have 2 different FSMs both listening for /slider1 or /slider2 or anything else.

Another way to put this:

If you want to have more than one FSM making use of the same incoming OSC value, create a single FSM that deals with the OSC and stores it into global PlayMaker variables, then access those from your other FSMs.

Also please note that so far I have only made actions that capture either 1 or 3 float values from an OSC message. Non-floats and different quantity of values will require new PlayMaker Actions, but most of these will be very easy to make by looking at my float examples.

With that disclaimer out of the way, I will post the files shortly.

elbows

  • Playmaker Newbie
  • *
  • Posts: 15
    • View Profile
Re: Can playmaker support OSC? like touchosc?
« Reply #10 on: February 29, 2012, 02:53:48 PM »
EDIT - Please see page two of this thread for a newer version of all files except UDPPacketIO.cs which hasn't changed since this post was first written.

Files should be attached.

Put Osc.cs and UDPPacketIO.cs files into your /Plugins folder (create this folder if it doesn't already exist in your project).

Put PMOSC.cs into your /Scripts folder (again create this folder if it does not already exist in your project)

You may be able to put the above files somewhere else if you prefer, but script compilation order issues may arise so be aware of that stuff before putting these files elsewhere.

Put GetOscFloat.cs and GetOscVector3 into your PlayMaker/Actions folder.

Create an Empty GameObject in your scene and call it OSC
Attach Osc.cs, UDPPacketIO.cs and PMOSC.cs scripts to this game object
Set the port that you would like to listen to OSC messages on by changing the 'Listener Port' variable of the PMOSC Script using the unity inspector.
If you like, drag the OSC GameObject to the Project Window to create a prefab for future use in other scenes.

Now in a playmaker FSM, add to a state one of the new actions that you will find in the Action Browser in the 'OpenSoundControl' section.
Choose a FSM variable that will store the OSC message float value
Type in the Osc Message Address that you want to listen for (for example /1/fader1)
You do not need to specify an Osc Game Object unless you called yours something other than OSC
If you want to move to a different state as soon as a matching OSC message is received, select an event to trigger in the 'Osc Message Event' section.

Tip: If you are wanting to process a continual fast stream of changing OSC values related to a specific message address, don't change state every time a message is received. Rather, do something with the resulting FSM float variable in the same state as the OSC listener state is attached to. e.g. follow the above instructions, make sure you have created a float variable in your FSM and told the OSC Action to use it, and then add another action to the same state which will affect a game object in unity in some way. e.g. don't set a 'Osc message event', add a 'Set Position' action below the Get Osc Float action, and tell it to use your variable to change the X position of a game object.

I probably made everything sound more complicated than it really is by trying to explain it thoroughly, but there you go. The main OSC scripts are attached to this post, the PlayMaker actions themselves will follow very shortly.

EDIT - most attachments removed as newer versions are available in a later post
« Last Edit: March 02, 2012, 01:34:22 PM by elbows »

elbows

  • Playmaker Newbie
  • *
  • Posts: 15
    • View Profile
Re: Can playmaker support OSC? like touchosc?
« Reply #11 on: February 29, 2012, 03:02:01 PM »
Here is the Action for receiving a single float from an OSC message. I haven't tested the one that captures 3 floats from a message yet, so I won't post that straight away.

EDIT - attachment removed as a newer version is available in a later post
« Last Edit: March 02, 2012, 01:34:44 PM by elbows »

elbows

  • Playmaker Newbie
  • *
  • Posts: 15
    • View Profile
Re: Can playmaker support OSC? like touchosc?
« Reply #12 on: February 29, 2012, 03:59:55 PM »
OK managed to find a device I could use to spit out OSC messages that have three floats so that I could test this action, and it seems to work so here it is:

(for reference I used a 3DConnexion SpaceNagivator device with OSCulator software to test this)

This particular action turns OSC message that have 3 float values into a PlayMaker Vector3 variable but it would be trivial to store them as 3 separate floats if thats what you wanted.

EDIT - attachment removed as a newer version is available in a later post
« Last Edit: March 02, 2012, 01:34:59 PM by elbows »

kyy921

  • Junior Playmaker
  • **
  • Posts: 50
    • View Profile
    • 上海杉蔓数字科技
Re: Can playmaker support OSC? like touchosc?
« Reply #13 on: March 01, 2012, 07:38:09 AM »
It works well! great!!! thank you elbows!!!

kyy921

  • Junior Playmaker
  • **
  • Posts: 50
    • View Profile
    • 上海杉蔓数字科技
Re: Can playmaker support OSC? like touchosc?
« Reply #14 on: March 01, 2012, 08:04:38 AM »
if you take 2 get osc float in the same fsm seen have some problem, have you try control something with the xy-pad mode ? using vector3??