pub struct Tuning {
pub scale: Scale,
pub keyboard_mapping: KeyboardMapping,
/* private fields */
}
Expand description
The Tuning struct is the primary place where you will interact with this library.
It is constrcted for a scale and mapping and then gives you the ability to determine frequencies across and beyond the MIDI keyboard. Since modulation can force key number well outside the [0, 127] range, we support a MIDI note range from -256 to +256 spanning more than the entire frequency space reasonable.
To use this struct, you construct a fresh instance every time you want to use a different
Scale
and KeyboardMapping
. If you want to tune to a different scale or mapping, just
construct a new instance.
let s = Scale::even_temperament_12_note_scale(); // or any other function constructing a Scale
let k = KeyboardMapping::tune_a69_to(432.0); // or any other function constructing a KeyboardMapping
let t1 = Tuning::from_scale(s.clone());
let t2 = Tuning::from_keyboard_mapping(k.clone());
let t3 = Tuning::from_scale_and_keyboard_mapping(s.clone(), k.clone(), AllowTuningOnUnmapped(false));
Fields§
§scale: Scale
Scale of the tuning.
keyboard_mapping: KeyboardMapping
Keyboard mapping of the tuning.
Implementations§
Source§impl Tuning
impl Tuning
Sourcepub fn from_scale(scale: Scale) -> Result<Self, TuningError>
pub fn from_scale(scale: Scale) -> Result<Self, TuningError>
Constructs a Tuning
with given scale
and standard mapping.
Sourcepub fn from_keyboard_mapping(
keyboard_mapping: KeyboardMapping,
) -> Result<Self, TuningError>
pub fn from_keyboard_mapping( keyboard_mapping: KeyboardMapping, ) -> Result<Self, TuningError>
Constructs a Tuning
with 12-EDO scale and given keyboard_mapping
.
Sourcepub fn from_scale_and_keyboard_mapping(
scale: Scale,
keyboard_mapping: KeyboardMapping,
allow_tuning_center_on_unmapped: AllowTuningOnUnmapped,
) -> Result<Self, TuningError>
pub fn from_scale_and_keyboard_mapping( scale: Scale, keyboard_mapping: KeyboardMapping, allow_tuning_center_on_unmapped: AllowTuningOnUnmapped, ) -> Result<Self, TuningError>
Constructs a Tuning
with given scale
and keyboard_mapping
.
Sourcepub fn with_skipped_notes_interpolated(&self) -> Self
pub fn with_skipped_notes_interpolated(&self) -> Self
Fills unmapped notes with interpolated vaules.
Sourcepub fn frequency_for_midi_note(&self, midi_note: i32) -> f64
pub fn frequency_for_midi_note(&self, midi_note: i32) -> f64
Retunrs the frequency in Hz for a given MIDI note.
let t = Tuning::new();
assert!((t.frequency_for_midi_note(69) - 440.0).abs() < 1e-4); // A
assert!((t.frequency_for_midi_note(60) - 261.6256).abs() < 1e-4); // middle C
Sourcepub fn frequency_for_midi_note_scaled_by_midi0(&self, midi_note: i32) -> f64
pub fn frequency_for_midi_note_scaled_by_midi0(&self, midi_note: i32) -> f64
Returns the frequency but with the standard frequency of MIDI note 0 divided out.
let t = Tuning::new();
assert_eq!(t.frequency_for_midi_note_scaled_by_midi0(0), 1.0);
assert_eq!(t.frequency_for_midi_note_scaled_by_midi0(60), 32.0);
Sourcepub fn log_scaled_frequency_for_midi_note(&self, midi_note: i32) -> f64
pub fn log_scaled_frequency_for_midi_note(&self, midi_note: i32) -> f64
Returns the log base 2 of the scaled frequency.
let t = Tuning::new();
assert_eq!(t.log_scaled_frequency_for_midi_note(0), 0.0);
assert_eq!(t.log_scaled_frequency_for_midi_note(60), 5.0);
The value increases by one per frequency double.
Sourcepub fn scale_position_for_midi_note(&self, midi_note: i32) -> i32
pub fn scale_position_for_midi_note(&self, midi_note: i32) -> i32
Returns the space in the logical scale. Note 0 is the root. It has a maximum value of
count-1
. Note that SCL files omit the root internally and so this logical scale position
is off by 1 from the index in the tones vector of the Scale data.
Sourcepub fn is_midi_note_mapped(&self, midi_note: i32) -> bool
pub fn is_midi_note_mapped(&self, midi_note: i32) -> bool
Returns whether a given midi_note
is mapped in the Tuning
’s KeyboardMapping
.