23
23
from subprocess import call
24
24
from distutils.sysconfig import get_python_lib
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
34
33
import pyo as current_pyo
36
print "pyo version %s (uses single precision)" % PYO_VERSION
38
36
from _maps import *
39
37
from _widgets import createCtrlWindow, createViewTableWindow, createViewMatrixWindow
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.
117
double : boolean, optional
118
If True, force the example to run in double precision (64-bit)
119
123
>>> example(Sine)
122
doc = cls.__doc__.split("Examples:")[1]
123
lines = doc.splitlines()
126
doc = cls.__doc__.split("Examples:")
128
print "There is no manual example for %s object." % cls.__name__
130
if "Server" in doc[1]:
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"
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
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)
148
f.write('print """\n%s\n"""\n' % ex)
138
151
p = call(["python", '/tmp/pyo_example.py'])
140
def example(cls, dur=5):
153
def example(cls, dur=5, toprint=True, double=False):
142
155
Execute the example given in the documentation of the object as an argument.
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.
168
double : boolean, optional
169
If True, force the example to run in double precision (64-bit)
155
174
>>> example(Sine)
158
doc = cls.__doc__.split("Examples:")[1]
159
lines = doc.splitlines()
177
doc = cls.__doc__.split("Examples:")
179
print "There is no manual example for %s object." % cls.__name__
181
if "Server" in doc[1]:
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"
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
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)
199
f.write('print """\n%s\n"""\n' % ex)
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.
307
339
if not serverBooted():
308
340
print "\nPYO Error: The Server must be booted before creating any audio object.\n"
311
342
self._target_dict = {}
312
343
self._signal_dict = {}
313
344
self._keep_trace = []
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
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
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
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)])
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
345
370
def __iadd__(self, x):
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)])
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)])
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
364
386
def __rsub__(self, x):
365
self._keep_trace.append(x)
366
387
x, lmax = convertArgsToLists(x)
367
388
if self.__len__() >= lmax:
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)
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
384
405
def __isub__(self, x):
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)])
394
414
if isinstance(x, PyoObject):
395
_mul_dummy = x * self
415
_mul_dummy = x * self
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
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)])
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
411
430
def __imul__(self, x):
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)])
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)])
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
430
446
def __rdiv__(self, x):
431
self._keep_trace.append(x)
432
447
x, lmax = convertArgsToLists(x)
433
448
if self.__len__() >= lmax:
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)
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
450
465
def __idiv__(self, x):
454
469
def __getitem__(self, i):
456
471
return self._trig_objs
458
472
if type(i) == SliceType or i < len(self._base_objs):
459
473
return self._base_objs[i]
461
475
if type(i) == StringType:
462
476
print "Object %s has no stream named '%s'!" % (self.__class__, i)
464
print "'i' too large!"
478
print "'i' too large in slicing object %s!" % self.__class__.__name__
466
480
def __len__(self):
467
481
return len(self._base_objs)
470
for obj in self._base_objs:
474
if hasattr(self, "_trig_objs"):
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():
485
if hasattr(self._input, "getBaseObjects"):
486
for obj in self._input.getBaseObjects():
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():
503
if hasattr(self, "_in_fader"):
506
483
def __repr__(self):
507
484
return '< Instance of %s class >' % self.__class__.__name__
486
def isPlaying(self, all=False):
488
Returns True if the object is playing, otherwise, returns False.
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.
500
return [obj._getStream().isPlaying() for obj in self._base_objs]
502
return self._base_objs[0]._getStream().isPlaying()
504
def isOutputting(self, all=False):
506
Returns True if the object is sending samples to dac, otherwise, returns False.
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.
518
return [obj._getStream().isOutputting() for obj in self._base_objs]
520
return self._base_objs[0]._getStream().isOutputting()
511
524
Print the number of streams and the current status of the
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)]
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)]
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)))]
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)]
751
770
port : float, optional
752
771
Time, in seconds, to reach the new value
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])
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]
764
789
def ctrl(self, map_list=None, title=None, wxnoserver=False):
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.
907
sr = int(self._base_objs[0].getServer().getSamplingRate())
908
if len(self._base_objs) == 1:
909
samples = self._base_objs[0].getTable()
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)
914
934
def write(self, path, oneline=True):
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.