index.js
function(tune) {
  var ret = {
    attributes: {
      divisions: 1 /tune.getBeatLength(),
      clef: {
        line: 2
      },
      key: {},
      time: {}
    }
  };
  var measures = [];
  var measureCounter = 0;
  var barlineCounter = 0;

  // parse lines
  for (var l = 0; l < tune.lines.length; l++) {
    for (var s = 0; s < tune.lines[l].staff.length; s++) {
      var staff = tune.lines[l].staff[s];

      // parse default clef, key, meter
      if (l === 0 && s === 0) {
        ret.attributes.clef.sign = getKeyByValue(clefs, staff.clef.type);
        ret.attributes.clef.line = staff.clef.clefPos / 2;
        ret.attributes.key.fifths = parseInt(getKeyByValue(circleOfFifths, staff.key.root));
        ret.attributes.time.beats = staff.meter.value[0].num;
        ret.attributes.time['beat-type'] = staff.meter.value[0].den;
      }

      for (var v = 0; v < staff.voices.length; v++) {
        for (var t = 0; t < staff.voices[v].length; t++) {
          var token = staff.voices[v][t];

          // init measure if none exists
          if (measures[measureCounter] === undefined) {
            measures[measureCounter] = new Measure();
          }

          switch (token.el_type) {
            case "note":
              measures[measureCounter].addNote(token, ret.attributes.divisions, ret.attributes.time['beat-type']);
              break;
            case "bar":
              if (token.type === 'bar_right_repeat') {
                measures[measureCounter].setRepeatRight();
              }
              measureCounter++;
              if (measures[measureCounter] === undefined) {
                measures[measureCounter] = new Measure();
              }
              if (token.type === 'bar_left_repeat') {
                measures[measureCounter].setRepeatLeft();
              }
              break;
            default:
              console.log(token);
              break;
          }
        }
      }
    }
  }

  // put measures together
  ret.measures = [];
  for (var i = 0; i < measures.length; i++) {
    var measure = measures[i].get();
    if (measure.notes.length > 0) {
      ret.measures.push(measure);
    }
  }
  return ret;
}
function(tune) {
  var ret = {
    attributes: {
      divisions: 1 /tune.getBeatLength(),
      clef: {
        line: 2
      },
      key: {},
      time: {}
    }
  };
  var measures = [];
  var measureCounter = 0;
  var barlineCounter = 0;

  // parse lines
  for (var l = 0; l < tune.lines.length; l++) {
    for (var s = 0; s < tune.lines[l].staff.length; s++) {
      var staff = tune.lines[l].staff[s];

      // parse default clef, key, meter
      if (l === 0 && s === 0) {
        ret.attributes.clef.sign = getKeyByValue(clefs, staff.clef.type);
        ret.attributes.clef.line = staff.clef.clefPos / 2;
        ret.attributes.key.fifths = parseInt(getKeyByValue(circleOfFifths, staff.key.root));
        ret.attributes.time.beats = staff.meter.value[0].num;
        ret.attributes.time['beat-type'] = staff.meter.value[0].den;
      }

      for (var v = 0; v < staff.voices.length; v++) {
        for (var t = 0; t < staff.voices[v].length; t++) {
          var token = staff.voices[v][t];

          // init measure if none exists
          if (measures[measureCounter] === undefined) {
            measures[measureCounter] = new Measure();
          }

          switch (token.el_type) {
            case "note":
              measures[measureCounter].addNote(token, ret.attributes.divisions, ret.attributes.time['beat-type']);
              break;
            case "bar":
              if (token.type === 'bar_right_repeat') {
                measures[measureCounter].setRepeatRight();
              }
              measureCounter++;
              if (measures[measureCounter] === undefined) {
                measures[measureCounter] = new Measure();
              }
              if (token.type === 'bar_left_repeat') {
                measures[measureCounter].setRepeatLeft();
              }
              break;
            default:
              console.log(token);
              break;
          }
        }
      }
    }
  }

  // put measures together
  ret.measures = [];
  for (var i = 0; i < measures.length; i++) {
    var measure = measures[i].get();
    if (measure.notes.length > 0) {
      ret.measures.push(measure);
    }
  }
  return ret;
}
function ( tune ) { var ret = { attributes : { divisions : 1 / tune . getBeatLength ( ) , clef : { line : 2 } , key : { } , time : { } } } ; var measures = [ ] ; var measureCounter = 0 ; var barlineCounter = 0 ; // parse lines for ( var l = 0 ; l < tune . lines . length ; l ++ ) { for ( var s = 0 ; s < tune . lines [ l ] . staff . length ; s ++ ) { var staff = tune . lines [ l ] . staff [ s ] ; // parse default clef, key, meter if ( l === 0 && s === 0 ) { ret . attributes . clef . sign = getKeyByValue ( clefs , staff . clef . type ) ; ret . attributes . clef . line = staff . clef . clefPos / 2 ; ret . attributes . key . fifths = parseInt ( getKeyByValue ( circleOfFifths , staff . key . root ) ) ; ret . attributes . time . beats = staff . meter . value [ 0 ] . num ; ret . attributes . time [ 'beat-type' ] = staff . meter . value [ 0 ] . den ; } for ( var v = 0 ; v < staff . voices . length ; v ++ ) { for ( var t = 0 ; t < staff . voices [ v ] . length ; t ++ ) { var token = staff . voices [ v ] [ t ] ; // init measure if none exists if ( measures [ measureCounter ] === undefined ) { measures [ measureCounter ] = new Measure ( ) ; } switch ( token . el_type ) { case "note" : measures [ measureCounter ] . addNote ( token , ret . attributes . divisions , ret . attributes . time [ 'beat-type' ] ) ; break ; case "bar" : if ( token . type === 'bar_right_repeat' ) { measures [ measureCounter ] . setRepeatRight ( ) ; } measureCounter ++ ; if ( measures [ measureCounter ] === undefined ) { measures [ measureCounter ] = new Measure ( ) ; } if ( token . type === 'bar_left_repeat' ) { measures [ measureCounter ] . setRepeatLeft ( ) ; } break ; default : console . log ( token ) ; break ; } } } } } // put measures together ret . measures = [ ] ; for ( var i = 0 ; i < measures . length ; i ++ ) { var measure = measures [ i ] . get ( ) ; if ( measure . notes . length > 0 ) { ret . measures . push ( measure ) ; } } return ret ; }
Creates json object from abc tunes object
@param {object} tune - The parsed tune object
@returns {object}
Creates json object from abc tunes object