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

Re: [sc-users] Strange behavior of event type 'phrase'?



On Saturday, December 28, 2013 7:16:16 AM HKT, tasos tsesmetzis wrote:
Hello,
I tried to play a Pdef through an Event by using the event type 'phrase'.
However, the frequencies from Pdef's pattern doesn't seem to embed in the
Event.

I see what the problem is. It's a bug.

First, a note for Julian or any of the other JIT folks -- the rest check in with the phrase event function is 1/ out of date (should use currentEnvironment.isRest):

			freq = ~freq.value;
			rest = freq.isKindOf(Symbol); // check for outer rests

and 2/ superfluous, because the phrase function will never be called if it's a rest, because the default event prototype's play function does:

	if(currentEnvironment.isRest.not) { ~eventTypes[~type].value(server) };

So I would suggest removing that. It doesn't accomplish anything.

Back to the original problem: Actually, it comes from Event:isRest, which I wrote, specifically these two lines:

	// save detunedFreq so that it won't be re-calculated later
	(~detunedFreq = ~detunedFreq.value).isRest

For typical note-type events, this is more efficient. Without the reassignment back into ~detunedFreq, the event would calculate the frequency once while checking if the event is a rest and again while evaluating the event type's function.

For \phrase, anything that's in the phrase-type event gets passed into the child's pattern, and this bypasses normal frequency calculation.

So the easiest fix is to replace the above with the single line:

	~detunedFreq.value.isRest

I will go ahead and do that. I benchmarked and the extra cost of evaluating ~detunedFreq seems insignificant (on the order of 0.3%). In the meantime, you can do that in your own copy of the class library and the problem should go away.

(
var parent = (play: {
	var freq;
	if(currentEnvironment.isRest.not) {
		freq = ~detunedFreq.value
	}
});
bench { 100000.do { ().parent_(parent).play } };
)

~detunedFreq.value.isRest
time to run: 1.430979013443 seconds.

(~detunedFreq = ~detunedFreq.value).isRest
time to run: 1.4364700317383 seconds.

hjh

_______________________________________________
sc-users mailing list

info (subscription, etc.): http://www.beast.bham.ac.uk/research/sc_mailing_lists.shtml
archive: https://listarc.bham.ac.uk/marchives/sc-users/
search: https://listarc.bham.ac.uk/lists/sc-users/search/