From 362b703d7b1ed0f7f8fb4e06a2396e7b098c94b2 Mon Sep 17 00:00:00 2001 From: inthar-raven Date: Mon, 26 Aug 2024 17:23:25 -0400 Subject: [PATCH] Add chirality information for every scale (iss #23) --- README.md | 1 + index.js | 6 ++++++ src/lib.rs | 16 +++++++++++++--- src/words.rs | 3 ++- 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 6fa70dd..70edb6d 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/index.js b/index.js index 350d48f..aec79d3 100644 --- a/index.js +++ b/index.js @@ -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"]; @@ -497,6 +498,11 @@ stack()` ) { el.innerHTML += `None
`; } + if (currentProfile["chirality"] === "Achiral") { + el.innerHTML += `
Chirality: Achiral`; + } else { + el.innerHTML += `
Chirality: ${currentProfile["chirality"]} (reversed: ${currentProfile["reversed"]})`; + } el.innerHTML += `
Maximum variety ${currentProfile["mv"]}`; } } diff --git a/src/lib.rs b/src/lib.rs index d655e86..ade262d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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" { @@ -96,6 +95,10 @@ pub struct ScaleProfile { word: String, /// unimodular basis for lattice is there is one lattice_basis: Option>>, + /// chirality + chirality: Chirality, + /// brightest mode of reversed word + reversed: String, /// lowest-complexity guide frame structure provided there is one structure: Option, /// whether scale is L=M monotone MOS @@ -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::>()); + let reversed = numbers_to_string(&reversed); let mv = maximum_variety(query) as u8; let step_sig = word_to_sig(query) .iter() @@ -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, @@ -329,6 +337,8 @@ pub fn word_to_profile(query: &[usize]) -> ScaleProfile { ScaleProfile { word: brightest, lattice_basis: None, + chirality, + reversed, structure: None, lm, ms, diff --git a/src/words.rs b/src/words.rs index 15e960e..2e4da98 100644 --- a/src/words.rs +++ b/src/words.rs @@ -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; @@ -35,7 +36,7 @@ impl Subtendable for CountVector { } /// 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,