Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
iPod20台を通信/制御/連携してみた【Max × Swift × OSC】 ref: http://qiita.com/watakemi725/items/b8090c7f09de68516f19
import UIKit
//デリゲートまわりでF53OSCPacketDestinationの追加
class OscRecieveViewController: UIViewController,F53OSCPacketDestination {
//osc受信のためのoscServerの初期化
let oscServer = F53OSCServer.init()
override func viewDidLoad() {
super.viewDidLoad()
//portの指定など
oscServer.port = 3333
oscServer.delegate = self
if oscServer.startListening() {
print("Listening for messages on port \(oscServer.port)")
} else {
print("Error: Server was unable to start listening on port \(oscServer.port)")
}
}
//OSC受信するためのメソッド
func takeMessage(message: F53OSCMessage!) {
print(message)
//OSCmessageによる比較
if message.addressPattern == "/value" {
//OSCargumentsによる比較
if message.arguments[0] as! Int == 123{
print("hello 123")
}else if message.arguments[0] as! Int == 321{
print("hello 321")
}
}
}
}
import UIKit
class OscSendViewController: UIViewController {
//osc送信のためのoscClientの初期化
let oscClient = F53OSCClient.init()
override func viewDidLoad() {
super.viewDidLoad()
//OSCを送りたい先のIPアドレスを指定
oscClient.host = "192.000.0.000"
//贈りたい先のport番号を指定
oscClient.port = 3333
}
@IBAction func sendOSC(){
//123というメッセージをOSCで送信
self.sendMessage(oscClient, addressPattern: "/value", arguments: [123])
//複数の値を送る場合はarguments:[123,231,312]
}
//osc送信のためのメソッド
func sendMessage(client: F53OSCClient, addressPattern: String, arguments: [AnyObject]) {
let message = F53OSCMessage(addressPattern: addressPattern, arguments: arguments)
client.sendPacket(message)
print("Sent '\(message)' to \(client.host):\(client.port)")
}
}
let myIPaddress = getIFAddresses()[0]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment