This file is indexed.

/usr/share/pyshared/pyolib/opensndctrl.py is in python-pyo 0.6.8-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
"""
Objects to manage values on an Open Sound Control port.

OscSend takes the first value of each buffersize and send it on an
OSC port.

OscReceive creates and returns audio streams from the value in its 
input port.

The audio streams of these objects are essentially intended to be
controls and can't be sent to the output soundcard.

"""

"""
Copyright 2010 Olivier Belanger

This file is part of pyo, a python module to help digital signal
processing script creation.

pyo is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

pyo is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with pyo.  If not, see <http://www.gnu.org/licenses/>.
"""
import sys
from _core import *
from _maps import *
from types import IntType, ListType

######################################################################
### Open Sound Control
######################################################################
class OscSend(PyoObject):
    """
    Sends values over a network via the Open Sound Control protocol.

    Uses the OSC protocol to share values to other softwares or other 
    computers. Only the first value of each input buffersize will be 
    sent on the OSC port.

    :Parent: :py:class:`PyoObject`

    :Args:

        input : PyoObject
            Input signal.
        port : int
            Port on which values are sent. Receiver should listen on the 
            same port.
        address : string
            Address used on the port to identify values. Address is in 
            the form of a Unix path (ex.: '/pitch').
        host : string, optional
            IP address of the target computer. The default, '127.0.0.1', 
            is the localhost.

    .. note::

        The out() method is bypassed. OscSend's signal can not be sent 
        to audio outs.
        
        OscSend has no `mul` and `add` attributes.

    >>> s = Server().boot()
    >>> s.start()
    >>> a = Sine(freq=[1,1.5], mul=[100,.1], add=[600, .1])
    >>> b = OscSend(a, port=10001, address=['/pitch','/amp'])
    
    """
    def __init__(self, input, port, address, host="127.0.0.1"):
        PyoObject.__init__(self)
        self._input = input
        self._in_fader = InputFader(input)
        in_fader, port, address, host, lmax = convertArgsToLists(self._in_fader, port, address, host)
        self._base_objs = [OscSend_base(wrap(in_fader,i), wrap(port,i), wrap(address,i), wrap(host,i)) for i in range(lmax)]

    def setInput(self, x, fadetime=0.05):
        """
        Replace the `input` attribute.

        :Args:

            x : PyoObject
                New signal to process.
            fadetime : float, optional
                Crossfade time between old and new input. Defaults to 0.05.

        """
        self._input = x
        self._in_fader.setInput(x, fadetime)
            
    def out(self, chnl=0, inc=1, dur=0, delay=0):
        return self.play(dur, delay)

    def setMul(self, x):
        pass
        
    def setAdd(self, x):
        pass    

    def setBufferRate(self, x):
        """
        Sets how many buffers to wait before sending a new value.
        
        :Args:

            x : int
                Changes the data output frequency in multiples of the buffer size.
                Should be greater or equal to 1.

        """
        [obj.setBufferRate(x) for obj in self._base_objs]

    @property
    def input(self):
        """PyoObject. Input signal.""" 
        return self._input
    @input.setter
    def input(self, x): self.setInput(x)
         
class OscReceive(PyoObject):
    """
    Receives values over a network via the Open Sound Control protocol.

    Uses the OSC protocol to receive values from other softwares or 
    other computers. Get a value at the beginning of each buffersize 
    and fill its buffer with it.

    :Parent: :py:class:`PyoObject`

    :Args:

        port : int
            Port on which values are received. Sender should output on 
            the same port. 
            
            Unlike OscSend object, there can be only one port per OscReceive 
            object. 
            
            Available at initialization time only.
        address : string
            Address used on the port to identify values. Address is in 
            the form of a Unix path (ex.: '/pitch').

    .. note::

        Audio streams are accessed with the `address` string parameter. 
        The user should call :

        OscReceive['/pitch'] to retreive stream named '/pitch'.

        The out() method is bypassed. OscReceive's signal can not be sent 
        to audio outs.

    >>> s = Server().boot()
    >>> s.start()
    >>> a = OscReceive(port=10001, address=['/pitch', '/amp'])
    >>> b = Sine(freq=a['/pitch'], mul=a['/amp']).mix(2).out()

    """

    def __init__(self, port, address, mul=1, add=0):
        PyoObject.__init__(self, mul, add)
        if type(port) != IntType:
            print >> sys.stderr, 'TypeError: "port" argument of %s must be an integer.\n' % self.__class__.__name__
            exit()
        address, mul, add, lmax = convertArgsToLists(address, mul, add)
        self._address = address
        self._mainReceiver = OscReceiver_base(port, address)
        self._base_objs = [OscReceive_base(self._mainReceiver, wrap(address,i), wrap(mul,i), wrap(add,i)) for i in range(lmax)]

    def __getitem__(self, i):
        if type(i) == type(''):
            return self._base_objs[self._address.index(i)]
        elif i < len(self._base_objs):
            return self._base_objs[i]
        else:
            print "'i' too large!"

    def getAddresses(self):
        """
        Returns the addresses managed by the object.

        """
        return self._address

    def addAddress(self, path, mul=1, add=0):
        """
        Adds new address(es) to the object's handler.

        :Args:

            path : string or list of strings
                New path(s) to receive from.
            mul : float or PyoObject
                Multiplication factor. Defaults to 1.
            add : float or PyoObject
                Addition factor. Defaults to 0.

        """
        path, lmax = convertArgsToLists(path)
        mul, add, lmax2 = convertArgsToLists(mul, add)
        for i, p in enumerate(path):
            if p not in self._address:
                self._mainReceiver.addAddress(p)
                self._address.append(p)
                self._base_objs.append(OscReceive_base(self._mainReceiver, p, wrap(mul,i), wrap(add,i)))

    def delAddress(self, path):
        """
        Removes address(es) from the object's handler.

        :Args:

            path : string or list of strings
                Path(s) to remove.

        """
        path, lmax = convertArgsToLists(path)
        self._mainReceiver.delAddress(path)
        indexes = [self._address.index(p) for p in path]
        for ind in reversed(indexes):
            self._address.pop(ind)
            obj = self._base_objs.pop(ind)

    def setInterpolation(self, x):
        """
        Activate/Deactivate interpolation. Activated by default.

        :Args:

            x : boolean
                True activates the interpolation, False deactivates it.
        
        """
        [obj.setInterpolation(x) for obj in self._base_objs]

    def setValue(self, path, value):
        """
        Sets value for a given address.
        
        :Args:
        
            path : string
                Address to which the value should be attributed.
            value : float
                Value to attribute to the given address.

        """
        path, value, lmax = convertArgsToLists(path, value)
        for i in range(lmax):
            p = wrap(path,i)
            if p in self._address:
                self._mainReceiver.setValue(p, wrap(value,i))
            else:
                print 'Error: OscReceive.setValue, Illegal address "%s"' % p 

    def get(self, identifier=None, all=False):
        """
        Return the first sample of the current buffer as a float.

        Can be used to convert audio stream to usable Python data.

        Address as string must be given to `identifier` to specify
        which stream to get value from.

        :Args:

            identifier : string
                Address string parameter identifying audio stream.
                Defaults to None, useful when `all` is True to 
                retreive all streams values.
            all : boolean, optional
                If True, the first value of each object's stream
                will be returned as a list. Otherwise, only the value
                of the first object's stream will be returned as a float.
                Defaults to False.

        """
        if not all:
            return self._base_objs[self._address.index(identifier)]._getStream().getValue()
        else:
            return [obj._getStream().getValue() for obj in self._base_objs]
             
    def out(self, chnl=0, inc=1, dur=0, delay=0):
        return self.play(dur, delay)

class OscDataSend(PyoObject):
    """
    Sends data values over a network via the Open Sound Control protocol.

    Uses the OSC protocol to share values to other softwares or other 
    computers. Values are sent on the form of a list containing `types`
    elements.

    :Parent: :py:class:`PyoObject`

    :Args:

        types : str
            String specifying the types sequence of the message to be sent.
            Possible values are:
                - integer : "i"
                - long integer : "h"
                - float : "f"
                - double : "d"
                - string : "s"
                
            The string "ssfi" indicates that the value to send will be a list
            containing two strings followed by a float and an integer.
        port : int
            Port on which values are sent. Receiver should listen on the 
            same port.
        address : string
            Address used on the port to identify values. Address is in 
            the form of a Unix path (ex.: '/pitch').
        host : string, optional
            IP address of the target computer. The default, '127.0.0.1', 
            is the localhost.

    .. note::

        The out() method is bypassed. OscDataSend has no audio signal.

        OscDataSend has no `mul` and `add` attributes.

    >>> s = Server().boot()
    >>> s.start()
    >>> a = OscDataSend("fissif", 9900, "/data/test")
    >>> def pp(address, *args):
    ...     print address
    ...     print args
    >>> b = OscDataReceive(9900, "/data/test", pp)
    >>> msg = [3.14159, 1, "Hello", "world!", 2, 6.18]
    >>> a.send(msg)

    """
    def __init__(self, types, port, address, host="127.0.0.1"):    
        PyoObject.__init__(self)
        types, port, address, host, lmax = convertArgsToLists(types, port, address, host)
        self._base_objs = [OscDataSend_base(wrap(types,i), wrap(port,i), wrap(address,i), wrap(host,i)) for i in range(lmax)]
        self._addresses = {}
        for i, adr in enumerate(address):
            self._addresses[adr] = self._base_objs[i]
            
    def out(self, chnl=0, inc=1, dur=0, delay=0):
        return self.play(dur, delay)

    def setMul(self, x):
        pass

    def setAdd(self, x):
        pass    

    def getAddresses(self):
        """
        Returns the addresses managed by the object.

        """
        return self._addresses.keys()

    def addAddress(self, types, port, address, host="127.0.0.1"):
        """
        Adds new address(es) to the object's handler.

        :Args:

            types : str
                String specifying the types sequence of the message to be sent.
                Possible values are:
                    - integer : "i"
                    - long integer : "h"
                    - float : "f"
                    - double : "d"
                    - string : "s"

                The string "ssfi" indicates that the value to send will be a list
                containing two strings followed by a float and an integer.
            port : int
                Port on which values are sent. Receiver should listen on the 
                same port.
            address : string
                Address used on the port to identify values. Address is in 
                the form of a Unix path (ex.: '/pitch').
            host : string, optional
                IP address of the target computer. The default, '127.0.0.1', 
                is the localhost.

        """
        types, port, address, host, lmax = convertArgsToLists(types, port, address, host)
        objs = [OscDataSend_base(wrap(types,i), wrap(port,i), wrap(address,i), wrap(host,i)) for i in range(lmax)]
        self._base_objs.extend(objs)
        for i, adr in enumerate(address):
            self._addresses[adr] = objs[i]

    def delAddress(self, path):
        """
        Removes address(es) from the object's handler.

        :Args:

            path : string or list of strings
                Path(s) to remove.

        """
        path, lmax = convertArgsToLists(path)
        for p in path:
            self._base_objs.remove(self._addresses[p])
            del self._addresses[p]

    def send(self, msg, address=None):
        """
        Method used to send `msg` values as a list.
        
        :Args:
        
            msg : list
                List of values to send. Types of values in list
                must be of the kind defined of `types` argument
                given at the object's initialization.
            address : string, optional
                Address destination to send values. If None, values
                will be sent to all addresses managed by the object.
        
        """
        if address == None:
            [obj.send(msg) for obj in self._base_objs]
        else:
            self._addresses[address].send(msg)

class OscDataReceive(PyoObject):
    """
    Receives data values over a network via the Open Sound Control protocol.

    Uses the OSC protocol to receive data values from other softwares or 
    other computers. When a message is received, the function given at the
    argument `function` is called with the current address destination in 
    argument followed by a tuple of values.

    :Parent: :py:class:`PyoObject`

    :Args:

        port : int
            Port on which values are received. Sender should output on 
            the same port. Unlike OscDataSend object, there can be only 
            one port per OscDataReceive object. Available at initialization 
            time only.
        address : string
            Address used on the port to identify values. Address is in 
            the form of a Unix path (ex.: "/pitch"). There can be as many
            addresses as needed on a single port.
        function : callable
            This function will be called whenever a message with a known
            address is received. there can be only one function per 
            OscDataReceive object. Available at initialization time only.

    .. note::

        The header of the callable given at `function` argument must be in this form :

        def my_func(address, *args):
            ...

        The out() method is bypassed. OscDataReceive has no audio signal.

        OscDataReceive has no `mul` and `add` attributes.

    >>> s = Server().boot()
    >>> s.start()
    >>> a = OscDataSend("fissif", 9900, "/data/test")
    >>> def pp(address, *args):
    ...     print address
    ...     print args
    >>> b = OscDataReceive(9900, "/data/test", pp)
    >>> msg = [3.14159, 1, "Hello", "world!", 2, 6.18]
    >>> a.send(msg)

    """

    def __init__(self, port, address, function):
        PyoObject.__init__(self)
        if type(port) != IntType:
            print >> sys.stderr, 'TypeError: "port" argument of %s must be an integer.\n' % self.__class__.__name__
            exit()
        self._port = port
        if not callable(function):
            print >> sys.stderr, 'TypeError: "function" argument of %s must be callable.\n' % self.__class__.__name__
            exit()
        self._function = function
        self._address, lmax = convertArgsToLists(address)
        # self._address is linked with list at C level
        self._base_objs = [OscDataReceive_base(port, self._address, function)]

    def setMul(self, x):
        pass
        
    def setAdd(self, x):
        pass

    def out(self, chnl=0, inc=1, dur=0, delay=0):
        return self.play(dur, delay)

    def getAddresses(self):
        """
        Returns the addresses managed by the object.
        
        """
        return self._address

    def addAddress(self, path):
        """
        Adds new address(es) to the object's handler.
        
        :Args:
        
            path : string or list of strings
                New path(s) to receive from.

        """
        path, lmax = convertArgsToLists(path)
        for p in path:
            if p not in self._address:
                self._base_objs[0].addAddress(p)

    def delAddress(self, path):
        """
        Removes address(es) from the object's handler.

        :Args:

            path : string or list of strings
                Path(s) to remove.

        """
        path, lmax = convertArgsToLists(path)
        for p in path:
            index = self._address.index(p)
            self._base_objs[0].delAddress(index)

class OscListReceive(PyoObject):
    """
    Receives list of values over a network via the Open Sound Control protocol.

    Uses the OSC protocol to receive list of floating-point values from other 
    softwares or other computers. The list are converted into audio streams.
    Get values at the beginning of each buffersize and fill buffers with them.

    :Parent: :py:class:`PyoObject`

    :Args:

        port : int
            Port on which values are received. Sender should output on 
            the same port. Unlike OscSend object, there can be only one 
            port per OscListReceive object. Available at initialization time 
            only.
        address : string
            Address used on the port to identify values. Address is in 
            the form of a Unix path (ex.: '/pitch').
        num : int, optional
            Length of the lists in input. The object will generate `num` audio
            streams per given address. Available at initialization time only.
            This value can't be a list. That means all addresses managed by an 
            OscListReceive object are of the same length. Defaults to 8.

    .. note::

        Audio streams are accessed with the `address` string parameter. 
        The user should call :

        OscReceive['/pitch'] to retreive list of streams named '/pitch'.

        The out() method is bypassed. OscReceive's signal can not be sent 
        to audio outs.

    >>> s = Server().boot()
    >>> s.start()
    >>> # 8 oscillators
    >>> a = OscListReceive(port=10001, address=['/pitch', '/amp'], num=8)
    >>> b = Sine(freq=a['/pitch'], mul=a['/amp']).mix(2).out()

    """

    def __init__(self, port, address, num=8, mul=1, add=0):
        PyoObject.__init__(self, mul, add)
        if type(port) != IntType:
            print >> sys.stderr, 'TypeError: "port" argument of %s must be an integer.\n' % self.__class__.__name__
            exit()
        if type(num) != IntType:
            print >> sys.stderr, 'TypeError: "num" argument of %s must be an integer.\n' % self.__class__.__name__
            exit()
        self._num = num
        self._op_duplicate = self._num
        address, mul, add, lmax = convertArgsToLists(address, mul, add)
        self._address = address
        self._mainReceiver = OscListReceiver_base(port, address, num)
        self._base_objs = [OscListReceive_base(self._mainReceiver, wrap(address,i), j, wrap(mul,i), wrap(add,i)) for i in range(lmax) for j in range(self._num)]
        
    def __getitem__(self, i):
        if type(i) == type(''):
            first = self._address.index(i) * self._num
            return self._base_objs[first:first+self._num]
        elif i < len(self._base_objs):
            first = i * self._num
            return self._base_objs[first:first+self._num]
        else:
            print "'i' too large!"

    def getAddresses(self):
        """
        Returns the addresses managed by the object.

        """
        return self._address

    def addAddress(self, path, mul=1, add=0):
        """
        Adds new address(es) to the object's handler.

        :Args:

            path : string or list of strings
                New path(s) to receive from.
            mul : float or PyoObject
                Multiplication factor. Defaults to 1.
            add : float or PyoObject
                Addition factor. Defaults to 0.

        """
        path, lmax = convertArgsToLists(path)
        mul, add, lmax2 = convertArgsToLists(mul, add)
        for i, p in enumerate(path):
            if p not in self._address:
                self._mainReceiver.addAddress(p)
                self._address.append(p)
                self._base_objs.extend([OscListReceive_base(self._mainReceiver, p, j, wrap(mul,i), wrap(add,i)) for j in range(self._num)])

    def delAddress(self, path):
        """
        Removes address(es) from the object's handler.

        :Args:

            path : string or list of strings
                Path(s) to remove.

        """
        path, lmax = convertArgsToLists(path)
        self._mainReceiver.delAddress(path)
        indexes = [self._address.index(p) for p in path]
        for ind in reversed(indexes):
            self._address.pop(ind)
            first = ind * self._num
            for i in reversed(range(first, first+self._num)):
                obj = self._base_objs.pop(i)

    def setInterpolation(self, x):
        """
        Activate/Deactivate interpolation. Activated by default.

        :Args:

            x : boolean
                True activates the interpolation, False deactivates it.

        """
        [obj.setInterpolation(x) for obj in self._base_objs]

    def setValue(self, path, value):
        """
        Sets value for a given address.
        
        :Args:
        
            path : string
                Address to which the value should be attributed.
            value : list of floats
                List of values to attribute to the given address.

        """
        path, lmax = convertArgsToLists(path)
        for i in range(lmax):
            p = wrap(path,i)
            if p in self._address:
                if type(value[0]) == ListType:
                    val = wrap(value,i)
                else:
                    val = value
                if len(val) == self._num:
                    self._mainReceiver.setValue(p, val)
                else:
                    print 'Error: OscListReceive.setValue, value must be of the same length as the `num` attribute.'
            else:
                print 'Error: OscListReceive.setValue, Illegal address "%s"' % p 

    def get(self, identifier=None, all=False):
        """
        Return the first list of samples of the current buffer as floats.

        Can be used to convert audio stream to usable Python data.

        Address as string must be given to `identifier` to specify
        which stream to get value from.

        :Args:

            identifier : string
                Address string parameter identifying audio stream.
                Defaults to None, useful when `all` is True to 
                retreive all streams values.
            all : boolean, optional
                If True, the first list of values of each object's stream
                will be returned as a list of lists. Otherwise, only the 
                the list of the object's identifier will be returned as a 
                list of floats. Defaults to False.

        """
        if not all:
            first = self._address.index(identifier) * self._num
            return [obj._getStream().getValue() for obj in self._base_objs[first:first+self._num]]
        else:
            outlist = []
            for add in self._address:
                first = self._address.index(add) * self._num
                l = [obj._getStream().getValue() for obj in self._base_objs[first:first+self._num]]
                outlist.append(l)
            return outlist

    def out(self, chnl=0, inc=1, dur=0, delay=0):
        return self.play(dur, delay)