libsmp
A C++ library for symbolic music processing
libsmp is a library for Symbolic Music Processing.
It can be useful for writting programs that have to deal with basic musical
concepts such as notes, intervals and chords in the equally tempered musical
system.
libsmp defines these new data types:
-
struct NOTE {int octave; int pitch; ACCIDENTAL accidental; }
where octave=3 is the central octave, pitch is 0 for C (Do),
1 for D (Re), ..., 6 for B (Si) and accidental is an enum that can be
one of these self-explaining symbolic values: DOUBLEFLAT, FLAT, NATURAL,
SHARP, DOUBLESHARP.
-
struct INTERVAL {int name; INTERVALTYPE type; DIRECTIONTYPE direction;}
where name is 0 for first, 1, for second and so on, type can be MAJOR, MINOR,
PERFECT, AUGMENTED, DIMINISHED, MTAUGMENTED (more than augmented),
MTDIMINISHED (more than diminished) and direction can be ABOVE or
BELOW.
-
struct TRIAD {NOTE foundamental;INTERVAL i1,i2;
int doubld;POSITIONTYPE position;} where
foundamental
is the foundamental (but not necessarily the basso) NOTE,
doubld is the doubled note (in a tipical four note harmony), i1
and i2 are the third and the fifth (what matters here is just the
type of third and fifth) and position can be FOUNDAMENTAL, FIRST
(first inversion) and SECOND (second inversion). Currently this
structure is used just for packing the information returned by the Triad(NOTE,NOTE,NOTE,NOTE),
but
in future other operations on TRIADs will be implemented. The same remark
can be made for:
-
struct TONALITY {NOTE tonic, MODE mode} that
is self-explanatory but is almost completely unsupported.
libsmp defines the LA3
and DO3 constant NOTEs, the
double LA3FREQ = 440 (Hz) and the double
HALFTONEFACTOR
as the 12-th root of 2.
Here's a summary of the libsmp functions
with a brief explanation:
-
NOTE Ascii2Note(String s)
coverts an ascii String s to a NOTE following the simple
rules of an arbitrary human-readable notation (see).
-
INTERVAL Interval(NOTE n1, NOTE n2)
returns the INTERVAL between n1 and n2.
-
String Interval2Ascii(INTERVAL i)
returns the String correspoding to the INTERVAL i
in the h-r notation (see).
-
INTERVAL Ascii2Interval(String s)
coverts an ascii String s to an INTERVAL.
-
int CanBePerfect(INTERVAL i) returns
the boolean TRUE if the name field of i is compatible
with the type PERFECT (unison, fourth, fifth, eight etc.)
-
int CanBePerfect(int n)
same as above but n is the name of an INTERVAL.
-
DIRECTIONTYPE SortExtremes(NOTE &n1,NOTE &n2)
if n1 is higher than n2, swaps n1 and n2 and
returns BELOW, else returns ABOVE.
-
void SwapExtremes(NOTE &n1,NOTE &n2)
despite of its name swaps two NOTEs n1 and n2.
-
void ShrinkInterval(INTERVAL& i, int n)
shrinks n times the interval i, giving care to the kind of
interval (perfect or major).
-
void EnlargeInterval(INTERVAL&,int)
like above but enlarge i.
-
INTERVAL SimpleInterval(INTERVAL i)
return i if it's a simple interval or the its relative simple interval
if it's compound (ninth is considered compound).
-
INTERVAL Inversion(INTERVAL i)
returns the inversion of a simple interval i or the inversion of
its relative simple interval if it's compound (note that usually the inversion
of a compound interval is not defined).
-
NOTE GetNote(void)
gets a String (see) from the standard
input and converts to a NOTE.
-
NOTE CentralOctave(NOTE n)
returns a NOTE that has the same pitch and accidental of
n,
but belonging to the central octave.
-
int SameNote(NOTE n1, NOTE n2)
return the boolean TRUE if n1 and n2 have same pitch,
accidental
and octave.
-
int SameInterval(INTERVAL i1, INTERVAL i2)
return the boolean TRUE if i1 and i2 have same name,
type
and direction.
-
TRIAD Triad(NOTE b, NOTE t, NOTE c, NOTE s)
computes foundamental note, third and fifth of the triad specified by the
NOTE b, t, c and s (respectively basso, tenore, contralto and soprano),
its double note and the position.
-
String Triad2Ascii(TRIAD t)
composes a triad description.
-
String Int2Ascii(int)
int to String cast.
-
TONALITY GetTonality(void)
gets a String from standard input and
-
TONALITY Ascii2Tonality(String s)
converts a String s containing a h-r notation (see)
specification of a tonality in a TONALITY.
-
String Accidental2Ascii(ACCIDENTAL a)
returns the symbold for the ACCIDENTAL a.
-
int Halftones(INTERVAL i)
returns the length of the INTERVAL i in halftones.
-
String Note2Ascii(NOTE n)
returns the h-r notation (see) name of the
NOTE n.
-
double Note2Freq(NOTE n)
returns the foundamental frequency of n in the standard equally tempered
system with LA3 <-> 440 Hz.
-
INTERVAL Ascending(INTERVAL i)
returns i if its direction is ABOVE (ascending interval)
or its inversion if it's descending (its direction is BELOW).
-
double logHTF(double x)
returns the logarithm in base HALFTONEFACTOR of x.
-
NOTE Freq2Note(double f, double& d)
returns the NOTE corresponding to a foundamental frequency f
and sets d to the detuning ratio.
-
NOTE ReachingNote(NOTE n, int s, HALFTONETYPE
t) returns the upper note of an interval
starting from n and s halftones long. The t parameter specify
if an eventually "odd" semitone will be considered DIATONIC or CHROMATIC.
-
NOTE ReachingNote(NOTE n, INTERVAL i)
returns the upper note of the INTERVAL i starting from n.
-
void AddPitch(NOTE &n1, int s)
raises the pitch of n1 by s halftones. It cares about tones
and halftone between different pitches.
-
NOTE randomNote(void)
returns a random NOTE in the low or central octaves (only one accidental
is allowed).
-
void Randomize(void)
sets the 48 bit integer aritmethic random numer generator seed using time()
and the standard rng.
-
inline double boundedRandom(double max)
returns a double in interval [0,max).
Human-readable notation is case sensitive. Square bracket mean that
a parameter is mandatory.
Notes:
[pitch]{accidental}{octave}
Italian-style (default) pitch symbols are: do, re, mi, fa, sol, la, si.
English-style pitch symbols are: C, D, E, F, G, A, B.
Unique-style accidental symbols are: # (sharp), b (flat), default (no symbol)
is natural.
Italian-style octave symbols are: numbers (0, 1, 2...) or B (lower), C
(central), A (higher).
English-style octave symbols are: numers (0, 1, 2...) or l (lower), c (central),
h (higher).
Here you can find gzipped libsmp source
code (and some example).
The first liboopsmp alpha version is also avaiable.
Home