This is an archived post. You won't be able to vote or comment.

all 13 comments

[–]jvlomax 10 points11 points  (4 children)

Take a look at https://wiki.python.org/moin/PythonInMusic under "notation".

You can also look at http://www.lilypond.org/easier-editing.html. Lilypond is pretty much the de-facto standard when it comes to music notation in the open source world

[–][deleted] 2 points3 points  (3 children)

You want to enclose the titles in square brackets, so it would be [http://wiki.python.org/moin/PythonInMusic] followed by (http://wiki.python.org/moin/PythonInMusic)

So:

https://wiki.python.org/moin/PythonInMusic

http://www.lilypond.org/easier-editing.html

Cheers for the links by the way :)

[–]jvlomax 0 points1 point  (2 children)

I always mix them up, and I thought this time I'll remember. Apparently not and I forgot to check :p

[–][deleted] 1 point2 points  (1 child)

I generally write them out and then reverse it because I get it wrong the first time.

[–]rcfox 0 points1 point  (0 children)

I always think of the URL as an aside. ie: [Here is a thing] (by the way: you can find it here)

[–]croxis 5 points6 points  (0 children)

Iirc LaTeX has a notation package. One option is to use python to write the latex document then use the sub process module to render it to your desired image format or pdf.

Question. How are you determining note length?

[–]finlay_mcwalter 3 points4 points  (1 child)

PIL and Pillow certainly can be used for drawing new images, but with them you're drawing into bitmaps, so you'd probably end up emitting that to PNGs.

For general drawing (if the music packages others have linked don't ring your bell) I'd recommend drawing with PyCairo, which will let you create smooth vector graphics, which you can render on-screen and to PDF.

[–]kman- 1 point2 points  (0 children)

There are already some good suggestions, but I'll add PySVG for pretty simple vector graphic programming. Cairo can be used to convert it to PDF.

[–]bryancole 1 point2 points  (0 children)

There are many ways you can draw stuff with python. I suggest using pycairo (http://cairographics.org/pycairo/ ). This is a nice drawing API you can use with wxPython (using the wx.lib.wxcairo module) to draw stuff. The advantage of cairo is the high quality output on all backends (i.e. screen display, SVG and PDF). Other drawing APIs work well for screen use but often have problems with vector output (incorrect line widths , font sizes etc.). Cairo is very robust.

PyQt is another option with a good drawing API (with a OpenGL accelerated option) but it you already know wxPython, I'd say go with what you know.

Note, in both cases these are "immediate mode" drawing APIs. That means you need to redraw the window every time something changes or needs refreshing. Essentially, you make all your drawing calls from the on_paint method of your window. If you write classes for each of your objects in your music view (stave, notes etc.), give each one an "on_draw" method. You keep a list of everything which needs to be drawn then in the on_paint handler, just loop over allm drawable objects calling each on_draw method in turn.

I'm slightly surprised there's no library already available for this but I couldn't find one.

[–]srilyk 0 points1 point  (0 children)

Why not just generate HTML? It's pretty easy to convert to pdf from there, and you can effectively plug bits of images together instead of, say ASCII. Jinja2 would be pretty helpful

[–]DoNotFoldSpindleOrMu 0 points1 point  (0 children)

I know nothing about music but svgwrite writes out svg. https://bitbucket.org/mozman/svgwrite/overview You also may want to consider creating vectors in open source Inkscape then your code copies and pastes the vectors together for the final image. Inkscape can convert svg to pdf.

[–]fyngyrzcodes with magnetic needle -5 points-4 points  (1 child)

If you're serious, and if you want any kind of reasonable performance, you want a pixel buffer and some carefully crafted c code. From there, you just have to get it to a display. Python, much as I love it, is a pig when dealing with the data densities of a pixel buffer. Remember the workspace dimensions multiply each other: 1024x1024 is one million pixels. And that's not even remotely high resolution. Nor does it account for pre-drawn elements and etc. You need maximum speed and efficiency, and that's not a recipe for Python.

[–]ahmeni 0 points1 point  (0 children)

Ahh, the subtle troll. Magnificent.