Home

Awesome

Tuning Library Python bindings

Python bindings for the Surge Synth Team Tuning Library.

Installation

To install from PyPI:

$ pip install tuning-library

or to clone the repo and install from source:

$ git clone --recurse-submodules https://github.com/surge-synthesizer/tuning-library-python.git
$ cd tuning-library-python
$ python3 -m pip install .

Examples

Read scl file and find frequency of midi note 69

import tuning_library as tl

scale = tl.read_scl_file("scale.scl")
tuning = tl.Tuning(scale)
f = tuning.frequency_for_midi_note(69)

Read scl and kbm files and find frequency of midi note 69

import tuning_library as tl

scale = tl.read_scl_file("scale.scl")
mapping = tl.read_kbm_file("mapping.kbm")
tuning = tl.Tuning(scale, mapping)
f = tuning.frequency_for_midi_note(69)

There are some scripts which use tuning_library in the examples directory in the repo.

Wrapper names

The names in the C++ Tuning Library and this Python wrapper correspond as follows

C++Python
readSCLFileread_scl_file
parseSCLDataparse_scl_data
evenTemperament12NoteScaleeven_temperament_12_note_scale
evenDivisionOfSpanByMeven_division_of_span_by_m
evenDivisionOfCentsByMeven_division_of_cents_by_m
readKBMFileread_kbm_file
parseKBMDataparse_kbm_data
tuneA69Totune_A69_to
tuneNoteTotune_note_to
startScaleOnAndTuneNoteTostart_scale_on_and_tune_note_to
Scale::nameScale.name
Scale::descriptionScale.description
Scale::rawTextScale.raw_text
Scale::countScale.count
Scale::tonesScale.tones
KeyboardMapping::countKeyboardMapping.count
KeyboardMapping::firstMidiKeyboardMapping.first_midi
KeyboardMapping::lastMidiKeyboardMapping.last_midi
KeyboardMapping::middleNoteKeyboardMapping.middle_note
KeyboardMapping::tuningConstantNoteKeyboardMapping.tuning_constant_note
KeyboardMapping::tuningFrequencyKeyboardMapping.tuning_frequency
KeyboardMapping::tuningPitchKeyboardMapping.tuning_pitch
KeyboardMapping::octaveDegreesKeyboardMapping.octave_degrees
KeyboardMapping::keysKeyboardMapping.keys
KeyboardMapping::rawTextKeyboardMapping.raw_text
KeyboardMapping::nameKeyboardMapping.name
Tuning::NTuning.N
Tuning::withSkippedNotesInterpolatedTuning.with_skipped_notes_interpolated
Tuning::frequencyForMidiNoteTuning.frequency_for_midi_note
Tuning::frequencyForMidiNoteScaledByMidi0Tuning.frequency_for_midi_note_scaled_by_midi_0
Tuning::logScaledFrequencyForMidiNoteTuning.log_scaled_frequency_for_midi_note
Tuning::retuningFromEqualInCentsForMidiNoteTuning.retuning_from_equal_in_cents_for_midi_note
Tuning::retuningFromEqualInSemitonesForMidiNoteTuning.retuning_from_equal_in_semitones_for_midi_note
Tuning::scalePositionForMidiNoteTuning.scale_position_for_midi_note
Tuning::isMidiNoteMappedTuning.is_midi_note_mapped
Tuning::scaleTuning.scale
Tuning::keyboardMappingTuning.keyboard_mapping
Tone::typeTone.type
Tone::centsTone.cents
Tone::ratio_dTone.ratio_d
Tone::ratio_nTone.ratio_n
Tone::stringRepTone.string_rep
Tone::floatValueTone.float_value
toneFromStringtone_from_string

Extra

The tuning_library Python package also includes a scala_files_to_frequencies convenience function which is not in the C++ library. It can be called as

import tuning_library as tl

frequencies = tl.scala_files_to_frequencies("scale.scl", "mapping.kbm")

or, using a default keyboard mapping,

frequencies = tl.scala_files_to_frequencies("scale.scl")

and returns a list of 128 frequencies in Hz, one for each each midi note.