Converting a Class to an Event?

Hi there -

I’m in a situation where I can’t easily load extensions and classes onto a secondary computer. I’m wondering what sorts of things might be able to be “snuck in” via basic SuperCollider code. Most specifically, I was thinking it would be particularly useful if I could use Peuclid (class source code, posted below) .

Does anyone know if this is possible or if it would require a major re-tooling of the source code?

Peuclid : Pattern {
	var <>numHits, <>numBeats, <>repeats;

	*new { |numHits = 7, numBeats = 12, repeats = 1|
		^super.newCopyArgs(numHits, numBeats, repeats)
	}

	embedInStream { |inval|
		var currval = 0, lastval = -1;
		var repStream = repeats.asStream;
		var numHitStream = numHits.asStream;
		var numBeatStream = numBeats.asStream;

		repStream.next(inval).do { arg j;
			var numBeatVal = numBeatStream.next(inval);
			var numHitVal = numHitStream.next(inval);
			var increment;

			if (numBeatVal.notNil and: numHitVal.notNil) {
				// cant have more hits than beats
				numHitVal = min(numBeatVal, numHitVal);
				increment = (numHitVal / numBeatVal);

				numBeatVal.do { arg i;
					var isHit;
					isHit = (currval - lastval).round(1e-10) >= 1;
					// [currval, lastval, isHit].postln;
					if (isHit) { lastval = currval.round(1e-10).trunc };
					inval = isHit.binaryValue.embedInStream(inval);
					currval = (currval + increment);
				};
			}
		};
		^inval;
	}

	storeArgs { ^[ numHits, numBeats, repeats ] }
}

Object prototyping with Event can’t handle pattern/stream usage because it can’t override methods that Event already understands – including asStream and embedInStream, which are crucial for patterns.

But some years ago, I wrote a class Proto (ddwPrototype quark) that makes an environment behave like a class, and does provide hooks for a few of these important methods. You can use a Proto like a pattern by setting ~canStream = true in its environment, and implementing either ~asStream or preferably ~embedInStream.

I’m in a meeting now, could perhaps post code later.

hjh

Good to know, thanks for the explanation. I’ll check out Proto, but it might not hold for the current project (if I could get Quarks loaded, I wouldn’t necessarily be shooting for a workaround…).

Ah right… no extensions.

I think there is no way to make a “soft” class definition in plain SC that will respond to the pattern/stream interface (because it’s a global interface – all classes already respond to it).

hjh

If this is the same project as https://scsynth.org/t/autoloading-scd-on-a-rasperry-pi-zero, you could copy the Peuclid class file to the SCClassLibrary inside the standalone - you don’t necessarily need to do it through the Quarks interface. But I’m just guessing here!