Created
May 18, 2020 23:35
-
-
Save PhilippeCarphin/cedaaf2170348d26c2ab2d47687635a1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function setSumOfDatumDurationsPerMusicExpression(tokens) { | |
let areSummingDatumDurations = false | |
let sumOfDatumDurations | |
let indexOfOpenMusicExpr | |
let numExprFlags | |
let numExprDots | |
for (let i = deepestDepth; i >= 0; i--) { | |
tokens.forEach((token, j) => { | |
if(token.depth === i+1 && areSummingDatumDurations && token.type === 'OPEN_MUSIC_EXPR'){ | |
sumOfDatumDurations += token.duration | |
} | |
if(token.depth != i){ | |
continue | |
} | |
if (token.type === 'OPEN_VOICING_EXPR' | |
|| token.type === 'OPEN_MUSIC_EXPR') | |
{ | |
areSummingDatumDurations = true | |
sumOfDatumDurations = 0 | |
indexOfOpenMusicExpr = j | |
numExprFlags = j > 0 && tokens[j - 1].type === 'RHYTHM_FLAGS' | |
? tokens[j - 1].value.length | |
: 0 | |
} else if (token.type === 'CLOSE_VOICING_EXPR' | |
|| token.type === 'CLOSE_MUSIC_EXPR') | |
{ | |
areSummingDatumDurations = false | |
const k = indexOfOpenMusicExpr | |
tokens[k].sumOfDatumDurations = sumOfDatumDurations | |
if (tokens[k].duration === 'EQUAL') { | |
tokens[k].duration = sumOfDatumDurations | |
} | |
numExprFlags = j < tokens.length - 1 && tokens[j + 1].type === 'RHYTHM_DOTS' | |
? tokens[j + 1].value.length | |
: 0 | |
tokens[k].duration = calculateFlags(tokens[k].duration, numExprFlags) | |
tokens[k].duration = calculateDots(tokens[k].duration, numExprDots) | |
} else if (areSummingDatumDurations | |
&& token.type === 'DATUM') | |
{ | |
sumOfDatumDurations += token.duration | |
} | |
} | |
) | |
} | |
} | |
function setSumOfDatumDurationsPerMusicExpression(tokens) { | |
let areSummingDatumDurations = false | |
let sumOfDatumDurations | |
let indexOfOpenMusicExpr | |
let numExprFlags | |
let numExprDots | |
for (let i = deepestDepth; i >= 0; i--) { | |
tokens.forEach((token, j) => { | |
if(token.depth === i+1 && areSummingDatumDurations && token.type === 'OPEN_MUSIC_EXPR'){ | |
sumOfDatumDurations += token.duration | |
} | |
if(token.depth === i){ | |
if (token.type === 'OPEN_VOICING_EXPR' | |
|| token.type === 'OPEN_MUSIC_EXPR') | |
{ | |
areSummingDatumDurations = true | |
sumOfDatumDurations = 0 | |
indexOfOpenMusicExpr = j | |
numExprFlags = j > 0 && tokens[j - 1].type === 'RHYTHM_FLAGS' | |
? tokens[j - 1].value.length | |
: 0 | |
} else if (token.type === 'CLOSE_VOICING_EXPR' | |
|| token.type === 'CLOSE_MUSIC_EXPR') | |
{ | |
areSummingDatumDurations = false | |
const k = indexOfOpenMusicExpr | |
tokens[k].sumOfDatumDurations = sumOfDatumDurations | |
if (tokens[k].duration === 'EQUAL') { | |
tokens[k].duration = sumOfDatumDurations | |
} | |
numExprFlags = j < tokens.length - 1 && tokens[j + 1].type === 'RHYTHM_DOTS' | |
? tokens[j + 1].value.length | |
: 0 | |
tokens[k].duration = calculateFlags(tokens[k].duration, numExprFlags) | |
tokens[k].duration = calculateDots(tokens[k].duration, numExprDots) | |
} else if (areSummingDatumDurations | |
&& token.type === 'DATUM') | |
{ | |
sumOfDatumDurations += token.duration | |
} | |
} | |
} | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment