~ubuntu-branches/ubuntu/trusty/python-pyo/trusty

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
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
"""
Objects to retrieve Midi informations for a specific Midi port and channel.

Objects creates and returns audio streams from the value in their Midi input.

The audio streams of these objects are essentially intended to be
used as 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 *

######################################################################
### MIDI
######################################################################                                       
class Midictl(PyoObject):
    """
    Get the current value of a Midi controller.
    
    Get the current value of a controller and optionally map it 
    inside a specified range.

    Parentclass: PyoObject
    
    Parameters:
    
    ctlnumber : int
        Controller number.
    minscale : float, optional
        Low range value for mapping. Defaults to 0.
    maxscale : float, optional
        High range value for mapping. Defaults to 1.
    init : float, optional
        Initial value. Defaults to 0.
    channel : int, optional
        Midi channel. 0 means all channels. Defaults to 0.

    Methods:

    setCtlNumber(x) : Replace the `ctlnumber` attribute.
    setMinScale(x) : Replace the `minscale` attribute.
    setMaxScale(x) : Replace the `maxscale` attribute.
    setChannel(x) : Replace the `channel` attribute.
    setValue(x) : Reset audio stream to value in argument.
    setInterpolation(x) : Activate/Deactivate interpolation. Activated by default.

    Attributes:

    ctlnumber : Controller number.
    minscale : Minimum value for scaling.
    maxscale : Maximum value for scaling.
    channel : Midi channel. 0 means all channels.

    Notes:

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

    Examples:
    
    >>> s = Server().boot()
    >>> s.start()
    >>> m = Midictl(ctlnumber=[107,102], minscale=250, maxscale=1000)
    >>> p = Port(m, .02)
    >>> a = Sine(freq=p, mul=.3).out()
    >>> a1 = Sine(freq=p*1.25, mul=.3).out()
    >>> a2 = Sine(freq=p*1.5, mul=.3).out()
        
    """
    def __init__(self, ctlnumber, minscale=0, maxscale=1, init=0, channel=0, mul=1, add=0):
        PyoObject.__init__(self, mul, add)
        self._ctlnumber = ctlnumber
        self._minscale = minscale
        self._maxscale = maxscale
        self._channel = channel
        ctlnumber, minscale, maxscale, init, channel, mul, add, lmax = convertArgsToLists(ctlnumber, minscale, maxscale, init, channel, mul, add)
        self._base_objs = [Midictl_base(wrap(ctlnumber,i), wrap(minscale,i), wrap(maxscale,i), wrap(init,i), wrap(channel,i), wrap(mul,i), wrap(add,i)) for i in range(lmax)]

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

    def setCtlNumber(self, x):
        """
        Replace the `ctlnumber` attribute.

        Parameters:

        x : int
            new `ctlnumber` attribute.

        """
        self._ctlnumber = x
        x, lmax = convertArgsToLists(x)
        [obj.setCtlNumber(wrap(x,i)) for i, obj in enumerate(self._base_objs)]

    def setMinScale(self, x):
        """
        Replace the `minscale` attribute.

        Parameters:

        x : int
            new `minscale` attribute.

        """
        self._minscale = x
        x, lmax = convertArgsToLists(x)
        [obj.setMinScale(wrap(x,i)) for i, obj in enumerate(self._base_objs)]

    def setMaxScale(self, x):
        """
        Replace the `maxscale` attribute.

        Parameters:

        x : int
            new `maxscale` attribute.

        """
        self._maxscale = x
        x, lmax = convertArgsToLists(x)
        [obj.setMaxScale(wrap(x,i)) for i, obj in enumerate(self._base_objs)]

    def setChannel(self, x):
        """
        Replace the `channel` attribute.

        Parameters:

        x : int
            new `channel` attribute.

        """
        self._channel = x
        x, lmax = convertArgsToLists(x)
        [obj.setChannel(wrap(x,i)) for i, obj in enumerate(self._base_objs)]

    def setValue(self, x):
        """
        Reset audio stream to value in argument.

        Parameters:

        x : float
            new current value.

        """
        x, lmax = convertArgsToLists(x)
        [obj.setValue(wrap(x,i)) for i, obj in enumerate(self._base_objs)]

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

        Parameters:

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

        """
        x, lmax = convertArgsToLists(x)
        [obj.setInterpolation(wrap(x,i)) for i, obj in enumerate(self._base_objs)]

    @property
    def ctlnumber(self): return self._ctlnumber
    @ctlnumber.setter
    def ctlnumber(self, x): self.setCtlNumber(x)   

    @property
    def minscale(self): return self._minscale
    @minscale.setter
    def minscale(self, x): self.setMinScale(x)   

    @property
    def maxscale(self): return self._maxscale
    @maxscale.setter
    def maxscale(self, x): self.setMaxScale(x)   

    @property
    def channel(self): return self._channel
    @channel.setter
    def channel(self, x): self.setChannel(x)   

class CtlScan(PyoObject):
    """
    Scan the Midi controller's number in input.
    
    Scan the Midi controller's number in input and send it to
    a standard python `function`. Useful to implement a MidiLearn
    algorithm.

    Parentclass: PyoObject
    
    Parameters:
    
    function : Python function
        Function to be called. The function must be declared
        with an argument for the controller number in input. Ex.: 
        def ctl_scan(ctlnum):
            print ctlnum
    toprint : boolean, optional
        If True, controller number and value will be print to 
        the console.

    Methods:

    setFunction(x) : Replace the `function` attribute.
    setToprint(x) : Replace the `toprint` attribute.

    Attributes:
    
    function : Python function. Function to be called.
    toprint : boolean. If True, print values to the console.

    Notes:

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

    Examples:
    
    >>> s = Server()
    >>> s.setMidiInputDevice(0) # enter your device number (see pm_list_devices())
    >>> s.boot()
    >>> s.start()
    >>> def ctl_scan(ctlnum):
    ...     print ctlnum
    >>> a = CtlScan(ctl_scan)
        
    """
    def __init__(self, function, toprint=True):
        PyoObject.__init__(self)
        if not callable(function):
            print >> sys.stderr, 'TypeError: "function" argument of %s must be callable.\n' % self.__class__.__name__
            exit()
        self._function = function
        self._toprint = toprint
        self._base_objs = [CtlScan_base(self._function, self._toprint)]

    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 setSub(self, x):
        pass

    def setDiv(self, x):
        pass

    def setFunction(self, x):
        """
        Replace the `function` attribute.

        Parameters:

        x : Python function
            new `function` attribute.

        """
        self._function = x
        x, lmax = convertArgsToLists(x)
        [obj.setFunction(wrap(x,i)) for i, obj in enumerate(self._base_objs)]

    def setToprint(self, x):
        """
        Replace the `toprint` attribute.

        Parameters:

        x : int
            new `toprint` attribute.

        """
        self._toprint = x
        x, lmax = convertArgsToLists(x)
        [obj.setToprint(wrap(x,i)) for i, obj in enumerate(self._base_objs)]

    @property
    def function(self): return self._function
    @function.setter
    def function(self, x): self.setFunction(x)   
    @property
    def toprint(self): return self._toprint
    @toprint.setter
    def toprint(self, x): self.setToprint(x)   

class CtlScan2(PyoObject):
    """
    Scan the Midi channel and controller number in input.

    Scan the Midi channel and controller number in input and send them 
    to a standard python `function`. Useful to implement a MidiLearn 
    algorithm.

    Parentclass: PyoObject

    Parameters:

    function : Python function
        Function to be called. The function must be declared
        with two arguments, one for the controller number and 
        one for the midi channel. Ex.: 
        def ctl_scan(ctlnum, midichnl):
            print ctlnum, midichnl
    toprint : boolean, optional
        If True, controller number and value will be print to 
        the console.

    Methods:

    setFunction(x) : Replace the `function` attribute.
    setToprint(x) : Replace the `toprint` attribute.

    Attributes:

    function : Python function. Function to be called.
    toprint : boolean. If True, print values to the console.

    Notes:

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

    Examples:

    >>> s = Server()
    >>> s.setMidiInputDevice(0) # enter your device number (see pm_list_devices())
    >>> s.boot()
    >>> s.start()
    >>> def ctl_scan(ctlnum, midichnl):
    ...     print ctlnum, midichnl
    >>> a = CtlScan2(ctl_scan)

    """
    def __init__(self, function, toprint=True):
        PyoObject.__init__(self)
        if not callable(function):
            print >> sys.stderr, 'TypeError: "function" argument of %s must be callable.\n' % self.__class__.__name__
            exit()
        self._function = function
        self._toprint = toprint
        self._base_objs = [CtlScan2_base(self._function, self._toprint)]

    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 setSub(self, x):
        pass

    def setDiv(self, x):
        pass

    def setFunction(self, x):
        """
        Replace the `function` attribute.

        Parameters:

        x : Python function
            new `function` attribute.

        """
        self._function = x
        x, lmax = convertArgsToLists(x)
        [obj.setFunction(wrap(x,i)) for i, obj in enumerate(self._base_objs)]

    def setToprint(self, x):
        """
        Replace the `toprint` attribute.

        Parameters:

        x : int
            new `toprint` attribute.

        """
        self._toprint = x
        x, lmax = convertArgsToLists(x)
        [obj.setToprint(wrap(x,i)) for i, obj in enumerate(self._base_objs)]

    @property
    def function(self): return self._function
    @function.setter
    def function(self, x): self.setFunction(x)   
    @property
    def toprint(self): return self._toprint
    @toprint.setter
    def toprint(self, x): self.setToprint(x)   

class Notein(PyoObject):
    """
    Generates Midi note messages.
    
    From a Midi device, takes the notes in the range defined with 
    `first` and `last` parameters, and outputs up to `poly` 
    noteon - noteoff streams in the `scale` format (Midi, hertz 
    or transpo).
    
    Parentclass: PyoObject

    Parameters:
    
    poly : int, optional
        Number of streams of polyphony generated. Defaults to 10.
    scale : int, optional
        Pitch output format. 0 = Midi, 1 = Hertz, 2 = transpo. 
        In the transpo mode, the default central key (the key where 
        there is no transposition) is (`first` + `last`) / 2. The
        central key can be changed with the setCentralKey method.
    first : int, optional
        Lowest Midi value. Defaults to 0.
    last : int, optional
        Highest Midi value. Defaults to 127.
    channel : int, optional
        Midi channel. 0 means all channels. Defaults to 0.

    Methods:

    setChannel(x) : Replace the `channel` attribute.
    setCentralKey(x) : Set the midi key where there is no transposition.
    get(identifier, all) : Return the first sample of the current 
        buffer as a float.

    Attributes:
    
    channel : Midi channel. 0 means all channels.
    
    Notes:
    
    Pitch and velocity are two separated set of streams. 
    The user should call :
    
    Notein['pitch'] to retrieve pitch streams.
    Notein['velocity'] to retrieve velocity streams.    

    Velocity is automatically scaled between 0 and 1.
    
    The out() method is bypassed. Notein's signal can not be sent 
    to audio outs.
    
    Examples:

    >>> s = Server().boot()
    >>> s.start()
    >>> notes = Notein(poly=10, scale=1, mul=.5)
    >>> p = Port(notes['velocity'], .001, .5)
    >>> b = Sine(freq=notes['pitch'], mul=p).out()
    >>> c = Sine(freq=notes['pitch'] * 0.997, mul=p).out()
    >>> d = Sine(freq=notes['pitch'] * 1.005, mul=p).out()
    
    """
    def __init__(self, poly=10, scale=0, first=0, last=127, channel=0, mul=1, add=0):
        PyoObject.__init__(self, mul, add)
        self._pitch_dummy = []
        self._velocity_dummy = []
        self._poly = poly
        self._scale = scale
        self._first = first
        self._last = last
        self._channel = channel
        mul, add, lmax = convertArgsToLists(mul, add)
        self._base_handler = MidiNote_base(self._poly, self._scale, self._first, self._last, self._channel)
        self._base_objs = []
        for i in range(lmax * poly):
            self._base_objs.append(Notein_base(self._base_handler, i, 0, 1, 0))
            self._base_objs.append(Notein_base(self._base_handler, i, 1, wrap(mul,i), wrap(add,i)))

    def __getitem__(self, str):
        if str == 'pitch':
            self._pitch_dummy.append(Dummy([self._base_objs[i*2] for i in range(self._poly)]))
            return self._pitch_dummy[-1]
        if str == 'velocity':
            self._velocity_dummy.append(Dummy([self._base_objs[i*2+1] for i in range(self._poly)]))
            return self._velocity_dummy[-1]

    def setChannel(self, x):
        """
        Replace the `channel` attribute.

        Parameters:

        x : int
            new `channel` attribute.

        """
        self._channel = x
        self._base_handler.setChannel(x)

    def setCentralKey(self, x):
        """
        Set the midi key where there is no transposition.
        
        Used for transpo conversion. This value must be greater than or
        equal to `first` and lower than or equal to `last`.

        Parameters:

        x : int
            new centralkey value.

        """
        self._base_handler.setCentralKey(x)

    def get(self, identifier="pitch", all=False):
        """
        Return the first sample of the current buffer as a float.
        
        Can be used to convert audio stream to usable Python data.
        
        "pitch" or "velocity" must be given to `identifier` to specify
        which stream to get value from.
        
        Parameters:

            identifier : string {"pitch", "velocity"}
                Address string parameter identifying audio stream.
                Defaults to "pitch".
            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.__getitem__(identifier)[0]._getStream().getValue()
        else:
            return [obj._getStream().getValue() for obj in self.__getitem__(identifier).getBaseObjects()]
                        
    def play(self, dur=0, delay=0):
        self._base_handler.play()
        return PyoObject.play(self, dur, delay)

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

    def stop(self):
        self._base_handler.stop()
        return PyoObject.stop(self)

    @property
    def channel(self): return self._channel
    @channel.setter
    def channel(self, x): self.setChannel(x)   

class Bendin(PyoObject):
    """
    Get the current value of the pitch bend controller.

    Get the current value of the pitch bend controller and optionally 
    maps it inside a specified range.

    Parentclass: PyoObject

    Parameters:

    brange : float, optional
        Bipolar range of the pitch bend in semitones. Defaults to 2.
        -brange <= value < brange.
    scale : int, optional
        Output format. 0 = Midi, 1 = transpo. 
        The transpo mode is useful if you want to transpose values that 
        are in a frequency (Hz) format. Defaults to 0.
    channel : int, optional
        Midi channel. 0 means all channels. Defaults to 0.

    Methods:

    setBrange(x) : Replace the `brange` attribute.
    setScale(x) : Replace the `scale` attribute.
    setChannel(x) : Replace the `channel` attribute.

    Attributes:

    brange : Bipolar range of the pitch bend in semitones.
    scale : Output format. 0 = Midi, 1 = transpo.
    channel : Midi channel. 0 means all channels.

    Notes:

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

    Examples:

    >>> s = Server().boot()
    >>> s.start()
    >>> notes = Notein(poly=10, scale=1, mul=.5)
    >>> bend = Bendin(brange=2, scale=1)
    >>> p = Port(notes['velocity'], .001, .5)
    >>> b = Sine(freq=notes['pitch'] * bend, mul=p).out()
    >>> c = Sine(freq=notes['pitch'] * bend * 0.997, mul=p).out()
    >>> d = Sine(freq=notes['pitch'] * bend * 1.005, mul=p).out()

    """
    def __init__(self, brange=2, scale=0, channel=0, mul=1, add=0):
        PyoObject.__init__(self, mul, add)
        self._brange = brange
        self._scale = scale
        self._channel = channel
        brange, scale, channel, mul, add, lmax = convertArgsToLists(brange, scale, channel, mul, add)
        self._base_objs = [Bendin_base(wrap(brange,i), wrap(scale,i), wrap(channel,i), wrap(mul,i), wrap(add,i)) for i in range(lmax)]

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

    def setBrange(self, x):
        """
        Replace the `brange` attribute.

        Parameters:

        x : int
            new `brange` attribute.

        """
        self._brange = x
        x, lmax = convertArgsToLists(x)
        [obj.setBrange(wrap(x,i)) for i, obj in enumerate(self._base_objs)]

    def setScale(self, x):
        """
        Replace the `scale` attribute.

        Parameters:

        x : int
            new `scale` attribute.

        """
        self._scale = x
        x, lmax = convertArgsToLists(x)
        [obj.setScale(wrap(x,i)) for i, obj in enumerate(self._base_objs)]

    def setChannel(self, x):
        """
        Replace the `channel` attribute.

        Parameters:

        x : int
            new `channel` attribute.

        """
        self._channel = x
        x, lmax = convertArgsToLists(x)
        [obj.setChannel(wrap(x,i)) for i, obj in enumerate(self._base_objs)]

    @property
    def brange(self): 
        """float. Bipolar range of the pitch bend in semitones."""
        return self._brange
    @brange.setter
    def brange(self, x): self.setBrange(x)   

    @property
    def scale(self): 
        """int. Output format. 0 = Midi, 1 = transpo."""
        return self._scale
    @scale.setter
    def scale(self, x): self.setScale(x)   

    @property
    def channel(self): 
        """int. Midi channel. 0 means all channels."""
        return self._channel
    @channel.setter
    def channel(self, x): self.setChannel(x)   

class Touchin(PyoObject):
    """
    Get the current value of an after-touch Midi controller.

    Get the current value of an after-touch Midi controller and optionally 
    maps it inside a specified range.

    Parentclass: PyoObject

    Parameters:

    minscale : float, optional
        Low range value for mapping. Defaults to 0.
    maxscale : float, optional
        High range value for mapping. Defaults to 1.
    init : float, optional
        Initial value. Defaults to 0.
    channel : int, optional
        Midi channel. 0 means all channels. Defaults to 0.

    Methods:

    setMinScale(x) : Replace the `minscale` attribute.
    setMaxScale(x) : Replace the `maxscale` attribute.
    setChannel(x) : Replace the `channel` attribute.

    Attributes:

    minscale : Minimum value for scaling.
    maxscale : Maximum value for scaling.
    channel : Midi channel. 0 means all channels.

    Notes:

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

    Examples:

    >>> s = Server().boot()
    >>> s.start()
    >>> notes = Notein(poly=10, scale=1, mul=.5)
    >>> touch = Touchin(minscale=1, maxscale=2, init=1)
    >>> p = Port(notes['velocity'], .001, .5)
    >>> b = Sine(freq=notes['pitch'] * touch, mul=p).out()
    >>> c = Sine(freq=notes['pitch'] * touch * 0.997, mul=p).out()
    >>> d = Sine(freq=notes['pitch'] * touch * 1.005, mul=p).out()

    """
    def __init__(self, minscale=0, maxscale=1, init=0, channel=0, mul=1, add=0):
        PyoObject.__init__(self, mul, add)
        self._minscale = minscale
        self._maxscale = maxscale
        self._channel = channel
        minscale, maxscale, init, channel, mul, add, lmax = convertArgsToLists(minscale, maxscale, init, channel, mul, add)
        self._base_objs = [Touchin_base(wrap(minscale,i), wrap(maxscale,i), wrap(init,i), wrap(channel,i), wrap(mul,i), wrap(add,i)) for i in range(lmax)]

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

    def setMinScale(self, x):
        """
        Replace the `minscale` attribute.

        Parameters:

        x : int
            new `minscale` attribute.

        """
        self._minscale = x
        x, lmax = convertArgsToLists(x)
        [obj.setMinScale(wrap(x,i)) for i, obj in enumerate(self._base_objs)]

    def setMaxScale(self, x):
        """
        Replace the `maxscale` attribute.

        Parameters:

        x : int
            new `maxscale` attribute.

        """
        self._maxscale = x
        x, lmax = convertArgsToLists(x)
        [obj.setMaxScale(wrap(x,i)) for i, obj in enumerate(self._base_objs)]

    def setChannel(self, x):
        """
        Replace the `channel` attribute.

        Parameters:

        x : int
            new `channel` attribute.

        """
        self._channel = x
        x, lmax = convertArgsToLists(x)
        [obj.setChannel(wrap(x,i)) for i, obj in enumerate(self._base_objs)]

    @property
    def minscale(self): return self._minscale
    @minscale.setter
    def minscale(self, x): self.setMinScale(x)   

    @property
    def maxscale(self): return self._maxscale
    @maxscale.setter
    def maxscale(self, x): self.setMaxScale(x)   

    @property
    def channel(self): return self._channel
    @channel.setter
    def channel(self, x): self.setChannel(x)   

class Programin(PyoObject):
    """
    Get the current value of a program change Midi controller.

    Get the current value of a program change Midi controller.

    Parentclass: PyoObject

    Parameters:

    channel : int, optional
        Midi channel. 0 means all channels. Defaults to 0.

    Methods:

    setChannel(x) : Replace the `channel` attribute.

    Attributes:

    channel : Midi channel. 0 means all channels.

    Notes:

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

    Examples:

    >>> s = Server().boot()
    >>> s.start()
    >>> notes = Notein(poly=10, scale=1, mul=.5)
    >>> pchg = Programin(mul=1./12, add=1)
    >>> p = Port(notes['velocity'], .001, .5)
    >>> b = Sine(freq=notes['pitch'] * pchg, mul=p).out()
    >>> c = Sine(freq=notes['pitch'] * pchg * 0.997, mul=p).out()
    >>> d = Sine(freq=notes['pitch'] * pchg * 1.005, mul=p).out()

    """
    def __init__(self, channel=0, mul=1, add=0):
        PyoObject.__init__(self, mul, add)
        self._channel = channel
        channel, mul, add, lmax = convertArgsToLists(channel, mul, add)
        self._base_objs = [Programin_base(wrap(channel,i), wrap(mul,i), wrap(add,i)) for i in range(lmax)]

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

    def setChannel(self, x):
        """
        Replace the `channel` attribute.

        Parameters:

        x : int
            new `channel` attribute.

        """
        self._channel = x
        x, lmax = convertArgsToLists(x)
        [obj.setChannel(wrap(x,i)) for i, obj in enumerate(self._base_objs)]

    @property
    def channel(self): return self._channel
    @channel.setter
    def channel(self, x): self.setChannel(x)   

class MidiAdsr(PyoObject):
    """
    Midi triggered ADSR envelope generator.

    Calculates the classical ADSR envelope using linear segments. 
    The envelope starts when it receives a positive value in input,
    this value is used as the peak amplitude of the envelope. The
    `sustain` parameter is a fraction of the peak value and sets
    the real sustain value. A 0 in input (note off) starts the
    release part of the envelope.

    Parentclass: PyoObject

    Parameters:

    input : PyoObject
        Input signal used to trigger the envelope. A positive value
        sets the peak amplitude and starts the envelope. A 0 starts
        the release part of the envelope.
    attack : float, optional
        Duration of the attack phase in seconds. Defaults to 0.01.
    decay : float, optional
        Duration of the decay phase in seconds. Defaults to 0.05.
    sustain : float, optional
        Amplitude of the sustain phase, as a fraction of the peak
        amplitude at the start of the envelope. Defaults to 0.7.
    release : float, optional
        Duration of the release phase in seconds. Defaults to 0.1.

    Methods:

    setInput(x, fadetime) : Replace the `input` attribute.
    setAttack(x) : Replace the `attack` attribute.
    setDecay(x) : Replace the `decay` attribute.
    setSustain(x) : Replace the `sustain` attribute.
    setRelease(x) : Replace the `release` attribute.

    Attributes:

    input : PyoObject. Input signal used to trigger the envelope.
    attack : float. Duration of the attack phase in seconds.
    decay : float. Duration of the decay in seconds.
    sustain : float. Amplitude of the sustain phase.
    release : float. Duration of the release in seconds.

    Notes:

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

    Shape of a classical Adsr:

          -
         -  -
        -     -
       -        ------------------------
      -                                  -
     -                                     -
    -                                        -
      att - dec -        sustain       - rel

    Examples:

    >>> s = Server().boot()
    >>> s.start()
    >>> mid = Notein(scale=1)
    >>> env = MidiAdsr(mid['velocity'], attack=.005, decay=.1, sustain=.4, release=1)
    >>> a = SineLoop(freq=mid['pitch'], feedback=.1, mul=env).out()
    >>> b = SineLoop(freq=mid['pitch']*1.005, feedback=.1, mul=env).out(1)

    """
    def __init__(self, input, attack=0.01, decay=0.05, sustain=0.7, release=0.1, mul=1, add=0):
        PyoObject.__init__(self, mul, add)
        self._input = input
        self._attack = attack
        self._decay = decay
        self._sustain = sustain
        self._release = release
        self._in_fader = InputFader(input)
        in_fader, attack, decay, sustain, release, mul, add, lmax = convertArgsToLists(self._in_fader, attack, decay, sustain, release, mul, add)
        self._base_objs = [MidiAdsr_base(wrap(in_fader,i), wrap(attack,i), wrap(decay,i), wrap(sustain,i), wrap(release,i), wrap(mul,i), wrap(add,i)) for i in range(lmax)]

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

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

        Parameters:

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

        """
        self._input = x
        self._in_fader.setInput(x, fadetime)

    def setAttack(self, x):
        """
        Replace the `attack` attribute.

        Parameters:

        x : float
            new `attack` attribute.

        """
        self._attack = x
        x, lmax = convertArgsToLists(x)
        [obj.setAttack(wrap(x,i)) for i, obj in enumerate(self._base_objs)]

    def setDecay(self, x):
        """
        Replace the `decay` attribute.

        Parameters:

        x : float
            new `decay` attribute.

        """
        self._decay = x
        x, lmax = convertArgsToLists(x)
        [obj.setDecay(wrap(x,i)) for i, obj in enumerate(self._base_objs)]

    def setSustain(self, x):
        """
        Replace the `sustain` attribute.

        Parameters:

        x : float
            new `sustain` attribute.

        """
        self._sustain = x
        x, lmax = convertArgsToLists(x)
        [obj.setSustain(wrap(x,i)) for i, obj in enumerate(self._base_objs)]

    def setRelease(self, x):
        """
        Replace the `sustain` attribute.

        Parameters:

        x : float
            new `sustain` attribute.

        """
        self._release = x
        x, lmax = convertArgsToLists(x)
        [obj.setRelease(wrap(x,i)) for i, obj in enumerate(self._base_objs)]

    @property
    def attack(self):
        """float. Duration of the attack phase in seconds.""" 
        return self._attack
    @attack.setter
    def attack(self, x): self.setAttack(x)

    @property
    def decay(self):
        """float. Duration of the decay phase in seconds.""" 
        return self._decay
    @decay.setter
    def decay(self, x): self.setDecay(x)

    @property
    def sustain(self):
        """float. Amplitude of the sustain phase, as fraction of the peak amplitude.""" 
        return self._sustain
    @sustain.setter
    def sustain(self, x): self.setSustain(x)

    @property
    def release(self):
        """float. Duration of the release phase in seconds.""" 
        return self._release
    @release.setter
    def release(self, x): self.setRelease(x)

class MidiDelAdsr(PyoObject):
    """
    Midi triggered ADSR envelope generator with pre-delay.

    Calculates the classical ADSR envelope using linear segments. 
    The envelope starts after `delay` seconds when it receives a 
    positive value in input, this value is used as the peak amplitude 
    of the envelope. The `sustain` parameter is a fraction of the 
    peak value and sets the real sustain value. A 0 in input (note off) 
    starts the release part of the envelope.

    Parentclass: PyoObject

    Parameters:

    input : PyoObject
        Input signal used to trigger the envelope. A positive value
        sets the peak amplitude and starts the envelope. A 0 starts
        the release part of the envelope.
    delay : float, optional
        Duration of the delay phase, before calling the envelope 
        in seconds. Defaults to 0.
    attack : float, optional
        Duration of the attack phase in seconds. Defaults to 0.01.
    decay : float, optional
        Duration of the decay phase in seconds. Defaults to 0.05.
    sustain : float, optional
        Amplitude of the sustain phase, as a fraction of the peak
        amplitude at the start of the envelope. Defaults to 0.7.
    release : float, optional
        Duration of the release phase in seconds. Defaults to 0.1.

    Methods:

    setInput(x, fadetime) : Replace the `input` attribute.
    setDelay(x) : Replace the `delay` attribute.
    setAttack(x) : Replace the `attack` attribute.
    setDecay(x) : Replace the `decay` attribute.
    setSustain(x) : Replace the `sustain` attribute.
    setRelease(x) : Replace the `release` attribute.

    Attributes:

    input : PyoObject. Input signal used to trigger the envelope.
    delay : float. Duration of the delay phase in seconds.
    attack : float. Duration of the attack phase in seconds.
    decay : float. Duration of the decay in seconds.
    sustain : float. Amplitude of the sustain phase.
    release : float. Duration of the release in seconds.

    Notes:

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

    Shape of a DelAdsr envelope:

                -
               -  -
              -     -
             -        ------------------------
            -                                  -
           -                                     -
    -------                                        -
    delay - att - dec -        sustain       - rel

    Examples:

    >>> s = Server().boot()
    >>> s.start()
    >>> mid = Notein(scale=1)
    >>> env = MidiDelAdsr(mid['velocity'], delay=.25, attack=.005, decay=.1, sustain=.4, release=1)
    >>> a = SineLoop(freq=mid['pitch'], feedback=.1, mul=env).out()
    >>> b = SineLoop(freq=mid['pitch']*1.005, feedback=.1, mul=env).out(1)

    """
    def __init__(self, input, delay=0, attack=0.01, decay=0.05, sustain=0.7, release=0.1, mul=1, add=0):
        PyoObject.__init__(self, mul, add)
        self._input = input
        self._delay = delay
        self._attack = attack
        self._decay = decay
        self._sustain = sustain
        self._release = release
        self._in_fader = InputFader(input)
        in_fader, delay, attack, decay, sustain, release, mul, add, lmax = convertArgsToLists(self._in_fader, delay, attack, decay, sustain, release, mul, add)
        self._base_objs = [MidiDelAdsr_base(wrap(in_fader,i), wrap(delay,i), wrap(attack,i), wrap(decay,i), wrap(sustain,i), wrap(release,i), wrap(mul,i), wrap(add,i)) for i in range(lmax)]

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

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

        Parameters:

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

        """
        self._input = x
        self._in_fader.setInput(x, fadetime)

    def setDelay(self, x):
        """
        Replace the `delay` attribute.

        Parameters:

        x : float
            new `delay` attribute.

        """
        self._delay = x
        x, lmax = convertArgsToLists(x)
        [obj.setDelay(wrap(x,i)) for i, obj in enumerate(self._base_objs)]

    def setAttack(self, x):
        """
        Replace the `attack` attribute.

        Parameters:

        x : float
            new `attack` attribute.

        """
        self._attack = x
        x, lmax = convertArgsToLists(x)
        [obj.setAttack(wrap(x,i)) for i, obj in enumerate(self._base_objs)]

    def setDecay(self, x):
        """
        Replace the `decay` attribute.

        Parameters:

        x : float
            new `decay` attribute.

        """
        self._decay = x
        x, lmax = convertArgsToLists(x)
        [obj.setDecay(wrap(x,i)) for i, obj in enumerate(self._base_objs)]

    def setSustain(self, x):
        """
        Replace the `sustain` attribute.

        Parameters:

        x : float
            new `sustain` attribute.

        """
        self._sustain = x
        x, lmax = convertArgsToLists(x)
        [obj.setSustain(wrap(x,i)) for i, obj in enumerate(self._base_objs)]

    def setRelease(self, x):
        """
        Replace the `sustain` attribute.

        Parameters:

        x : float
            new `sustain` attribute.

        """
        self._release = x
        x, lmax = convertArgsToLists(x)
        [obj.setRelease(wrap(x,i)) for i, obj in enumerate(self._base_objs)]

    @property
    def delay(self):
        """float. Duration of the delay phase in seconds.""" 
        return self._delay
    @delay.setter
    def delay(self, x): self.setDelay(x)

    @property
    def attack(self):
        """float. Duration of the attack phase in seconds.""" 
        return self._attack
    @attack.setter
    def attack(self, x): self.setAttack(x)

    @property
    def decay(self):
        """float. Duration of the decay phase in seconds.""" 
        return self._decay
    @decay.setter
    def decay(self, x): self.setDecay(x)

    @property
    def sustain(self):
        """float. Amplitude of the sustain phase, as fraction of the peak amplitude.""" 
        return self._sustain
    @sustain.setter
    def sustain(self, x): self.setSustain(x)

    @property
    def release(self):
        """float. Duration of the release phase in seconds.""" 
        return self._release
    @release.setter
    def release(self, x): self.setRelease(x)