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

Creating the link object *sometimes* changes the tempo. #7

Open
bolau opened this issue Mar 28, 2024 · 5 comments
Open

Creating the link object *sometimes* changes the tempo. #7

bolau opened this issue Mar 28, 2024 · 5 comments

Comments

@bolau
Copy link

bolau commented Mar 28, 2024

As far as I can see, I have to provide a float tempo value when creating the Link object, e.g.

    link = Link(120, loop)
    link.enabled = True

Most of the time, this doesn't change the tempo in the linked Ableton, but adjusts to the tempo that is currently set in Ableton. But sometimes it is the other way around, and the tempo in Ableton is changed to the value provided in the constructor, roughly 10% of my trials. Is there a way of controlling this?

I tried using strange values like None, float('nan'), but that just yields an error message or non-working code, respectively. I also tried proving -1 or 0 as tempo, but that causes the same behavior as using 20 (sometimes setting Ableton's tempo to 20, or not changing the tempo most of the time).

What can I do?

Thanks for any help,
Best, Boris

@artfwo
Copy link
Owner

artfwo commented Mar 28, 2024

It might be a problem with the underlying Link library. I think a workaround for this could be adding a small delay between instantiating Link and setting link.enabled.

@bolau
Copy link
Author

bolau commented Mar 28, 2024

Thanks for the advice, that was very helpful. Indeed, a delay of 500ms does the job (while 200ms does not). For future reference:

    link = Link(120, loop)
    await asyncio.sleep(0.5)
    link.enabled = True

Cheers, Boris

@bolau bolau closed this as completed Mar 28, 2024
@artfwo
Copy link
Owner

artfwo commented Apr 2, 2024

@bolau i'd like to report this upstream, on which system does it happen for you? also does this only happen with Ableton Live or other Link-enabled apps?

@bolau
Copy link
Author

bolau commented Apr 2, 2024

Hi Artem,
I'm running on MacOS 13.6.2 (Ventura) on an M1 CPU. Below is a script to reproduce the issue:

  1. Start Ableton+Link, or run the script below, e.g., python test.py 120, keep it running.
  2. Run the script as an additional instance with a different tempo, e.g., python test.py 130.

Expected result: the second instance should adopt the tempo of the already running instance.

What actually happens: In roughly 70% of the trials, the second adopts the tempo of the first. But in roughly 30% of the trials, the tempo changes to that of the second instance.

If I uncomment the line containing the sleep, the latter does not happen anymore and I get the expected result.

import asyncio
import time
import sys
from aalink import Link

async def main():
    loop = asyncio.get_running_loop()

    tempo = int(sys.argv[1])

    link = Link(tempo, loop)
    # await asyncio.sleep(0.5)
    link.quantum = 4
    link.enabled = True
    print(dir(link))
    while True:
        r = await link.sync(1)
        print(link.tempo)

asyncio.run(main())

I hope this is clear. The issue happens with Ableton but also with two instances of the same script using aalink.

Best, Boris

@bolau bolau reopened this Apr 2, 2024
@artfwo
Copy link
Owner

artfwo commented Apr 5, 2024

Thanks @bolau !

So far I'm unable to reproduce it with pure C++ minimal example, but I can consistently reproduce it with your example in Python.

So it might be that the issue is actually with aalink (even though it's rather strange, since Python only calls the appropriate C++ counterparts). I'll keep looking into it!

Cheers,
Artem

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

No branches or pull requests

2 participants