MeasuringPolyphony / mp_editor

https://editor.measuringpolyphony.org
5 stars 2 forks source link

Issue with humdrum loading staves with ligatures / inputting ligatures #80

Closed karend27 closed 3 years ago

karend27 commented 3 years ago

@craigsapp I think this is one for you: this is happening either with music input of a new ligature, where after entering a bracket the staff input stops working; and also when trying to reload a file that had ligatures in it; those staves are not viewable. The attached is an MEI file which can be opened in the MP Editor (editor.measuringpolyphony.org). If you enter 949 in the folio box, and click on one of the staves with ligatures nothing shows up. If I download the Humdrum data from that screen and then try to paste it into Verovio Humdrum viewer nothing shows up. I've also attached the humdrum data here. 807e37dd-107b-4842-87fc-a99c118d7626.txt

je_sui_aussi_MENSURAL.mei.zip

craigsapp commented 3 years ago

@lpugin: I suspect this is related to my direct import of Humdrum data into verovio without the intermediate step through the MEIInput class. Do you do any post processing of ligatures in MEI when loading the data? I will look soon, but an overview might be useful since the following abbreviated score gives a segmentation fault due to an out-of-bounds vector access:

terminating with uncaught exception of type std::out_of_range: vector

__pthread_kill + 10
pthread_kill + 430
abort + 120
abort_message + 231
demangling_terminate_handler() + 238
_objc_terminate() + 104
std::__terminate(void (*)()) + 8
__cxxabiv1::failed_throw(__cxxabiv1::__cxa_exception*) + 27
__cxa_throw + 113
std::__1::__throw_out_of_range(char const*) + 56
std::__1::__vector_base_common<true>::__throw_out_of_range() const + 16
vrv::View::DrawLigatureNote(vrv::DeviceContext*, vrv::LayerElement*, vrv::Layer*, vrv::Staff*) + 1150
vrv::View::DrawMensuralNote(vrv::DeviceContext*, vrv::LayerElement*, vrv::Layer*, vrv::Staff*, vrv::Measure*) + 286
vrv::View::DrawDurationElement(vrv::DeviceContext*, vrv::LayerElement*, vrv::Layer*, vrv::Staff*, vrv::Measure*) + 406
vrv::View::DrawLayerElement(vrv::DeviceContext*, vrv::LayerElement*, vrv::Layer*, vrv::Staff*, vrv::Measure*) + 546
vrv::View::DrawLayerChildren(vrv::DeviceContext*, vrv::Object*, vrv::Layer*, vrv::Staff*, vrv::Measure*) + 130 (view_page.cpp:1465)
vrv::View::DrawLigature(vrv::DeviceContext*, vrv::LayerElement*, vrv::Layer*, vrv::Staff*, vrv::Measure*) + 150 (view_mensural.cpp:397)
vrv::View::DrawLayerElement(vrv::DeviceContext*, vrv::LayerElement*, vrv::Layer*, vrv::Staff*, vrv::Measure*) + 942
vrv::View::DrawLayerChildren(vrv::DeviceContext*, vrv::Object*, vrv::Layer*, vrv::Staff*, vrv::Measure*) + 130 (view_page.cpp:1465)
vrv::View::DrawLayer(vrv::DeviceContext*, vrv::Layer*, vrv::Staff*, vrv::Measure*) + 165 (view_page.cpp:1285)
vrv::View::DrawStaffChildren(vrv::DeviceContext*, vrv::Object*, vrv::Staff*, vrv::Measure*) + 135 (view_page.cpp:1442)
vrv::View::DrawStaff(vrv::DeviceContext*, vrv::Staff*, vrv::Measure*, vrv::System*) + 434
vrv::View::DrawMeasureChildren(vrv::DeviceContext*, vrv::Object*, vrv::Measure*, vrv::System*) + 135 (view_page.cpp:1415)
vrv::View::DrawMeasure(vrv::DeviceContext*, vrv::Measure*, vrv::System*) + 329 (view_page.cpp:932)
vrv::View::DrawSystemChildren(vrv::DeviceContext*, vrv::Object*, vrv::System*) + 281 (view_page.cpp:1382)
vrv::View::DrawSystem(vrv::DeviceContext*, vrv::System*) + 346 (view_page.cpp:171)
vrv::View::DrawCurrentPage(vrv::DeviceContext*, bool) + 270 (view_page.cpp:91)
vrv::Page::LayOutHorizontally() + 1476
vrv::Doc::CastOffDocBase(bool, bool) + 135 (doc.cpp:850)
vrv::Toolkit::LoadData(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) + 4953 (toolkit.cpp:689)
vrv::Toolkit::LoadFile(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) + 447
main + 6535 (main.cpp:444)

Here is the short sample file that needs to be converted into MEI that generates the above error:

**mens  **text
*black  *
*clefC4 *
[LG .
SF#]    .
sG  .
MF  .
ME  .
=-  =-
*-  *-

Both creating MEI or SVG data give the same error:

verovio test.krn -atmei         # MEI output
verovio test.krn                # svg output

In other words, I cannot convert the Humdrum data into MEI to see what is happening. It looks like verovio is rendering the notation when I am exporting MEI. Is that expected?

When I remove the ligature there is no problem converting/rendering the example:

**mens  **text
*black  *
*clefC4 *
sG  .
MF  .
ME  .
=-  =-
*-  *-
Screen Shot 2021-01-11 at 6 36 00 PM
craigsapp commented 3 years ago

@lpugin: verovio is crashing at this line in view_mensural.cpp in the View::DrawLigatureNote:

int shape = ligature->m_drawingShapes.at(position);

The problem is that the size of the ligature->m_drawingShapes vector is zero. Do you know why? If I force shape to be set to 0, I get the following MEI conversion:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-model href="https://music-encoding.org/schema/4.0.0/mei-all.rng" type="application/xml" schematypens="http://relaxng.org/ns/structure/1.0"?>
<?xml-model href="https://music-encoding.org/schema/4.0.0/mei-all.rng" type="application/xml" schematypens="http://purl.oclc.org/dsdl/schematron"?>
<mei xmlns="http://www.music-encoding.org/ns/mei" meiversion="4.0.0">
 <meiHead>
  <fileDesc>
   <titleStmt>
    <title />
   </titleStmt>
   <pubStmt />
  </fileDesc>
  <encodingDesc>
   <appInfo>
    <application isodate="2021-01-11T23:22:04" version="3.1.0-dev-1666d80-dirty">
     <name>Verovio</name>
     <p>Transcoded from Humdrum</p>
    </application>
   </appInfo>
  </encodingDesc>
  <workList>
   <work>
    <title />
   </work>
  </workList>
 </meiHead>
 <music>
  <body>
   <mdiv xml:id="mdiv-0000000750632470">
    <score xml:id="score-0000001560980812">
     <scoreDef xml:id="scoredef-0000001863532927" midi.bpm="400">
      <staffGrp xml:id="staffgrp-0000002094351924">
       <staffDef xml:id="staffdef-0000000739601127" n="1" notationtype="mensural.black" lines="5">
        <clef xml:id="clef-L3F1" shape="C" line="4" />
       </staffDef>
      </staffGrp>
     </scoreDef>
     <section xml:id="section-L1F1">
      <staff xml:id="staff-0000002067606108" n="1">
       <layer xml:id="layer-L1F1N1" n="1">
        <ligature xml:id="ligature-L4F1" form="recta">
         <note xml:id="note-L4F1" dur="longa" oct="3" pname="g" />
         <note xml:id="note-L5F1" dur="brevis" oct="3" pname="f">
          <accid xml:id="accid-L5F1" accid="s" />
         </note>
        </ligature>
        <note xml:id="note-L6F1" dur="semibrevis" oct="3" pname="g" />
        <note xml:id="note-L7F1" dur="minima" oct="3" pname="f" />
        <note xml:id="note-L8F1" dur="minima" oct="3" pname="e" />
       </layer>
      </staff>
     </section>
    </score>
   </mdiv>
  </body>
 </music>
</mei>

which seems reasonable (but perhaps I have to run a Mensural castoff function or other Mensural setup function(s)?), although the graphic notation squashes the ligature since there is no information about the note shapes presumably:

Screen Shot 2021-01-11 at 11 25 40 PM

I tried make install to ensure that the fonts installed in the share folder are up-to-date, but the same error occurs.

Ligature::m_drawingShapes is filled in in the file ligature.cpp in the Ligature::CalcLigatureNotePos() function, but this function is not being called when I load the test Humdrum data into verovio. When I load the MEI conversion directly via MEIInput, that function does get called (through the Functor system which is hard to trace through 😝 ), which produces a non-squashed ligature:

Screen Shot 2021-01-11 at 11 54 01 PM
craigsapp commented 3 years ago

Commit https://github.com/rism-ch/verovio/commit/0361cac6da7810370c8b170af409f4553d4d9f20 may fix the problem (it is getting late, so I haven't checked in the MP editor yet).

The problem was that a variable called doc->m_notationType needed to be set to NOTATIONTYPE_mensural. If it is not set, then the variable Ligature::m_drawingShapes will not be filled in, and in turn this causes a problem in view_mensural.cpp on the lines mentioned in the previous post:

int shape = ligature->m_drawingShapes.at(position);
int prevShape = (position > 0) ? ligature->m_drawingShapes.at(position - 1) : 0;

Translation somewhat into English: m_drawingShapes is a list of items, and shape is the position in the in the list to look at. When the list is empty an error occurs if you try to get an item out of it. Setting doc->m_notationType triggers the list to be filled in, which makes the above code happy.

It would be useful @lpugin if the function Doc::SetMensuralMusicOnly() handled setting the Doc::m_notationType to mensural music. An assert on the size of Ligature::m_drawingShapes might be useful(butvector::at` was also doing the same thing to mark that area as the problem region).

craigsapp commented 3 years ago

Unrelated, the Humdrum data has a typo:

**mens  **text
*black  *
*clefC4 *
[LG .
SF#]    .
sG  .
MF  .
ME  .
[LD .
S:C .
sD  .
[SF .
SG  .
LA] .
LD  .
LF# .
MG  .
sd  .
Mc  .
Me  .
Md  .
Mc  .
MB- .
LA  .
[LG .
SF] .
MG  .
MF# .
MG  .
MD  .
LF  .
Lr  .
MG  .
MF  .
MG  .
MD  .
LF# .
MG  .
sd  .
Mc  .
[sB-    .
sA  .
LG] .
Lr  .
[SA .
LB] .
[sA .
sG] .
s:F .
MG  .
[sF .
sE  .
SD] .
Sr  .
=-  =-
*-  *-
!!!RDF**kern: @ = marked note

There is a long note starting a ligature on line 9 that is never closed. Presumably this would be noticed by the MP editor user as they are typing in the music, so it is not relevant to the problem. Verovio gives warning messages about nested ligatures, but will try to generate notation:

Screen Shot 2021-01-13 at 1 40 06 AM

Removing the unmatches ligature opening gives:

Screen Shot 2021-01-13 at 1 40 14 AM

There is also the line:

!!!RDF**kern: @ = marked note

which has no effect (since there are no marks on any notes in the score). I wonder how it got there @karend27? Presumably it was added in VHV and not by the MP interface.

karend27 commented 3 years ago

Hi @craigsapp - thanks for fixing this! I just checked the editor and it looks like previously created files with ligatures are all loading okay now into MP Editor, and I just tried some new music input as well with ligatures and seems to be working okay. I will continue checking today as I plan on working with the editor a bit today. I don't what the !!!RDFkern: @ = marked note** is for - maybe @JRegimbal might have an idea why it is there?