require("../js/players/players.js");
require("../js/sequencing/sequencing.js");
require("../js/progression/progression.js");
require("../js/theory/theory.js");
require("../js/mn-scale.js");

var assert = require("assert");

function testSequenceRendering(baseSequence, progression, expected)
{
  var signature = new Signature;
  var ticksPerBeat = kTicksPerBeats;

  // Build the basic chord structure

  var chords = makeChordProgression(progression.root, progression.scale, progression.degrees);

  var harmonicStructure = createTimeline(chords, createSequencingPosition(ticksPerBeat * signature.denominator, ticksPerBeat));
  var length = createSequencingPosition(chords.length * ticksPerBeat * signature.denominator, ticksPerBeat);
  harmonicStructure.setLength(length);
  // render the combination

  var rendered = renderSequence(harmonicStructure, baseSequence, signature, ticksPerBeat);

  // Test against expected

  expected.length = convertToPosition(expected.length, signature, ticksPerBeat)
  expected.sequence.forEach(function(element)
  {
    element.position = convertToPosition(element.position, signature, ticksPerBeat)
  });
  assert.deepEqual(rendered, expected);
}

//==============================================================================

var baseSequence = {
    length : "1.4.1",
    sequence:
      [
        { position: "1.1.1", degrees: [{d:1, t:-12}, 1,2]},
        { position: "1.2.1", degrees: [2]},
        { position: "1.3.1", degrees: [3,1]},
      ]
    }

var progression = {
    root: "c3",
    scale: "major",
    degrees: [1,5]
}

var expected = {
  length: "3.1.1",
  sequence:
    [
      { position: "1.1.1", notes: [36, 48, 52]},
      { position: "1.2.1", notes: [52]},
      { position: "1.3.1", notes: [55, 48]},
      { position: "1.4.1", notes: [36, 48, 52]},
      { position: "2.1.1", notes: [43, 55, 59]},
      { position: "2.2.1", notes: [59]},
      { position: "2.3.1", notes: [62, 55]},
      { position: "2.4.1", notes: [43, 55, 59]},
    ]
}

testSequenceRendering(baseSequence, progression, expected);

@@ -240,32 +240,43 @@
 quenceRendering(
+signature, 
 baseSequence, pr
@@ -302,41 +302,8 @@
 )%0A%7B%0A
-  var signature = new Signature;%0A
   va
@@ -561,39 +561,37 @@
 eat * signature.
-denomin
+numer
 ator, ticksPerBe
@@ -681,15 +681,13 @@
 ure.
-denomin
+numer
 ator
@@ -1111,16 +1111,134 @@
 )%0A  %7D);%0A
+//  console.log(%22%3E%3E%3E%22 + JSON.stringify(rendered,null ,2));%0A//  console.log(%22%3C%3C%3C%22 + JSON.stringify(expected,null ,2));%0A
   assert
@@ -2093,16 +2093,47 @@
    %5D%0A%7D%0A%0A
+var signature = new Signature;%0A
 testSequ
@@ -2146,16 +2146,27 @@
 ndering(
+signature, 
 baseSequ
@@ -2183,20 +2183,460 @@
 ression, expected);%0A
+%0Asignature.numerator = 3;%0Avar expectedOn3_4 = %7B%0A  length: %223.1.1%22,%0A  sequence:%0A    %5B%0A      %7B position: %221.1.1%22, notes: %5B36, 48, 52%5D%7D,%0A      %7B position: %221.2.1%22, notes: %5B52%5D%7D,%0A      %7B position: %221.3.1%22, notes: %5B55, 48%5D%7D,%0A      %7B position: %222.1.1%22, notes: %5B43, 55, 59%5D%7D,%0A      %7B position: %222.2.1%22, notes: %5B59%5D%7D,%0A      %7B position: %222.3.1%22, notes: %5B62, 55%5D%7D,%0A    %5D%0A%7D%0A%0AtestSequenceRendering(signature, baseSequence, progression, expectedOn3_4);%0A

Add test for non 4/4 timesignature