Home Forums Tips & Techniques Script to rewrite OSC for Kyma

Tagged: 

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #1029
    Cristian Vogel
    Participant

      I work with OSC a lot mostly for communicating between apps and code, rather than external controllers.

      I would like to share a script that I created during my research residency at ZKM earlier this year, useful for rewriting from standard OSC message syntax to Kyma widgets – directly in the Kyma signal flow.

      This can be very handy when working with a large OSC protocol, that has many repeated messages, for example the Sonic Emotions Wave I wavefield synthesis system or Iannix gesture sequencer.  You can copy and paste a long list directly into the script.

      Use this in a Script Sound and it will create widgets for you with the correct OSC formatting, contained in an array called ?IncomingOSCMessagesRewrittenForKyma 

      You will then need to collect this array using a  SyntheticSpectrumFromArray or (if you are a NeverEngineLabs subscriber ) our ArrayToGlobal Controllers Class.

      Good luck!

       

      “### Rewrite OSC for Kyma Widgets
      ## # (c) 2016 neverenginelabs.com
      ###

      | OSCMessagesRaw rewriter OSCMessagesRewrittenForKyma |

      OSCMessagesRaw := #(
      “################################
      Add your list of addresses below this line
      enclosed in single quotes.
      Kyma recognises float arguments over OSC
      therefore add an ‘f’ seperated by spaces for each argument and you will get a seperate
      widget for each message, as required by the Kyma protocol
      ################################”

      ‘/position/x’
      ‘/position/xyz f f f’
      ‘/position/ad f f’

      ).

      rewriter:=
      [:inputList |
      | result |
      result := OrderedCollection new.
      inputList do: [:message |
      | stem argCount  |
      stem := (‘osc_’&(message copyFrom: 2 to: message size) copyReplaceAll: #($/) with: #($_)).

      argCount := message occurrencesOf: $f.
      (argCount > 0) ifTrue: [
      (1 to: argCount) do: [:n |
      stem := (stem copyUpTo: $ )&’__’&n.
      result add: (stem asHotValue).
      ]
      ] ifFalse: [    result add: (stem asHotValue).]
      ].
      result
      ].

      OSCMessagesRewrittenForKyma := rewriter value: OSCMessagesRaw.

      (inputs at: 1)
      start: 0 s
      IncomingOSCMessagesRewrittenForKyma: OSCMessagesRewrittenForKyma

      #1030
      Cristian Vogel
      Participant

        I made a little mistake in the code posted above… but seems like the forum won’t let me edit my post. The rewrite block should read:

         

        rewriter:=
        [:inputList |
        | result |
        result := OrderedCollection new.
        inputList do: [:message |
        | stem argCount  |
        stem := (‘osc_’&(message copyFrom: 2 to: message size) copyReplaceAll: #($/) with: #($_)).

        argCount := message occurrencesOf: $f.
        (argCount > 0) ifTrue: [
        (1 to: argCount) do: [:n | |
        arg |
        arg := (stem copyUpTo: $ )&’__’&n.
        result add: (arg asHotValue).
        ]
        ] ifFalse: [    result add: (stem asHotValue).]
        ].
        result
        ].

         

      Viewing 2 posts - 1 through 2 (of 2 total)
      • You must be logged in to reply to this topic.