root/bin/pkechoosc @ 1

Revision 1, 2.6 KB (checked in by anonymous, 6 years ago)

Imported old repos

  • Property svn:executable set to *
Line 
1#!/usr/bin/env python
2#
3#   Copyright (C) 2006 by Patrick Stinson                                 
4#   patrickkidd@gmail.com                                                   
5#                                                                         
6#   This program is free software; you can redistribute it and/or modify 
7#   it under the terms of the GNU General Public License as published by 
8#   the Free Software Foundation; either version 2 of the License, or     
9#   (at your option) any later version.                                   
10#                                                                         
11#   This program is distributed in the hope that it will be useful,       
12#   but WITHOUT ANY WARRANTY; without even the implied warranty of       
13#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         
14#   GNU General Public License for more details.                         
15#                                                                         
16#   You should have received a copy of the GNU General Public License     
17#   along with this program; if not, write to the                         
18#   Free Software Foundation, Inc.,                                       
19#   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. 
20#
21
22import sys
23import time
24import socket
25import threading
26import scosc
27from scosc import OSC
28
29
30class OSCEcho(threading.Thread):
31
32    _timeout = .1
33   
34    def __init__(self, port):
35        threading.Thread.__init__(self)       
36        self._running = False
37        self.socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
38        self.socket.bind(('', port))
39        self.socket.settimeout(self._timeout)
40
41    def quit(self):
42        self._running = False
43
44    def run(self):
45        self._running = True
46        try:
47            while self._running:
48                try:
49                    data, address = self.socket.recvfrom(2**12)
50                    print address
51                    OSC.hexDump(data)
52                    print scosc.decode(data)
53                except socket.timeout:
54                    pass
55        except KeyboardInterrupt, e:
56            pass
57
58
59def main():
60    import sys
61    print """This dumps the hex and ascii of OSC messages like SuperCollider"""
62
63    if '-h' in sys.argv:
64        help = """Usage: %s [port] """ % sys.argv[0]
65        print help
66        sys.exit()
67   
68    if len(sys.argv) == 2:
69        port = int(sys.argv[1])
70    else:
71        port = 57110
72
73    echoosc = OSCEcho(port)
74    echoosc.start()
75    print 'Hit enter to exit'
76    sys.stdin.read(1)
77    echoosc.quit()
78    echoosc.join()
79   
80if __name__ == '__main__':
81   main()
Note: See TracBrowser for help on using the browser.