Skip to content

Adding click and play note for Lattices#701

Open
wilckerson wants to merge 1 commit intoxenharmonic-devs:mainfrom
wilckerson:lattice-click-support
Open

Adding click and play note for Lattices#701
wilckerson wants to merge 1 commit intoxenharmonic-devs:mainfrom
wilckerson:lattice-click-support

Conversation

@wilckerson
Copy link
Copy Markdown
Contributor

This PR comes from a feature that I miss, which I didn't find an open issue, where the Lattices could play the notes by clicking/touching them. The feature was added to the Lattice node and label, helping with the click region that may become small on mobile phones.

The logic used to handle the click/touch was the same as VirtualPiano.vue. I think it could be extracted in a helper function and refactored to all places to use the same underlying implementation. However, it can be done in another PR to avoid this one getting bigger.

Thanks.

@wilckerson
Copy link
Copy Markdown
Contributor Author

@frostburn would you mind reviewing this one? Thanks

@frostburn
Copy link
Copy Markdown
Member

The issues are poorly organized. Playing notes by clicking is mentioned here in comment in a TODO list: #38

The main reason playing hasn't been implemented is the ambiquity of the equave. Shepard tones could solve that issue, but come with their own set of issues.

Let's see what you got here...

Comment thread src/components/GridLattice.vue Outdated
onMouseEnter:MouseEventCallback
onMouseLeave:MouseEventCallback
}>()
type TouchEventCallback = (event: TouchEvent, index: number) => void
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

These types are repeated multiple times. Make a src/types.ts or similar so that they can be tweaked from a single location in the future if needed.

@frostburn
Copy link
Copy Markdown
Member

Stuff I noticed

  1. The lattice nodes are hard to click on. Activating the closest vertex when the SVG is clicked could lead to a better UX.
  2. I was kind of expecting to hear 1/1 when clicking the equave, but I guess it makes sense to play what the label says.
  3. Sustaining clicked nodes when Shift is pressed could be nice, but we'd need that on the virtual keyboard as well.
  4. Missing an entry in CHANGELOG.md

Nice work overall!

@frostburn
Copy link
Copy Markdown
Member

Please make an issue about the refactoring if you're not going to do it here.

@frostburn
Copy link
Copy Markdown
Member

@wilckerson What's the status of this PR? Just let us know if you don't have time to work on it and I can tidy it up.

@wilckerson
Copy link
Copy Markdown
Contributor Author

@frostburn Sorry for taking so long, I can work on those fixes in the following days. But thank you for offering help =)

@frostburn
Copy link
Copy Markdown
Member

@frostburn Sorry for taking so long, I can work on those fixes in the following days. But thank you for offering help =)

No problem. Thanks for keeping us in the loop.

@wilckerson wilckerson force-pushed the lattice-click-support branch from 17d59f9 to d4bfe71 Compare June 11, 2024 02:13
onMounted(() => {
window.addEventListener('mouseup', onWindowMouseUp)
})
const playNote = usePlayNote(props.noteOn);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

All the play note logic is now refactored inside this hook. It is referenced here and other components.

)

type NoteOff = () => void
type NoteOnCallback = (index: number) => NoteOff
Copy link
Copy Markdown
Contributor Author

@wilckerson wilckerson Jun 11, 2024

Choose a reason for hiding this comment

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

Removing this in favor of the already existing type inside the xen-midi.

@wilckerson
Copy link
Copy Markdown
Contributor Author

wilckerson commented Jun 11, 2024

@frostburn I have handled your feedback and you may close this PR. Sorry for taking so long.
The only parts that I was not able to implement here were:

  • Activating the closest vertex by clicking
  • Sustaining clicked nodes when Shift is pressed
    I think those could be handled later as an improvement of the current feature.
    Thanks.

import { LEFT_MOUSE_BTN } from '@/constants'
import type { NoteOff, NoteOnCallback } from 'xen-midi'

export function usePlayNote(noteOn: NoteOnCallback) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Semantically this appears to be better implemented as a class.

stroke-width="1"
pointer-events="none"
/>
<rect x="100" y="100" width="98" height="98" rx="5" ry="5" :fill="noteOffFill" stroke="lightslategray"
Copy link
Copy Markdown
Member

@frostburn frostburn Jun 11, 2024

Choose a reason for hiding this comment

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

While stuff like this arguably looks better, we use automatic formatting so just do npm run format please. If you strongly disagree with the formatter make a separate PR tweaking its settings.

@frostburn
Copy link
Copy Markdown
Member

Clicking on a lattice node and dragging away enters a buggy mode where the note plays when you hover over the node again. Clicking on the node when in this buggy state makes the note play indefinitely.

@frostburn
Copy link
Copy Markdown
Member

The frequencies associated with a node are incorrect when using lattice permutations such as created using Generator sequence and pressing the Lattice button: https://sw3.lumipakkanen.com/scale/_1if4acyL

@frostburn
Copy link
Copy Markdown
Member

Cycles and 3D lattice options were added recently? Are you going to add functionality for them too?

import type { NoteOnCallback } from 'xen-midi'

defineProps<{
noteOn: NoteOnCallback
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This prop now has the incorrect type (wrong number of arguments). You need to modify App.vue too.

@frostburn
Copy link
Copy Markdown
Member

Fixing the buggy click and drag behavior probably requires redesigning of the whole event system. My suggestion is to put this lattice stuff on hold and redesign the event system in a separate PR if you're up for it. Adding touch dragging similar to Hexatone addressing #717 would be nice too.

@wilckerson
Copy link
Copy Markdown
Contributor Author

Alright. It sounds good. Let me see what I can do.
Thanks

@frostburn
Copy link
Copy Markdown
Member

Is this still being worked on? Had to do a big overhaul of the codebase because the JS ecosystem had rushed ahead once again. npm audit was not happy to say the least.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants