[sc-users] MathLib
Julian Rohrhuber
rohrhuber at uni-hamburg.de
Sun Mar 4 00:47:15 PST 2007
>Julian,
>
>The MarkovSet class has some very nice potential. Do you happen to
>have an example of how to use it from within a Pbind or similar? It'd
>be nice to be able to use it to generate Pattern sequences but I can't
>spot how, I'm afraid.
When I have some time for it I'll rework the clsses a little, so that
they have a cleaner interface. But it is already easy to do:
// event streams
(
SynthDef("mark", { arg out, freq, sustain=1, amp=0.1, pan;
var env, u=1;
env = EnvGen.kr(Env.perc(0.03, sustain, 5), 1, doneAction:2);
3.do { var d; d = exprand(0.01, 1); u = SinOsc.ar(d * 300, u,
rrand(0.1, 0.4) * d, 1) };
Out.ar(out, Pan2.ar(SinOsc.ar(u + 1 * freq, 0, amp * env), pan));
}).store;
)
(
a = Pbind(
\freq, Pshuf([203, 490, 231, 764, 234], inf),
\dur, Pshuf([0.5, 0.5, 1.0, 0.25, 0.125, 0.5], inf)
);
m = MarkovSet.fill(20, Pevent(a, Event.default).asStream);
)
m.dict.keysValuesDo { |key, val| postf("key: %\t\tvalue: %\n", key, val) }; ""
// compare:
b = Pchain(Pfsm2(m), (instrument: \mark));
c = Pchain(a, (instrument: \mark));
Ppar([b, c]).play;
With Pspy you can collect events from running streams into a markov
set and if you set updateKeys to true you can use it at the same time
to generate a stream from the current state.
Note that event equality checks equality for each key. I have almost
finished an event pattern matching system that would be better for
this - I might combine the two systems in MathLib.
>Thanks
>Dan
>
>2007/3/3, Julian Rohrhuber <rohrhuber at uni-hamburg.de>:
>>I've fixed those, thank you for your suggestions! I've improved the
>>stream methods a bit, too.
>>
>>>
>>>I was trying out MarkovSetN (v3.4 from the MathLib quark) and it didn't seem
>>>to be behaving quite as I was expecting when using it in a stream:
>>>
>>>1. The lookUpDict values get rewritten as the buffer gets updated.
>>>2. When a seed is chosen, the stream returns nil n=order times rather than
>>>the values of the seed.
>>>3. Why is nil.alwaysYield used instead of automatically choosing a new seed
>>>like in MarkovSet?
>>>
>>>Just wondered whether these were bugs or misunderstandings on my part. The
>>>following changes work for me anyway...
>>>jamie
>>>
>>>/*
>>>m=MarkovSetN.fill(inf, Pseq("ababababaabb"),2); m.makeSeeds;
>>>n=m.asStream;
>>>30.do {n.next.postln;};
>>>*/
>>>
>>>+ MarkovSetN {
>>>
>>> embedInStream { arg inval, repeats=inf;
>>> var item, buffer, key;
>>>
>>> repeats.do {
>>> key = seeds.choose; //get a seed name
>>> ("chose a seed at random" + key).postln;
>>>
>>> //buffer = lookUpDict.at(key).asArray;
>>> buffer = lookUpDict.at(key).asArray.copy;
>>>//must be copied otherwise lookUpDict gets changed by buffer.removeAt(0)
>>>below
>>>
>>> //buffer.do { "fromBuffer: ".post;
>>>inval = item.yield };
>>> buffer.do {|item| "fromBuffer:
>>>".post; inval = item.yield };
>>>//arg item missing otherwise get nil for n=order items in the stream
>>>
>>> while {
>>> item = this.get(key);
>>> item.notNil;
>>> } {
>>> buffer.removeAt(0);
>>> buffer = buffer.add(item);
>>> key = buffer.asSymbol;
>>> item.yield;
>>> };
>>> //nil.alwaysYield;
>>>//why not choose seed at random like MarkovSet?
>>> };
>>> ^inval;
>>> }
>>>}
>>>
>>>
>>>
>>>
>>>
>>>Julian Rohrhuber wrote:
>>>>
>>>> I've bundled a couple of math-related classes and extensions
>>>> into a thematic quark library: MathLib. It is not my personal library,
>>>> so please feel free to suggest things to add that are missing.
>> >>
>>>>
>>>> //////////////
>>>> installing it:
>>>>
>>>> Quarks.install("MathLib");
>>>>
>>>> if you run into problems with svn, see Quarks.help.
>>>>
>>>>
>>>> /////////////////
>>>> MathLib contents:
>>>>
>>>> MarkovSet:
>>>> MarkovSet
>>>> MarkovSetN
>>>> IdentityMarkovSet
>>>> LookupMarkovSet
>>>> ShannonFinger
>>>> FuzzyDictionary
>>>> FuzzySet
>>>>
>>>> Patterns:
>>>> P3n1
>>>> Pboolnet // an adaption of Sekhar's boolean network pattern.
>>>>
>>>>
>>>> extensions:
>>>> statistical methods by Alberto de Campo
>>>> information theory stuff for Bag
>>>> matrix elimination by Kathi Vogt
>>>> a test whether a number is a cantor number
>>>> a simple way to write a quine
>>>>
>>>> and a LaTeX table generator
>>>> --
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> .
>>>> _______________________________________________
>>>> sc-users mailing list
>>>> sc-users at create.ucsb.edu
>>>> http://www.create.ucsb.edu/mailman/listinfo/sc-users
>>>>
>>>>
>>>
>>>--
>>>View this message in context:
>>>http://www.nabble.com/MathLib-tf3229108.html#a9287638
>>>Sent from the Supercollider - User mailing list archive at Nabble.com.
>>>
>>>_______________________________________________
>>>sc-users mailing list
>>>sc-users at create.ucsb.edu
>>>http://www.create.ucsb.edu/mailman/listinfo/sc-users
>>
>>
>>--
>>
>>
>>
>>
>>
>>.
>>_______________________________________________
>>sc-users mailing list
>>sc-users at create.ucsb.edu
>>http://www.create.ucsb.edu/mailman/listinfo/sc-users
>>
>
>
>--
>http://www.mcld.co.uk
>_______________________________________________
>sc-users mailing list
>sc-users at create.ucsb.edu
>http://www.create.ucsb.edu/mailman/listinfo/sc-users
--
.
More information about the sc-users
mailing list