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

Re: [Sc-devel] Scale




Am 11.02.2008 um 19:29 schrieb Tim Walters:

It's nice to be able to do
a = Scale().ionian

This could be done if we'd put a dictionary straight into *new

	*new {
		^()
		.ionian_([2,2,1,2,2,2,1])
		.augmented_([3,1,2,1,3,1]); // etc.
	}

Is this how you'd do it?

Building a dictionary into each instance seems like a lot of overhead.


Yes.

Maybe Felix will do it similar to Spec.specs

(where one can add new entries at runtime)






Using doesNotUnderstand is arguably a bit cheesy, but avoids that:

ScaleTest {

	classvar scaleDict;

	var <>stepRatios;

	*initClass {
		scaleDict = IdentityDictionary[
			\ionian -> [2, 2, 1, 2, 2, 2, 1],
			\aeolian -> [2, 1, 2, 2, 1, 2, 2],
			// etc.
		];
	}

	*new {
		|key|
		var newScale;
		newScale = super.new;
^(scaleDict.includesKey(key)).if({ newScale.init(key) }, { newScale })
	}

	init {
		|key|
		stepRatios = scaleDict[key];
		^stepRatios.isNil.if({ nil }, { this })
	}

	*doesNotUnderstand {
		|selector, args|
^(scaleDict.includesKey(selector)).if({ this.new(selector) }, { nil })
	}
}


--
Tim Walters | http://doubtfulpalace.com


_______________________________________________
Sc-devel mailing list
Sc-devel@xxxxxxxxxxxxxxx
http://lists.create.ucsb.edu/mailman/listinfo/sc-devel