Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion js/data/mn-to-try.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
rafale + reotini = { 1,3,4,4,4b,4b } ?
Possible alteration rule:

rafale + rebotini = either { 1,3,4,I} or { 1,1,4,I} depending on what we choose the bassline to be.
It comes from https://en.wikipedia.org/wiki/Picardy_third

to find out:
lars and.. "me,me,me" (trentemoller remix)
space art
107 changes: 107 additions & 0 deletions js/players/mn-sequence-renderer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
var renderSequenceWithTicks = function(harmonicStructure, baseSequence, ticksPerBeat)
{
var result = new Object;
result.length = createSequencingPosition(harmonicStructure.length, ticksPerBeat);
result.sequence = [];

var harmonyIndex = 0;
// Do all of the harmonic steps
while (harmonyIndex < harmonicStructure.structure.length)
{
var harmonyStep = harmonicStructure.structure[harmonyIndex];

var stepEndPosition =
harmonyIndex < harmonicStructure.structure.length - 1
? harmonicStructure.structure[harmonyIndex + 1].tickCount
: harmonicStructure.length;

// At this point, we'll a new copy the base sequence and loop it until the next or final step

var sequenceIndex = 0;
var render = true;

var notes = harmonyStep.element.notes;
var baseSequenceOffset = 0;

while (render)
{
var sequenceStep = baseSequence.sequence[sequenceIndex];
var currentPosition = harmonyStep.tickCount + sequenceStep.tickCount + baseSequenceOffset;

if (currentPosition < stepEndPosition)
{
var step =
{
position: createSequencingPosition(currentPosition, ticksPerBeat),
notes: []
}

sequenceStep.degrees.forEach(function(degree){
if (degree <= notes.length)
{
step.notes.push(notes[degree-1])
}
})

result.sequence.push(step);

// next one and wrap sequence if needed
sequenceIndex++;
if (sequenceIndex >= baseSequence.sequence.length)
{
sequenceIndex = 0;
baseSequenceOffset += baseSequence.length;
// render = false; // for a single iteration
}
}
else {
render = false;
}
}

harmonyIndex++;
}
return result;
}

// renders a serie of note events to be played from
// a base array sequence in the form:
// { position: "1.1.1", degrees: [1,3] }
// and a harmonic structure
// structure: [{ position: "1.1.1", midiNoteList: [35,67] }]
// length: "4.1.1" // In bars

renderSequence = function(harmonicStructure, baseSequence, signature, ticksPerBeat)
{
// Convert base sequence to use ticks for position
var tickBaseSequence = new Object;
tickBaseSequence.length = stringPositionToTicks(baseSequence.length, signature, ticksPerBeat);
tickBaseSequence.sequence = [];

baseSequence.sequence.forEach(function(element)
{
tickBaseSequence.sequence.push(
{
tickCount: stringPositionToTicks(element.position, signature, ticksPerBeat),
degrees: element.degrees
});
})

// Convert harmonicStructure to use ticks for position

var tickBaseStructure = new Object;
tickBaseStructure.length = stringPositionToTicks(harmonicStructure.length, signature, ticksPerBeat);
tickBaseStructure.structure = [] ;

harmonicStructure.structure.forEach(function(item)
{
tickBaseStructure.structure.push(
{
tickCount: stringPositionToTicks(item.position, signature, ticksPerBeat),
element: item.element
}
)
});

return renderSequenceWithTicks(tickBaseStructure, tickBaseSequence, ticksPerBeat);
}
10 changes: 0 additions & 10 deletions js/players/mn-sequencer-renderer.js

This file was deleted.

1 change: 1 addition & 0 deletions js/players/players.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require("./mn-sequence-renderer.js")
17 changes: 4 additions & 13 deletions js/progression/mn-chord-progression.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
// Build a chord object to manipulate the content

ProgressionElement = function (notes, bass)
ProgressionElement = function (notes)
{
this.notes_ = notes;
this.bass_ = bass;
}

// return the notes

ProgressionElement.prototype.notes = function()
{
return this.notes_;
this.notes = notes;
}

// Chord progression helper object
Expand All @@ -31,7 +23,6 @@ ChordProgression.prototype.makeChord = function(degree, alteration)
{
var n = this.scaleNotes_;
var root = n[degree-1];
var bass = root - 24;

// If there's an alteration, force it
if (alteration && alteration.length_ != 0)
Expand All @@ -43,10 +34,10 @@ ChordProgression.prototype.makeChord = function(degree, alteration)
current += interval;
notes.push(current);
})
return new ProgressionElement(notes, bass )
return new ProgressionElement(notes)
}
// return the default chord for the scale
return new ProgressionElement([n[degree-1], n[degree+1], n[degree+3]], bass);
return new ProgressionElement([n[degree-1], n[degree+1], n[degree+3]]);
}

// creates a chord progression from a list of scale degree
Expand Down
10 changes: 5 additions & 5 deletions js/progression/mn-voicing.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ var rectify_progression_sequential = function(sequence)
{
for (var i = 0; i < sequence.length-1; i++)
{
sequence[i+1].notes_ = rectify_closest(sequence[i].notes_,sequence[i+1].notes_);
sequence[i+1].notes = rectify_closest(sequence[i].notes,sequence[i+1].notes);
}
}

var rectify_progression_to_first = function(sequence)
{
for (var i = 0; i < sequence.length-1; i++)
{
sequence[i+1].notes_ = rectify_closest(sequence[0].notes_,sequence[i+1].notes_);
sequence[i+1].notes = rectify_closest(sequence[0].notes,sequence[i+1].notes);
}
}

Expand All @@ -59,15 +59,15 @@ var rectify_progression_inwards = function(sequence)
var leftIndex = 1;
var rightIndex = sequence.length -1;

sequence[rightIndex].notes_ = rectify_closest(sequence[0].notes_, sequence[rightIndex].notes_);
sequence[rightIndex].notes = rectify_closest(sequence[0].notes, sequence[rightIndex].notes);
rightIndex--;

while (leftIndex < rightIndex)
{
sequence[leftIndex].notes_ = rectify_closest(sequence[leftIndex -1].notes_, sequence[leftIndex].notes_);
sequence[leftIndex].notes = rectify_closest(sequence[leftIndex -1].notes, sequence[leftIndex].notes);
if (rightIndex > leftIndex)
{
sequence[rightIndex].notes_ = rectify_closest(sequence[rightIndex+1].notes_, sequence[rightIndex].notes_);
sequence[rightIndex].notes = rectify_closest(sequence[rightIndex+1].notes, sequence[rightIndex].notes);
}
rightIndex--;
leftIndex++;
Expand Down
45 changes: 45 additions & 0 deletions js/sequencing/mn-beat-time-line.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,56 @@ createSequencingPosition = function(tickCount, ticksPerBeat)
return position;
}

ticksFromPosition = function(position)
{
var tickCount = position.beats_;
tickCount = 4 * tickCount + position.sixteenth_;
tickCount = tickCount * (position.ticksPerBeat_ / 4) + position.ticks_;
return tickCount;
}

comparePositions = function(pos1, pos2)
{
var ticks1 = ticksFromPosition(pos1);
var ticks2 = ticksFromPosition(pos2);
if (ticks1 == ticks2) return 0;
return ticks1 < ticks2 ? -1 : 1;
}

addPositions = function(pos1, pos2)
{
var ticks1 = ticksFromPosition(pos1);
var ticks2 = ticksFromPosition(pos2);
return createSequencingPosition(ticks1 + ticks2, pos1.ticksPerBeat_);
}

moduloPosition = function(pos1, pos2)
{
var ticks1 = ticksFromPosition(pos1);
var ticks2 = ticksFromPosition(pos2);
return createSequencingPosition(ticks1 % ticks2, pos1.ticksPerBeat_);
}

subPositions = function(pos1, pos2)
{
var ticks1 = ticksFromPosition(pos1);
var ticks2 = ticksFromPosition(pos2);
return createSequencingPosition(ticks1 - ticks2, pos1.ticksPerBeat_);
}

sixteenthCount = function(position)
{
return position.sixteenth_ + 4 * position.beats_;
}


stringPositionToTicks = function(position, signature, ticksPerBeat)
{
var elementPosition = convertToPosition(position, signature, ticksPerBeat);
var elementPositionInTicks = ticksFromPosition(elementPosition);
return elementPositionInTicks;
}

// converts a beat string ("1.1.3.2") to a sequencing position

convertToPosition = function(beatString, signature, ticksPerBeat)
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@
"pegjs":"x.x",
"hapi":"x.x",
"inert":"x.x"
"lodash":"x.x"
}
}
11 changes: 7 additions & 4 deletions terminal/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ Application.prototype.updateSequence = function()
// create chord progression
var chordSequence = makeChordProgression(this.rootNote_, this.scale_, this.progression_);
// apply desired inversion to the first chord
chordSequence[0].notes_ = invertChord(chordSequence[0].notes_,this.inversion_);
chordSequence[0].notes = invertChord(chordSequence[0].notes,this.inversion_);
// apply voicing
rectify_progression(chordSequence, this.rectificationMethod_);
console.log("should send chord seaquence")
Expand All @@ -91,7 +91,7 @@ Application.prototype.currentSequenceString = function()
var chordSequence = this.chordSequencer_.getContent();
chordSequence.forEach(function (chord)
{
chordnameList += chordname(chord.notes_) + ",";
chordnameList += chordname(chord.notes) + ",";
})
return chordnameList;*/
}
Expand All @@ -112,7 +112,10 @@ Application.prototype.exit = function(arguments)
Application.prototype.rebuild = function()
{
var chordSequence = this.harmony_.rebuild();
this.engine_.setChordSequence(chordSequence);
if (chordSequence)
{
this.engine_.setChordSequence(chordSequence);
}
}

Application.prototype.setScale = function(arguments)
Expand All @@ -127,7 +130,7 @@ Application.prototype.setScale = function(arguments)
scaleChordsNameList = "";
scaleChords.forEach(function (chord)
{
scaleChordsNameList += chordname(chord.notes_) + ",";
scaleChordsNameList += chordname(chord.notes) + ",";
})

return "Scale chords: " + scaleChordsNameList;
Expand Down
2 changes: 1 addition & 1 deletion terminal/harmony-engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ HarmonyEngine.prototype.rebuild = function()
// create chord progression
var chordSequence = makeChordProgression(this.rootNote_, this.scale_, this.progression_);
// apply desired inversion to the first chord
chordSequence[0].notes_ = invertChord(chordSequence[0].notes_,this.inversion_);
chordSequence[0].notes = invertChord(chordSequence[0].notes,this.inversion_);
// apply voicing
rectify_progression(chordSequence, this.rectificationMethod_);
return chordSequence;
Expand Down
6 changes: 3 additions & 3 deletions terminal/main.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict';

//if ( global.v8debug) {
// global.v8debug.Debug.setBreakOnException(); // enable it, global.v8debug is only defined when the --debug or --debug-brk flag is set
//}
if ( global.v8debug) {
global.v8debug.Debug.setBreakOnException(); // enable it, global.v8debug is only defined when the --debug or --debug-brk flag is set
}

var app = require('./application.js');
app.init({
Expand Down
8 changes: 4 additions & 4 deletions terminal/playback-engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ ChordPlayer.prototype.tick = function(position)
&&(step.position.ticks_ == wrapped.ticks_))
{
console.log("queing " + JSON.stringify(step));
noteQueuer.queueNotes(step.chord.notes_);
noteQueuer.queueNotes(step.element.notes);
}
})
}
Expand Down Expand Up @@ -123,20 +123,20 @@ PlaybackEngine.prototype.run = function()
this.heartbeat_.run();
}

PlaybackEngine.prototype.setChordSequence = function(chordSequence)
PlaybackEngine.prototype.setChordSequence = function(harmonicProgression)
{
var currentBar = 1;
var timeline = new Object;
var signature = this.signature_;

timeline.sequence_ = [];
chordSequence.forEach(function(chord)
harmonicProgression.forEach(function(element)
{
var position = new SequencingPosition(this.ticksPerBeat_);
position.beats_ = (currentBar - 1) * signature.denominator;
timeline.sequence_.push({
position : position,
chord : chord
element : element
});
currentBar++;
})
Expand Down
2 changes: 1 addition & 1 deletion test/scale-detection.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function makeChordList()

chordSequence.forEach(function (chord)
{
chordList.push(chordname(chord.notes_));
chordList.push(chordname(chord.notes));
})
return chordList;
}
Expand Down
12 changes: 6 additions & 6 deletions test/test-chord-progression.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ require("../js/mn-scale.js");

var sequence = [1,6];
var progression = makeChordProgression("c3", "minor", sequence);
assert.equal(chordname(progression[0].notes_), "cm");
assert.equal(chordname(progression[1].notes_), "g#");
assert.equal(chordname(progression[0].notes), "cm");
assert.equal(chordname(progression[1].notes), "g#");

var sequence = ["1","6"];
var progression = makeChordProgression("c3", "minor", sequence);
assert.equal(chordname(progression[0].notes_), "cm");
assert.equal(chordname(progression[1].notes_), "g#");
assert.equal(chordname(progression[0].notes), "cm");
assert.equal(chordname(progression[1].notes), "g#");

var sequence = ["1","5M"];
var progression = makeChordProgression("c3", "major", sequence);
assert.equal(chordname(progression[0].notes_), "c");
assert.equal(chordname(progression[1].notes_), "g");
assert.equal(chordname(progression[0].notes), "c");
assert.equal(chordname(progression[1].notes), "g");

// Rectification

Expand Down
Loading