Skip to content

Commit

Permalink
Merge pull request #127 from vsicurella/Rank2TemperamentLineTypes
Browse files Browse the repository at this point in the history
Rank-2 temperament line types
  • Loading branch information
SeanArchibald authored Sep 11, 2021
2 parents f24a464 + c7496d4 commit 53fe5d9
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 39 deletions.
7 changes: 7 additions & 0 deletions index.htm
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,13 @@ <h3>Isomorphic keyboard settings</h3>
<p style="text-align:right;">(ignore MOS with steps smaller than <input id="input_rank-2_mos_threshold" name=""
type="number" min="0.1" max="600" value="2.5" style="width:4em;" /> cents)</p>
<span id="info_rank_2_mos" style="display:block;margin-top:10px;"></span>
<hr />
<label>Output type:</label>
<select id="input_rank-2_type" name="" class="form-control" value="preserve">
<option value="preserve">Preserve types</option>
<option value="cents">Cents</option>
<option value="decimals">Decimals</option>
</select>
</div>

<div id="modal_generate_harmonic_series_segment" class="modal" title="Generate harmonic series segment">
Expand Down
67 changes: 28 additions & 39 deletions src/js/generators.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,19 @@ function generate_rank_2_temperament() {

var generator = getLine('#input_rank-2_generator', 'Warning: no generator')

var generator_cents = line_to_cents(generator);
var generatorType = getLineType(generator);

// bail if generator is invalid
if (!generator_cents) {
if (generatorType === LINE_TYPE.INVALID) {
return false;
}

var period = getLine('#input_rank-2_period', 'Warning: no period')

var period_cents = line_to_cents(period);
var periodType = getLineType(period);

// bail if period is invalid
if (!period_cents) {
if (periodType === LINE_TYPE.INVALID) {
return false;
}

Expand All @@ -81,7 +81,9 @@ function generate_rank_2_temperament() {
return false;
}

setTuningData(generate_rank_2_temperament_data(parseFloat(generator_cents), parseFloat(period_cents), size, up))
var lineType = jQuery("#input_rank-2_type").val();

setTuningData(generate_rank_2_temperament_data(generator, period, size, up, lineType))

setScaleName("Rank 2 scale (" + generator + ", " + period + ")");

Expand All @@ -93,48 +95,35 @@ function generate_rank_2_temperament() {
return true;
}

function generate_rank_2_temperament_data(generator, period, size, up) {

function generate_rank_2_temperament_data(generator, period, size, up, lineType) {
// empty existing tuning data
var tuning_data = "";

// array aa stores the scale data, starting from 1/1 (0.0 cents)
var aa = [0.0];
for (i = 1; i < size; i++) {

// calculate generators up
if (i <= up) {

aa[i] = (aa[i - 1] + generator).mod(period);
console.log('up: ' + i + ': ' + aa[i]);

}

else {

// first down generator
if (i == up + 1) {
aa[i] = (aa[0] - generator).mod(period);
}
let tuningData = '';

// subsequent down generators
else {
aa[i] = (aa[i - 1] - generator).mod(period);
}
console.log('down: ' + i + ': ' + aa[i]);
}

}
// Start scale on the lowest generator
let scale = [moduloLine(transposeSelf(generator, up - size + 1), period)];

// Transpose each line by the generator and period reduce
for (let i = 1; i < size; i++)
scale.push(moduloLine(transposeLine(generator, scale[i - 1]), period));

// sort the scale ascending
aa.sort(function (a, b) { return a - b });
scale.sort((a, b) => [a, b].map(line_to_decimal).reduce((a, b) => a - b));

// add the period to the scale
aa.push(period);
scale.push(period);

// convert scale to output line type
switch (lineType) {
case "cents":
scale = scale.map(x => line_to_cents(x).toFixed(6));
break;
case "decimals":
scale = scale.map(x => line_to_commadecimal(x, 6));
}

tuning_data += aa.slice(1, size + 1).map(num => num.toFixed(6)).join(unix_newline)
tuningData += scale.slice(1, size + 1).join(unix_newline);

return tuning_data
return tuningData;
}

function generate_harmonic_series_segment() {
Expand Down

0 comments on commit 53fe5d9

Please sign in to comment.