Last active
December 23, 2016 11:21
-
-
Save watakemi725/eaefb5197699e753f52a1f94b5e0f0d5 to your computer and use it in GitHub Desktop.
iPod20台を通信/制御/連携してみた【Max × Swift × OSC】 ref: http://qiita.com/watakemi725/items/b8090c7f09de68516f19
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <ifaddrs.h> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | |
} | |
} | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)") | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let myIPaddress = getIFAddresses()[0] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment