Skip to content

Commit

Permalink
added .startUI and .stopUI
Browse files Browse the repository at this point in the history
  • Loading branch information
zakaton committed Jun 13, 2019
1 parent 92cf5dc commit 90cbd86
Show file tree
Hide file tree
Showing 11 changed files with 93 additions and 18 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"liveServer.settings.port": 80
}
2 changes: 1 addition & 1 deletion build/pink-trombone.min.js

Large diffs are not rendered by default.

60 changes: 58 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,72 @@
</head>

<body>
<pink-trombone ui></pink-trombone>
<pink-trombone></pink-trombone>

<script>
const pinkTromboneElement = document.querySelector("pink-trombone");

pinkTromboneElement.addEventListener("load", event => {
pinkTromboneElement.setAudioContext()
.then(pinkTrombone => {
pinkTromboneElement.enableUI();
pinkTromboneElement.startUI();
pinkTromboneElement.connect(pinkTromboneElement.audioContext.destination);
pinkTromboneElement.start();

if(false) {
function say(_tongue, _constriction, duration, timeout, intensity, tenseness, frequency) {
return new Promise(resolve => {
window.setTimeout(() => {
if(_tongue.index)
pinkTromboneElement.parameters.tongue.index.linearRampToValueAtTime(_tongue.index, pinkTromboneElement.audioContext.currentTime+duration);
if(_tongue.diameter)
pinkTromboneElement.parameters.tongue.diameter.linearRampToValueAtTime(_tongue.diameter, pinkTromboneElement.audioContext.currentTime+duration);
if(_constriction.index)
pinkTromboneElement.constrictions[0].index.linearRampToValueAtTime(_constriction.index, pinkTromboneElement.audioContext.currentTime+duration);
if(_constriction.diameter)
pinkTromboneElement.constrictions[0].diameter.linearRampToValueAtTime(_constriction.diameter, pinkTromboneElement.audioContext.currentTime+duration);

if(tenseness !== undefined) {
tenseness = 1 - Math.cos((tenseness) * Math.PI * 0.5);
pinkTromboneElement.parameters.tenseness.linearRampToValueAtTime(tenseness, pinkTromboneElement.audioContext.currentTime+duration);
const loudness = Math.pow(tenseness, 0.25);
pinkTromboneElement.parameters.loudness.linearRampToValueAtTime(loudness, pinkTromboneElement.audioContext.currentTime+duration);
}
if(intensity !== undefined)
pinkTromboneElement.parameters.intensity.linearRampToValueAtTime(intensity, pinkTromboneElement.audioContext.currentTime+duration);
if(frequency !== undefined)
pinkTromboneElement.parameters.frequency.linearRampToValueAtTime(frequency, pinkTromboneElement.audioContext.currentTime+duration);

window.setTimeout(() => {
resolve();
}, duration*1000)
}, timeout);
});
}
const constriction = pinkTromboneElement.newConstriction(40, 3);

window.say = say;
window.constriction = constriction;

// (_tongue, _constriction, duration, timeout, intensity, tenseness, frequency)
var baseFrequency = pinkTromboneElement.parameters.frequency.value;
window.sayE = () => say({index : 27.5, diameter : 2}, {diameter : 3}, 0.1, 0, 0, undefined, baseFrequency);
window.sayU = () => say({index : 22.6, diameter : 2}, {index : 40, diameter : 0.8}, 0.3, 0.5, 1, undefined, baseFrequency*2^(6/12));
window.sayK = () => say({}, {index : 20, diameter : -0.3}, 0.1, 0.5, 0, 0);
window.sayA = () => say({index : 17, diameter : 3}, {index : 25, diameter : 4}, 0.1, 0, 1, 0.8, baseFrequency*2^(3/12));
window.sayT = () => say({}, {index : 36, diameter : -0.5}, 0.1, 0, 0, 1);
window.sayO = () => say({index : 12.6, diameter : 2.3}, {diameter : 3}, 0.1, 0, 1, undefined, baseFrequency);
window.sayN = () => say({}, {index : 36, diameter : -1.4}, 0.2, 0, 0.2, undefined);
window.shutUp = () => say({}, {}, 0.1, 1, 0);

window.sayUKATON = () => sayE().then(sayU).then(sayK).then(sayA).then(sayT).then(sayO).then(sayN).then(shutUp);

window.addEventListener("keypress", event => {
baseFrequency = pinkTromboneElement.parameters.frequency.value;
window.sayUKATON();
})
}

});
});

Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pink-trombone.min.js

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions script/PinkTrombone.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class PinkTrombone {
this._fricativeFilter.connect(this._pinkTromboneNode.noise);

this._gain = this.audioContext.createGain();
this._gain.gain.value = 0;
this._pinkTromboneNode.connect(this._gain);
}

Expand All @@ -69,10 +70,10 @@ class PinkTrombone {
}

start() {
this._noise.start();
this._gain.gain.value = 1;
}
stop() {
this._noise.stop();
this._gain.gain.value = 0;
}

get constrictions() {
Expand Down
2 changes: 2 additions & 0 deletions script/audio/nodes/noise/AudioNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ window.AudioContext.prototype.createNoise = function() {
noiseNode.buffer = buffer;
noiseNode.loop = true;

noiseNode.start();

return noiseNode;
}

Expand Down
31 changes: 19 additions & 12 deletions script/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class PinkTromboneElement extends HTMLElement {

this.addEventListener("resume", event => {
this.audioContext.resume();
this.pinkTrombone.start();
event.target.dispatchEvent(new CustomEvent("didResume"));
});

Expand Down Expand Up @@ -168,9 +169,22 @@ class PinkTromboneElement extends HTMLElement {
disableUI() {
if(this.UI !== undefined) {
this.UI.hide();
this.stopUI();
}
}

startUI() {
if(this.UI !== undefined) {
this._isRunning = true;
window.requestAnimationFrame(highResTimeStamp => {
this._requestAnimationFrameCallback(highResTimeStamp);
});
}
}
stopUI() {
this._isRunning = false;
}

// getAttribute getter?
static get observedAttributes() {
return [
Expand Down Expand Up @@ -228,30 +242,23 @@ class PinkTromboneElement extends HTMLElement {

start() {
if(this.pinkTrombone) {
this.isRunning = true;

if(this.UI !== undefined) {
window.requestAnimationFrame(highResTimeStamp => {
this._requestAnimationFrameCallback(highResTimeStamp);
});
}

return this.pinkTrombone.start();
this.pinkTrombone.start();
this.startUI();
}
else
throw "Pink Trombone hasn't been set yet";
}
stop() {
if(this.pinkTrombone) {
this.isRunning = false;
return this.pinkTrombone.stop();
this.pinkTrombone.stop();
this.stopUI();
}
else
throw "Pink Trombone hasn't been set yet";
}

_requestAnimationFrameCallback(highResTimeStamp) {
if(this.isRunning) {
if(this._isRunning) {
this._animationFrameObservers.forEach(element => {
const customEvent = new CustomEvent("animationFrame", {
detail : {
Expand Down

0 comments on commit 90cbd86

Please sign in to comment.