OSC with special characters

Post your questions here and we'll all try to help.
elgarf
Posts: 287
Joined: Sun Sep 13, 2015 05:52

Re: OSC with special characters

Post by elgarf »

Hi,

Looks like processing on windows works with win-1251 codepage :roll:

Here is my sketch. I'm not very experienced in Java, so it can be ugly =)

Code: Select all

import netP5.*;
import oscP5.*;
import java.nio.charset.*;


class OscMessageUTF extends OscMessage
{   
    public OscMessageUTF( final String theAddrPattern ) {
      super( theAddrPattern , new Object[ 0 ] );
    }  
  
    public OscMessage addUTF( final String theValue ) {
      _myTypetag = Bytes.append( _myTypetag , new byte[] { 0x73 } );
      //string must be in UTF-8
      final byte[] myString = theValue.getBytes(Charset.forName("UTF-8"));
      _myData = Bytes.append( _myData , myString , new byte[ align( myString.length ) ] );
      _myArguments = increase( 1 );
      _myArguments[ _myArguments.length - 1 ] = theValue;
      return this;
    }
}


OscP5 osc = new OscP5( this , 12000); //<>//
NetAddress remote = new NetAddress("127.0.0.1", 7000);

OscMessageUTF message = new OscMessageUTF("/composition/layers/67/clips/1/video/source/blocktextgenerator/text/params/lines");
message.addUTF("hüpfen");
osc.send(message, remote);   
I've extended OscMessage class with addUTF method, because I don't know how to edit packages.

Code: Select all

theValue.getBytes(Charset.forName("UTF-8"));
Do the trick.

Post Reply