cuthbertLab / music21

music21 is a Toolkit for Computational Musicology
https://www.music21.org/
Other
2.12k stars 402 forks source link

rhythmic inaccuracy when exporting lilypond files containing tuplets #263

Closed levinericzimmermann closed 5 years ago

levinericzimmermann commented 6 years ago

Hello,

thank you all for your amazing work! I have a question regarding the write-method of the Stream-object, using Lilypond as the output-format.

If I make a Stream-Object, containing notes within a tuplet and if I try to write the Stream to a Lilypond-File, the resulting Lilypond-File won't contain the tuplet:

from music21 import *
n0 = note.Note(0, duration=duration.Duration(1/3))
n1 = note.Note(2, duration=duration.Duration(1))
s0 = stream.Stream()
s0.append(n0)
s0.append(n1)
s0.write("lilypond", "test.ly")

test.ly might look like:

\version "2.18" 
\include "lilypond-book-preamble.ly"

color = #(define-music-function (parser location color) (string?) #{
        \once \override NoteHead #'color = #(x11-color color)
        \once \override Stem #'color = #(x11-color color)
        \once \override Rest #'color = #(x11-color color)
        \once \override Beam #'color = #(x11-color color)
     #})

\header { } 
\score  { 
 \new Voice { \new Voice { c' 8  
                d' 4  
                 } 

           } 

  } 

\paper { }
\layout {
  \context {
    \RemoveEmptyStaffContext
    \override VerticalAxisGroup #'remove-first = ##t
  }
 }

Am I'm doing anything wrong? If I write a musicxml-file with the write-Method and if I convert it to a Lilypond-File with musicxml2ly, the converted file might contain the tuplet:

\version "2.18.2"
% automatically converted by musicxml2ly from test.xml

\header {
    encodingsoftware = "Music21"
    encodingdate = "2017-12-02"
    composer = "Music21"
    title = "Music21 Fragment"
    }

#(set-global-staff-size 19.9169291339)
\paper {
    }
\layout {
    \context { \Score
        autoBeaming = ##f
        }
    }
PartPThreeFiveThreeTwoFourcThreeZerobEightTwoSevencFivedbThreeffSixfOneThreeSevenceSevencbTwoOneaVoiceNone = 
\relative c' {
    \clef "treble" \numericTimeSignature\time 4/4 \once \override
    TupletBracket #'stencil = ##f
    \times 2/3  {
        c8 }
    d4 \bar "|."
    }

% The score definition
\score {
    <<
        \new Staff <<
            \context Staff << 
                \context Voice = "PartPThreeFiveThreeTwoFourcThreeZerobEightTwoSevencFivedbThreeffSixfOneThreeSevenceSevencbTwoOneaVoiceNone" { \PartPThreeFiveThreeTwoFourcThreeZerobEightTwoSevencFivedbThreeffSixfOneThreeSevenceSevencbTwoOneaVoiceNone }
                >>
            >>

        >>
    \layout {}
    % To create MIDI output, uncomment the following line:
    %  \midi {}
    }

(The musicxml-file might look like:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE score-partwise
  PUBLIC '-//Recordare//DTD MusicXML 2.0 Partwise//EN'
  'http://www.musicxml.org/dtds/partwise.dtd'>
<score-partwise>
  <movement-title>Music21 Fragment</movement-title>
  <identification>
    <creator type="composer">Music21</creator>
    <encoding>
      <encoding-date>2017-12-02</encoding-date>
      <software>Music21</software>
      </encoding>
    </identification>
  <defaults>
    <scaling>
      <millimeters>7</millimeters>
      <tenths>40</tenths>
      </scaling>
    </defaults>
  <part-list>
    <score-part id="P35324c30b827c5db3ff6f137ce7cb21a">
      <part-name />
      </score-part>
    </part-list>
  <part id="P35324c30b827c5db3ff6f137ce7cb21a">
    <measure number="1">
      <attributes>
        <divisions>10080</divisions>
        <time>
          <beats>4</beats>
          <beat-type>4</beat-type>
          </time>
        <clef>
          <sign>G</sign>
          <line>2</line>
          </clef>
        </attributes>
      <note>
        <pitch>
          <step>C</step>
          <alter>0</alter>
          <octave>4</octave>
          </pitch>
        <duration>3360</duration>
        <type>eighth</type>
        <accidental>natural</accidental>
        <time-modification>
          <actual-notes>3</actual-notes>
          <normal-notes>2</normal-notes>
          <normal-type>eighth</normal-type>
          </time-modification>
        <notations>
          <tuplet bracket="no" number="1" placement="above" type="start">
            <tuplet-actual>
              <tuplet-number>3</tuplet-number>
              <tuplet-type>eighth</tuplet-type>
              </tuplet-actual>
            <tuplet-normal>
              <tuplet-number>2</tuplet-number>
              <tuplet-type>eighth</tuplet-type>
              </tuplet-normal>
            </tuplet>
          <tuplet number="1" type="stop" />
          </notations>
        </note>
      <note>
        <pitch>
          <step>D</step>
          <alter>0</alter>
          <octave>4</octave>
          </pitch>
        <duration>10080</duration>
        <type>quarter</type>
        <accidental>natural</accidental>
        </note>
      <barline location="right">
        <bar-style>light-heavy</bar-style>
        </barline>
      </measure>
    </part>
  </score-partwise>

)

mscuthbert commented 6 years ago

I think that in our Lilypond output we need to have complete tuplets in order to get correct output. Happy to take a patch that fixes this, but I don't think it'll be something that the core dev team can get to anytime soon.

mscuthbert commented 5 years ago

Closing because Lilypond support is being removed