Struct tune::layout::IsomorphicKeyboard
source · 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
impl IsomorphicKeyboard
sourcepub fn coprime(self) -> IsomorphicKeyboard
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);
sourcepub fn get_key(&self, num_primary_steps: i16, num_secondary_steps: i16) -> i32
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
impl Clone for IsomorphicKeyboard
source§fn clone(&self) -> IsomorphicKeyboard
fn clone(&self) -> IsomorphicKeyboard
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreAuto Trait Implementations§
impl RefUnwindSafe for IsomorphicKeyboard
impl Send for IsomorphicKeyboard
impl Sync for IsomorphicKeyboard
impl Unpin for IsomorphicKeyboard
impl UnwindSafe for IsomorphicKeyboard
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more