added inheritance support for "balance"

pull/89/head
jmoenig 2019-04-04 18:40:13 +02:00
rodzic 82deaac4f2
commit 837e95e329
4 zmienionych plików z 32 dodań i 9 usunięć

Wyświetl plik

@ -63,6 +63,7 @@
* moved "stage width" and "stage height" into attribute menu of the OF block for the stage * moved "stage width" and "stage height" into attribute menu of the OF block for the stage
* added 'volume' and 'balance' selectors to the OF block * added 'volume' and 'balance' selectors to the OF block
* Objects, Threads, Blocks: added inheritance support for "volume" * Objects, Threads, Blocks: added inheritance support for "volume"
* Objects, Threads, Blocks: added inheritance support for "balance"
### 2019-04-03 ### 2019-04-03
* Objects, Threads: Safari compatibility tweaks (only use StereoPanner if available) * Objects, Threads: Safari compatibility tweaks (only use StereoPanner if available)

Wyświetl plik

@ -2668,7 +2668,8 @@ BlockMorph.prototype.userMenu = function () {
direction: 'direction', direction: 'direction',
getScale: 'size', getScale: 'size',
getCostumeIdx: 'costume #', getCostumeIdx: 'costume #',
getVolume: 'volume' getVolume: 'volume',
getPan: 'balance'
}[this.selector]; }[this.selector];
if (field && rcvr && rcvr.exemplar) { if (field && rcvr && rcvr.exemplar) {
menu.addLine(); menu.addLine();

Wyświetl plik

@ -126,6 +126,7 @@ SpriteMorph.prototype.attributes =
'costumes', 'costumes',
'costume #', 'costume #',
'volume', 'volume',
'balance',
'sounds', 'sounds',
'scripts' 'scripts'
]; ];
@ -2045,7 +2046,7 @@ SpriteMorph.prototype.blockTemplates = function (category) {
blocks.push(block('changePan')); blocks.push(block('changePan'));
blocks.push(block('setPan')); blocks.push(block('setPan'));
blocks.push(watcherToggle('getPan')); blocks.push(watcherToggle('getPan'));
blocks.push(block('getPan')); blocks.push(block('getPan', this.inheritsAttribute('balance')));
blocks.push('-'); blocks.push('-');
blocks.push(block('playFreq')); blocks.push(block('playFreq'));
blocks.push(block('stopFreq')); blocks.push(block('stopFreq'));
@ -3323,7 +3324,7 @@ SpriteMorph.prototype.playSound = function (name) {
if (pan) { if (pan) {
gain.connect(pan); gain.connect(pan);
pan.connect(ctx.destination); // perhaps redundant pan.connect(ctx.destination); // perhaps redundant
this.setPan(this.pan); // yep, should be redundant, but still... this.setPan(this.getPan()); // yep, should be redundant
} else { } else {
gain.connect(ctx.destination); gain.connect(ctx.destination);
} }
@ -3388,7 +3389,7 @@ SpriteMorph.prototype.audioContext = function () {
// SpriteMorph stero panning // SpriteMorph stero panning
SpriteMorph.prototype.setPan = function (num) { SpriteMorph.prototype.setPan = function (num, noShadow) {
var panner = this.getPannerNode(); var panner = this.getPannerNode();
if (!panner) {return; } if (!panner) {return; }
this.pan = Math.max(Math.min((+num || 0), 100), -100); this.pan = Math.max(Math.min((+num || 0), 100), -100);
@ -3396,13 +3397,27 @@ SpriteMorph.prototype.setPan = function (num) {
this.pan / 100, this.pan / 100,
this.audioContext().currentTime this.audioContext().currentTime
); );
// propagate to children that inherit my balance
if (!noShadow) {
this.shadowAttribute('balance');
}
this.instances.forEach(function (instance) {
if (instance.cachedPropagation) {
if (instance.inheritsAttribute('balance')) {
instance.setPan(num, true);
}
}
});
}; };
SpriteMorph.prototype.changePan = function (delta) { SpriteMorph.prototype.changePan = function (delta) {
this.setPan(this.pan + (+delta || 0)); this.setPan(this.getPan() + (+delta || 0));
}; };
SpriteMorph.prototype.getPan = function () { SpriteMorph.prototype.getPan = function () {
if (this.inheritsAttribute('balance')) {
return this.exemplar.getPan();
}
return this.pan; return this.pan;
}; };
@ -5839,7 +5854,8 @@ SpriteMorph.prototype.updatePropagationCache = function () {
'direction', 'direction',
'size', 'size',
'costume #', 'costume #',
'volume' 'volume',
'balance'
], ],
function (att) { function (att) {
return contains(myself.inheritedAttributes, att); return contains(myself.inheritedAttributes, att);
@ -5963,6 +5979,10 @@ SpriteMorph.prototype.refreshInheritedAttribute = function (aName) {
this.cachedPropagation = true; this.cachedPropagation = true;
this.setVolume(this.getVolume(), true); this.setVolume(this.getVolume(), true);
break; break;
case 'balance':
this.cachedPropagation = true;
this.setPan(this.getPan(), true);
break;
case 'costumes': case 'costumes':
idx = this.getCostumeIdx(); idx = this.getCostumeIdx();
this.costumes = this.exemplar.costumes; this.costumes = this.exemplar.costumes;
@ -10055,7 +10075,8 @@ WatcherMorph.prototype.update = function () {
direction: 'direction', direction: 'direction',
getCostumeIdx: 'costume #', getCostumeIdx: 'costume #',
getScale: 'size', getScale: 'size',
getVolume: 'volume' getVolume: 'volume',
getPan: 'balance'
} [this.getter]; } [this.getter];
isGhosted = att ? this.target.inheritsAttribute(att) : false; isGhosted = att ? this.target.inheritsAttribute(att) : false;
} }

Wyświetl plik

@ -4103,8 +4103,8 @@ Process.prototype.doPlayNoteForSecs = function (pitch, secs) {
// interpolated // interpolated
var rcvr = this.blockReceiver(); var rcvr = this.blockReceiver();
if (!this.context.startTime) { if (!this.context.startTime) {
rcvr.setVolume(rcvr.getVolume()); // b/c Chrome needs lazy initialization rcvr.setVolume(rcvr.getVolume()); // b/c Chrome needs lazy init
rcvr.setPan(rcvr.pan); // b/c Chrome needs lazy initialization rcvr.setPan(rcvr.getPan()); // b/c Chrome needs lazy initialization
this.context.startTime = Date.now(); this.context.startTime = Date.now();
this.context.activeNote = new Note(pitch); this.context.activeNote = new Note(pitch);
this.context.activeNote.play( this.context.activeNote.play(