new experimental live audio-scripting support

pull/89/head
jmoenig 2019-03-28 17:20:28 +01:00
rodzic 5a2d4f2a16
commit d07b35a2d8
5 zmienionych plików z 74 dodań i 16 usunięć

Wyświetl plik

@ -10,6 +10,7 @@
* new "aspect AT location" reporter in Sensing category for sniffing colors and sprites
* new blocks for setting and changing the stage's background color
* new "microphone" reporter in Sensing for getting volume, note, pitch signals and frequencies
* new experimental live audio-scripting support
* new "object" reporter in the Sensing category for getting a sprite by its name
* blocks for changing and querying the "flat line ends" setting
* selectors for changing and querying "draggable" and "rotation style" settings
@ -51,6 +52,9 @@
* German
* French
### 2019-03-28
* Blocks, Threaeds, Objects: new experimental live audio scripting support
### 2019-03-26
* updated French translation
* updated animation library with partial French translation

Wyświetl plik

@ -6,9 +6,9 @@
<link rel="shortcut icon" href="src/favicon.ico">
<script type="text/javascript" src="src/morphic.js?version=2019-02-07"></script>
<script type="text/javascript" src="src/widgets.js?version=2018-10-02"></script>
<script type="text/javascript" src="src/blocks.js?version=2019-03-18"></script>
<script type="text/javascript" src="src/threads.js?version=2019-03-18"></script>
<script type="text/javascript" src="src/objects.js?version=2019-03-15"></script>
<script type="text/javascript" src="src/blocks.js?version=2019-03-28"></script>
<script type="text/javascript" src="src/threads.js?version=2019-03-28"></script>
<script type="text/javascript" src="src/objects.js?version=2019-03-28"></script>
<script type="text/javascript" src="src/gui.js?version=2019-03-25"></script>
<script type="text/javascript" src="src/paint.js?version=2019-02-22"></script>
<script type="text/javascript" src="src/lists.js?version=2019-02-07"></script>

Wyświetl plik

@ -148,7 +148,7 @@ CustomCommandBlockMorph, SymbolMorph, ToggleButtonMorph, DialMorph*/
// Global stuff ////////////////////////////////////////////////////////
modules.blocks = '2019-March-18';
modules.blocks = '2019-March-28';
var SyntaxElementMorph;
var BlockMorph;
@ -628,6 +628,10 @@ SyntaxElementMorph.prototype.getVarNamesDict = function () {
'rotation x' : ['rotation x'],
'rotation y' : ['rotation y']
};
if (this.world().currentKey === 16) { // shift
dict.my['~'] = null;
dict.my['microphone modifier'] = ['microphone modifier'];
}
}
return dict;
}
@ -987,14 +991,7 @@ SyntaxElementMorph.prototype.labelPart = function (spec) {
part = new InputSlotMorph(
null, // text
false, // numeric?
{
'volume' : ['volume'],
'note' : ['note'],
'frequency' : ['frequency'],
'samples' : ['samples'],
'spectrum' : ['spectrum'],
'resolution' : ['resolution']
},
'audioMenu',
true // read-only
);
break;
@ -8967,6 +8964,23 @@ InputSlotMorph.prototype.directionDialMenu = function () {
return {'§_dir': null};
};
InputSlotMorph.prototype.audioMenu = function () {
var dict = {
'volume' : ['volume'],
'note' : ['note'],
'frequency' : ['frequency'],
'samples' : ['samples'],
'spectrum' : ['spectrum'],
'resolution' : ['resolution']
};
if (this.world().currentKey === 16) { // shift
dict['~'] = null;
dict.modifier = ['modifier'];
dict.output = ['output'];
}
return dict;
};
InputSlotMorph.prototype.setChoices = function (dict, readonly) {
// externally specify choices and read-only status,
// used for custom blocks

Wyświetl plik

@ -74,7 +74,7 @@ ThreadManager, VariableFrame, detect, BlockMorph, BoxMorph, Color, Animation,
CommandBlockMorph, FrameMorph, HatBlockMorph, MenuMorph, Morph, MultiArgMorph,
Point, ReporterBlockMorph, ScriptsMorph, StringMorph, SyntaxElementMorph,
TextMorph, contains, degrees, detect, newCanvas, nop, radians, Array,
CursorMorph, Date, FrameMorph, HandMorph, Math, MenuMorph, Morph,
CursorMorph, Date, FrameMorph, HandMorph, Math, MenuMorph, Morph, invoke,
MorphicPreferences, Object, PenMorph, Point, Rectangle, ScrollFrameMorph,
SliderMorph, String, StringMorph, TextMorph, contains, copy, degrees, detect,
document, isNaN, isString, newCanvas, nop, parseFloat, radians, window,
@ -84,7 +84,7 @@ BlockEditorMorph, BlockDialogMorph, PrototypeHatBlockMorph, localize,
TableMorph, TableFrameMorph, normalizeCanvas, BooleanSlotMorph, HandleMorph,
AlignmentMorph, Process, XML_Element, VectorPaintEditorMorph*/
modules.objects = '2019-March-15';
modules.objects = '2019-March-28';
var SpriteMorph;
var StageMorph;
@ -8933,8 +8933,13 @@ function Microphone() {
this.resolution = 2;
this.GOOD_ENOUGH_CORRELATION = 0.96;
// modifier
this.modifier = null;
this.output = [];
// memory alloc
this.correlations = []; //new Array(MAX_SAMPLES), // +++
this.correlations = [];
this.wrapper = new List([0]);
// metered values:
this.volume = 0;
@ -9074,6 +9079,7 @@ Microphone.prototype.stepAudio = function (event) {
// signals:
this.signals = event.inputBuffer.getChannelData(0);
this.output = event.outputBuffer.getChannelData(0);
// frequency bins:
this.analyser.getByteFrequencyData(this.frequencies);
@ -9122,6 +9128,12 @@ Microphone.prototype.detectPitchAndVolume = function (buf, sampleRate) {
this.processor.lastClip = window.performance.now();
}
rms += val * val;
// apply modifier, if any
if (this.modifier) {
this.wrapper.contents[0] = val;
this.output[i] = invoke(this.modifier, this.wrapper);
}
}
rms = Math.sqrt(rms/SIZE);
this.volume = Math.max(rms, this.volume * this.processor.averaging);

Wyświetl plik

@ -62,7 +62,7 @@ StageMorph, SpriteMorph, StagePrompterMorph, Note, modules, isString, copy,
isNil, WatcherMorph, List, ListWatcherMorph, alert, console, TableMorph, Color,
TableFrameMorph, ColorSlotMorph, isSnapObject, Map*/
modules.threads = '2019-March-18';
modules.threads = '2019-March-28';
var ThreadManager;
var Process;
@ -2257,6 +2257,9 @@ Process.prototype.reportAudio = function (choice) {
if (selection === 'resolution') {
return stage.microphone.binSize();
}
if (selection === 'modifier') {
return stage.microphone.modifier;
}
if (stage.microphone.isOn()) {
switch (selection) {
case 'volume':
@ -2267,6 +2270,8 @@ Process.prototype.reportAudio = function (choice) {
return stage.microphone.note;
case 'samples':
return new List(stage.microphone.signals);
case 'output':
return new List(stage.microphone.output);
case 'spectrum':
return new List(stage.microphone.frequencies);
default:
@ -2277,6 +2282,26 @@ Process.prototype.reportAudio = function (choice) {
this.pushContext();
};
Process.prototype.setMicrophoneModifier = function (modifier) {
var stage = this.blockReceiver().parentThatIsA(StageMorph),
invalid = [
'sprite',
'stage',
'list',
'costume',
'sound',
'number',
'text',
'Boolean'
];
if (!modifier || contains(invalid, this.reportTypeOf(modifier))) {
stage.microphone.modifier = null;
stage.microphone.stop();
return;
}
stage.microphone.modifier = modifier;
};
// Process user prompting primitives (interpolated)
Process.prototype.doAsk = function (data) {
@ -3792,6 +3817,9 @@ Process.prototype.doSet = function (attribute, value) {
this.assertType(value, 'number');
rcvr.setRotationY(value);
break;
case 'microphone modifier':
this.setMicrophoneModifier(value);
break;
default:
throw new Error(
'"' + localize(name) + '" ' + localize('is read-only')