maia-util
Version:
Utility math and music functions supporting various applications by Music Artificial Intelligence Algorithms, Inc.
33 lines (30 loc) • 949 B
JavaScript
import sort_points_asc_by_id from './sort_points_asc_by_id'
export default function group_grace_by_contiguous_id(grace_array){
// Tom Collins 18/2/2015.
// In
// grace_array Array mandatory
// An array of grace notes is the input to this function. The function groups
// these grace notes into new arrays whose membership is determined by
// contiguity of the id fields. This is to make sure that if several grace
// notes precede an ordinary note, these are grouped together and (later)
// attached to this ordinary note.
var ga = grace_array.sort(sort_points_asc_by_id);
if (ga.length > 0){
var gag = [[ga[0]]];
var gj = 0;
for (let gi = 1; gi < ga.length; gi++){
if (parseFloat(ga[gi].ID) ==
parseFloat(gag[gj][gag[gj].length - 1].ID) + 1){
gag[gj].push(ga[gi]);
}
else{
gag.push([ga[gi]]);
gj++;
}
}
}
else{
var gag = [];
}
return gag;
}