Skip to content

Commit 7c77133

Browse files
committed
Solves issue #79 by making a workaround for Firefox on attack and release envelopes.
1 parent 2578808 commit 7c77133

4 files changed

Lines changed: 62 additions & 29 deletions

File tree

distr/Pizzicato.js

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -777,16 +777,21 @@
777777
value: function() {
778778
var currentValue = this.fadeNode.gain.value;
779779
this.fadeNode.gain.cancelScheduledValues(Pz.context.currentTime);
780-
this.fadeNode.gain.setValueAtTime(currentValue, Pz.context.currentTime);
781780

782781
if (!this.attack) {
783-
this.fadeNode.gain.setValueAtTime(1.0, Pizzicato.context.currentTime);
782+
this.fadeNode.gain.setTargetAtTime(1.0, Pz.context.currentTime, 0.001);
784783
return;
785784
}
786785

787-
var remainingAttackTime = (1 - this.fadeNode.gain.value) * this.attack;
788-
this.fadeNode.gain.setValueAtTime(this.fadeNode.gain.value, Pizzicato.context.currentTime);
789-
this.fadeNode.gain.linearRampToValueAtTime(1, Pizzicato.context.currentTime + remainingAttackTime);
786+
// We can't calculate the remaining attack time
787+
// in Firefox due to https://bugzilla.mozilla.org/show_bug.cgi?id=893020
788+
var isFirefox = navigator.userAgent.toLowerCase().indexOf('firefox') > -1;
789+
var remainingAttackTime = this.attack;
790+
791+
if (!isFirefox)
792+
remainingAttackTime = (1 - this.fadeNode.gain.value) * this.attack;
793+
794+
this.fadeNode.gain.setTargetAtTime(1.0, Pz.context.currentTime, remainingAttackTime * 2);
790795
}
791796
},
792797

@@ -807,16 +812,22 @@
807812

808813
var currentValue = this.fadeNode.gain.value;
809814
this.fadeNode.gain.cancelScheduledValues(Pz.context.currentTime);
810-
this.fadeNode.gain.setValueAtTime(currentValue, Pz.context.currentTime);
811815

812816
if (!this.release) {
817+
this.fadeNode.gain.setTargetAtTime(0.0, Pz.context.currentTime, 0.001);
813818
stopSound();
814819
return;
815820
}
816821

817-
var remainingReleaseTime = this.fadeNode.gain.value * this.release;
818-
this.fadeNode.gain.setValueAtTime(this.fadeNode.gain.value, Pizzicato.context.currentTime);
819-
this.fadeNode.gain.linearRampToValueAtTime(0.00001, Pizzicato.context.currentTime + remainingReleaseTime);
822+
// We can't calculate the remaining attack time
823+
// in Firefox due to https://bugzilla.mozilla.org/show_bug.cgi?id=893020
824+
var isFirefox = navigator.userAgent.toLowerCase().indexOf('firefox') > -1;
825+
var remainingReleaseTime = this.release;
826+
827+
if (!isFirefox)
828+
remainingReleaseTime = this.fadeNode.gain.value * this.release;
829+
830+
this.fadeNode.gain.setTargetAtTime(0.00001, Pz.context.currentTime, remainingReleaseTime / 5);
820831

821832
window.setTimeout(function() {
822833
stopSound();

distr/Pizzicato.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

site/Pizzicato.js

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -777,16 +777,21 @@
777777
value: function() {
778778
var currentValue = this.fadeNode.gain.value;
779779
this.fadeNode.gain.cancelScheduledValues(Pz.context.currentTime);
780-
this.fadeNode.gain.setValueAtTime(currentValue, Pz.context.currentTime);
781780

782781
if (!this.attack) {
783-
this.fadeNode.gain.setValueAtTime(1.0, Pizzicato.context.currentTime);
782+
this.fadeNode.gain.setTargetAtTime(1.0, Pz.context.currentTime, 0.001);
784783
return;
785784
}
786785

787-
var remainingAttackTime = (1 - this.fadeNode.gain.value) * this.attack;
788-
this.fadeNode.gain.setValueAtTime(this.fadeNode.gain.value, Pizzicato.context.currentTime);
789-
this.fadeNode.gain.linearRampToValueAtTime(1, Pizzicato.context.currentTime + remainingAttackTime);
786+
// We can't calculate the remaining attack time
787+
// in Firefox due to https://bugzilla.mozilla.org/show_bug.cgi?id=893020
788+
var isFirefox = navigator.userAgent.toLowerCase().indexOf('firefox') > -1;
789+
var remainingAttackTime = this.attack;
790+
791+
if (!isFirefox)
792+
remainingAttackTime = (1 - this.fadeNode.gain.value) * this.attack;
793+
794+
this.fadeNode.gain.setTargetAtTime(1.0, Pz.context.currentTime, remainingAttackTime * 2);
790795
}
791796
},
792797

@@ -807,16 +812,22 @@
807812

808813
var currentValue = this.fadeNode.gain.value;
809814
this.fadeNode.gain.cancelScheduledValues(Pz.context.currentTime);
810-
this.fadeNode.gain.setValueAtTime(currentValue, Pz.context.currentTime);
811815

812816
if (!this.release) {
817+
this.fadeNode.gain.setTargetAtTime(0.0, Pz.context.currentTime, 0.001);
813818
stopSound();
814819
return;
815820
}
816821

817-
var remainingReleaseTime = this.fadeNode.gain.value * this.release;
818-
this.fadeNode.gain.setValueAtTime(this.fadeNode.gain.value, Pizzicato.context.currentTime);
819-
this.fadeNode.gain.linearRampToValueAtTime(0.00001, Pizzicato.context.currentTime + remainingReleaseTime);
822+
// We can't calculate the remaining attack time
823+
// in Firefox due to https://bugzilla.mozilla.org/show_bug.cgi?id=893020
824+
var isFirefox = navigator.userAgent.toLowerCase().indexOf('firefox') > -1;
825+
var remainingReleaseTime = this.release;
826+
827+
if (!isFirefox)
828+
remainingReleaseTime = this.fadeNode.gain.value * this.release;
829+
830+
this.fadeNode.gain.setTargetAtTime(0.00001, Pz.context.currentTime, remainingReleaseTime / 5);
820831

821832
window.setTimeout(function() {
822833
stopSound();

src/Sound.js

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -573,16 +573,21 @@ Pizzicato.Sound.prototype = Object.create(Pizzicato.Events, {
573573
value: function() {
574574
var currentValue = this.fadeNode.gain.value;
575575
this.fadeNode.gain.cancelScheduledValues(Pz.context.currentTime);
576-
this.fadeNode.gain.setValueAtTime(currentValue, Pz.context.currentTime);
577576

578577
if (!this.attack) {
579-
this.fadeNode.gain.setValueAtTime(1.0, Pizzicato.context.currentTime);
578+
this.fadeNode.gain.setTargetAtTime(1.0, Pz.context.currentTime, 0.001);
580579
return;
581580
}
582581

583-
var remainingAttackTime = (1 - this.fadeNode.gain.value) * this.attack;
584-
this.fadeNode.gain.setValueAtTime(this.fadeNode.gain.value, Pizzicato.context.currentTime);
585-
this.fadeNode.gain.linearRampToValueAtTime(1, Pizzicato.context.currentTime + remainingAttackTime);
582+
// We can't calculate the remaining attack time
583+
// in Firefox due to https://bugzilla.mozilla.org/show_bug.cgi?id=893020
584+
var isFirefox = navigator.userAgent.toLowerCase().indexOf('firefox') > -1;
585+
var remainingAttackTime = this.attack;
586+
587+
if (!isFirefox)
588+
remainingAttackTime = (1 - this.fadeNode.gain.value) * this.attack;
589+
590+
this.fadeNode.gain.setTargetAtTime(1.0, Pz.context.currentTime, remainingAttackTime * 2);
586591
}
587592
},
588593

@@ -603,16 +608,22 @@ Pizzicato.Sound.prototype = Object.create(Pizzicato.Events, {
603608

604609
var currentValue = this.fadeNode.gain.value;
605610
this.fadeNode.gain.cancelScheduledValues(Pz.context.currentTime);
606-
this.fadeNode.gain.setValueAtTime(currentValue, Pz.context.currentTime);
607611

608612
if (!this.release) {
613+
this.fadeNode.gain.setTargetAtTime(0.0, Pz.context.currentTime, 0.001);
609614
stopSound();
610615
return;
611616
}
612617

613-
var remainingReleaseTime = this.fadeNode.gain.value * this.release;
614-
this.fadeNode.gain.setValueAtTime(this.fadeNode.gain.value, Pizzicato.context.currentTime);
615-
this.fadeNode.gain.linearRampToValueAtTime(0.00001, Pizzicato.context.currentTime + remainingReleaseTime);
618+
// We can't calculate the remaining attack time
619+
// in Firefox due to https://bugzilla.mozilla.org/show_bug.cgi?id=893020
620+
var isFirefox = navigator.userAgent.toLowerCase().indexOf('firefox') > -1;
621+
var remainingReleaseTime = this.release;
622+
623+
if (!isFirefox)
624+
remainingReleaseTime = this.fadeNode.gain.value * this.release;
625+
626+
this.fadeNode.gain.setTargetAtTime(0.00001, Pz.context.currentTime, remainingReleaseTime / 5);
616627

617628
window.setTimeout(function() {
618629
stopSound();

0 commit comments

Comments
 (0)