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

Re: [Sc-devel] Scale



> 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.

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