Sampler in ChucK
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

103 行
3.1KB

  1. """ Basic module to ease the use of pyOSC module https://trac.v2.nl/wiki/pyOSC
  2. you must have pyOSC installed for this to run.
  3. This is meant to be used by students or newies that are starting to experiment with OSC. If you are an advanced user
  4. you probably want to bypass this module and use directly pyOSC, we have some examples of very simple use in our website.
  5. Check the pyOSC website for more documentation.
  6. License : LGPL
  7. This library is free software; you can redistribute it and/or
  8. modify it under the terms of the GNU Lesser General Public
  9. License as published by the Free Software Foundation; either
  10. version 2.1 of the License, or (at your option) any later version.
  11. This library 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 GNU
  14. Lesser General Public License for more details.
  15. You should have received a copy of the GNU Lesser General Public
  16. License along with this library; if not, write to the Free Software
  17. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. """
  19. try :
  20. from OSC import *
  21. except :
  22. print "Warning!!! you must have pyOSC installed -> https://trac.v2.nl/wiki/pyOSC"
  23. import threading
  24. basic_client = 0
  25. basic_server = 0
  26. st = 0
  27. def printing_handler(addr, tags, data, source):
  28. print "---"
  29. print "received new osc msg from %s" % getUrlStr(source)
  30. print "with addr : %s" % addr
  31. print "typetags :%s" % tags
  32. print "the actual data is : %s" % data
  33. print "---"
  34. def initOSCClient(ip='127.0.0.1', port=9000) :
  35. global basic_client
  36. basic_client = OSCClient()
  37. basic_client.connect( (ip,port) )
  38. def initOSCServer(ip='127.0.0.1', port=9001, mode=0) :
  39. """ mode 0 for basic server, 1 for threading server, 2 for forking server
  40. """
  41. global basic_server, st
  42. if mode == 0 :
  43. basic_server = OSCServer( (ip ,port) ) # basic
  44. elif mode == 1 :
  45. basic_server = ThreadingOSCServer( (ip ,port) ) # threading
  46. elif mode == 2 :
  47. basic_server = ForkingOSCServer( (ip ,port) ) # forking
  48. basic_server.addDefaultHandlers()
  49. st = threading.Thread( target = basic_server.serve_forever )
  50. st.start()
  51. def setOSCHandler(address="/print", hd=printing_handler) :
  52. basic_server.addMsgHandler(address, hd) # adding our function
  53. def closeOSC() :
  54. if basic_client is not 0 : basic_client.close()
  55. if basic_server is not 0: basic_server.close()
  56. if st is not 0: st.join()
  57. def reportOSCHandlers() :
  58. print "Registered Callback-functions are :"
  59. for addr in basic_server.getOSCAddressSpace():
  60. print addr
  61. def sendOSCMsg( address='/print', data=[] ) :
  62. m = OSCMessage()
  63. m.setAddress(address)
  64. for d in data :
  65. m.append(d)
  66. basic_client.send(m)
  67. def createOSCBundle() : # just for api consistency
  68. return OSCBundle()
  69. def sendOSCBundle(b):
  70. basic_client.send(b)
  71. def createOSCMsg(address='/print', data=[]) :
  72. m = OSCMessage()
  73. m.setAddress(address)
  74. for d in data :
  75. m.append(d)
  76. return m