[Microbit-Python] J.S.MicroBach

Matthew Else matthewelse1997 at gmail.com
Wed Sep 23 22:59:50 CEST 2015


Hi Nick

That's awesome!

I could probably save some space by implementing the music module in C/C++,
instead of Python which shouldn't be too difficult, but it just makes it a
bit harder for people to experiment with if they want to add functionality.

I was also planning to have a look at making the BLE API library (and the
associated NRF51 specific bits of that) an optional extra in the DAL, but I
haven't got round to that yet - essentially, I'm free for the next week and
a bit until I start uni, so I'm happy to do all of these sorts of things
since I don't have a great deal of other stuff to do. I would suggest that
the best thing to do would be to create an issue on GitHub about flash/ram
size issues, and I'll see to what extent I can try and reduce RAM usage (I
would imagine Damien would probably be of more help with that, since I'm
not that familiar with the internals of micropython), since it would be a
shame if kids were to run out of RAM when they're doing awesome things like
that.

I've created a pull request with the music module included as a frozen
python module (I think this is the right way of doing it for modules
written in Python), which allows you to do things like: import music...

Of course I agree with the changes to the API - I think it makes sense to
do it that way. In the more recent version of the music code there's an
'add_notes' method, which lets you specify the notes as a list of tuples
(essentially representing the arguments to the add_note method) - this
would do more or less what you've done in your bach example.

On Wed, Sep 23, 2015 at 9:42 PM Nicholas H.Tollervey <ntoll at ntoll.org>
wrote:

> Hi Folks,
>
> So it's not exactly amazing quality sound... in fact, I've basically
> made one of those bloody annoying bloopy-bleep-bleep birthday cards, but
> this:
>
> https://www.youtube.com/watch?v=4L12BP64AQM
>
> :-)
>
> Great work Matthew (whose work I've adapted to make this work). You
> pretty much nailed it, although I've changed the musical representation
> a little and I feel there's a tad more to do to make it child-friendly
> and familiar given other music representation systems on the computer.
>
> Damien, please find attached two scripts:
>
> The first script, bach.py, is what is flashed onto the device in the
> demo. When I connect to the REPL I get this...
>
> >>> dir()
> Traceback (most recent call last):
>   File "<stdin>", line 1
> MemoryError: parser could not allocate enough memory
>
> I'm guessing we've run out of RAM. Given the code (and my lack of
> experience writing for embedded platforms with MicroPython) any hints on
> what I could do?
>
> The second script, music.py, is essentially the same as the first but
> with more of the music added to the notes list. When I try to flash the
> device I see the following scrolling across the screen:
>
> memory allocation error
>
> I'm guessing the script is simply too big to compile given the 16k RAM
> we have available..?
>
> Hey ho... I'm guessing this is a similar situation to David's pancake game.
>
> This is a GOOD THING for us to encounter. At the very worst we'll be
> unable to do anything about it in a technical sense so will have a heads
> up and time to get the messaging of such states correct so users have a
> chance to work out what's going on.
>
> My feeling is that we could create a whole new music based namespace
> under microbit (i.e. microbit.music) containing things like the
> following made up off the top of my head in a hand-wavy sort of a way:
>
> microbit.music.Tune - based on Matthew's class demonstrated in the video
> but implemented in C.
> microbit.music.play('c', 1, 1000) - play the note C in octave 1 for 1
> second.
> microbit.music.pitch(440, 1000) - play the pitch for 1 second. The play
> method above is basically a friendly wrapper around this one.
> microbit.music.stop() - what you'd expect ;-)
>
> The final millisecond argument to the play and pitch methods could be
> optional (the device just keeps playing the note until it's changed). We
> could then use the accelerometer to change the pitch etc...
>
> Also, we could use the wait keyword as Damien suggested with the display
> methods to make musical things run in the background.
>
> Does this make sense..?
>
> As always, ideas, constructive critique and feedback is most welcome!
>
> All the best,
>
> Nicholas.
> _______________________________________________
> Microbit mailing list
> Microbit at python.org
> https://mail.python.org/mailman/listinfo/microbit
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.python.org/mailman/private/microbit/attachments/20150923/b6be36a0/attachment.html>


More information about the Microbit mailing list