Change a barline with a plugin

• Aug 18, 2021 - 16:06

Hi,
Could someone explain to me how to change a barline with a plugin please ?
I've made some attempts through newElement(Element.BARLINE) and through var seg.segmentType but I cannot find a way. Everything made Musescore crash and I didn't manage to find examples.
Thank you !


Comments

In reply to by jeetee

Thank you very much for your advices. I managed to do it by modifying a existing barline instead of creating one. This is what I've done :

  var cursor = curScore.newCursor()
  cursor.rewind(0)
  var segment = cursor.segment

  while(segment)
  {
        if(segment.segmentType == Segment.EndBarLine)
        {
             break
        }

   segment = segment.next
  }
  var bar = segment.elementAt(0)
  bar.barlineType = 2 //BarLineType.DOUBLE ?

My only problem is that I don't manage to access to the enum BarLineType that is shown here : https://musescore.github.io/MuseScore_PluginAPI_Docs/plugins/html/names…
I wrote 2 because it is the value of one of the barline on the doc, but do you have any idea on the proper way to write the several values of the enum please ? Thank you !

In reply to by millermix

The BarLineType enum values are available as per that link, but the enum itself is not exposed according to https://musescore.github.io/MuseScore_PluginAPI_Docs/plugins/html/class…

What you could do is create your own local mapping object to use as an enum instead. See this quickly thrown together example which changes barlines to DOUBLE if they appear within the first 10 segments of a score.

      var BarLineTypes = Object.freeze({
            NORMAL       : 1,
            SINGLE       : 1,//BarLineType::NORMAL,
            DOUBLE       : 2,
            START_REPEAT : 4,
            LEFT_REPEAT  : 4,//BarLineType::START_REPEAT,
            END_REPEAT   : 8,
            RIGHT_REPEAT : 8,//BarLineType::END_REPEAT,
            BROKEN       : 0x10,
            DASHED       : 0x10,//BarLineType::BROKEN,
            END          : 0x20,
            FINAL        : 0x20,//BarLineType::END,
            END_START_REPEAT  : 0x40,
            LEFT_RIGHT_REPEAT : 0X40,//BarLineType::END_START_REPEAT,
            DOTTED         : 0x80,
            REVERSE_END    : 0x100,
            REVERSE_FINALE : 0x100,//BarLineType::REVERSE_END,
            HEAVY          : 0x200,
            DOUBLE_HEAVY   : 0x400
      });

      curScore.startCmd();
            var seg = curScore.firstSegment();
            for (var i = 10; i--;)
            {
            var isBarLine = !!(Segment.BarLineType & seg.segmentType);
               console.log(seg.segmentType, isBarLine);
               if (isBarLine)
               {
                  seg.elementAt(0).barlineType = BarLineTypes.DOUBLE;
               }
               seg = seg.next;
            }
      curScore.endCmd();

Do you still have an unanswered question? Please log in first to post your question.