Generating pdf & midi from musicxml
Asked Answered
T

2

6

I've been trying to load a MusicXML file, edit it (removing several parts), and create a PDF sheet document + midi/mp3, all of this using Python.

I've first looked at music21, that would load my MusicXML file right, but as far as I could find, would not output a proper file (all the details in the output files have disappeared, all that's left is the notes and the title)

Then I found abjad which looked promising. It did output great quality ly/pdf files, but there was no musicxml imported.

Then, I discovered that Lilypond comes with a musicxml2ly script. I was able to call it and get the result lilypond file in python using sh (great lib !) but then the abjad lilypond parser would not parse it (the doc says it parses a "large subset" for lilypond, without more precisions).

Finally, I found that music21 had an exporter to abjad python objects but it seems not to be present in the codebase anymore and the source code for the exporter clearly just exported the notes.

I'm a little out of options, what could I do to achieve these goals ?

(additional point : I still don't know how I'm going to do the second part, going to midi/mp3 using soundfonts, but that may not be the hardest part. Any suggestion ?)

Truitt answered 5/4, 2014 at 16:29 Comment(2)
Hi Joachim, did you think discussing these issues at LilyPond's mailing list, where you can contact other LilyPond users and developers? Normally that is the best (and fastest) way to solve a problem or get an answer. To sign up, please visit lilypond.org/contact.htmlSnout
The music21 to Abjad converter was just a proof of concept to Abjad 1 (hacked it out w/ the Abjad creators one day) and was removed because it didn't get very far and didn't work with Abjad 2. You're right that music21's conversion to Lilypond is not particularly robust. Why not edit the MusicXML file with music21 and then write out a new MusicXML file and send that to musicxml2ly?Deoxygenate
D
4

If you have MuseScore 2+, you can set it up in python

import music21
c = music21.converter.parse('path_to_musicxml.xml')
c.show('musicxml.pdf')
c.show('midi')
Deoxygenate answered 3/8, 2015 at 21:23 Comment(0)
C
0

%run /mnt/data/add_libraries_py from ai_song_maker import song_maker

Define ABC notation for the Intro section

abc_notation_intro = """ M:4/4 L:1/4 Q:1/4=70 K:C V:1 clef=treble name="Piano" snm="Piano" | [C2E2G2]4 | [G2B2D2]4 | [A2C2E2]4 | [F2A2C2]4 | """

ordered_part_instrument_intro = {'Piano': 'Piano'}

musicxml_path_intro = '/mnt/data/song_intro_musicxml.xml' midi_path_intro = '/mnt/data/song_intro_midi.mid'

Process the ABC notation to create MusicXML and MIDI files

parts_data_intro, score_data_intro = song_maker.process_abc(abc_notation_intro, ordered_part_instrument_intro, musicxml_path_intro, midi_path_intro)

musicxml_path_intro, midi_path_intro

Chrissychrist answered 27/5 at 14:9 Comment(1)
Might you please edit your post to format the code for readability, following How do I format my code blocks?? Thanks!Rizal

© 2022 - 2024 — McMap. All rights reserved.