Merge pull request #506 from andrewcsmith/patch-2
[supercollider.git] / HelpSource / Classes / Index.schelp
blob0a95ecab979c6ee5514dad226d5f15318d93496f
1 class:: Index
2 summary:: Index into a table with a signal
3 related:: Classes/WrapIndex, Classes/Shaper
4 categories::  UGens>Buffer
6 Description::
7 Index into a table with a signal.
8 The input signal value is truncated to an integer value and used as an
9 index into the table. Out-of-range index values are clipped to the valid
10 range.
12 classmethods::
14 method::ar, kr
16 argument::bufnum
17 Index of the buffer.
19 argument::in
20 The input signal.
22 argument::mul
23 Output will be multiplied by this value.
25 argument::add
26 This value will be added to the output.
29 Examples::
30 code::
31 // indexing into a fixed table
34         SinOsc.ar(
35                         Index.kr(
36                                 LocalBuf.newFrom([ 200, 300, 400, 500, 600, 800 ]),
37                                 LFSaw.kr(2.0).range(0, 7)
38                         ),
39                         0,
40                         0.5
41                 )
42 }.play;
45 // with mouse control
48         SinOsc.ar(
49                         Index.kr(
50                                 LocalBuf.newFrom([ 200, 300, 400, 500, 600, 800 ]),
51                                 MouseX.kr(0, 7)
52                         ),
53                         0,
54                         0.5
55                 )
56 }.play;
60 // indexing into a changeable table
61 s = Server.local;
62 t = [ 200, 300, 400, 500, 600, 800 ];
63 b = Buffer(s, t.size, 1);
65 // alloc and set the values
66 s.listSendMsg( b.allocMsg( b.setnMsg(0, t) ).postln );
68 SynthDef(\help_Index, { arg out = 0, i_bufnum = 0;
69         Out.ar(0,
70                 SinOsc.ar(
71                         Index.kr(
72                                 i_bufnum,
73                                 LFSaw.kr(2).range(0, 7)
74                         ),
75                         0,
76                         0.5
77                 )
78         )
79 }).play(s, [\i_bufnum, b]);
82 b.setn(*[ 200, 300, 400, 500, 600, 800 ].scramble.postln - 30);
86 SynthDef(\help_Index, { arg out=0,i_bufnum=0;
87         Out.ar(0,
88                 SinOsc.ar(
89                         Index.kr(
90                                 i_bufnum,
91                                 MouseX.kr(0, BufFrames.ir(i_bufnum))
92                         ),
93                         0,
94                         0.5
95                 )
96         )
97 }).play(s, [\i_bufnum, b]);
100 b.free;