³ò
”ö²Mc           @   sŽ  d  d k  l Z l Z d  d k l Z l Z l Z d  d k Z d  d k Z d  d k	 Z	 d  d k
 Z
 d  d k Z d  d k Z d  d k Z d  d k Z e e d ƒ o d  d k	 l Z n d  d k	 l Z e i d ƒ Z e e i d  ƒ d	 j  o d d d
 „ Z e e
 i _ n d e f d „  ƒ  YZ d e
 i f d „  ƒ  YZ d e
 i f d „  ƒ  YZ d d d „  ƒ  YZ d „  Z e d j o e ƒ  n d S(   iÿÿÿÿ(   t   Popent   PIPE(   t   environt   readt   getcwdNt   poll(   t   poll2(   R   s   [
]+i   gÍÌÌÌÌÌ@c         C   sA   d |  _  d |  _ t i ƒ  |  _ t i i |  d | d | ƒd  S(   Nt    t   sockt   map(   t   ac_in_buffert   ac_out_buffert   asynchatt   fifot   producer_fifot   asyncoret
   dispatchert   __init__(   t   selft   connR	   (    (    s   ./Pd.pyt   asynchat_monkey_init   s    		t   PdExceptionc           B   s   e  Z RS(    (   t   __name__t
   __module__(    (    (    s   ./Pd.pyR   #   s   t   PdSendc           B   sA   e  Z d d  „ Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   c         C   s,   t  i i |  d | ƒg  |  _ t |  _ d  S(   NR	   (   R   t
   async_chatR   t   _cachet   Falset   _success(   R   R	   (    (    s   ./Pd.pyR   '   s    	c         C   s8   t  |  _ g  } |  i D] } | |  i | ƒ q ~ d  S(   N(   t   TrueR   R   t   Send(   R   t   _[1]t   d(    (    s   ./Pd.pyt   handle_connect,   s    	c         C   s   |  i  ƒ  d  S(   N(   t   close(   R   (    (    s   ./Pd.pyt   handle_close0   s    c         C   s   d GH|  i  ƒ  d  S(   Ns3   PdSend: connection failed (win) or OOB data (linux)(   R"   (   R   (    (    s   ./Pd.pyt   handle_expt3   s    c         C   s'   |  i  t i t i ƒ |  i | ƒ d  S(   N(   t   create_sockett   sockett   AF_INETt   SOCK_STREAMt   connect(   R   t   addr(    (    s   ./Pd.pyt   Connect7   s    c         C   sc   |  i  oE t i i |  d i g  } | D] } | t | ƒ q' ~ ƒ d ƒ n |  i i | ƒ d  S(   Nt    s   ;
(   R   R   R   t   pusht   joint   strR   t   append(   R   t   dataR   R    (    (    s   ./Pd.pyR   ;   s    
EN(	   R   R   t   NoneR   R!   R#   R$   R+   R   (    (    (    s   ./Pd.pyR   &   s   				t	   PdReceivec           B   s;   e  Z d d d „ Z d „  Z d „  Z d „  Z d „  Z RS(	   s	   127.0.0.1irv  c         C   s¬   | |  _  t i i |  d | ƒd |  _ |  i d ƒ d |  _ t i d | ƒ |  _	 |  i
 |  i	 _ |  i	 i t i t i ƒ |  i	 i ƒ  |  i	 i | ƒ |  i	 i d ƒ d  S(   NR	   R   s   ;
i   (   t   _parentR   R   R   t   _ibuffert   set_terminatort   _remoteR   R   t   _serversockett   handle_accept_servert   handle_acceptR%   R&   R'   R(   t   set_reuse_addrt   bindt   listen(   R   t   parentt	   localaddrR	   (    (    s   ./Pd.pyR   B   s    			c         C   sc   |  i  i ƒ  } | o9 | \ } } | |  _ |  i  i ƒ  |  `  |  i | ƒ n d G|  i G| GHd  S(   Ns+   Dropped spurious PdReceive connect! socket:(   R8   t   acceptR7   R"   t
   set_sockett   _socket(   R   t   acceptedR   R*   (    (    s   ./Pd.pyR9   Q   s    	c         C   s   |  i  i |  i ƒ d  S(   N(   R4   R+   R7   (   R   (    (    s   ./Pd.pyR!   ^   s    c         C   s   |  i  | 7_  d  S(   N(   R5   (   R   R1   (    (    s   ./Pd.pyt   collect_incoming_dataa   s    c         C   sh   |  i  i d ƒ } d |  _  t |  i d | d d  ƒ } | o | |  | d ƒ n |  i i | ƒ d  S(   NR,   R   t   Pd_i    i   (   R5   t   splitt   getattrR4   R2   t	   PdMessage(   R   R1   t   method(    (    s   ./Pd.pyt   found_terminatord   s    	(   s	   127.0.0.1irv  N(   R   R   R2   R   R9   R!   RD   RJ   (    (    (    s   ./Pd.pyR3   A   s
   			t   Pdc           B   s˜   e  Z d  Z h  Z d e d d d g d e d „ Z d „  Z d „  Z d „  Z	 d „  Z
 d	 „  Z d
 „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   sj  
		Start Pure Data in a subprocess.
		
		>>> from time import time, sleep
		>>> from os import path, getcwd
		>>> 
		>>> start = time()
		>>> # launching pd
		>>> pd = Pd(nogui=False)
		>>> pd.Send(["test message", 1, 2, 3])
		>>> 
		>>> def Pd_hello(self, message):
		... 	print "Pd called Pd_hello(%s)" % message
		...
		>>> pd.Pd_hello = Pd_hello
		>>> 
		>>> sentexit = False
		>>> # running a bunch of stuff for up to 20 seconds
		>>> while time() - start < 20 and pd.Alive():
		... 	if time() - start > 0.5 and not sentexit:
		... 		pd.Send(["exit"])
		... 		sentexit = True
		... 	pd.Update()
		...
		...
		Pd called Pd_hello(['this', 'is', 'my', 'message', 'to', 'python'])
		untrapped message: ['this', 'is', 'another', 'message']
		untrapped stderr output: "connecting to port 30322"
		untrapped stderr output: "python-connected: 0"
		untrapped stderr output: "python-connected: 1"
		untrapped stderr output: "from-python: test message 1 2 3"
		untrapped stderr output: "closing audio..."
		untrapped stderr output: "pd_gui: pd process exited"
		untrapped stderr output: "closing MIDI..."...
		Pd died!
		>>> pd.Exit()
	iqv  s   python-interface-help.pdt   patchesc         C   sç  d |  _ t i d j o
 d } nH t i d j o
 d } n. t i d j o
 d } n t d t i ƒ ‚ | g }	 | o |	 i d ƒ n | o |	 i d	 ƒ n | o |	 i d
 ƒ |	 i | ƒ n | o |	 i d ƒ |	 i | ƒ n x( | D]  }
 |	 i d ƒ |	 i |
 ƒ qô W| o |	 | i d ƒ 7}	 n y4 t |	 d d d t d t d t i d j ƒ|  _	 Wn, t
 j
 o  t d | t ƒ  f ƒ ‚ n X| o | |  _ n h  |  _ t d |  i ƒ |  _ t |  d |  i ƒ|  _ d S(   sq  
		port - what port to connect to [netreceive] on.
		nogui - boolean: whether to start Pd with or without a gui. Defaults to nogui=True
		open - string: full path to a .pd file to open on startup.
		cmd - message to send to Pd on startup.
		path - an array of paths to add to Pd startup path.
		extra - a string containing extra command line arguments to pass to Pd.
		t   win32s   pd\bin\pd.exet   linux2t   pdt   darwins"   ./Pd.app/Contents/Resources/bin/pds7   Unknown Pd executable location on your platform ('%s').s   -stderrs   -noguis   -opens   -sends   -pathR,   t   stdint   stderrt   stdoutt	   close_fdss   Problem running `%s` from '%s'R	   N(   R2   t   connectCallbackt   syst   platformR   R0   RF   R    R   RO   t   OSErrorR   t   portt   _mapR   t   _pdSendR3   t
   _pdReceive(   R   RY   t   noguit   opent   cmdt   patht   extraRR   t   pdexet   argst   p(    (    s   ./Pd.pyR   •   sD    		


	 4	c         C   sÀ   t  d |  i ƒ |  i i ƒ  } |  i i ƒ  } | o@ g  } t i | ƒ D]! } | o | |  i | ƒ qI qI ~ n | o@ g  } t i | ƒ D]! } | o | |  i | ƒ q q ~ n d  S(   NR	   (	   R   RZ   RO   t   recvt   recv_errt   crRF   t
   CheckStartt   Error(   R   RQ   RR   R   t   tt   _[2](    (    s   ./Pd.pyt   UpdateÌ   s    @c         C   s   |  i  i | ƒ d S(   s’   
		Send an array of data to Pd.
		It will arrive at the [python-interface] object as a space delimited list.
		
		p.Send(["my", "test", "yay"])
		N(   R[   R   (   R   t   msg(    (    s   ./Pd.pyR   Õ   s    c         C   s   d G| GHd S(   s7   
		Override this method to receive messages from Pd.
		s   untrapped message:N(    (   R   R1   (    (    s   ./Pd.pyRH   Þ   s    c         C   s!   |  i  i | d |  i f ƒ d  S(   Ni    (   R[   R+   RY   (   R   R*   (    (    s   ./Pd.pyR+   ä   s    c         C   s   d | j o |  i  ƒ  n d  S(   Ns   _Start() called(   t	   PdStarted(   R   Rm   (    (    s   ./Pd.pyRh   ç   s    c         C   sq   | i  d ƒ } t |  d | d d ƒ } | o | | ƒ n0 | |  i j o |  i | ƒ  n d | d GHd S(   sR   
		Override this to catch anything sent by Pd to stderr (e.g. [print] objects).
		R,   t   Error_i    s   untrapped stderr output: "t   "N(   RF   RG   R2   t   errorCallbacks(   R   t   errort   errorsRI   (    (    s   ./Pd.pyRi   ë   s    c         C   s   d  |  _ |  i ƒ  d  S(   N(   R2   RO   t   PdDied(   R   (    (    s   ./Pd.pyt   Deadø   s    	c         C   s   d S(   s4    Override this to catch the definitive start of Pd. N(    (   R   (    (    s   ./Pd.pyRn   ü   s    c         C   s	   d GHd S(   s7   
		Override this to catch the Pd subprocess exiting.
		s   Pd died!N(    (   R   (    (    s   ./Pd.pyRt      s    c         C   s#   t  |  i o |  i i ƒ  d j ƒ S(   s5   
		Check whether the Pd subprocess is still alive.
		i    (   t   boolRO   R   (   R   (    (    s   ./Pd.pyt   Alive  s    c         C   s’   |  i  ƒ  of t i d j o, d d k } | i t |  i i ƒ d ƒ qs d d k l	 } | |  i i
 t i ƒ n |  i o |  i i ƒ  n d S(   s$   
		Kill the Pd process right now.
		RM   iÿÿÿÿN(   t   kill(   Rw   RV   RW   t   win32apit   TerminateProcesst   intRO   t   _handlet   osRx   t   pidt   signalt   SIGINTt   wait(   R   Ry   Rx   (    (    s   ./Pd.pyt   Exit  s     
N(   R   R   t   __doc__Rq   R   R2   R   Rl   R   RH   R+   Rh   Ri   Ru   Rn   Rt   Rw   R‚   (    (    (    s   ./Pd.pyRK   n   s   %!7												c          C   s#   d d  k  }  |  i d |  i ƒ d  S(   Niÿÿÿÿt   optionflags(   t   doctestt   testmodt   ELLIPSIS(   R…   (    (    s   ./Pd.pyt   _test  s    t   __main__(    (    t   monkeysubprocessR    R   R}   R   R   R   RV   R   R   R   R&   t   selectt   ret   hasattrR   R   t   compileRg   t   floatt   versionR2   R   R   R   t	   ExceptionR   R   R3   RK   Rˆ   R   (    (    (    s   ./Pd.pys   <module>   s.   -¯	