Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Classlib: Fix Pfindur bug where the last event could lose its Rest status #5113

Merged
merged 2 commits into from
Aug 13, 2020

Conversation

jamshark70
Copy link
Contributor

Purpose and Motivation

When Pfindur reaches the end of its duration, it replaces the original event with a copy, where delta has been shortened so that the total duration matches the Pfindur limit.

But if event[\delta] is a Rest, then localdur - elapsed is not a rest -- so the event loses its isRest status and may play sound, even though the user pattern specified a Rest.

Pfindur(1, Pbind(\dur, Rest(1))).trace.play;
( 'dur': Rest(1), 'delta': 1.0 )   -- does not make sound

Pfindur(1, Pbind(\delta, Rest(1))).trace.play;
( 'delta': 1.0 )   -- does make sound

(It is valid for a pattern to specify timing using \delta, and it's valid for rests to be specified in a \delta stream -- so, Pfindur should respect that.)

Types of changes

  • Bug fix

To-do list

  • Code is tested
  • All tests are passing
  • This PR is ready for review

@jamshark70 jamshark70 added bug Issues that relate to unexpected/unwanted behavior. Don't use for PRs. comp: class library SC class library labels Jul 31, 2020
@jamshark70 jamshark70 mentioned this pull request Aug 1, 2020
Copy link
Contributor

@mossheim mossheim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ran the tests and checked the code from the PR description and it works. thanks!

i have some questions about one of the class library lines if you'll humor me ^^

@@ -433,7 +434,9 @@ Pfindur : FilterPattern {
if (nextElapsed.roundUp(tolerance) >= localdur) {
// must always copy an event before altering it.
// fix delta time and yield to play the event.
inevent = inevent.copy.put(\delta, localdur - elapsed).yield;
remaining = localdur - elapsed;
if(inevent.isRest) { remaining = Rest(remaining) };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIUC, with this current version, if delta isn't a rest, and inevent.isRest is true for another reason, outgoing event's delta is still a rest (i don't know if this is okay or not but it feels a bit messy). would it be better here to check delta.isRest? that would also be more efficient -- for any event that isn't a rest, with the line above we'll cycle through all of the key/value pairs every time.

am i right in thinking that inevent.isRest is true and delta isn't a rest, and we make a copy of inevent with a different delta, then inevent should still be a rest?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would it be better here to check delta.isRest?

The variable delta is always a number, because the event-delta primitive unwraps Rests and rejects non-numeric types. So delta.isRest is always false.

I could change it to inevent[\delta].isRest.

outgoing event's delta is still a rest (i don't know if this is okay or not but it feels a bit messy.

That's true. I didn't think it was especially harmful because (degree: Rest(0), delta: 1) and (degree: Rest(0), delta: Rest(1)) are both rests, so there's no change in outward behavior. But we don't know what the user is doing with anEvent[\delta] so you're right that it would be better to make it more precise.

am i right in thinking that inevent.isRest is true and delta isn't a rest, and we make a copy of inevent with a different delta, then inevent should still be a rest?

Yes. The bug occurs here if delta is the only Rest inside the event.

(Btw, aside, this is one of those places in the pattern library where the meanings of event and inevent are reversed. inevent should come from the argument or the previous yield and event should come from the stream. I never understood how this inverted convention got started but this isn't the only embedInStream method that makes this mistake.)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable delta is always a number, because the event-delta primitive unwraps Rests and rejects non-numeric types. So delta.isRest is always false.
I could change it to inevent[\delta].isRest.

ah okay, i didn't realize Event:-delta is not just a member access, but that makes sense. yeah, i think limiting it that way would be better.

(Btw, aside, this is one of those places in the pattern library where the meanings of event and inevent are reversed. inevent should come from the argument or the previous yield and event should come from the stream. I never understood how this inverted convention got started but this isn't the only embedInStream method that makes this mistake.)

possibly someone misinterpreting inevent as meaning 'the event we are in' rather than 'the input/incoming event' (is that the intended meaning?).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, done.

@mossheim mossheim added to-cherry-pick this PR should be cherry-picked onto the current release branch and removed to-cherry-pick this PR should be cherry-picked onto the current release branch labels Aug 9, 2020
Copy link
Contributor

@mossheim mossheim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks!

@mossheim mossheim merged commit c2a5587 into supercollider:develop Aug 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issues that relate to unexpected/unwanted behavior. Don't use for PRs. comp: class library SC class library
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants