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

How to get BPM? #1565

Closed
xorinzor opened this issue Apr 11, 2021 · 8 comments
Closed

How to get BPM? #1565

xorinzor opened this issue Apr 11, 2021 · 8 comments
Labels

Comments

@xorinzor
Copy link

When I try to get the BPM and store it in a variable using this code

bpm_a = 0
source_a = bpm(every=30., (fun(_) -> bpm_a), source_a)

It says

Error 5: this value has type
  (...) -> int
but it should be a subtype of
  (...) -> unit

But from what I can find in the documentation, I can't set a variable to "unit" (which would made sense since it's pretty ambiguous).
What would be the correct way of doing this?

@xorinzor xorinzor added the usage label Apr 11, 2021
@rrolla
Copy link
Contributor

rrolla commented Apr 12, 2021

maybe can help #467 :)

@xorinzor
Copy link
Author

Thanks, I did see that, but rather then using a separate function, I'd like to use a small anonymous function to keep the code more readable (need to get the BPM for 2 tracks).

It's also a matter of trying to understand the script language and how I should write it :)

@smimram
Copy link
Member

smimram commented Apr 12, 2021

You can store the bpm in a reference as follows (non-tested code but you should get the idea):

bpm_a = ref(0.)
source_a = bpm(every=30., (fun(b) -> bpm_a := b), source_a)

The reference bpm_a should then regularly be updated and you can get the bpm with !bpm_a.

For future reference, I have just improved the interface to something more sensible: 1401b4a.

@xorinzor
Copy link
Author

Is the bpm calculated when it's called?

When I use it like this:

bpm_a = ref(0.)
bpm_b = ref(0.)
source_a = bpm(every=10., (fun(bpm) -> bpm_a := bpm), source_a)
source_b = bpm(every=10., (fun(bpm) -> bpm_b := bpm), source_b)

log("BPM track A: #{string_of(!bpm_a)}")
log("BPM track B: #{string_of(!bpm_b)}")

the log always returns:

2021/04/12 15:57:07 [autodj_cross:3] BPM track A: 0.
2021/04/12 15:57:07 [autodj_cross:3] BPM track B: 0.

@smimram
Copy link
Member

smimram commented Apr 12, 2021

In your example, the bpm is updated every 10 seconds (and the first time it has to wait for 10 seconds, so that your log always display the initial value for the variables).

@xorinzor
Copy link
Author

Gotcha, I figured it would update instantly, and then every x amount of seconds (which is why I just gave it a higher value).
Is there a way of executing it once? If not I'll just use one of my other ideas :)

@smimram
Copy link
Member

smimram commented Apr 12, 2021

The thing is that the operator has to be fed with some audio before being able to compute the bpm...

I don't think there is an easy way of executing it once currently (if you really need this we can think of something based on switch I think, but it is not going to be easy)

@xorinzor
Copy link
Author

Ah, that makes sense.
No worries! My application will pre-process each track before ever adding it in liquidsoap anyway, so I can just store the BPM in a metatag and fetch it that way.

Thanks for the help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants