Library API

Conversion API

Music hkr::parse_music(std::string text)

Parse a string into a structured form.

Please refer to the syntax guide for more details.

Parameters

text – Text input.

Returns

Parsed music structure.

void hkr::export_to_lilypond(std::ostream &stream, Music music)

Convert structured music into Lilypond notation.

Parameters
  • stream – The output stream to write into.

  • music – The music to export.

Music Structures

enum hkr::NoteBase

The base part of a note name (C, D, E, F, G, A, B).

Values:

enumerator c
enumerator d
enumerator e
enumerator f
enumerator g
enumerator a
enumerator b
enum hkr::IntervalQuality

Different qualities for an interval.

Values:

enumerator diminished
enumerator minor
enumerator perfect
enumerator major
enumerator augmented
struct Interval

A music interval between two notes.

Public Functions

int semitones() const

Count how many semitones are there in the interval.

Public Members

int number = 1

Diatonic number.

IntervalQuality quality = IntervalQuality::perfect

Interval quality.

struct Time

Time signature.

Public Members

int numerator = 4

Numerator of the time signature, or how many beats are there in a measure.

int denominator = 4

Denominator of the time signature, or the duration of a single beat.

struct Note

A musical note.

Public Functions

Note transposed_up(int semitones) const noexcept

Find the note n seminotes above this one.

Note transposed_down(int semitones) const noexcept

Find the note n seminotes below this one.

Note transposed_up(Interval interval) const noexcept

Find the note at some interval above this one.

Note transposed_down(Interval interval) const noexcept

Find the note at some interval below this one.

std::int8_t pitch_id() const

Get the MIDI pitch ID of the note.

Public Members

NoteBase base

Base of the note.

int octave

Octave of the note, C4 (octave=4) is the middle C.

int accidental

Accidental of a note, positive integer for the amount of sharps, or flats if negative.

struct Chord

A chord containing multiple notes.

Public Members

std::vector<Note> notes

Constituents of this chord.

bool sustained = false

Whether this chord is a prolongation of the previous one.

Attributes attributes

Attributes of this chord.

struct Attributes

Attributes of a chord.

Public Members

std::optional<float> tempo

Tempo marking of this chord.

using hkr::Voice = std::vector<Chord>

A voice containing multiple chords.

using hkr::Beat = std::vector<Voice>

A beat containing multiple voices.

using hkr::Staff = std::vector<Beat>

A staff containing multiple beats.

struct Measure

Information about a measure.

Public Members

std::size_t start_beat = 0

Index of the first beat in this measure.

Attributes attributes

Attributes of this measure.

struct Attributes

Attributes of a measure.

Public Functions

void merge_with(const Attributes &other)

Merge another set of measure attributes into this one.

Any non-null attribute in the other attribute set will be overwritten upon this set.

Parameters

other – The other measure.

inline bool is_null() const noexcept

Checks whether this attribute set is completely empty.

Public Members

std::optional<int> key

The amount of sharps in the key signature, negative integer for flats.

std::optional<Time> time

Time signature of the current measure.

std::optional<Time> partial

The actual time of the current measure (for pick-up beats).

struct Section

A music section, containing multiple staves.

Public Functions

std::pair<std::size_t, std::size_t> beat_index_range_of_measure(std::size_t measure) const

Find the starting and ending beat indices of a measure in this section.

Parameters

measure – Index of the measure.

Returns

A pair of std::size_t being the starting (inclusive) and ending (exclusive) beats’ indices.

Public Members

std::vector<Staff> staves

The staves.

std::vector<Measure> measures

Measure information.

using hkr::Music = std::vector<Section>

Music structure, containing multiple sections.