Vital
Loading...
Searching...
No Matches
Tuning Class Reference

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 &note)
 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.
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ Tuning() [1/2]

Tuning::Tuning ( )

Constructs a Tuning object representing default (12-tone equal temperament) tuning.

◆ Tuning() [2/2]

Tuning::Tuning ( File file)

Constructs a Tuning object from a given file, loading that tuning.

Parameters
fileThe tuning file.

Member Function Documentation

◆ allFileExtensions()

String Tuning::allFileExtensions ( )
static

Returns a string listing all supported tuning file extensions.

E.g., "*.scl;*.kbm;*.tun"

Returns
A string of semicolon-separated file extensions.

◆ convertMidiNote()

vital::mono_float Tuning::convertMidiNote ( int note) const

Converts a MIDI note number to a pitch offset based on the current tuning.

Parameters
noteThe MIDI note number.
Returns
A mono_float representing the pitch offset (in semitones).

◆ getName()

std::string Tuning::getName ( ) const
inline

Gets the name of the current tuning, combining tuning and mapping names if both exist.

Returns
A string representing the tuning name.

◆ getTuningForFile()

Tuning Tuning::getTuningForFile ( File file)
static

Creates a Tuning object from a given file.

Supported files include Scala (.scl), .tun, and .kbm files. The tuning data is loaded and parsed into a form usable by the synthesizer.

Parameters
fileThe file to load the tuning from.
Returns
A Tuning object representing the loaded tuning.

◆ isDefault()

bool Tuning::isDefault ( ) const
inline

Checks if the tuning is the default equal temperament.

Returns
True if default, false otherwise.

◆ jsonToState()

void Tuning::jsonToState ( const json & data)

Restores the tuning state from a JSON object.

Parameters
dataThe JSON object containing tuning state data.

◆ loadFile()

void Tuning::loadFile ( File file)

Loads a tuning from a given file, automatically detecting its format (.scl, .kbm, .tun).

Parameters
fileThe tuning file.

◆ loadScalaFile()

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.

Parameters
scala_linesThe lines of the Scala file.

◆ loadScale()

void Tuning::loadScale ( std::vector< float > scale)

Loads a custom scale from a vector of offsets, specified in semitones or transposition units.

Parameters
scaleA vector of floats representing scale steps.

◆ noteToMidiKey()

int Tuning::noteToMidiKey ( const String & note)
static

Converts a note name (e.g. "A4") to a MIDI key number.

Parameters
noteThe note name string.
Returns
The MIDI note number or -1 if invalid.

◆ setConstantTuning()

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.

Parameters
noteThe constant pitch offset to apply.

◆ setDefaultTuning()

void Tuning::setDefaultTuning ( )

Resets the tuning to the default 12-tone equal temperament with a standard reference pitch.

◆ setName()

void Tuning::setName ( const std::string & name)
inline

Sets a custom name for the current tuning, clearing any mapping name.

Parameters
nameThe new tuning name.

◆ setReferenceFrequency()

void Tuning::setReferenceFrequency ( float frequency)

Sets the reference frequency used for calculating pitches.

Parameters
frequencyThe reference frequency in Hz.

◆ setReferenceNote()

void Tuning::setReferenceNote ( int reference_note)
inline

Sets the reference MIDI note number around which the tuning is centered.

Parameters
reference_noteThe reference MIDI note.

◆ setReferenceNoteFrequency()

void Tuning::setReferenceNoteFrequency ( int midi_note,
float frequency )

Sets the reference note and frequency pair.

Parameters
midi_noteThe reference MIDI note.
frequencyThe frequency to assign to this MIDI note.

◆ setReferenceRatio()

void Tuning::setReferenceRatio ( float ratio)

Sets the reference ratio, defining a pitch offset in ratio form.

Parameters
ratioThe ratio used to set the reference note offset.

◆ setStartMidiNote()

void Tuning::setStartMidiNote ( int start_midi_note)
inline

Sets the starting MIDI note for the scale mapping.

Parameters
start_midi_noteThe MIDI note to start the scale at.

◆ stateToJson()

json Tuning::stateToJson ( ) const

Saves the current tuning state into a JSON object.

Returns
A JSON object representing the tuning state.

Member Data Documentation

◆ kTuningCenter

int Tuning::kTuningCenter = vital::kMidiSize
staticconstexpr

The center index of the tuning table.

This is the "middle" reference point used when indexing tuning values by MIDI note offsets.

◆ kTuningSize

int Tuning::kTuningSize = 2 * vital::kMidiSize
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.


The documentation for this class was generated from the following files: