<commit_before>//    abc_graphelements.js: All the drawable and layoutable datastructures to be printed by ABCPrinter
//    Copyright (C) 2010 <NAME> (<EMAIL>)
//
//    This program is free software: you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    (at your option) any later version.
//
//    This program is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License
//    along with this program.  If not, see <http://www.gnu.org/licenses/>.

/*global ABCPrinter */
/*extern  ABCVoiceElement ABCRelativeElement ABCAbsoluteElement ABCBeamElem ABCEndingElem ABCTripletElem ABCTieElem */

function ABCStaffGroupElement() {
  this.voices = [];
  this.staffs = [];
}

ABCStaffGroupElement.prototype.addVoice = function (voice) {
  this.voices[this.voices.length] = voice;
  for (var i=0; i<this.staffs.length;i++) {
    if (this.staffs[i]==voice.y) return;
  }
  this.staffs[this.staffs.length] = voice.y;
};

ABCStaffGroupElement.prototype.finished = function() {
  for (var i=0;i<this.voices.length;i++) {
      if (this.voices[i].i<this.voices[i].children.length) return false;
    }
  return true;
}

ABCStaffGroupElement.prototype.layout = function(spacing) {
  var x = 0;
  var currentduration = 0;
  for (var i=0;i<this.voices.length;i++) {
    this.voices[i].beginLayout();
  }

  while (!this.finished()) {
    var childx=x;
    var cont=true;
    // find smallest duration to be laid out among candidates across voices
    var currentduration= null; 
    for (var i=0;i<this.voices.length;i++) {
      if (!currentduration || this.voices[i].durationindex<currentduration) currentduration=this.voices[i].durationindex;
    }

    // among the current duration level find the one which needs starting furthest right
    for (var i=0;i<this.voices.length;i++) {
      if (this.voices[i].durationindex != currentduration) continue;
      if (this.voices[i].nextx>x) x=this.voices[i].nextx;
    }
    while (cont) {
      cont = false;
      for (var i=0;i<this.voices.length;i++) {
	if (this.voices[i].durationindex != currentduration) continue;
	var voicechildx = this.voices[i].layoutOneItem(x,childx,spacing);
	if (voicechildx>childx) {
	  childx = voicechildx;
	  cont = true; //TODO not optimised for single cases
	} 
      }
    }
    for (var i=0;i<this.voices.length;i++) {
      var voice = this.voices[i]; 
      if (voice.durationindex != currentduration) continue;
      voice.durationindex += voice.children[voice.i].duration;
      voice.i++;
    }
  }
  // increment to the greatest x
  for (var i=0;i<this.voices.length;i++) {
    if (this.voices[i].nextx>x) x=this.voices[i].nextx;
  }

  this.w = x;
};

ABCStaffGroupElement.prototype.draw = function (printer) {
  for (var i=0;i<this.voices.length;i++) {
    this.voices[i].draw(printer);
  }
  for (var i=0;i<this.staffs.length;i++) {
    printer.setY(this.staffs[i]);
    printer.printStave(this.w);
    printer.unSetY();
  }
};

function ABCVoiceElement(y) {
  this.children = [];
  this.otherchildren = []; // ties, slurs, beams, triplets
  this.w = 0;
  this.y = y;
}

ABCVoiceElement.prototype.addChild = function (child) {
  this.children[this.children.length] = child;
};

ABCVoiceElement.prototype.addInvisibleChild = function (child) {
  child.invisible = true;
  this.addChild(child);
};

ABCVoiceElement.prototype.addOther = function (child) {
  this.otherchildren[this.otherchildren.length] = child;
};

ABCVoiceElement.prototype.beginLayout = function () {
  this.i=0;
  this.durationindex=0;
  this.ii=this.children.length;
  this.extraroom=0;
  this.durationroom=0;
  this.room=0;
  this.nextx=0;<commit_msg>connecting line between bars<commit_after>//    abc_graphelements.js: All the drawable and layoutable datastructures to be printed by ABCPrinter
//    Copyright (C) 2010 <NAME> (gregdyke at gmail dot com)
//
//    This program is free software: you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    (at your option) any later version.
//
//    This program is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License
//    along with this program.  If not, see <http://www.gnu.org/licenses/>.

/*global ABCPrinter */
/*extern  ABCVoiceElement ABCRelativeElement ABCAbsoluteElement ABCBeamElem ABCEndingElem ABCTripletElem ABCTieElem */

function ABCStaffGroupElement() {
  this.voices = [];
  this.staffs = [];
}

ABCStaffGroupElement.prototype.addVoice = function (voice) {
  this.voices[this.voices.length] = voice;
  for (var i=0; i<this.staffs.length;i++) {
    if (this.staffs[i]==voice.y) return;
  }
  this.staffs[this.staffs.length] = voice.y;
};

ABCStaffGroupElement.prototype.finished = function() {
  for (var i=0;i<this.voices.length;i++) {
      if (this.voices[i].i<this.voices[i].children.length) return false;
    }
  return true;
}

ABCStaffGroupElement.prototype.layout = function(spacing) {
  var x = 0;
  var currentduration = 0;
  for (var i=0;i<this.voices.length;i++) {
    this.voices[i].beginLayout();
  }

  while (!this.finished()) {
    var childx=x;
    var cont=true;
    // find smallest duration to be laid out among candidates across voices
    var currentduration= null; 
    for (var i=0;i<this.voices.length;i++) {
      if (!currentduration || this.voices[i].durationindex<currentduration) currentduration=this.voices[i].durationindex;
    }

    // among the current duration level find the one which needs starting furthest right
    for (var i=0;i<this.voices.length;i++) {
      if (this.voices[i].durationindex != currentduration) continue;
      if (this.voices[i].nextx>x) x=this.voices[i].nextx;
    }
    while (cont) {
      cont = false;
      for (var i=0;i<this.voices.length;i++) {
	if (this.voices[i].durationindex != currentduration) continue;
	var voicechildx = this.voices[i].layoutOneItem(x,childx,spacing);
	if (voicechildx>childx) {
	  childx = voicechildx;
	  cont = true; //TODO not optimised for single cases
	} 
      }
    }
    for (var i=0;i<this.voices.length;i++) {
      var voice = this.voices[i]; 
      if (voice.durationindex != currentduration) continue;
      voice.durationindex += voice.children[voice.i].duration;
      voice.i++;
    }
  }
  // increment to the greatest x
  for (var i=0;i<this.voices.length;i++) {
    if (this.voices[i].nextx>x) x=this.voices[i].nextx;
  }

  this.w = x;
};

ABCStaffGroupElement.prototype.draw = function (printer) {
  for (var i=0;i<this.voices.length;i++) {
    this.voices[i].draw(printer);
  }

  if (this.staffs.length>1) {
    printer.setY(this.staffs[0]);
    var top = printer.calcY(10);
    printer.setY(this.staffs[this.staffs.length-1]);
    var bottom = printer.calcY(2);
    printer.printStem(0, 0.6, top, bottom);
  }

  for (var i=0;i<this.staffs.length;i++) {
    printer.setY(this.staffs[i]);
    printer.printStave(this.w);
  }
  printer.unSetY();
};

function ABCVoiceElement(y) {
  this.children = [];
  this.otherchildren = []; // ties, slurs, beams, triplets
  this.w = 0;
  this.y = y;
}

ABCVoiceElement.prototype.addChild = function (child) {
  this.children[this.children.length] = child;
};

ABCVoiceElement.prototype.addInvisibleChild = function (child) {
  child.invisible = true;
  this.addChild(child);
};

ABCVoiceElement.prototype.addOther = function (child) {
  this.otherchildren[this.otherchildren.length] = child;
};

ABCVoiceElement.prototype.beginLayout = function () {
  this.i=0;
  this.durationindex=0;
  this.ii=this.children.length;
  this.extraroom=0;
  this.durationroom=0;
  this.room=0;
  this.nextx=0;
{'fraction_non_alphanumeric': 0.1367604267701261, 'fraction_numerical': 0.0069107662463627545, 'mean_word_length': 3.5399009356081454, 'pattern_counts': {'":': 0, '<': 32, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3995907', 'n_tokens_mistral': 2846, 'n_tokens_neox': 2810, 'n_words': 660}