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

Add binary and binaryN #1226

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open

Add binary and binaryN #1226

wants to merge 14 commits into from

Conversation

heerman
Copy link

@heerman heerman commented Dec 11, 2024

Create patterns from binary, such as binary(5) -> "1 0 1".

"hh".s().struct(binary(5))
// "hh".s().struct("1 0 1")
"hh".s().struct(binaryN(55532, 16))
// "hh".s().struct("1 1 0 1 1 0 0 0 1 1 1 0 1 1 0 0")

From tidal cycles https://userbase.tidalcycles.org/binary.html

Addresses #670

@heerman
Copy link
Author

heerman commented Dec 11, 2024

Hey, this is my first contribution to strudel. Loving strudel and the live coding community!

@felixroos
Copy link
Collaborator

great stuff thanks :) the test is still failing, you can fix it by running pnpm codeformat

@felixroos
Copy link
Collaborator

tests now failing.. you can fix it withm pnpm snapshot i think. also it would be ace if these functions appeared in the docs, maybe here: https://strudel.cc/learn/factories/ (generated from factories.mdx)

@heerman
Copy link
Author

heerman commented Dec 27, 2024

also it would be ace if these functions appeared in the docs, maybe here: https://strudel.cc/learn/factories/ (generated from factories.mdx)

@felixroos I'm having trouble getting the example from signal.mjs to show in factories.mdx <JsDoc client:idle name="binaryN" h={0} />. Is there another step I need? Thanks.

@felixroos
Copy link
Collaborator

also it would be ace if these functions appeared in the docs, maybe here: https://strudel.cc/learn/factories/ (generated from factories.mdx)

@felixroos I'm having trouble getting the example from signal.mjs to show in factories.mdx <JsDoc client:idle name="binaryN" h={0} />. Is there another step I need? Thanks.

ah yes, if you change the example in the jsdoc, you need to restart the dev server (or run pnpm jsdoc-json) to regenerate the doc metadata

@heerman
Copy link
Author

heerman commented Dec 27, 2024

Ok got it @felixroos. I found a silly issue with my @name getting set to a multi-line string. All good now, ready for re-review.

@felixroos
Copy link
Collaborator

thanks! this looks good, i only wonder why you've decided against using fmap (similar to #670)?
there's still a formatting error. btw you can run pnpm check to see if your branch has an error, so you don't need to wait for the ci to run the tests

@heerman
Copy link
Author

heerman commented Dec 28, 2024

Well I did like the look of your binpatn, but I ran into a small limitation where I wasn't able to pattern the input "decimal".

Maybe that's just crazy? This is why I took a different approach to make it work. Thoughts?

let binpatn = (dec, len) => seq(
  ...dec.toString(2)
    .padStart(len, '0')
    .split('')
    .map(Number)
)
setcpm(144/4)

// patterned `dec` causes an error
d1: binpatn("<7 8 7 9>", 8)  // cannot parse as numeral: "NaN"
  .add(60).note().piano()._pianoroll({ labels: true })

// d1: binaryN("<7 8 7 9>", 8) // works
//   .add(60).note().piano()._pianoroll({ labels: true })

@felixroos

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