Skip to content
Permalink
Browse files

Temperament lookup table (#1214)

* Temperament lookup table

* Added set-temperament block and its functioning

* Removed some unwanted console.log

* Added custom table

* Created lookup table in synth utils

* Reverting unwanted changes in logo.js

* Reverting unnecessary calling of function

* Added 'pitch in hertz' block for status widget

* Added 1/3 comma meantone ratios

* Fixed temperament name block and cleaned some calculations

* Suggested changed made

* Added extra width to temperament name block
  • Loading branch information...
riyalohia authored and walterbender committed May 23, 2018
1 parent 48dc7c3 commit a2f7d328b81a467a3c74dd24819e54b19ef0b4a3
Showing with 340 additions and 9 deletions.
  1. +24 −1 js/basicblocks.js
  2. +33 −2 js/block.js
  3. +3 −0 js/blocks.js
  4. +22 −1 js/logo.js
  5. +4 −2 js/macros.js
  6. +3 −0 js/palette.js
  7. +1 −1 js/turtledefs.js
  8. +171 −1 js/utils/musicutils.js
  9. +69 −1 js/utils/synthutils.js
  10. +10 −0 js/widgets/status.js
@@ -1123,6 +1123,14 @@ function initBasicProtoBlocks(palettes, blocks) {
elapsedNotes2.adjustWidthToLabel();
elapsedNotes2.oneArgMathBlock();

var pitchInHertzBlock = new ProtoBlock('pitchinhertz');
pitchInHertzBlock.palette = palettes.dict['meter'];
blocks.protoBlockDict['pitchinhertz'] = pitchInHertzBlock;
//.TRANS: the current pitch expressed in Hertz
pitchInHertzBlock.staticLabels.push(_('pitch in hertz'));
pitchInHertzBlock.adjustWidthToLabel();
pitchInHertzBlock.parameterBlock();

var driftBlock = new ProtoBlock('drift');
driftBlock.palette = palettes.dict['meter'];
blocks.protoBlockDict['drift'] = driftBlock;
@@ -1498,7 +1506,22 @@ function initBasicProtoBlocks(palettes, blocks) {
setTimbreBlock.flowClampOneArgBlock();
setTimbreBlock.dockTypes[1] = 'textin';
//.TRANS: user-defined
setTimbreBlock.defaults.push(_('custom'));
setTimbreBlock.defaults.push(_('custom'));

var setTemperamentBlock = new ProtoBlock('settemperament');
setTemperamentBlock.palette = palettes.dict['tone'];
blocks.protoBlockDict['settemperament'] = setTemperamentBlock;
setTemperamentBlock.staticLabels.push(_('set temperament'));
setTemperamentBlock.adjustWidthToLabel();
setTemperamentBlock.oneArgBlock();

var temperamentNameBlock = new ProtoBlock('temperamentname');
temperamentNameBlock.palette = palettes.dict['tone'];
blocks.protoBlockDict['temperamentname'] = temperamentNameBlock;
temperamentNameBlock.valueBlock();
temperamentNameBlock.hidden = true;
temperamentNameBlock.extraWidth = 50;
temperamentNameBlock.dockTypes[0] = 'anyout';

// INTERVALS (PITCH TRANSFORMS) PALETTE

@@ -16,8 +16,8 @@ const STRINGLEN = 9;
const LONGPRESSTIME = 1500;
const COLLAPSABLES = ['drum', 'start', 'action', 'matrix', 'pitchdrummatrix', 'rhythmruler', 'timbre', 'status', 'pitchstaircase', 'tempo', 'pitchslider', 'modewidget'];
const NOHIT = ['hidden', 'hiddennoflow'];
const SPECIALINPUTS = ['text', 'number', 'solfege', 'eastindiansolfege', 'notename', 'voicename', 'modename', 'drumname', 'filtertype', 'oscillatortype', 'boolean', 'intervalname', 'invertmode', 'accidentalname'];
const WIDENAMES = ['intervalname', 'accidentalname', 'drumname', 'voicename', 'modename'];
const SPECIALINPUTS = ['text', 'number', 'solfege', 'eastindiansolfege', 'notename', 'voicename', 'modename', 'drumname', 'filtertype', 'oscillatortype', 'boolean', 'intervalname', 'invertmode', 'accidentalname', 'temperamentname'];
const WIDENAMES = ['intervalname', 'accidentalname', 'drumname', 'voicename', 'modename', 'temperamentname'];
const EXTRAWIDENAMES = ['modename'];

// Define block instance objects and any methods that are intra-block.
@@ -598,6 +598,9 @@ function Block(protoblock, blocks, overrideName) {
case 'oscillatortype':
this.value = getOscillatorTypes(DEFAULTOSCILLATORTYPE);
break;
case 'temperamentname':
this.value = 'equal';
break;
}
}

@@ -1040,6 +1043,8 @@ function Block(protoblock, blocks, overrideName) {
this.text.x *= 1.75;
} else if (this.name === 'text') {
this.text.x = this.width / 2;
} else if (this.name === 'temperamentname') {
this.text.x += 15;
}
} else if (this.name === 'nameddo') {
this.text.textAlign = 'center';
@@ -1950,6 +1955,32 @@ function Block(protoblock, blocks, overrideName) {
labelElem.innerHTML = labelHTML;
this.label = docById('voicenameLabel');
selectorWidth = 150;
} else if (this.name === 'temperamentname') {
var type = 'temperamentname';
if (this.value != null) {
var selectedTemperament = getTemperamentName(this.value);
} else {
var selectedTemperament = getTemperamentName(DEFAULTTEMPERAMENT);
}

var labelHTML = '<select name="temperamentname" id="temperamentnameLabel" style="position: absolute; background-color: #00b0a4; width: 60px;">'
for (var i = 0; i < TEMPERAMENTS.length; i++) {
if (TEMPERAMENTS[i][0].length === 0) {
// work around some weird i18n bug
labelHTML += '<option value="' + TEMPERAMENTS[i][1] + '">' + TEMPERAMENTS[i][1] + '</option>';
} else if (selectedTemperament === TEMPERAMENTS[i][0]) {
labelHTML += '<option value="' + selectedTemperament + '" selected>' + selectedTemperament + '</option>';
} else if (selectedTemperament === TEMPERAMENTS[i][1]) {
labelHTML += '<option value="' + selectedTemperament + '" selected>' + selectedTemperament + '</option>';
} else {
labelHTML += '<option value="' + TEMPERAMENTS[i][1] + '">' + TEMPERAMENTS[i][1] + '</option>';
}
}

labelHTML += '</select>';
labelElem.innerHTML = labelHTML;
this.label = docById('temperamentnameLabel');
selectorWidth = 150;
} else if (this.name === 'boolean') {
var type = 'boolean';
if (this.value != null) {
@@ -2170,6 +2170,8 @@ function Blocks () {
postProcessArg = [thisBlock, DEFAULTACCIDENTAL];
} else if (name === 'intervalname') {
postProcessArg = [thisBlock, DEFAULTINTERVAL];
} else if (name === 'temperamentname') {
postProcessArg = [thisBlock, DEFAULTTEMPERAMENT];
} else if (name === 'invertmode') {
postProcessArg = [thisBlock, DEFAULTINVERT];
} else if (name === 'number') {
@@ -3853,6 +3855,7 @@ function Blocks () {
case 'modename':
case 'accidentalname':
case 'intervalname':
case 'temperamentname':
case 'invertmode':
case 'filtertype':
case 'oscillatortype':
@@ -65,6 +65,7 @@ function Logo () {
this.rhythmRuler = null;
this.timbre = null;
this.pitchStaircase = null;
this.temperament = null;
this.tempo = null;
this.pitchSlider = null;
this.modeWidget = null;
@@ -294,6 +295,7 @@ function Logo () {
var turtleLength = 0;
var inLoop = 0;
var progressBarDivision;
var temperamentSelected = [];
// A place to save turtle state in order to store it after a compile
this._saveX = {};
this._saveY = {};
@@ -5840,6 +5842,16 @@ function Logo () {
}
}
}
break;
case 'settemperament':
that.synth.inTemperament = args[0];
temperamentSelected.push(args[0]);
var len = temperamentSelected.length;

if (temperamentSelected[len-1] !== temperamentSelected[len-2]) {
that.synth.changeInTemperament = true;
}

break;
case 'setnotevolume2':
// master volume in clamp form
@@ -7539,7 +7551,7 @@ function Logo () {
that.errorMsg(last(that.oscList[turtle][thisBlk]) + ': ' + _('synth cannot play chords.'), blk);
}

if (!that.suppressOutput[turtle]) {
if (!that.suppressOutput[turtle]) {
that.synth.trigger(turtle, notes, beatValue, last(that.oscList[turtle][thisBlk]), paramsEffects, null, false);
}

@@ -9312,6 +9324,15 @@ function Logo () {
that.blocks.blockList[blk].value = that.notesPlayed[turtle][0] / that.notesPlayed[turtle][1];
}
break;
case 'pitchinhertz':
if (that.inStatusMatrix && that.blocks.blockList[that.blocks.blockList[blk].connections[0]].name === 'print') {
that.statusFields.push([blk, 'pitchinhertz']);
} else {
if (that.lastNotePlayed[turtle] !== null) {
that.blocks.blockList[blk].value = that.synth.getFrequency(that.lastNotePlayed[turtle][0], that.synth.changeInTemperament);
}
}
break;
case 'turtleelapsednotes':
var value = null;
var cblk = that.blocks.blockList[blk].connections[1];

Some generated files are not rendered by default. Learn more.

@@ -738,6 +738,9 @@ function PaletteModel(palette, palettes, name) {
case 'voicename':
label = _('voice name');
break;
case 'temperamentname':
label = _('temperament name');
break;
case 'accidentalname':
//TRANS: accidental refers to sharps, flats, etc.
label = _('accidental');

0 comments on commit a2f7d32

Please sign in to comment.
You can’t perform that action at this time.