Skip to content

Commit

Permalink
Add chirality information for every scale (iss #23)
Browse files Browse the repository at this point in the history
  • Loading branch information
inthar-raven committed Aug 26, 2024
1 parent 1c0e20c commit 362b703
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ A microtonal scale research app chiefly dedicated to ternary scales (scales with
1. Visit `http://localhost:8080/` with your browser. Your browser must support WebAssembly; all major browsers should.

# Dev scripts

1. `npm run build`: Build the app
2. `npm run serve`: Deploy the app on a development server.
3. `npm run format`: Run `prettier` on all HTML, CSS, JavaScript, and TypeScript files.
Expand Down
6 changes: 6 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ let currentTuning = null;
let currentProfile = null;

const statusElement = document.getElementById("status");

function displayStepVector(vector) {
const keys = [...Object.keys(vector)];
const sizeIdentifiers = ["L", "M", "s"];
Expand Down Expand Up @@ -497,6 +498,11 @@ stack()`
) {
el.innerHTML += `None<br/>`;
}
if (currentProfile["chirality"] === "Achiral") {
el.innerHTML += `<br/>Chirality: Achiral`;
} else {
el.innerHTML += `<br/>Chirality: ${currentProfile["chirality"]} (reversed: ${currentProfile["reversed"]})`;
}
el.innerHTML += `<br/>Maximum variety ${currentProfile["mv"]}</small>`;
}
}
Expand Down
16 changes: 13 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ pub mod words;

use itertools::Itertools;
use wasm_bindgen::prelude::*;
use words::countvector_to_slice;
use words::dyad_on_degree;
use words::Letter;
use words::{chirality, countvector_to_slice, dyad_on_degree};
use words::{Chirality, Letter};

#[wasm_bindgen]
extern "C" {
Expand Down Expand Up @@ -96,6 +95,10 @@ pub struct ScaleProfile {
word: String,
/// unimodular basis for lattice is there is one
lattice_basis: Option<Vec<Vec<u8>>>,
/// chirality
chirality: Chirality,
/// brightest mode of reversed word
reversed: String,
/// lowest-complexity guide frame structure provided there is one
structure: Option<GuideResult>,
/// whether scale is L=M monotone MOS
Expand Down Expand Up @@ -305,6 +308,9 @@ pub fn word_to_profile(query: &[usize]) -> ScaleProfile {
let lm = monotone_lm(query);
let ms = monotone_ms(query);
let s0 = monotone_s0(query);
let chirality = chirality(query);
let reversed = least_mode(& query.iter().copied().rev().collect::<Vec<usize>>());
let reversed = numbers_to_string(&reversed);
let mv = maximum_variety(query) as u8;
let step_sig = word_to_sig(query)
.iter()
Expand All @@ -319,6 +325,8 @@ pub fn word_to_profile(query: &[usize]) -> ScaleProfile {
ScaleProfile {
word: brightest,
lattice_basis: Some(lattice_basis),
chirality,
reversed,
structure: Some(structure),
lm,
ms,
Expand All @@ -329,6 +337,8 @@ pub fn word_to_profile(query: &[usize]) -> ScaleProfile {
ScaleProfile {
word: brightest,
lattice_basis: None,
chirality,
reversed,
structure: None,
lm,
ms,
Expand Down
3 changes: 2 additions & 1 deletion src/words.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use itertools::Itertools;
use serde::Serialize;
use std::cmp::{max, Ordering};
use std::collections::{BTreeMap, BTreeSet, HashSet};
use std::hash::Hash;
Expand Down Expand Up @@ -35,7 +36,7 @@ impl Subtendable for CountVector<Letter> {
}

/// The [chirality](https://en.xen.wiki/w/Chirality) of a scale.
#[derive(Copy, Clone, Debug, Hash, PartialEq)]
#[derive(Copy, Clone, Debug, Hash, PartialEq, Serialize)]
pub enum Chirality {
/// Lexicographically first mode is greater than that of reversed scale word.
Left,
Expand Down

0 comments on commit 362b703

Please sign in to comment.