microbit-foundation / micropython-microbit-v2

Temporary home for MicroPython for micro:bit v2 as we stablise it before pushing upstream
MIT License
43 stars 24 forks source link

music.stop pin argument #31

Closed microbit-carlos closed 3 years ago

microbit-carlos commented 3 years ago

The music.stop() function can take a pin argument like play().

Does it currently correctly process tuples? It doesn't throw an error, but don't know if it works as expected. Technically in this case the user could also do music.stop(pin=pin_speaker) and music.stop(pin=pin0) to stop the music in both pins, but it does make sense to mirror play.

I guess my question is how having music play over multiple pins is going to interact with the stop function. Will it work when doing play(..., pin=(pin_speaker, pin0)) and then we only want to stop a single pin music.stop(pin=pin0)?

This on the REPL currently stops the music playing in the speaker

>>> music.play(music.PYTHON, wait=False)
>>> music.stop(pin0)

Another thing to consider for https://github.com/microbit-foundation/micropython-microbit-v2/issues/30 as well.

jaustin commented 3 years ago

New behaviour

This makes the pin argument mostly redundant, but kept for compatibility and the subtle case that you're, say, playing on pin2, and call stop on pin1 (speaker will stop in any case).

microbit-carlos commented 3 years ago

Related: https://github.com/microbit-foundation/micropython-microbit-v2/issues/50

jaustin commented 3 years ago

@dpgeorge did the stop behaviour described here get implemented in the end?

dpgeorge commented 3 years ago

did the stop behaviour described here get implemented in the end?

No. The current behaviour is simply that, whether or not music.stop() is given a pin argument, it stops the music and disconnects whatever pin was used from the mixer (hence also stopping all other sounds like expressions on that pin). The speaker stays connected though.

You can test this behaviour with:

music.play(music.NYAN,wait=0); audio.play(Sound.HAPPY); sleep(50); music.stop()

(that will play music for 50ms then stop it, but the HAPPY will continue, on the speaker)

dpgeorge commented 3 years ago

pin argument: stop on speaker and that pin if playing, do not stop on other pins

This is not really possible to do with the current CODAL, because you can only play on one pin at a time (in addition to the speaker).

dpgeorge commented 3 years ago

This issue is affected by the outcome of #50, so maybe that needs to be resolved first?

dpgeorge commented 3 years ago

This was implicitly fixed as part of #50 : music.stop() now only stops any ongoing sequencing of notes, it does not disconnect any pins.

The following test should now work as expected, the music stops but the sound expression continues (on both the internal speaker and external pin0):

music.play(music.NYAN,wait=0); audio.play(Sound.HAPPY,wait=0); sleep(50); music.stop()
dpgeorge commented 3 years ago

For completeness, this is the commit that addressed the issue here: 6790bb511b7966e727c147ff27269121e340435f