kopia lustrzana https://github.com/backface/turtlestitch
added "play frequency" primitive to "Sound" category
rodzic
39d19fabe1
commit
1300b227ea
|
@ -11,6 +11,7 @@
|
|||
* 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 "object" reporter in the Sensing category for getting a sprite by its name
|
||||
* new "play frequency" command in the Sound category
|
||||
* blocks for changing and querying the "flat line ends" setting
|
||||
* selectors for changing and querying "draggable" and "rotation style" settings
|
||||
* special context-aware drop-downs for custom blocks
|
||||
|
@ -50,6 +51,7 @@
|
|||
|
||||
### 2019-03-12
|
||||
* Threads: changed microphone volume (back) to a scale of 0-100
|
||||
* Threads, Objects: added "play frequency" primitive to "Sound" category
|
||||
|
||||
### 2019-03-11
|
||||
* added note / hz conversion blocks to audioComp library
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
<script type="text/javascript" src="src/widgets.js?version=2018-10-02"></script>
|
||||
<script type="text/javascript" src="src/blocks.js?version=2019-03-11"></script>
|
||||
<script type="text/javascript" src="src/threads.js?version=2019-03-12"></script>
|
||||
<script type="text/javascript" src="src/objects.js?version=2019-03-11"></script>
|
||||
<script type="text/javascript" src="src/objects.js?version=2019-03-12"></script>
|
||||
<script type="text/javascript" src="src/gui.js?version=2019-03-11"></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>
|
||||
|
|
|
@ -84,7 +84,7 @@ BlockEditorMorph, BlockDialogMorph, PrototypeHatBlockMorph, localize,
|
|||
TableMorph, TableFrameMorph, normalizeCanvas, BooleanSlotMorph, HandleMorph,
|
||||
AlignmentMorph, Process, XML_Element, VectorPaintEditorMorph*/
|
||||
|
||||
modules.objects = '2019-March-11';
|
||||
modules.objects = '2019-March-12';
|
||||
|
||||
var SpriteMorph;
|
||||
var StageMorph;
|
||||
|
@ -449,6 +449,12 @@ SpriteMorph.prototype.initBlocks = function () {
|
|||
spec: 'play note %note for %n beats',
|
||||
defaults: [60, 0.5]
|
||||
},
|
||||
doPlayFrequency: {
|
||||
type: 'command',
|
||||
category: 'sound',
|
||||
spec: 'play %n hz for %n secs',
|
||||
defaults: [440, 2]
|
||||
},
|
||||
doSetInstrument: {
|
||||
type: 'command',
|
||||
category: 'sound',
|
||||
|
@ -1951,6 +1957,8 @@ SpriteMorph.prototype.blockTemplates = function (category) {
|
|||
blocks.push(block('doSetTempo'));
|
||||
blocks.push(watcherToggle('getTempo'));
|
||||
blocks.push(block('getTempo'));
|
||||
blocks.push('-');
|
||||
blocks.push(block('doPlayFrequency'));
|
||||
blocks.push('=');
|
||||
blocks.push(this.makeBlockButton(cat));
|
||||
|
||||
|
@ -7210,6 +7218,8 @@ StageMorph.prototype.blockTemplates = function (category) {
|
|||
blocks.push(block('doSetTempo'));
|
||||
blocks.push(watcherToggle('getTempo'));
|
||||
blocks.push(block('getTempo'));
|
||||
blocks.push('-');
|
||||
blocks.push(block('doPlayFrequency'));
|
||||
blocks.push('=');
|
||||
blocks.push(this.makeBlockButton(cat));
|
||||
|
||||
|
@ -8786,12 +8796,14 @@ Sound.prototype.toDataURL = function () {
|
|||
|
||||
// Note /////////////////////////////////////////////////////////
|
||||
|
||||
// I am a single musical note
|
||||
// I am a single musical note.
|
||||
// alternatively I can be used to play a frequency in hz
|
||||
|
||||
// Note instance creation
|
||||
|
||||
function Note(pitch) {
|
||||
this.pitch = pitch === 0 ? 0 : pitch || 69;
|
||||
this.frequency = null; // alternative for playing a non-note frequency
|
||||
this.setupContext();
|
||||
this.oscillator = null;
|
||||
}
|
||||
|
@ -8841,8 +8853,8 @@ Note.prototype.play = function (type) {
|
|||
'sawtooth',
|
||||
'triangle'
|
||||
][(type || 1) - 1];
|
||||
this.oscillator.frequency.value =
|
||||
Math.pow(2, (this.pitch - 69) / 12) * 440;
|
||||
this.oscillator.frequency.value = isNil(this.frequency) ?
|
||||
Math.pow(2, (this.pitch - 69) / 12) * 440 : this.frequency;
|
||||
this.oscillator.connect(this.gainNode);
|
||||
this.gainNode.connect(this.audioContext.destination);
|
||||
this.oscillator.start(0);
|
||||
|
|
|
@ -4041,6 +4041,32 @@ Process.prototype.doPlayNoteForSecs = function (pitch, secs) {
|
|||
this.pushContext();
|
||||
};
|
||||
|
||||
Process.prototype.doPlayFrequency = function (hz, secs) {
|
||||
this.doPlayFrequencyForSecs(
|
||||
parseFloat(hz || '0'),
|
||||
parseFloat(secs || '0')
|
||||
);
|
||||
};
|
||||
|
||||
Process.prototype.doPlayFrequencyForSecs = function (hz, secs) {
|
||||
// interpolated
|
||||
if (!this.context.startTime) {
|
||||
this.context.startTime = Date.now();
|
||||
this.context.activeNote = new Note();
|
||||
this.context.activeNote.frequency = hz;
|
||||
this.context.activeNote.play(this.instrument);
|
||||
}
|
||||
if ((Date.now() - this.context.startTime) >= (secs * 1000)) {
|
||||
if (this.context.activeNote) {
|
||||
this.context.activeNote.stop();
|
||||
this.context.activeNote = null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
this.pushContext('doYield');
|
||||
this.pushContext();
|
||||
};
|
||||
|
||||
Process.prototype.doSetInstrument = function (num) {
|
||||
this.instrument = +num;
|
||||
this.receiver.instrument = +num;
|
||||
|
|
Ładowanie…
Reference in New Issue