pub struct IsomorphicKeyboard {
    pub primary_step: u16,
    pub secondary_step: u16,
}
Expand description

A straightforward data structure for retrieving scale degrees on an isomorphic keyboard.

Fields§

§primary_step: u16

The primary step width of the isometric keyboard.

§secondary_step: u16

The secondary step width of the isometric keyboard.

Implementations§

source§

impl IsomorphicKeyboard

source

pub fn coprime(self) -> IsomorphicKeyboard

Make the keyboard coprime s.t. all scale degrees are reachable.

This addresses the scenario where not all key degrees can be reached when the step sizes are not coprime. For instance, when primary_step == 4 and secondary_step == 2, degrees with odd numbers cannot be obtained.

This function solves the issue by adjusting secondary_step to divide the step width along the sharp axis into smaller segments.

Examples
let already_coprime = IsomorphicKeyboard {
    primary_step: 3,
    secondary_step: 2,
}.coprime();

// Already coprime => Do nothing
assert_eq!(already_coprime.primary_step, 3);
assert_eq!(already_coprime.secondary_step, 2);

let positive_sharp_value = IsomorphicKeyboard {
    primary_step: 4,
    secondary_step: 2,
}.coprime();

// Sharp value is 4-2=2 before and 4-3=1 afterwards
assert_eq!(positive_sharp_value.primary_step, 4);
assert_eq!(positive_sharp_value.secondary_step, 3);

let negative_sharp_value = IsomorphicKeyboard {
    primary_step: 2,
    secondary_step: 4,
}.coprime();

// Sharp value is 2-4=-2 before and 2-3=-1 afterwards
assert_eq!(negative_sharp_value.primary_step, 2);
assert_eq!(negative_sharp_value.secondary_step, 3);

let zero_sharp_value = IsomorphicKeyboard {
    primary_step: 2,
    secondary_step: 2,
}.coprime();

// Special case: Sharp value is 2-2=0 before and 2-1=1 afterwards
assert_eq!(zero_sharp_value.primary_step, 2);
assert_eq!(zero_sharp_value.secondary_step, 1);

let large_sharp_value = IsomorphicKeyboard {
    primary_step: 6,
    secondary_step: 2,
}.coprime();

// Special case: Sharp value is 6-2=4 before and 6-5=1 afterwards
assert_eq!(large_sharp_value.primary_step, 6);
assert_eq!(large_sharp_value.secondary_step, 5);
source

pub fn get_key(&self, num_primary_steps: i16, num_secondary_steps: i16) -> i32

Get the scale degree of the key at location (x, y).

let keyboard = IsomorphicKeyboard {
    primary_step: 5,
    secondary_step: 3,
};

assert_eq!(keyboard.get_key(-2, -2), -16);
assert_eq!(keyboard.get_key(-2, -1), -13);
assert_eq!(keyboard.get_key(-2, 0), -10);
assert_eq!(keyboard.get_key(-1, 0), -5);
assert_eq!(keyboard.get_key(0, 0), 0);
assert_eq!(keyboard.get_key(0, 1), 3);
assert_eq!(keyboard.get_key(0, 2), 6);
assert_eq!(keyboard.get_key(1, 2), 11);
assert_eq!(keyboard.get_key(2, 2), 16);

Trait Implementations§

source§

impl Clone for IsomorphicKeyboard

source§

fn clone(&self) -> IsomorphicKeyboard

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for IsomorphicKeyboard

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.