Skip to content

Commit

Permalink
Show displacement in notation
Browse files Browse the repository at this point in the history
  • Loading branch information
wasabigeek committed Jul 27, 2020
1 parent 1b672d9 commit 3c901f7
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 26 deletions.
17 changes: 10 additions & 7 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -244,10 +244,18 @@ <h3><span class="text-gray-600">Roadmap:</span></h3>
var newScore = new Orchestrator({ drumset: drumset, allowedOrchestrations: orchestrations })
.orchestrate(sticking);

return newScore.map(function(grouping) {
newScore = newScore.map(function(grouping) {
grouping.setDuration(DURATION_SIXTEENTH);
return grouping;
});

newScore = new Displacer({ drumset: drumset })
.displace(
newScore,
{ counts: document.getElementById('displacement').value }
);

return newScore;
}

var newSticking = document.getElementById('sticking').value;
Expand All @@ -263,12 +271,7 @@ <h3><span class="text-gray-600">Roadmap:</span></h3>
var tempo = document.getElementById('tempo').value;
var groove = null;

var playbackScore = new Displacer({ drumset: drumset })
.displace(
score,
{ counts: document.getElementById('displacement').value }
);
player.play(playbackScore, { tempo: tempo })
player.play(score, { tempo: tempo })
}

document.getElementById('shuffleForm').onsubmit = function(e) {
Expand Down
57 changes: 38 additions & 19 deletions js/Notator.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ function Notator(options) {
elementId: options.elementId,
backend: Vex.Flow.Renderer.Backends.SVG,
width: 500,
height: 120,
height: 300,
},
});

Expand All @@ -17,9 +17,7 @@ function Notator(options) {
FLOOR_TOM: 'a/4',
}

this.toNotation = function(noteGroup) {
var keys = noteGroup.notes.map(function(note) { return note.verticalPosition });

this.toDuration = function(noteGroup) {
var vfDuration;
switch (noteGroup.duration) {
case DURATION_EIGHTH:
Expand All @@ -32,34 +30,55 @@ function Notator(options) {
break;
}

return vfDuration;
}

this.toNotation = function(noteGroup) {
var keys = noteGroup.notes.map(function(note) { return note.verticalPosition });

return {
keys: keys,
duration: vfDuration
duration: this.toDuration(noteGroup)
}
}

this.addStave = function(subScore, staveOptions = {}) {
var stave = this.vf.Stave(staveOptions)
.addClef('percussion')
.addTimeSignature('4/4');

var tickables = [];
for (var noteGroup of subScore) {
tickables.push(this.vf.StaveNote(this.toNotation(noteGroup)));
}

var voice0 = this.vf.Voice().addTickables(tickables);
this.vf.Beam({ notes: voice0.getTickables() });

this.vf.Formatter()
.joinVoices(this.vf.getVoices())
.formatToStave(this.vf.getVoices(), stave);

return stave;
}

this.generateNotation = function(score) {
var context = this.vf.getContext()
context.clear();

var stave = this.vf.Stave()
.addClef('percussion')
.addTimeSignature('4/4');
var totalSixteenths = 0;
var subScore1 = [];
var subScore2 = score.slice();
do {
var noteGroup = subScore2.shift();
totalSixteenths += 1 / this.toDuration(noteGroup) * 16

if (score.length > 0) {
var tickables = [];
for (var noteGroup of score) {
tickables.push(this.vf.StaveNote(this.toNotation(noteGroup)));
}
subScore1.push(noteGroup)
} while (totalSixteenths < 16)

var voice0 = this.vf.Voice().addTickables(tickables);
this.vf.Beam({ notes: voice0.getTickables() });
this.addStave(subScore1, { y: 30} );
this.addStave(subScore2, { y: 180 });

this.vf.Formatter()
.joinVoices(this.vf.getVoices())
.formatToStave(this.vf.getVoices(), stave);
}
this.vf.draw();
}
}
Expand Down

0 comments on commit 3c901f7

Please sign in to comment.