|
| 1 | +var renderSequenceWithTicks = function(harmonicStructure, baseSequence, ticksPerBeat) |
| 2 | +{ |
| 3 | + var result = new Object; |
| 4 | + result.length = createSequencingPosition(harmonicStructure.length, ticksPerBeat); |
| 5 | + result.sequence = []; |
| 6 | + |
| 7 | + var harmonyIndex = 0; |
| 8 | + // Do all of the harmonic steps |
| 9 | + while (harmonyIndex < harmonicStructure.structure.length) |
| 10 | + { |
| 11 | + var harmonyStep = harmonicStructure.structure[harmonyIndex]; |
| 12 | + |
| 13 | + var stepEndPosition = |
| 14 | + harmonyIndex < harmonicStructure.structure.length - 1 |
| 15 | + ? harmonicStructure.structure[harmonyIndex + 1].tickCount |
| 16 | + : harmonicStructure.length; |
| 17 | + |
| 18 | + // At this point, we'll a new copy the base sequence and loop it until the next or final step |
| 19 | + |
| 20 | + var sequenceIndex = 0; |
| 21 | + var render = true; |
| 22 | + |
| 23 | + var notes = harmonyStep.element.notes; |
| 24 | + var baseSequenceOffset = 0; |
| 25 | + |
| 26 | + while (render) |
| 27 | + { |
| 28 | + var sequenceStep = baseSequence.sequence[sequenceIndex]; |
| 29 | + var currentPosition = harmonyStep.tickCount + sequenceStep.tickCount + baseSequenceOffset; |
| 30 | + |
| 31 | + if (currentPosition < stepEndPosition) |
| 32 | + { |
| 33 | + var step = |
| 34 | + { |
| 35 | + position: createSequencingPosition(currentPosition, ticksPerBeat), |
| 36 | + notes: [] |
| 37 | + } |
| 38 | + |
| 39 | + sequenceStep.degrees.forEach(function(degree){ |
| 40 | + if (degree <= notes.length) |
| 41 | + { |
| 42 | + step.notes.push(notes[degree-1]) |
| 43 | + } |
| 44 | + }) |
| 45 | + |
| 46 | + result.sequence.push(step); |
| 47 | + |
| 48 | + // next one and wrap sequence if needed |
| 49 | + sequenceIndex++; |
| 50 | + if (sequenceIndex >= baseSequence.sequence.length) |
| 51 | + { |
| 52 | + sequenceIndex = 0; |
| 53 | + baseSequenceOffset += baseSequence.length; |
| 54 | +// render = false; // for a single iteration |
| 55 | + } |
| 56 | + } |
| 57 | + else { |
| 58 | + render = false; |
| 59 | + } |
| 60 | + } |
| 61 | + |
| 62 | + harmonyIndex++; |
| 63 | + } |
| 64 | + return result; |
| 65 | +} |
| 66 | + |
| 67 | +// renders a serie of note events to be played from |
| 68 | +// a base array sequence in the form: |
| 69 | +// { position: "1.1.1", degrees: [1,3] } |
| 70 | +// and a harmonic structure |
| 71 | +// structure: [{ position: "1.1.1", midiNoteList: [35,67] }] |
| 72 | +// length: "4.1.1" // In bars |
| 73 | + |
| 74 | +renderSequence = function(harmonicStructure, baseSequence, signature, ticksPerBeat) |
| 75 | +{ |
| 76 | + // Convert base sequence to use ticks for position |
| 77 | + var tickBaseSequence = new Object; |
| 78 | + tickBaseSequence.length = stringPositionToTicks(baseSequence.length, signature, ticksPerBeat); |
| 79 | + tickBaseSequence.sequence = []; |
| 80 | + |
| 81 | + baseSequence.sequence.forEach(function(element) |
| 82 | + { |
| 83 | + tickBaseSequence.sequence.push( |
| 84 | + { |
| 85 | + tickCount: stringPositionToTicks(element.position, signature, ticksPerBeat), |
| 86 | + degrees: element.degrees |
| 87 | + }); |
| 88 | + }) |
| 89 | + |
| 90 | + // Convert harmonicStructure to use ticks for position |
| 91 | + |
| 92 | + var tickBaseStructure = new Object; |
| 93 | + tickBaseStructure.length = stringPositionToTicks(harmonicStructure.length, signature, ticksPerBeat); |
| 94 | + tickBaseStructure.structure = [] ; |
| 95 | + |
| 96 | + harmonicStructure.structure.forEach(function(item) |
| 97 | + { |
| 98 | + tickBaseStructure.structure.push( |
| 99 | + { |
| 100 | + tickCount: stringPositionToTicks(item.position, signature, ticksPerBeat), |
| 101 | + element: item.element |
| 102 | + } |
| 103 | + ) |
| 104 | + }); |
| 105 | + |
| 106 | + return renderSequenceWithTicks(tickBaseStructure, tickBaseSequence, ticksPerBeat); |
| 107 | +} |
0 commit comments