ExistentialAudio / SwiftOSC

SwiftOSC is an Open Sound Control client and server framework written in Swift.
MIT License
270 stars 51 forks source link

Sending multiple messages but in concise way #17

Closed enzyme69 closed 6 years ago

enzyme69 commented 6 years ago

Probably more like a basic Swift question, but anyhow maybe you have a good tips.

Supposedly there are thousands of vertices XYZ position (exactly that) and I need to send message via OSC.

        var mymessage:[Float] = []

        for data in dataY {
            mymessage.append(data.x)
            mymessage.append(data.y)
            mymessage.append(data.z)
        }

        let message = OSCMessage( OSCAddressPattern("/hello/iPhoneX"),
                                  mymessage[0],
                                  mymessage[1],
                                  mymessage[2],
                                  mymessage[3],
                                  mymessage[4],
                                  mymessage[5],
                                  ..... 
        )

Would not there be a way to just to do this:

        let message = OSCMessage( OSCAddressPattern("/hello/iPhoneX"),
                                  {all the messages unpacked into float separated by space}
)
devinroth commented 6 years ago

You could always do this.

var message = OSCMessage( OSCAddressPattern("/hello/iPhoneX")) for data in dataY { message.add(data.x) message.add(data.y) message.add(data.z) }

And since you made a valid point I added a new overload init for OSCMessage that accepts arrays. It's currently in the develop branch.

You can now do this.

let message = OSCMessage( OSCAddressPattern("/hello/iPhoneX"), mymessage)

enzyme69 commented 6 years ago

Thanks Devin!