Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to play/draw one channel specified by parameter #689

Merged
merged 3 commits into from
Apr 2, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Add channel parameter for drawing specified channel
  • Loading branch information
whenov committed Apr 1, 2016
commit fd6efe66bc4320b7ebec5e489634ac9a7746a015
10 changes: 10 additions & 0 deletions src/drawer.canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ WaveSurfer.util.extend(WaveSurfer.Drawer.Canvas, {
this.setHeight(channels.length * this.params.height * this.params.pixelRatio);
channels.forEach(this.drawBars, this);
return;
} else if (this.params.channel > -1) { // Channel specified
if (this.params.channel >= channels.length) {
throw new error('Channel doesn\'t exist');
}
peaks = channels[this.params.channel];
} else {
peaks = channels[0];
}
Expand Down Expand Up @@ -126,6 +131,11 @@ WaveSurfer.util.extend(WaveSurfer.Drawer.Canvas, {
this.setHeight(channels.length * this.params.height * this.params.pixelRatio);
channels.forEach(this.drawWave, this);
return;
} else if (this.params.channel > -1) { // Channel specified
if (this.params.channel >= channels.length) {
throw new error('Channel doesn\'t exist');
}
peaks = channels[this.params.channel];
} else {
peaks = channels[0];
}
Expand Down
7 changes: 7 additions & 0 deletions src/wavesurfer.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ var WaveSurfer = {
audioRate : 1,
interact : true,
splitChannels : false,
channel : -1,
mediaContainer: null,
mediaControls : false,
renderer : 'Canvas',
Expand Down Expand Up @@ -296,6 +297,12 @@ var WaveSurfer = {
this.fireEvent('zoom', pxPerSec);
},

setChannel: function (channel) {
this.params.channel = channel;
this.drawer.clearWave();
this.drawBuffer();
},

/**
* Internal method.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/webaudio.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ WaveSurfer.WebAudio = {
}
}

return this.params.splitChannels ? splitPeaks : mergedPeaks;
return (this.params.splitChannels || this.params.channel > -1) ? splitPeaks : mergedPeaks;
},

getPlayedPercents: function () {
Expand Down