author | cavaliet |
Mon, 20 Oct 2014 18:02:31 +0200 | |
changeset 48 | a7abfcfd7959 |
parent 21 | 89d235bcbbf3 |
child 54 | 31cea001a298 |
permissions | -rw-r--r-- |
0 | 1 |
#!/usr/bin/env python |
2 |
""" |
|
3 |
Example of a UDP txosc sender with Twisted. |
|
4 |
||
5 |
This example is in the public domain. |
|
6 |
""" |
|
7 |
||
8 |
import csv |
|
9 |
import sys |
|
10 |
import time |
|
11 |
||
12 |
from twisted.internet import reactor |
|
13 |
from txosc import osc |
|
14 |
from txosc import dispatch |
|
15 |
from txosc import async |
|
16 |
||
17 |
||
18 |
class UDPSenderApplication(object): |
|
19 |
""" |
|
20 |
Example that sends UDP messages. |
|
21 |
""" |
|
22 |
def __init__(self, port, host, address, rows): |
|
23 |
self.port = port |
|
24 |
self.host = host |
|
25 |
self.client = async.DatagramClientProtocol() |
|
26 |
self._client_port = reactor.listenUDP(0, self.client) |
|
27 |
self.rows = rows |
|
28 |
self.address = address |
|
29 |
reactor.callLater(0, self.send_messages) |
|
30 |
||
31 |
def _send(self, element): |
|
32 |
# This method is defined only to simplify the example |
|
33 |
self.client.send(element, (self.host, self.port)) |
|
34 |
print("Sent %s to %s:%d" % (element, self.host, self.port)) |
|
35 |
||
36 |
def send_messages(self): |
|
37 |
tc = 0 |
|
38 |
for row in self.rows: |
|
39 |
row_conv = [ osc.TimeTagArgument(float(row[0]))] + [osc.IntArgument(int(a)) for a in row[1:]] |
|
21 | 40 |
#time.sleep((row_conv[1].value-tc)/10**3) |
41 |
time.sleep(0.1) |
|
48
a7abfcfd7959
real time with piano roll and new category management
cavaliet
parents:
21
diff
changeset
|
42 |
#tc = row_conv[1].value |
0 | 43 |
self._send(osc.Message(self.address,*row_conv)) |
44 |
print("Goodbye.") |
|
45 |
reactor.callLater(0.1, reactor.stop) |
|
46 |
||
47 |
if __name__ == "__main__": |
|
48 |
||
49 |
with open(sys.argv[1], 'rU') as datafile: |
|
50 |
reader = csv.reader(datafile, delimiter=' ') |
|
48
a7abfcfd7959
real time with piano roll and new category management
cavaliet
parents:
21
diff
changeset
|
51 |
app = UDPSenderApplication(9090, "127.0.0.1", '/pianoroll/test_1/', list(reader)) |
0 | 52 |
|
53 |
reactor.run() |