Skip to content

Commit

Permalink
Merge pull request #50 from music-encoding/develop
Browse files Browse the repository at this point in the history
Release 2.0.3
  • Loading branch information
ahankinson authored Oct 20, 2016
2 parents a789d0b + b784f1c commit 2fea149
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 47 deletions.
15 changes: 0 additions & 15 deletions lib/libmei.plg
Original file line number Diff line number Diff line change
Expand Up @@ -1289,21 +1289,6 @@ GetChildren "(element) {
SetChildren "(element, childarr) {
element.children = childarr;
}"
AddChildAtPosition "(element, child, position) {
c = element.children;
r = CreateSparseArray();
// copy the children to the new array. Add two
// beyond the length since we'll be adding a new element.
for i = c.Length + 2 {
if (i = position) {
r[i] = child;
i = i + 1;
} else {
r[i] = c[i];
}
}
element.children = r;
}"
AddChild "(element, child) {
cid = child._id;
child._parent = element._id;
Expand Down
20 changes: 20 additions & 0 deletions src/ExportConverters.mss
Original file line number Diff line number Diff line change
Expand Up @@ -793,6 +793,26 @@ function ConvertPositionToTimestamp (position, bar) {
return ret;
} //$end

function ConvertPositionWithDurationToTimestamp (bobj) {
//$module(ExportConverters.mss)

/*
Like ConvertPositionToTimestamp, but suitable to filling out the tstamp2 parameter
with an object of a specific duration (such as a slur or hairpin), e.g., 1m+2
NB: Can only be used on objects with EndBarNumber and EndPosition attributes, like Lines.
*/
startBar = bobj.ParentBar;
startBarNum = startBar.BarNumber;
endBarNum = bobj.EndBarNumber;
endBar = startBar.ParentStaff.NthBar(endBarNum);
endPosition = bobj.EndPosition;
measureDuration = endBarNum - startBarNum;
position = ConvertPositionToTimestamp(endPosition, endBar);

return measureDuration & 'm+' & position;
} //$end

function ConvertTupletStyle (tupletStyle) {
//$module(ExportConverters.mss)
switch (tupletStyle)
Expand Down
107 changes: 84 additions & 23 deletions src/ExportGenerators.mss
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,10 @@ function GenerateMEIMusic () {
section = libmei.Section();
libmei.AddChild(sco, section);

systf = score.SystemStaff;

currentScoreDef = null;

for j = 1 to numbars + 1
{
// this value may get changed by the volta processor
Expand All @@ -210,6 +214,61 @@ function GenerateMEIMusic () {
Self._property:PageBreak = null;
}

currTimeS = systf.CurrentTimeSignature(j);
currKeyS = systf.CurrentKeySignature(j);

// Do not try to get the signatures for bar 0 -- will not work
if (j > 1)
{
prevTimeS = systf.CurrentTimeSignature(j - 1);
prevKeyS = systf.CurrentKeySignature(j - 1);
}
else
{
prevTimeS = systf.CurrentTimeSignature(j);
prevKeyS = systf.CurrentKeySignature(j);
}

/*
This will check for a change in the current time signature and create a new
scoredef element if it's changed. The key signature will always be processed later,
so by then we will either have a new scoredef with a timesig change, or we'll need
to create one just for the keysig change.
*/
if ((currTimeS.Numerator != prevTimeS.Numerator) or (currTimeS.Denominator != prevTimeS.Denominator))
{
currentScoreDef = libmei.ScoreDef();
// Log('Time Signature Change in Bar ' & j);
libmei.AddAttribute(currentScoreDef, 'meter.count', currTimeS.Numerator);
libmei.AddAttribute(currentScoreDef, 'meter.unit', currTimeS.Denominator);
libmei.AddAttribute(currentScoreDef, 'meter.sym', ConvertNamedTimeSignature(currTimeS.Text));
}

if (currKeyS.Sharps != prevKeyS.Sharps)
{
if (currentScoreDef = null)
{
currentScoreDef = libmei.ScoreDef();
}

libmei.AddAttribute(currentScoreDef, 'key.sig', ConvertKeySignature(currKeyS.Sharps));
}

if (currentScoreDef != null)
{
// The sig changes must be added just before we add the measure to keep
// the proper order.
if (ending != null)
{
libmei.AddChild(ending, currentScoreDef);
}
else
{
libmei.AddChild(section, currentScoreDef);
}
currentScoreDef = null;
}

if (ending != null)
{
libmei.AddChild(section, ending);
Expand All @@ -230,7 +289,7 @@ function GenerateMeasure (num) {
score = Self._property:ActiveScore;
// measureties
Self._property:MeasureTies = CreateSparseArray();
Self._property:MeasureLines = CreateSparseArray();
Self._property:MeasureObjects = CreateSparseArray();

m = libmei.Measure();
libmei.AddAttribute(m, 'n', num);
Expand Down Expand Up @@ -275,7 +334,7 @@ function GenerateMeasure (num) {
m.children.Push(tie);
}

mlines = Self._property:MeasureLines;
mlines = Self._property:MeasureObjects;

for each line in mlines
{
Expand Down Expand Up @@ -395,7 +454,7 @@ function GenerateLayers (staffnum, measurenum) {
}

obj = null;
line = null;
mobj = null;
chordsym = null;
parent = null;
beam = null;
Expand Down Expand Up @@ -519,48 +578,52 @@ function GenerateLayers (staffnum, measurenum) {
}
case('Slur')
{
line = GenerateLine(bobj);
mobj = GenerateLine(bobj);
}
case('CrescendoLine')
{
line = GenerateLine(bobj);
mobj = GenerateLine(bobj);
}
case('DimuendoLine')
case('DiminuendoLine')
{
line = GenerateLine(bobj);
mobj = GenerateLine(bobj);
}
case('OctavaLine')
{
line = GenerateLine(bobj);
mobj = GenerateLine(bobj);
}
case('Trill')
{
line = GenerateLine(bobj);
mobj = GenerateLine(bobj);
}
case('RepeatTimeLine')
{
RegisterVolta(bobj);
}
case('Line')
{
line = GenerateLine(bobj);
mobj = GenerateLine(bobj);
}
case('Text')
{
mobj = ConvertText(bobj);
}
}

if (line != null)
if (mobj != null)
{
mlines = Self._property:MeasureLines;
mlines.Push(line._id);
Self._property:MeasureLines = mlines;
mobjs = Self._property:MeasureObjects;
mobjs.Push(mobj._id);
Self._property:MeasureObjects = mobjs;
}

// add chord symbols to the measure lines
// add chord symbols to the measure objects
// so that they get added to the measure later in the processing cycle.
if (chordsym != null)
{
mlines = Self._property:MeasureLines;
mlines = Self._property:MeasureObjects;
mlines.Push(chordsym._id);
Self._property:MeasureLines = mlines;
Self._property:MeasureObjects = mlines;
}
}

Expand Down Expand Up @@ -705,7 +768,7 @@ function GenerateNoteRest (bobj, layer) {
libmei.AddAttribute(fermata, 'layer', bobj.VoiceNumber);
libmei.AddAttribute(fermata, 'staff', bobj.ParentBar.ParentStaff.StaffNum);

mlines = Self._property:MeasureLines;
mlines = Self._property:MeasureObjects;
mlines.Push(fermata._id);
}

Expand All @@ -718,7 +781,7 @@ function GenerateNoteRest (bobj, layer) {
libmei.AddAttribute(fermata, 'layer', bobj.VoiceNumber);
libmei.AddAttribute(fermata, 'staff', bobj.ParentBar.ParentStaff.StaffNum);

mlines = Self._property:MeasureLines;
mlines = Self._property:MeasureObjects;
mlines.Push(fermata._id);
}

Expand All @@ -731,7 +794,7 @@ function GenerateNoteRest (bobj, layer) {
libmei.AddAttribute(fermata, 'layer', bobj.VoiceNumber);
libmei.AddAttribute(fermata, 'staff', bobj.ParentBar.ParentStaff.StaffNum);

mlines = Self._property:MeasureLines;
mlines = Self._property:MeasureObjects;
mlines.Push(fermata._id);
}

Expand Down Expand Up @@ -1088,8 +1151,6 @@ function GenerateBarRest (bobj) {
function GenerateScoreDef (score) {
//$module(ExportGenerators.mss)
scoredef = libmei.ScoreDef();
Self._property:_GlobalScoreDef = libmei.GetId(scoredef);

docSettings = score.DocumentSetup;

// this will ensure that the units specified by the user is the one that is
Expand Down Expand Up @@ -1259,7 +1320,7 @@ function GenerateLine (bobj) {
line = libmei.Hairpin();
libmei.AddAttribute(line, 'form', 'cres');
}
case ('DimuendoLine')
case ('DiminuendoLine')
{
line = libmei.Hairpin();
libmei.AddAttribute(line, 'form', 'dim');
Expand Down
10 changes: 5 additions & 5 deletions src/ExportProcessors.mss
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ function ProcessSymbol (sobj) {
{
// trill
trill = GenerateTrill(sobj);
mlines = Self._property:MeasureLines;
mlines = Self._property:MeasureObjects;
mlines.Push(trill._id);
}

Expand All @@ -483,7 +483,7 @@ function ProcessSymbol (sobj) {
// inverted mordent
mordent = libmei.Mordent();
libmei.AddAttribute(mordent, 'form', 'inv');
mlines = Self._property:MeasureLines;
mlines = Self._property:MeasureObjects;
mlines.Push(mordent._id);
}

Expand All @@ -492,7 +492,7 @@ function ProcessSymbol (sobj) {
// mordent
mordent = libmei.Mordent();
libmei.AddAttribute(mordent, 'form', 'norm');
mlines = Self._property:MeasureLines;
mlines = Self._property:MeasureObjects;
mlines.Push(mordent._id);
}

Expand All @@ -502,7 +502,7 @@ function ProcessSymbol (sobj) {
turn = libmei.Turn();
libmei.AddAttribute(turn, 'form', 'norm');
turn = AddBarObjectInfoToElement(sobj, turn);
mlines = Self._property:MeasureLines;
mlines = Self._property:MeasureObjects;
mlines.Push(turn._id);
}

Expand All @@ -512,7 +512,7 @@ function ProcessSymbol (sobj) {
turn = libmei.Turn();
libmei.AddAttribute(turn, 'form', 'inv');
turn = AddBarObjectInfoToElement(sobj, turn);
mlines = Self._property:MeasureLines;
mlines = Self._property:MeasureObjects;
mlines.Push(turn._id);
}

Expand Down
2 changes: 1 addition & 1 deletion src/GLOBALS.mss
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Version "2.0.2"
Version "2.0.3"
PluginName "Sibelius to MEI Exporter"
Author "Andrew Hankinson"

Expand Down
6 changes: 3 additions & 3 deletions src/Utilities.mss
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,11 @@ function AddBarObjectInfoToElement (bobj, element) {
}
}

libmei.AddAttribute(element, 'tstamp', ConvertPositionToTimestamp(bobj.Position, bobj.ParentBar));
libmei.AddAttribute(element, 'tstamp', ConvertPositionToTimestamp(bobj.Position, bar));

if (bobj.Type = 'Line' or bobj.Type = 'Slur')
if (bobj.Type = 'Line' or bobj.Type = 'Slur' or bobj.Type = 'DiminuendoLine' or bobj.Type = 'CrescendoLine')
{
libmei.AddAttribute(element, 'tstamp2', ConvertPositionToTimestamp(bobj.EndPosition, bar));
libmei.AddAttribute(element, 'tstamp2', ConvertPositionWithDurationToTimestamp(bobj));
}

libmei.AddAttribute(element, 'staff', bar.ParentStaff.StaffNum);
Expand Down

0 comments on commit 2fea149

Please sign in to comment.