Steve Hemmingsen
Steve Hemmingsen

Reputation: 393

Get the tempos of a parsed MusicXML file

In MusicXML, there can be direction tags that have <sound> tags, which sets the BPM. For example,

      <direction placement="above">
        <direction-type>
          <words>Molto vivace</words>
          </direction-type>
        <staff>1</staff>
        <sound tempo="260"/>
        </direction>

Is it possible to get the tempo markings located by their offset in a Measure?

Edit: I used a piece downloaded from MuseScore. I have currently found a solution that requires preprocessing the XML file before parsing it. The XML file I used had <direction> elements that had the <sound> element but did not have a <metronome> element. So what I did was after every <direction> element that had a <sound> element, I added a new <direction> element that has a <metronome> element, this seems to be the only way music21 will actually parse the <sound> element, where it is then usable with Stream.metronomeMarkBoundaries. Example:

      <direction placement="above">
        <direction-type>
          <metronome parentheses="no" default-y="40.00" relative-x="-39.33" relative-y="3.81">
            <beat-unit>half</beat-unit>
            <per-minute>128</per-minute>
            </metronome>
          </direction-type>
        <staff>1</staff>
        <sound tempo="256"/>
      </direction>

Upvotes: 2

Views: 567

Answers (0)

Related Questions