MCC
Loading...
Searching...
No Matches

Text formatting and parsing into caller-provided buffers. More...

Collaboration diagram for Notation:

Namespaces

namespace  MCC::Notation
 Text formatting and parsing for note names, pitches and intervals.

Classes

struct  MCC::NotationOptions
 Options for text output (SPEC-TXT-3). More...

Enumerations

enum class  MCC::NotationSymbols : uint8_t { MCC::NotationSymbols::Ascii , MCC::NotationSymbols::Unicode }
 Accidental symbols used in text output (SPEC-TXT-3). More...

Detailed Description

Text formatting and parsing into caller-provided buffers.

MCC::Notation::Format() writes note names, pitches, intervals and, when their modules are enabled, catalog scales, chord symbols and keys. Output follows snprintf semantics in code units and never allocates (SPEC-TXT-1..2). ASCII symbols are the default (C#4, Bbb, AA4); NotationOptions::symbols selects Unicode accidentals (C♯4, B𝄫) and explicitNatural writes the natural sign (SPEC-TXT-3). The buffer type selects the encoding: char for ASCII or UTF-8, char16_t for UTF-16 and char32_t for UTF-32 (SPEC-TXT-5). A CodePointSink overload sends each code point to a callback instead, so text can go straight to a serial port or display without a buffer. ParseNoteName(), ParsePitch() and ParseInterval() read any of the three encodings, ASCII or Unicode symbols, either letter case and x for the double sharp, and return the invalid value on malformed text (SPEC-TXT-4). Text constants are stored in program memory on AVR.

char text[16];
MCC::Notation::Format(text, sizeof(text), MCC::Notation::ParsePitch("F#3")); // "F#3"
MCC::Notation::Format(text, sizeof(text), root, MCC::Chords::Id::HalfDiminishedSeventh);
Pitch ParsePitch(const CharT *text) noexcept
Parses a note name followed by a signed octave: C4, bb-1, Unicode accidentals.
size_t Format(CharT *destination, size_t capacity, NoteName noteName, NotationOptions options=NotationOptions()) noexcept
Writes C, F#, Bbb (or the Unicode sharp and flat signs).

Available when MCC_NOTATION is defined. Requires the Interval module.

Enumeration Type Documentation

◆ NotationSymbols

enum class MCC::NotationSymbols : uint8_t
strong

Accidental symbols used in text output (SPEC-TXT-3).

Enumerator
Ascii 

#, b and n, repeated for multiples.

Unicode 

U+266F sharp, U+266D flat, U+266E natural, U+1D12A double sharp and U+1D12B double flat.