Skip to content

Commit

Permalink
FLOE-437: basic stop functionality added
Browse files Browse the repository at this point in the history
  • Loading branch information
waharnum committed Jan 21, 2016
1 parent 422d6ac commit 9b61f0b
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions src/js/sonifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ var flockingEnvironment = flock.init();
// Add the synth to the model
that.applier.change("synth", dataPianoBand);

floe.chartAuthoring.sonifier.playDataset(0, true, that);
floe.chartAuthoring.sonifier.processSonificationQueue(0, true, that);
};

// Passed a sonified dataset, this function + playDataAndQueueNext acts recursively
Expand All @@ -290,12 +290,10 @@ var flockingEnvironment = flock.init();
// when a sonification completes
// - we can fire an event when a voice label read completes, but can't know
// in advance how long it will take to read the label
floe.chartAuthoring.sonifier.playDataset = function(delay, noGap, that) {
floe.chartAuthoring.sonifier.processSonificationQueue = function(delay, noGap, that) {

var gapDuration = that.options.playbackOptions.gapDuration;

// console.log("floe.chartAuthoring.sonifier.playDataset");

var sonificationQueue = that.model.sonificationQueue;

var synth = that.model.synth;
Expand All @@ -316,17 +314,20 @@ var flockingEnvironment = flock.init();
});
};

// Recursion function called from floe.chartAuthoring.sonifier.playDataset
// Recursion function called from floe.chartAuthoring.sonifier.processSonificationQueue

floe.chartAuthoring.sonifier.playDataAndQueueNext = function(that) {

var synth = that.model.synth;
var sonificationQueue = that.model.sonificationQueue;
var data = sonificationQueue.shift();

// console.log("Voice label for " + data.label + " finshed");
var noteDuration = floe.chartAuthoring.sonifier.getTotalDuration(data.notes.durations);
// This prevents an error being thrown if a stop has been called but
// this function is queued or in the midst of execution
var noteDuration = (data !== undefined) ? floe.chartAuthoring.sonifier.getTotalDuration(data.notes.durations) : 0;

if(sonificationQueue.length > 0) {
floe.chartAuthoring.sonifier.playDataset(noteDuration, false, that);
floe.chartAuthoring.sonifier.processSonificationQueue(noteDuration, false, that);
} else {
// Stop the flocking environment after the last sonification is
// played
Expand All @@ -350,11 +351,16 @@ var flockingEnvironment = flock.init();
};

floe.chartAuthoring.sonifier.stopSonification = function(that) {
// Fire the stop event
that.events.onStopSonification.fire();
// Flush the sonification queue
that.applier.change("sonificationQueue",[]);
// Flush any outstanding flocking schedulers
that.model.synth.scheduler.clearAll();
// Stop any queued voices
// Stop the synth
that.textToSpeech.cancel();
// Stop the flocking environment
flockingEnvironment.stop();
// Fire the stop event
that.events.onStopSonification.fire();
};

})(jQuery, fluid);

0 comments on commit 9b61f0b

Please sign in to comment.