[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [sc-users] A method.chaining idiom for livecoding?



Daniel,

Thanks so much for all of this: just what I was looking for, a way to dip my toe into understanding and writing classes and methods. I will have a proper look at this over the next few days.

Oh, and thanks for your EventShortcuts, that I've now begun to use.

Simon

On Tue, 1 Jan 2019 at 14:00, <daniel-mayer@xxxxxxxx> wrote:

When not only scrambling one would also want to define the number of choices.
I'd rewrite Prandc with a length arg:

Prandc : ListPattern {
var <>length;

*new { arg list, repeats = inf, length;
^super.new(list, repeats).length_(length ?? { list.size })
}

embedInStream { arg inval;
var item, stream;
var localList = { list.choose } ! length;

repeats.value(inval).do({ arg j;
localList.size.do({ arg i;
item = localList.wrapAt(i);
inval = item.embedInStream(inval);
});
});
^inval;
}
}


// the wrapper has to be adapted

+ ArrayedCollection {
    prandc {|repeats=inf, length|
        ^Prandc(this, repeats, length);
    }
}

After recompile:

Pbindef(\a, \note, (0..7).prandc(2, 4).repeat, \dur, 0.15).play

Pbindef(\a, \note, (0..7).prandc(3, 4).repeat, \dur, 0.15).play

Pbindef(\a, \note, (0..7).prandc(2, 3).repeat, \dur, 0.15).play


// with no length passed the array length is taken

Pbindef(\a, \note, (0..7).prandc(2).repeat, \dur, 0.15).play


Greetings

Daniel

-----------------------------
http://daniel-mayer.at
-----------------------------



--
J. Simon van der Walt - Composer
www.jsimonvanderwalt.com
+44 (0) 7905 270 198