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

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



Next question: here's an idiom I use to make random patterns that repeat but change eg every four times:

Pbindef(\a, \note, Plazy({Pseq((0..7).scramble, 4)}).repeat, \dur, 1/4).play

With the new method from Jonathan (now called .pseq) I can do this:

Pbindef(\a, \note, Plazy({(0..7).scramble.pseq(4)}).repeat)

Would like to be able to write this

Pbindef(\a, \note, (0..7).pseq(4).plazy.repeat)

Or possibly this, although not as good:

Pbindef(\a, \note, {(0..7).pseq(4)}.plazy.repeat, \dur, 1/4)

But I can't figure it out. Tried two ideas below with the first syntax, neither work correctly:

+ Pattern {
    plazy {
        ^Plazy(this);
    }
}

+ Pattern {
    plazy {
        ^Plazy({this}); // added function braces
    }
}

Thanks,


On Sun, 30 Dec 2018 at 21:10, J. Simon van der Walt <tedthetrumpet@xxxxxxxxx> wrote:
Daniel,

'programming is mainly about saving typing' – that's rather profound! And, yes, pseq, prand etc makes more sense.

Ok, expect me back here with more questions along these lines… but so far, this is working nicely. Thanks both.

On Sun, 30 Dec 2018 at 20:18, <daniel-mayer@xxxxxxxx> wrote:
Am 30.12.2018 um 11:58 schrieb tedthetrumpet@xxxxxxxxx:

I'm not a programmer, so probably something fundamentally wrong with this… just an idea…

Not at all wrong, and: programming is mainly about saving typing !



Am 30.12.2018 um 12:31 schrieb info@xxxxxxxxxxxxxxxx:

Here's a simple example of how you could add such a method to ArrayedCollection. Put this in a class file (.sc) in your extensions directory.

+ ArrayedCollection {
    seq {|repeats=inf, offset=0|
        ^Pseq(this, repeats, offset);
    }
}


I second the idea. It's very easy to do, many people are using such personal wrappers.
One thing to take care of is the naming convention: as e.g. 'rand' is already taken for arrays
you wouldn't want to override the core method.
So it would look more natural to me to name the methods 'pseq', 'prand' etc.

Also +1 for the default repeats = inf in such case.

My PLx list patterns all default to repeats = inf.
miSCellaneous_lib contains several shortcuts for patterns, e.g. EventShortcuts which lets you customize
abbreviations for keys, by default e.g.  'n' means 'note', 'd' means 'dur' etc.
 
EventShortcuts.on

// PLbindef is also a wrapper for shorter replacement syntax

PLbindef(\x, \n, Pwhite(0, 10), \d, 0.2).play
~x.n = PLseq((0..5))

~x.n = PLrand((0..5))


// with pattern methods defined you could write

~x.n = (5..0).pseq
~x.n = (5..0).prand


BTW, already there are already some more core Patterns, where methods exist, 
resp. the methods are more commonly used than the syntax with Pattern objects, e.g. Pcollect

Regards

Daniel

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




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


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