Ebay
Introduction
This class constists of a number of functions, which are either not available as standard methods or calls. All methods within the class are Class-methods (i.e. they can not be called from instance of the class) and must be called after this scheme:
myResult = Ebay.method(parameters).
Class Ebay
The number of parameters equals the number of args in the corresponding function-definition. The class itself resides in SCClassLibrary and gets compiled automatically at each program-start.
Ebay { /* © Stefan Nussbaumer 2007, 2008 You may use, remix this for any purpose under the condition that the result is being passed on (published) under the same conditions (see license) as this originating piece of code. If any part of this is being published in a compiled program, the regarding parts have to be published as code together with the compiled program. The code must be available for free (at no expenses). If you alter this code you may add your name to the list of authors (copyright-holders). Please leave the names of authors having contributed before you untouched. published under the terms of this Creative-Commons-license: http://creativecommons.org/licenses/by-sa/2.0/at/deed.en */ // reading eBay-useraccounts // only necessary in version 02 *read { arg who, preprocessor; var curl, string, removeTags, tags, line, pipe, count, init; count = 0; curl = "curl -d \"user="++who++"&scout=1&submit=get%20data\" "++preprocessor++""; curl.postln; pipe = Pipe.new(curl, "r"); string = String.new; line = pipe.getLine; string = line; while({line.notNil or:{count < 100}}, {line = pipe.getLine; if(line.notNil, { /* "--------------------------".postln; line.postln;"--------------------------".postln; */ string = string ++ line}, { /*"--------------------------".postln; line.postln; "--------------------------".postln;*/ count = count+1;})}); pipe.close; // strip off junk-code like JavaScript generated adds ... removeTags = { arg html, tagname; var pos; var endpos; var headPart; var tailPart; pos = html.find("<" ++ tagname); if ( pos != nil, { headPart = html.copyFromStart(pos - 1); html = html.copyToEnd(pos); endpos = html.find(">"); if (endpos != nil, { // should always be !=nil, otherwise something's wrong html = html.copyToEnd(endpos + 1); // now remove end tag pos = html.find("</" ++ tagname ++ ">"); if ( pos!=nil, { headPart = headPart + html.copyFromStart(pos-1); html = html.copyToEnd(pos + tagname.size + 3); }); }); html = headPart + html; html = removeTags.value(html, tagname); // recursion to handle next occurrence }); html; }; tags = ["script"]; tags.do({|tag| string = removeTags.value(string, tag) }); ^string.interpret; } *divFunc { arg val, list, min, max, limit; var temp, outList, lim; if(limit.notNil, { if((max-(min+1)) < limit, { lim = max-(min+1) }, { lim = limit }); }); if(list.isNil, { outList = Array() }, { outList = list }); val.isPrime.if{val = val + 1}; val.do{ |i| if(i>min and:{i<max}, { temp = val/i; if(temp.mod(1) == 0 and:{ outList.includes(i).not }, { outList = outList.add(i) }); })}; if(limit.notNil and:{ outList.size < lim }, { ^this.divFunc(val+1, outList, min, max, lim) }, { ^outList.sort }); } // this function basically does the same as divFunc though it works with arrays as argument *divFuncArr { arg val, list, limit, inList, secondrun=false, pat=nil; var temp, outList, lim, max, min, orig; if(secondrun == false, { orig = list }, { orig = pat }); max = list.maxItem; min = list.minItem; if(limit.notNil, { if(list.size < limit, { lim = list.size }, { lim = limit }); }); if(inList.isNil, { outList = Array() }, { outList = inList }); val.isPrime.if{val = val + 1}; val.do{ |i| if(list.includes(i), { temp = val/i; if(temp.mod(1) == 0 and:{ outList.includes(i).not } and:{ orig.includes(i) }, { outList = outList.add(i) }); })}; if(limit.notNil and:{ outList.size < lim }, { ^this.divFuncArr(val+1, list, lim, outList, true, orig) // result contains less then the required number of items ("lim") }, { ^outList.sort }); } // result is an Array of trigger-values (e.g. [ 0, 0, 1, 0, 0, 1, 0, 1 ]) *trigList { |number, list, min, max| var temp, outList, lim; if(list.isNil, { outList = Array() }, { outList = list }); (min..max).do({ |i| temp = number/i; if(temp.mod(1) == 0, { outList = outList.add(1) }, { outList = outList.add(0) }); }); ^outList; } *gcdFunc { arg inList; // greatest common divisor, working on arrays in a way that each index gets compared to each index var outList; outList = List(); inList.do{ |i| inList.do{ |j| outList.add(i.asInteger.gcd(j.asInteger)) }; }; ^outList; } *lcmFunc { arg inList; // least common multiple, working in the same way as gcdFunc var outList; outList = List(); inList.do{ |i| inList.do{ |j| outList.add(i.asInteger.lcm(j.asInteger)) }; }; ^outList; } *harmSeries { arg inList; // stolen from JMC's diamond-tonality, generate a harmonic matrix. see also: http://en.wikipedia.org/wiki/Tonality_diamond var series1, series2, divisor, outList; outList = List(); series1 = List(); (1..inList.maxItem).do({ |i| if(inList.occurencesOf(i) > 0, { series1.add(i) })}); series1 = series1.asArray; series2 = series1 ++ (2 * series1) ++ (4 * (series1 ++ 16)); series1 = 4 * (series1 ++ 16); series1.postln; series2.postln; series2.reverse.do ({ |i| series1.do ({ |j| // [j, i].post; divisor = i gcd: j; // [j/divisor, i/divisor].postln; outList.add((j div: divisor) / (i div: divisor)); }); }); ^outList; } *harmScales { arg totalHarms, harmonics; // locate occurences of specific values in the scales generated with *harmScales var harmScales; harmScales = List(); harmonics.size.do({ |i| harmScales.add(List()); }); harmonics.do({ |i, j| totalHarms.do({ |k| // k.postln; if(i.occurencesOf(k) > 0 and:{harmScales[j].occurencesOf(k) < 1}, { harmScales[j].add(k); }); }) }) ^harmScales; } *roll { arg inList, number; // swap values in an array, each index is summed with number. if index+number goes beyond the range of values stored in the array, reduce or add up the result by inList.maxItem var temp, max, outArr; outArr = Array(inList.size); max = inList.maxItem; temp = inList+number.abs; temp.do({ |i| if(i >= 0 and:{ i <= max }, { outArr.add(i) }); if(i > max, { outArr.add(i-max) }); }); ^outArr; } }
Class EbaySynthDefs
For convenience all SynthDefs used in the process get compiled from a class when the program gets started. This class contains only one class-method which compiles all SynthDefs:
EbaySynthDefs { *load { // the SynthDef for sampling the user-comments SynthDef(\sampleIn1,{ arg bufnum=0, rq=13, emph=(-30); var in; in = SoundIn.ar(0); DiskOut.ar(bufnum, in * 0.75); }).store; // bass-drum SynthDef(\bd, { | out=0, amp, rq=0.35, emph=(-20), delaytime=0.001, decay=0.5 | var osc, env, base, son; osc = MidEQ.ar(FSinOsc.ar([47, 49], [0, pi]), 75, rq, emph); osc = RHPF.ar(osc, 40, 1); env = EnvGen.kr(Env.perc(0.01, 0.7), doneAction: 2); base = AllpassC.ar(RLPF.ar(osc, 70, 0,2), 0.6, delaytime, decay); Out.ar(out, (osc+Lag.ar(base, 2.0)) * env * amp); }).store; // snare-drum SynthDef(\sd, { | out=0, amp | var osc1, osc2, env; osc1 = WhiteNoise.ar; osc2 = FSinOsc.ar(200); env = EnvGen.kr(Env.perc(0, 0.05), doneAction: 2); Out.ar(out, Pan2.ar(LPF.ar(Mix([osc1, osc2]), 12000), 0, env * amp)); }).store; // high-hat SynthDef(\hat, { | out=0, ts=1, amp | var osc1, env; osc1 = PinkNoise.ar; env = EnvGen.kr(Env.perc(0, 0.01), timeScale:ts, doneAction: 2); Out.ar(out, Pan2.ar(osc1, 0, env * amp)); }).store; // delay SynthDef(\combDelay, { |out=0, dtime=0.2, decay=2, sust=1, gate=1| var in, env; env = Linen.kr(gate, 0.05, sust, 0.1, 2); in = In.ar(out, 2); Out.ar(0, CombC.ar(Decay.ar(in*env), 0.4, dtime, decay, 1, in)) }).store; // playing back the user-comments SynthDef(\sampleOutMono,{ arg out = 0, bufnum, startpos, duration, amp=1; var son, env; son = PlayBuf.ar(1, bufnum, BufRateScale.kr(bufnum), startPos:startpos, loop:1); env = EnvGen.kr(Env([0.1, 1.0, 1.0, 0.1], [0.5, duration-startpos-1.5, 1.0]), doneAction:2); Out.ar(out, son * env * amp); }).store; // band limited impulse wave oscillator SynthDef(\blipBase, { |out=0, freq, gate=1, length, rq=0.35, emph=20, amp, a=69, b=69, n1= 100, n2=100 | var env, sound; env = Env.new([0, 0.4, 0.15, 0]*amp, [0.2, 0.7, 0.6]*length, \sine); sound = Blip.ar([a, b]*freq, [n1, n2]); Out.ar(out, sound * EnvGen.kr(env, gate, doneAction:2)); }).store; // ping-pong delay SynthDef(\pingPong, { |out=0, bufnum, delaytime=0.2, feedback=0.5, bwidth=2000, xfade=0, coef=0.001, xout| var left, right, sound, env; env = Env([1, 1, 0], [2, 0.1], \sine); left = In.ar(out, 1); right = In.ar(out+1, 1); sound = PingPong.ar(bufnum, [left, right], delaytime, feedback, 1); XOut.ar(out, xout, Lag.ar(sound, 0.001) * EnvGen.kr(env, doneAction: 2)); }).store; // convert mono to stereo SynthDef(\panHelper, { |out=0| var in; in = In.ar(out, 1); ReplaceOut.ar(out, in ! 2); }).store; // vocoder SynthDef(\vocodeIt, { arg out=0, base, bufnumA, bufnumB, note, xfade=1; var inA, chainA, inB, chainB, chain, env; inA = LFSaw.ar([note * 75, note * 50], 0, 0.2).sum; inB = In.ar(out, 1); chainA = FFT(bufnumA, inA); chainB = FFT(bufnumB, inB); chain = PV_MagMul(chainA, chainB); ReplaceOut.ar(out, 0.2 * IFFT(chain)); }).store; // another voice-filter SynthDef(\specReduktor, { |out=0, numTeeth=32, phase=0, pulseWidth=0.4, bufnum, amp=1.0| var in, chain; in = In.ar(out, 1); chain = FFT(bufnum, in); chain = PV_RectComb(chain, numTeeth, phase, pulseWidth); ReplaceOut.ar(out, IFFT(chain) * amp); }).store; // low-pass filter SynthDef(\lowPass, { |out=0, rq=1, cutoff=800| var in; in = RLPF.ar(In.ar(out, 1), cutoff, rq); Out.ar(out, in); }).store; } }
page revision: 17, last edited: 14 Sep 2008 22:46