import jp.crestmuse.cmx.inference.Calculator;
import jp.crestmuse.cmx.inference.MusicRepresentation;
import jp.crestmuse.cmx.inference.MusicRepresentation.MusicElement;

public class ChordCalculator implements Calculator {

  private int[] chordMapping = { 0, 0, 1, 1, 2, 3, 3, 4, 4, 5, 5, 6 };

  public void update(MusicRepresentation musRep, MusicElement me, int index) {
    int division = musRep.getDivision();
    int measureLen = musRep.getMeasureNum();

    // 最後の小節なら処理しない
    if (index > division * (measureLen - 1))
      return;

    // ノートナンバー
    int noteNum = me.getHighestProbIndex();

    // 次の小節の開始インデックス
    int nextMeasureIndex = (index / division +  1) * division;

    // 次の小節のコードを決める
    MusicElement nextChord = musRep.getMusicElement("chord", nextMeasureIndex);
    nextChord.setEvidence(chordMapping[noteNum]);

    // 必要な場合更新する
    // musRep.update("chord", nextMeasureIndex);
  }

}

