~ubuntu-branches/ubuntu/quantal/python-pyo/quantal

« back to all changes in this revision

Viewing changes to pyolib/_core.py

  • Committer: Package Import Robot
  • Author(s): Tiago Bortoletto Vaz
  • Date: 2012-07-03 23:45:41 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20120703234541-jh5jg00lvljnwq8m
Tags: 0.6.2-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
from subprocess import call
24
24
from distutils.sysconfig import get_python_lib
25
25
 
26
 
PYO_VERSION = '0.6.1'
 
26
PYO_VERSION = '0.6.2'
27
27
 
28
28
import __builtin__
29
29
if hasattr(__builtin__, 'pyo_use_double'):
30
30
    import pyo64 as current_pyo
31
31
    from _pyo64 import *
32
 
    print "pyo version %s (uses double precision)" % PYO_VERSION
33
32
else:    
34
33
    import pyo as current_pyo
35
34
    from _pyo import *
36
 
    print "pyo version %s (uses single precision)" % PYO_VERSION
37
35
    
38
36
from _maps import *
39
37
from _widgets import createCtrlWindow, createViewTableWindow, createViewMatrixWindow
101
99
        return x
102
100
 
103
101
if sys.version_info[:2] <= (2, 5):
104
 
    def example(cls, dur=5):
 
102
    def example(cls, dur=5, toprint=True, double=False):
105
103
        """
106
104
    Execute the example given in the documentation of the object as an argument.
107
105
 
113
111
        Class reference of the desired object example.
114
112
    dur : float, optional
115
113
        Duration of the example.
 
114
    toprint : boolean, optional
 
115
        If True, the example script will be printed to the console.
 
116
        Defaults to True.
 
117
    double : boolean, optional
 
118
        If True, force the example to run in double precision (64-bit)
 
119
        Defaults to False.
116
120
 
117
121
    Examples:
118
122
 
119
123
    >>> example(Sine)
120
124
 
121
125
        """
122
 
        doc = cls.__doc__.split("Examples:")[1]
123
 
        lines = doc.splitlines()
 
126
        doc = cls.__doc__.split("Examples:")
 
127
        if len(doc) < 2:
 
128
            print "There is no manual example for %s object." % cls.__name__
 
129
            return
 
130
        if "Server" in doc[1]:
 
131
            with_server = True
 
132
        else:
 
133
            with_server = False
 
134
        lines = doc[1].splitlines()
124
135
        ex_lines = [line.lstrip("    ") for line in lines if ">>>" in line or "..." in line]
125
 
        if hasattr(__builtin__, 'pyo_use_double'):
 
136
        if hasattr(__builtin__, 'pyo_use_double') or double:
126
137
            ex = "import time\nfrom pyo64 import *\n"
127
138
        else:
128
139
            ex = "import time\nfrom pyo import *\n"
130
141
            if ">>>" in line: line = line.lstrip(">>> ")
131
142
            if "..." in line: line = "    " +  line.lstrip("... ")
132
143
            ex += line + "\n"
133
 
        ex += "time.sleep(%f)\ns.stop()\ntime.sleep(0.25)\ns.shutdown()\n" % dur
 
144
        if with_server:
 
145
            ex += "time.sleep(%f)\ns.stop()\ntime.sleep(0.25)\ns.shutdown()\n" % dur
134
146
        f = open('/tmp/pyo_example.py', 'w')
135
 
        f.write('print """\n%s\n"""\n' % ex)
 
147
        if toprint:
 
148
            f.write('print """\n%s\n"""\n' % ex)
136
149
        f.write(ex)
137
150
        f.close()    
138
151
        p = call(["python", '/tmp/pyo_example.py'])
139
152
else:
140
 
    def example(cls, dur=5):
 
153
    def example(cls, dur=5, toprint=True, double=False):
141
154
        """
142
155
    Execute the example given in the documentation of the object as an argument.
143
156
 
149
162
        Class reference of the desired object example.
150
163
    dur : float, optional
151
164
        Duration of the example.
 
165
    toprint : boolean, optional
 
166
        If True, the example script will be printed to the console.
 
167
        Defaults to True.
 
168
    double : boolean, optional
 
169
        If True, force the example to run in double precision (64-bit)
 
170
        Defaults to False.
152
171
 
153
172
    Examples:
154
173
 
155
174
    >>> example(Sine)
156
175
 
157
176
        """
158
 
        doc = cls.__doc__.split("Examples:")[1]
159
 
        lines = doc.splitlines()
 
177
        doc = cls.__doc__.split("Examples:")
 
178
        if len(doc) < 2:
 
179
            print "There is no manual example for %s object." % cls.__name__
 
180
            return
 
181
        if "Server" in doc[1]:
 
182
            with_server = True
 
183
        else:
 
184
            with_server = False
 
185
        lines = doc[1].splitlines()
160
186
        ex_lines = [line.lstrip("    ") for line in lines if ">>>" in line or "..." in line]
161
 
        if hasattr(__builtin__, 'pyo_use_double'):
 
187
        if hasattr(__builtin__, 'pyo_use_double') or double:
162
188
            ex = "import time\nfrom pyo64 import *\n"
163
189
        else:
164
190
            ex = "import time\nfrom pyo import *\n"
166
192
            if ">>>" in line: line = line.lstrip(">>> ")
167
193
            if "..." in line: line = "    " +  line.lstrip("... ")
168
194
            ex += line + "\n"
169
 
        ex += "time.sleep(%f)\ns.stop()\ntime.sleep(0.25)\ns.shutdown()\n" % dur
 
195
        if with_server:
 
196
            ex += "time.sleep(%f)\ns.stop()\ntime.sleep(0.25)\ns.shutdown()\n" % dur
170
197
        f = tempfile.NamedTemporaryFile(delete=False)
171
 
        f.write('print """\n%s\n"""\n' % ex)
 
198
        if toprint:
 
199
            f.write('print """\n%s\n"""\n' % ex)
172
200
        f.write(ex)
173
201
        f.close()    
174
202
        p = call(["python", f.name])
268
296
    ctrl(map_list, title) : Opens a sliders window to control parameters.
269
297
    get(all) : Return the first sample of the current buffer as a float.
270
298
    dump() : Print current status of the object's attributes.
 
299
    getBaseObjects() : Return a list of audio Stream objects managed by the instance.
 
300
    isPlaying(all) : Returns True if the object is playing, otherwise, returns False.
 
301
    isOutputting(all) : Returns True if the object is sending samples to dac, 
 
302
        otherwise, returns False.
271
303
 
272
304
    Attributes:
273
305
 
307
339
            if not serverBooted():
308
340
                print "\nPYO Error: The Server must be booted before creating any audio object.\n"
309
341
                exit()
310
 
 
311
342
        self._target_dict = {}
312
343
        self._signal_dict = {}
313
344
        self._keep_trace = []
314
345
        self._mul = 1.0
315
346
        self._add = 0.0
316
 
        self._mul_dummy_keep_trace = []
317
 
        self._add_dummy_keep_trace = []
318
 
        self._div_upsamp_keep_trace = []
319
 
        self._sub_upsamp_keep_trace = []
320
347
        self._op_duplicate = 1
321
348
 
322
349
    def __add__(self, x):
323
 
        self._keep_trace.append(x)
324
350
        x, lmax = convertArgsToLists(x)
325
351
        if self.__len__() >= lmax:
326
352
            _add_dummy = Dummy([obj + wrap(x,i/self._op_duplicate) for i, obj in enumerate(self._base_objs)])
329
355
                _add_dummy = x + self
330
356
            else:
331
357
                _add_dummy = Dummy([wrap(self._base_objs,i) + obj for i, obj in enumerate(x)])
332
 
        self._add_dummy_keep_trace.append(_add_dummy)
 
358
        self._keep_trace.append(_add_dummy)
333
359
        return _add_dummy
334
360
        
335
361
    def __radd__(self, x):
336
 
        self._keep_trace.append(x)
337
362
        x, lmax = convertArgsToLists(x)
338
363
        if self.__len__() >= lmax:
339
364
            _add_dummy = Dummy([obj + wrap(x,i/self._op_duplicate) for i, obj in enumerate(self._base_objs)])
340
365
        else:
341
366
            _add_dummy = Dummy([wrap(self._base_objs,i) + obj for i, obj in enumerate(x)])                
342
 
        self._add_dummy_keep_trace.append(_add_dummy)
 
367
        self._keep_trace.append(_add_dummy)
343
368
        return _add_dummy
344
369
            
345
370
    def __iadd__(self, x):
347
372
        return self
348
373
 
349
374
    def __sub__(self, x):
350
 
        self._keep_trace.append(x)
351
375
        x, lmax = convertArgsToLists(x)
352
376
        if self.__len__() >= lmax:
353
377
            _add_dummy = Dummy([obj - wrap(x,i/self._op_duplicate) for i, obj in enumerate(self._base_objs)])
354
378
        else:
355
379
            if isinstance(x, PyoObject):
356
 
                print 'Substraction Warning: %s - %s' % (self.__repr__(), x.__repr__()),
357
 
                print 'Right operator trunctaded to match left operator number of streams.'
358
 
                _add_dummy = Dummy([obj - wrap(x,i) for i, obj in enumerate(self._base_objs)])
 
380
                _add_dummy = Dummy([wrap(self._base_objs,i) - wrap(x,i) for i in range(lmax)])
359
381
            else:
360
382
                _add_dummy = Dummy([wrap(self._base_objs,i) - obj for i, obj in enumerate(x)])
361
 
        self._add_dummy_keep_trace.append(_add_dummy)
 
383
        self._keep_trace.append(_add_dummy)
362
384
        return _add_dummy
363
385
 
364
386
    def __rsub__(self, x):
365
 
        self._keep_trace.append(x)
366
387
        x, lmax = convertArgsToLists(x)
367
388
        if self.__len__() >= lmax:
368
389
            tmp = []
369
390
            for i, obj in enumerate(self._base_objs):
370
391
                sub_upsamp = Sig(wrap(x, i/self._op_duplicate))
371
 
                self._sub_upsamp_keep_trace.append(sub_upsamp)
 
392
                self._keep_trace.append(sub_upsamp)
372
393
                tmp.append(sub_upsamp - obj)
373
394
            _add_dummy = Dummy(tmp)
374
395
        else:
375
396
            tmp = []
376
397
            for i, obj in enumerate(x):
377
398
                sub_upsamp = Sig(obj)
378
 
                self._sub_upsamp_keep_trace.append(sub_upsamp)
 
399
                self._keep_trace.append(sub_upsamp)
379
400
                tmp.append(sub_upsamp - wrap(self._base_objs,i))
380
401
            _add_dummy = Dummy(tmp)
381
 
        self._add_dummy_keep_trace.append(_add_dummy)
 
402
        self._keep_trace.append(_add_dummy)
382
403
        return _add_dummy
383
404
 
384
405
    def __isub__(self, x):
386
407
        return self
387
408
 
388
409
    def __mul__(self, x):
389
 
        self._keep_trace.append(x)
390
410
        x, lmax = convertArgsToLists(x)
391
411
        if self.__len__() >= lmax:
392
412
            _mul_dummy = Dummy([obj * wrap(x,i/self._op_duplicate) for i, obj in enumerate(self._base_objs)])
393
413
        else:
394
414
            if isinstance(x, PyoObject):
395
 
                _mul_dummy = x * self 
 
415
                _mul_dummy = x * self
396
416
            else:
397
417
                _mul_dummy = Dummy([wrap(self._base_objs,i) * obj for i, obj in enumerate(x)])  
398
 
        self._mul_dummy_keep_trace.append(_mul_dummy)
 
418
        self._keep_trace.append(_mul_dummy)
399
419
        return _mul_dummy
400
420
        
401
421
    def __rmul__(self, x):
402
 
        self._keep_trace.append(x)
403
422
        x, lmax = convertArgsToLists(x)
404
423
        if self.__len__() >= lmax:
405
424
            _mul_dummy = Dummy([obj * wrap(x,i/self._op_duplicate) for i, obj in enumerate(self._base_objs)])
406
425
        else:
407
426
            _mul_dummy = Dummy([wrap(self._base_objs,i) * obj for i, obj in enumerate(x)])                
408
 
        self._mul_dummy_keep_trace.append(_mul_dummy)
 
427
        self._keep_trace.append(_mul_dummy)
409
428
        return _mul_dummy
410
429
            
411
430
    def __imul__(self, x):
413
432
        return self
414
433
 
415
434
    def __div__(self, x):
416
 
        self._keep_trace.append(x)
417
435
        x, lmax = convertArgsToLists(x)
418
436
        if self.__len__() >= lmax:
419
437
            _mul_dummy = Dummy([obj / wrap(x,i/self._op_duplicate) for i, obj in enumerate(self._base_objs)])
420
438
        else:
421
439
            if isinstance(x, PyoObject):
422
 
                print 'Division Warning: %s / %s' % (self.__repr__(), x.__repr__()),
423
 
                print 'Right operator trunctaded to match left operator number of streams.'
424
 
                _mul_dummy = Dummy([obj / wrap(x,i) for i, obj in enumerate(self._base_objs)])
 
440
                _mul_dummy = Dummy([wrap(self._base_objs,i) / wrap(x,i) for i in range(lmax)])
425
441
            else:
426
442
                _mul_dummy = Dummy([wrap(self._base_objs,i) / obj for i, obj in enumerate(x)])
427
 
        self._mul_dummy_keep_trace.append(_mul_dummy)
 
443
        self._keep_trace.append(_mul_dummy)
428
444
        return _mul_dummy
429
445
 
430
446
    def __rdiv__(self, x):
431
 
        self._keep_trace.append(x)
432
447
        x, lmax = convertArgsToLists(x)
433
448
        if self.__len__() >= lmax:
434
449
            tmp = []
435
450
            for i, obj in enumerate(self._base_objs):
436
451
                div_upsamp = Sig(wrap(x, i/self._op_duplicate))
437
 
                self._div_upsamp_keep_trace.append(div_upsamp)
 
452
                self._keep_trace.append(div_upsamp)
438
453
                tmp.append(div_upsamp / obj)
439
454
            _mul_dummy = Dummy(tmp)
440
455
        else:
441
456
            tmp = []
442
457
            for i, obj in enumerate(x):
443
458
                div_upsamp = Sig(obj)
444
 
                self._div_upsamp_keep_trace.append(div_upsamp)
 
459
                self._keep_trace.append(div_upsamp)
445
460
                tmp.append(div_upsamp / wrap(self._base_objs,i))
446
461
            _mul_dummy = Dummy(tmp)
447
 
        self._mul_dummy_keep_trace.append(_mul_dummy)
 
462
        self._keep_trace.append(_mul_dummy)
448
463
        return _mul_dummy
449
464
 
450
465
    def __idiv__(self, x):
454
469
    def __getitem__(self, i):
455
470
        if i == 'trig':
456
471
            return self._trig_objs
457
 
 
458
472
        if type(i) == SliceType or i < len(self._base_objs):
459
473
            return self._base_objs[i]
460
474
        else:
461
475
            if type(i) == StringType:
462
476
                print "Object %s has no stream named '%s'!" % (self.__class__, i)
463
477
            else:
464
 
                print "'i' too large!"         
 
478
                print "'i' too large in slicing object %s!" % self.__class__.__name__
465
479
 
466
480
    def __len__(self):
467
481
        return len(self._base_objs)
468
482
 
469
 
    def __del__(self):
470
 
        for obj in self._base_objs:
471
 
            obj.deleteStream()
472
 
            del obj
473
 
 
474
 
        if hasattr(self, "_trig_objs"):
475
 
            del self._trig_objs
476
 
 
477
 
        if hasattr(self, "_input"):
478
 
            if type(self._input) == ListType:
479
 
                for pyoObj in self._input:
480
 
                    if hasattr(pyoObj, "getBaseObjects"):
481
 
                        for obj in pyoObj.getBaseObjects():
482
 
                            obj.deleteStream()
483
 
                            del obj
484
 
            else:
485
 
                if hasattr(self._input, "getBaseObjects"):
486
 
                    for obj in self._input.getBaseObjects():
487
 
                        obj.deleteStream()
488
 
                        del obj
489
 
            del self._input
490
 
 
491
 
        for key in self.__dict__.keys():
492
 
            if isinstance(self.__dict__[key], PyoObject):
493
 
                del self.__dict__[key]
494
 
            elif type(self.__dict__[key]) == ListType:
495
 
                for ele in self.__dict__[key]:
496
 
                    if hasattr(ele, "getBaseObjects"):
497
 
                        for obj in ele.getBaseObjects():
498
 
                            obj.deleteStream()
499
 
                            del obj
500
 
                    else:
501
 
                        del ele
502
 
 
503
 
        if hasattr(self, "_in_fader"):
504
 
            del self._in_fader
505
 
 
506
483
    def __repr__(self):
507
484
        return '< Instance of %s class >' % self.__class__.__name__
508
 
        
 
485
    
 
486
    def isPlaying(self, all=False):
 
487
        """
 
488
        Returns True if the object is playing, otherwise, returns False.
 
489
 
 
490
        Parameters:
 
491
 
 
492
            all : boolean, optional
 
493
                If True, the object returns a list with the state of all
 
494
                streams managed by the object. If False, it return a 
 
495
                boolean corresponding to the state of the first stream.
 
496
                Defaults to False.
 
497
 
 
498
        """
 
499
        if all:
 
500
            return [obj._getStream().isPlaying() for obj in self._base_objs]
 
501
        else:
 
502
            return self._base_objs[0]._getStream().isPlaying()
 
503
 
 
504
    def isOutputting(self, all=False):
 
505
        """
 
506
        Returns True if the object is sending samples to dac, otherwise, returns False.
 
507
 
 
508
        Parameters:
 
509
 
 
510
            all : boolean, optional
 
511
                If True, the object returns a list with the state of all
 
512
                streams managed by the object. If False, it return a 
 
513
                boolean corresponding to the state of the first stream.
 
514
                Defaults to False.
 
515
 
 
516
        """
 
517
        if all:
 
518
            return [obj._getStream().isOutputting() for obj in self._base_objs]
 
519
        else:
 
520
            return self._base_objs[0]._getStream().isOutputting()
 
521
 
509
522
    def dump(self):
510
523
        """
511
524
        Print the number of streams and the current status of the 
539
552
                will be returned as a list. Otherwise, only the value
540
553
                of the first object's stream will be returned as a float.
541
554
                Defaults to False.
542
 
                 
 
555
 
543
556
        """
544
557
        if not all:
545
558
            return self._base_objs[0]._getStream().getValue()
548
561
            
549
562
    def getBaseObjects(self):
550
563
        """
551
 
        Return a list of audio Stream objects.
 
564
        Return a list of audio Stream objects managed by the instance.
552
565
        
553
566
        """
554
567
        return self._base_objs
573
586
        dur, delay, lmax = convertArgsToLists(dur, delay)
574
587
        if hasattr(self, "_trig_objs"):
575
588
            self._trig_objs.play(dur, delay)
576
 
        self._base_objs = [obj.play(wrap(dur,i), wrap(delay,i)) for i, obj in enumerate(self._base_objs)]
 
589
        if hasattr(self, "_base_players"):
 
590
            [obj.play(wrap(dur,i), wrap(delay,i)) for i, obj in enumerate(self._base_players)]
 
591
        [obj.play(wrap(dur,i), wrap(delay,i)) for i, obj in enumerate(self._base_objs)]
577
592
        return self
578
593
 
579
594
    def out(self, chnl=0, inc=1, dur=0, delay=0):
611
626
        dur, delay, lmax = convertArgsToLists(dur, delay)
612
627
        if hasattr(self, "_trig_objs"):
613
628
            self._trig_objs.play(dur, delay)
 
629
        if hasattr(self, "_base_players"):
 
630
            [obj.play(wrap(dur,i), wrap(delay,i)) for i, obj in enumerate(self._base_players)]
614
631
        if type(chnl) == ListType:
615
 
            self._base_objs = [obj.out(wrap(chnl,i), wrap(dur,i), wrap(delay,i)) for i, obj in enumerate(self._base_objs)]
 
632
            [obj.out(wrap(chnl,i), wrap(dur,i), wrap(delay,i)) for i, obj in enumerate(self._base_objs)]
616
633
        else:
617
634
            if chnl < 0:    
618
 
                self._base_objs = [obj.out(i*inc, wrap(dur,i), wrap(delay,i)) for i, obj in enumerate(random.sample(self._base_objs, len(self._base_objs)))]
 
635
                [obj.out(i*inc, wrap(dur,i), wrap(delay,i)) for i, obj in enumerate(random.sample(self._base_objs, len(self._base_objs)))]
619
636
            else:
620
 
                self._base_objs = [obj.out(chnl+i*inc, wrap(dur,i), wrap(delay,i)) for i, obj in enumerate(self._base_objs)]
 
637
                [obj.out(chnl+i*inc, wrap(dur,i), wrap(delay,i)) for i, obj in enumerate(self._base_objs)]
621
638
        return self
622
639
    
623
640
    def stop(self):
630
647
        """
631
648
        if hasattr(self, "_trig_objs"):
632
649
            self._trig_objs.stop()
 
650
        if hasattr(self, "_base_players"):
 
651
            [obj.stop() for obj in self._base_players]
633
652
        [obj.stop() for obj in self._base_objs]
634
653
        return self
635
654
 
728
747
 
729
748
        x : float or PyoObject
730
749
            New inversed `add` attribute.
731
 
        
 
750
 
732
751
        """
733
752
        self._mul = x
734
753
        x, lmax = convertArgsToLists(x)
737
756
    def set(self, attr, value, port=0.025):
738
757
        """
739
758
        Replace any attribute with portamento.
740
 
        
 
759
 
741
760
        This method is intended to be applied on attributes that are not
742
761
        already assigned to PyoObjects. It will work only with floats or
743
762
        list of floats.
744
 
                
 
763
 
745
764
        Parameters:
746
765
 
747
766
        attr : string
750
769
            New value.
751
770
        port : float, optional
752
771
            Time, in seconds, to reach the new value
753
 
        
 
772
 
754
773
        """
755
774
        self._target_dict[attr] = value
756
 
        self._signal_dict[attr] = VarPort(value, port, getattr(self, attr), self._reset_from_set, attr)
 
775
        init = getattr(self, attr)
 
776
        if self._signal_dict.has_key(attr):
 
777
            if isinstance(self._signal_dict[attr], VarPort):
 
778
                if self._signal_dict[attr].isPlaying():
 
779
                    init = self._signal_dict[attr].get(True)
 
780
                    self._signal_dict[attr].stop()
 
781
        self._signal_dict[attr] = VarPort(value, port, init, self._reset_from_set, attr)
757
782
        setattr(self, attr, self._signal_dict[attr])
758
783
 
759
784
    def _reset_from_set(self, attr=None):
760
 
        setattr(self, attr, self._target_dict[attr])
 
785
        if isinstance(getattr(self, attr), VarPort):
 
786
            setattr(self, attr, self._target_dict[attr])
761
787
        self._signal_dict[attr].stop()
762
 
        del self._signal_dict[attr]
763
788
        
764
789
    def ctrl(self, map_list=None, title=None, wxnoserver=False):
765
790
        """
769
794
 
770
795
        If a list of values are given to a parameter, a multisliders 
771
796
        will be used to control each stream independently.
772
 
        
 
797
 
773
798
        Parameters:
774
799
 
775
800
        map_list : list of SLMap objects, optional
790
815
        if map_list == []:
791
816
            print("There is no controls for %s object." % self.__class__.__name__)
792
817
            return
793
 
    
794
818
        createCtrlWindow(self, map_list, title, wxnoserver)
795
819
 
796
820
    @property
823
847
    getSize() : Return table size in samples.
824
848
    view() : Opens a window showing the contents of the table.
825
849
    dump() : Print current status of the object's attributes.
826
 
    save(path, format) : Writes the content of the table in an audio file.
 
850
    save(path, format, sampletype) : Writes the content of the table in an audio file.
827
851
    write(path, oneline) : Writes the content of the table in a text file.
828
852
    read(path) : Sets the content of the table from a text file.
829
853
    normalize() : Normalize table samples between -1 and 1.
832
856
    copy() : Returns a deep copy of the object.
833
857
    put(value, pos) : Puts a value at specified position in the table.
834
858
    get(pos) : Returns the value at specified position in the table.
 
859
    getBaseObjects() : Return a list of table Stream objects managed by the instance.
835
860
    
836
861
    Notes:
837
862
    
855
880
        if i < len(self._base_objs):
856
881
            return self._base_objs[i]
857
882
        else:
858
 
            print "'i' too large!"
 
883
            print "'i' too large in slicing table %s!" % self.__class__.__name__
859
884
 
860
885
    def __len__(self):
861
886
        return len(self._base_objs)
904
929
                4 : 64 bit float
905
930
 
906
931
        """
907
 
        sr = int(self._base_objs[0].getServer().getSamplingRate())
908
 
        if len(self._base_objs) == 1:
909
 
            samples = self._base_objs[0].getTable()
910
 
        else:
911
 
            samples = [obj.getTable() for i, obj in enumerate(self._base_objs)]
912
 
        savefile(samples, path, sr, len(self._base_objs), format, sampletype)
 
932
        savefileFromTable(self, path, format, sampletype)
913
933
    
914
934
    def write(self, path, oneline=True):
915
935
        """
966
986
        
967
987
    def getBaseObjects(self):
968
988
        """
969
 
        Return a list of table Stream objects.
 
989
        Return a list of table Stream objects managed by the instance.
970
990
        
971
991
        """
972
992
        return self._base_objs
1048
1068
            _size = self.getSize()
1049
1069
            if type(_size) != ListType:
1050
1070
                _size = [_size]
1051
 
 
1052
1071
            _chnls = len(self._base_objs)
1053
1072
            args[0] = None
1054
1073
            args.append(_chnls)
1102
1121
    boost(min, max, boost) : Boost the contrast of values in the matrix.
1103
1122
    put(value, x, y) : Puts a value at specified position in the matrix.
1104
1123
    get(x, y) : Returns the value at specified position in the matrix.
 
1124
    getBaseObjects() : Returns a list of matrix stream objects managed by the instance.
1105
1125
    
1106
1126
    Notes:
1107
1127
    
1125
1145
        if i < len(self._base_objs):
1126
1146
            return self._base_objs[i]
1127
1147
        else:
1128
 
            print "'i' too large!"
 
1148
            print "'i' too large in slicing matrix %s!" % self.__class__.__name__
1129
1149
 
1130
1150
    def __len__(self):
1131
1151
        return len(self._base_objs)
1185
1205
        
1186
1206
    def getBaseObjects(self):
1187
1207
        """
1188
 
        Returns a list of matrix stream objects.
 
1208
        Returns a list of matrix stream objects managed by the instance.
1189
1209
        
1190
1210
        """
1191
1211
        return self._base_objs
1361
1381
    def __dir__(self):
1362
1382
        return ['mul', 'add']
1363
1383
 
1364
 
    def __del__(self):
1365
 
        for obj in self._base_objs:
1366
 
            obj.deleteStream()
1367
 
            del obj
1368
 
        del self._base_objs
1369
 
        if type(self._input) == ListType:
1370
 
            for pyoObj in self._input:
1371
 
                for obj in pyoObj.getBaseObjects():
1372
 
                    obj.deleteStream()
1373
 
                    del obj
1374
 
        else:
1375
 
            for obj in self._input.getBaseObjects():
1376
 
                obj.deleteStream()
1377
 
                del obj
1378
 
        del self._input
1379
 
 
1380
1384
class Dummy(PyoObject):
1381
1385
    """
1382
1386
    Dummy object used to perform arithmetics on PyoObject.
1435
1439
 
1436
1440
    def __dir__(self):
1437
1441
        return ['mul', 'add']
1438
 
 
1439
 
    def deleteStream(self):
1440
 
        for obj in self._base_objs:
1441
 
            obj.deleteStream()
1442
 
            del obj
1443
1442
        
1444
1443
class InputFader(PyoObject):
1445
1444
    """
1622
1621
    >>> def callback(arg):
1623
1622
    ...     print "end of line"
1624
1623
    ...     print arg
1625
 
    .... 
 
1624
    ... 
1626
1625
    >>> fr = VarPort(value=500, time=2, init=250, function=callback, arg="YEP!")
1627
1626
    >>> a = SineLoop(freq=[fr,fr*1.01], feedback=0.05, mul=.2).out()
1628
1627