-
Notifications
You must be signed in to change notification settings - Fork 54
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
Multiple whiskers #62
Conversation
- allow to create multiple whiskers - whiskers can be removed - event listeners can be attached to whiskers - paperRemoved - paperAdded - whiskerMoved
client/paper/entry.js
Outdated
@@ -119,6 +136,9 @@ import { fillQuadTex, fillTriTex } from './canvasUtils'; | |||
callback, | |||
whiskerPointCallback, | |||
} = {}) => { | |||
// eslint-disable-next-line no-console | |||
console.warn('paper.whenPointsAt is deprecated, use the new whisker api instead'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know how we should handle deprecation of features. I've kept the original whiskers for now, but long term I think we should remove paper.whenPointsAt
to avoid confusion with the new whisker api.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we remove the code below and call get('whisker')
when calling this? So we don't have any duplicate code at least?
The console.warn
makes a lot of sense, let's keep that.
client/paper/whisker.js
Outdated
ctx.lineTo(whiskerEnd.x, whiskerEnd.y); | ||
ctx.stroke(); | ||
|
||
const dotFraction = Math.abs(Math.sin(Date.now() / 600)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've changed the dot animation to alternate direction. I wanted to avoid implying a direction of the dataflow which depends on what the whisker does and instead just visualize connectedness.
@@ -0,0 +1,171 @@ | |||
import EventEmitter from 'events'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've used the node EventEmitter because the browser event system adds unnecessary complication like event bubbling and dealing with Event objects instead of plain JS objects.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes sense, on the other hand this does add a non-standard API into Paper Programs. I think I would slightly prefer to use EventTarget
anyway because it's an accepted browser standard. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can see your point. I would like to make Paper Programs more accessible to people who are new to programming and don't know the web platforms. In this case, I don't see a lot of benefits or more powerful things you could do with the native browser events other than being compliant with the standard.
Maybe we should also have a more general discussion what the future goals of Paper Programs are. In the future, I would like to explore different programming models to make it easier to build things with Paper Programs. I probably should write down my thoughts about this sometime.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah that makes sense too. I'm mostly concerned about future compatibility, and bringing in concepts from Node feels a bit heavy in that respect. I don't have a super strong opinion though, so also happy to keep it this way.
And yeah, that would be useful! I don't really have goals for Paper Programs other than where you and other contributors want to take it. :)
docs/api.md
Outdated
whisker.destroy() | ||
``` | ||
|
||
*deprecated* old api: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe just delete this entirely?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are you referring to the part below "deprecated old api:" ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah!
client/paper/whisker.js
Outdated
} | ||
|
||
// render whisker with dot animation | ||
ctx.clearRect(0, 0, ctx.width, ctx.height); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Won't this wipe out the other whiskers too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch this does nothing, because ctx has no width and height
client/paper/whisker.js
Outdated
@@ -0,0 +1,171 @@ | |||
import EventEmitter from 'events'; | |||
|
|||
export default class WhiskerFactory { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure what the point is of this factory? The code might be simpler by just giving each whisker a unique identifier and getting a unique canvas for each whisker. Then you can keep everything contained in class Whisker
. Doesn't matter all that much, just thinking it might be simpler.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted to have just a single interval, but I agree that it would be simpler for each whisker to create its own interval. I'll change that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some small feedback here and there. Feel free to push back on points. 😄 Thanks for the PR!!
Let me know when you're happy with the PR, then I'll merge it. 👍 |
79309bc
to
785fb5f
Compare
Ready to merge |
785fb5f
to
fdb3894
Compare
Sorry for the late response 😞; and now it looks like there's a merge conflict. Let me know when it's resolved and I'll merge! |
I've resolved the merge conflicts now |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome thanks!!
Summary API Changes
as discussed in original issue: #49
Creation / Removal of whiskers
Currently, the API is missing a way to remove whiskers again. I would like to add a whisker only if the paper has something connected to the output. The program can change audio nodes dynamically so it should be possible to remove whiskers again if there is no longer anything connected to the sound output.
Different whisker color
If a paper has multiple whiskers it would be nice if you could change the color of the whisker to differentiate them better. Instead of a color change the "connected" state is indicated by the moving dot animation. If the paper is not connected a static line is rendered without the moving dot.
Separate event handlers for placement and removal of papers
I think it would be cleaner to have two separate events for when a paper is placed and when it's removed. This makes it easier to explain the API. It's not necessary to check for null and in the removed paper event handler we can also pass in the information about the paper which was removed.