Vital
|
A class for managing microtonal tunings and custom pitch mappings in Vital. More...
#include <tuning.h>
Public Member Functions | |
Tuning () | |
Constructs a Tuning object representing default (12-tone equal temperament) tuning. | |
Tuning (File file) | |
Constructs a Tuning object from a given file, loading that tuning. | |
void | loadScale (std::vector< float > scale) |
Loads a custom scale from a vector of offsets, specified in semitones or transposition units. | |
void | loadFile (File file) |
Loads a tuning from a given file, automatically detecting its format (.scl, .kbm, .tun). | |
void | setConstantTuning (float note) |
Sets a constant tuning, making all notes map to the same pitch offset. | |
void | setDefaultTuning () |
Resets the tuning to the default 12-tone equal temperament with a standard reference pitch. | |
vital::mono_float | convertMidiNote (int note) const |
Converts a MIDI note number to a pitch offset based on the current tuning. | |
void | setStartMidiNote (int start_midi_note) |
Sets the starting MIDI note for the scale mapping. | |
void | setReferenceNote (int reference_note) |
Sets the reference MIDI note number around which the tuning is centered. | |
void | setReferenceFrequency (float frequency) |
Sets the reference frequency used for calculating pitches. | |
void | setReferenceNoteFrequency (int midi_note, float frequency) |
Sets the reference note and frequency pair. | |
void | setReferenceRatio (float ratio) |
Sets the reference ratio, defining a pitch offset in ratio form. | |
std::string | getName () const |
Gets the name of the current tuning, combining tuning and mapping names if both exist. | |
void | setName (const std::string &name) |
Sets a custom name for the current tuning, clearing any mapping name. | |
bool | isDefault () const |
Checks if the tuning is the default equal temperament. | |
json | stateToJson () const |
Saves the current tuning state into a JSON object. | |
void | jsonToState (const json &data) |
Restores the tuning state from a JSON object. | |
void | loadScalaFile (const StringArray &scala_lines) |
Loads a Scala (.scl) file from a set of lines. | |
Static Public Member Functions | |
static Tuning | getTuningForFile (File file) |
Creates a Tuning object from a given file. | |
static String | allFileExtensions () |
Returns a string listing all supported tuning file extensions. | |
static int | noteToMidiKey (const String ¬e) |
Converts a note name (e.g. "A4") to a MIDI key number. | |
Static Public Attributes | |
static constexpr int | kTuningSize = 2 * vital::kMidiSize |
The total size of the internal tuning table. | |
static constexpr int | kTuningCenter = vital::kMidiSize |
The center index of the tuning table. | |
A class for managing microtonal tunings and custom pitch mappings in Vital.
The Tuning class allows loading and applying scales, .scl (Scala) files, .tun files, and keyboard mapping files (.kbm) to adjust how MIDI notes are mapped to frequencies. It supports setting a reference frequency, defining custom scales, and converting MIDI note numbers to pitch values according to the chosen tuning.
Tuning::Tuning | ( | ) |
Constructs a Tuning object representing default (12-tone equal temperament) tuning.
Tuning::Tuning | ( | File | file | ) |
Constructs a Tuning object from a given file, loading that tuning.
file | The tuning file. |
|
static |
Returns a string listing all supported tuning file extensions.
E.g., "*.scl;*.kbm;*.tun"
vital::mono_float Tuning::convertMidiNote | ( | int | note | ) | const |
Converts a MIDI note number to a pitch offset based on the current tuning.
note | The MIDI note number. |
|
inline |
Gets the name of the current tuning, combining tuning and mapping names if both exist.
|
static |
|
inline |
Checks if the tuning is the default equal temperament.
void Tuning::jsonToState | ( | const json & | data | ) |
Restores the tuning state from a JSON object.
data | The JSON object containing tuning state data. |
void Tuning::loadFile | ( | File | file | ) |
Loads a tuning from a given file, automatically detecting its format (.scl, .kbm, .tun).
file | The tuning file. |
void Tuning::loadScalaFile | ( | const StringArray & | scala_lines | ) |
Loads a Scala (.scl) file from a set of lines.
This helper allows loading Scala format from already read lines.
scala_lines | The lines of the Scala file. |
void Tuning::loadScale | ( | std::vector< float > | scale | ) |
Loads a custom scale from a vector of offsets, specified in semitones or transposition units.
scale | A vector of floats representing scale steps. |
|
static |
Converts a note name (e.g. "A4") to a MIDI key number.
note | The note name string. |
void Tuning::setConstantTuning | ( | float | note | ) |
Sets a constant tuning, making all notes map to the same pitch offset.
Useful as a fallback if scale loading fails.
note | The constant pitch offset to apply. |
void Tuning::setDefaultTuning | ( | ) |
Resets the tuning to the default 12-tone equal temperament with a standard reference pitch.
|
inline |
Sets a custom name for the current tuning, clearing any mapping name.
name | The new tuning name. |
void Tuning::setReferenceFrequency | ( | float | frequency | ) |
Sets the reference frequency used for calculating pitches.
frequency | The reference frequency in Hz. |
|
inline |
Sets the reference MIDI note number around which the tuning is centered.
reference_note | The reference MIDI note. |
void Tuning::setReferenceNoteFrequency | ( | int | midi_note, |
float | frequency ) |
Sets the reference note and frequency pair.
midi_note | The reference MIDI note. |
frequency | The frequency to assign to this MIDI note. |
void Tuning::setReferenceRatio | ( | float | ratio | ) |
Sets the reference ratio, defining a pitch offset in ratio form.
ratio | The ratio used to set the reference note offset. |
|
inline |
Sets the starting MIDI note for the scale mapping.
start_midi_note | The MIDI note to start the scale at. |
json Tuning::stateToJson | ( | ) | const |
Saves the current tuning state into a JSON object.
|
staticconstexpr |
The center index of the tuning table.
This is the "middle" reference point used when indexing tuning values by MIDI note offsets.
|
staticconstexpr |
The total size of the internal tuning table.
The table extends from -vital::kMidiSize to +vital::kMidiSize, creating a large range for indexing notes around a central reference.