a toolkit to utilize Chromatic-Solfege for JavaScript
A Node modue chromatic-solfege
is a library to operate the notes and the intervals
which are defined in Chromatic-Solfege. In this module, it defines all notes of
Chromatic-Solfege and offers functions to transpose specified note names.
var chromatic = require( 'chromatic-solfege' );
var r = chromatic.transpose( "re", "mi" )
console.log( r ); // "fi"
If you want to try following example, you could do it in your terminal as following:
> nodejs -e 'console.log( require("chromatic-solfege").transposeScript( "\\enh @do raw maw faw" ) )'
transpose( root : string, intervals: string, is_absolute : boolean ) : string
This function transposes a single note.
root
Specifies the root note.intervals
Specifies the interval from the root note.is_absolute
TODOreturns
transposed note name as a string value.console.log( chromatic.transpose( "do", "do" ) ); // "do"
console.log( chromatic.transpose( "do", "re" ) ); // "re"
console.log( chromatic.transpose( "do", "mi" ) ); // "mi"
console.log( chromatic.transpose( "fa", "do" ) ); // "fa"
console.log( chromatic.transpose( "fa", "re" ) ); // "sol"
console.log( chromatic.transpose( "fa", "mi" ) ); // "la"
transposeScript( macro : string, preference : Object )
This function transposes multiple notes at once. This function accepts an argument as a simple macro language which is called Chromatic-Solfege Abstraction Layer Language. See Chromatic-Solfege Abstraction Layer Language for further information.
macro
Takes a simple macro program.preference
Takes an object to override the current preference. This module takes
multilevel preference object system. See below.returns
an array that contains transposed note names.enharmonize(note)
This function returns an enharmonized note name of the given note.
console.log( c.enharmonize( "raw" ) ); // "do"
console.log( c.enharmonize( "de" ) ); // "ti"
enharmonize2(note)
This function returns an enharmonic note name of the given note. The note will be selected by an internally defined priority. This function is left for backward compatibility and new applications should not use this function.
putTripleAccidentals(note)
This is a lilypond helper function. This function puts a triple accidental tag before the note name if the specified is with a triple accidental.
respell(note)
This function converts note names with flat into sharp and vice a versa.
note2number(note)
Returns an integer value which denotes a specific note. We call the integer numbers as note index. The note indices start from zero. And the number will increase one with every half note.
console.log( c.note2number( "do" ) ); // 0
console.log( c.note2number( "re" ) ); // 2
console.log( c.note2number( "do'" ) ); // 12
console.log( c.note2number( "do," ) ); // -12
number2note(note)
Returns a note name of the specified note index.
console.log( c.number2note( 12 ) ); // do'
console.log( c.number2note( -12 ) ); // do,
note2alphabet(note)
Returns an alphabetical note name of the specified note name as unicode string.
console.log( c.note2alphabet( 'rai' ) ); // d𝄫
console.log( c.note2alphabet( 'di' ) ); // c♯
note2alphabet_tex(note)
Returns an alphabetical note name of the specified note name as tex command string.
console.log( c.note2alphabet_tex( 'rai' ) ); // "d \flatflat"
console.log( c.note2alphabet_tex( 'di' ) ); // "c \sharp"
isQuadrupleSharp Returns true if the specified value is a quadruple sharp.
isQuadrupleFlat Returns true if the specified value is a quadruple flat.
isQuadrupleAccidental Returns true if the specified value is with a quadruple accidental.
isTripleSharp Returns true if the specified value is with a triple sharp.
isTripleFlat Returns true if the specified value is with a triple flat.
isTripleAccidental Returns true if the specified value is with a triple accidental.
isDoubleSharp Returns true if the specified value is with a double sharp.
isDoubleFlat Returns true if the specified value is with a double flat.
isDoubleAccidental Returns true if the specified value is with a double accidental.
isSharp Returns true if the specified value is with a sharp.
isFlat Returns true if the specified value is with a flat.
isAccidental Returns true if the specified value is with an accidental.
isNatural Returns true if the specified value is natural and without any accidentals.
isNote Returns true if the specified value is a note name.
isIrregularAccidental Returns true if the specified value is one of ‘de’, ‘ta’ , ‘ma’, ‘fe’.
This function implements a simple commandline interface.
commandInterface( Array.prototype.slice.call( process.argv, 2) );
As mentioned above, the function transposeScript()
function accepts an
argument as a simple macro language which is called Csall. Csall stands
for Chromatic-Solfege Abstraction Layer Language.
The main purpose of this small language is dynamically transposing series of note names. This language also accepts some modifiers which can be specified by tags.
Note that the format of its output data is designed to be sent to lilypond afterwards in mind.
console.log( c.transposeScript( "do do re mi" ) ); // "do re mi"
console.log( c.transposeScript( "re do re mi" ) ); // "re mi fi"
console.log( c.transposeScript( "fa do re mi" ) ); // "fa sol la"
console.log( c.transposeScript( "@do do re mi" ) ); // "do re mi"
console.log( c.transposeScript( "@do do re mi @re do re mi" ) ); // "do re mi re mi fi"
'
and ,
are octave specifiers. It is transparently passed to the output. It
should come right after the note name.
console.log( c.transposeScript( "@do do, re, mi," ) ); // "do, re, mi'
Any of 0 1 2 3 4 5 6 7 8 9 0
are note value specifiers. It is transparently
passed to the output. It should come after the note name. In case there are any
octave specifier after the note name, the note value specifiers should come
after the octave specifier.
console.log( c.transposeScript( "@do do,4 re,4 mi,2" ) ); // "do,4 re,4 mi2'
You can put any number of mode specifiers before the all note sequence. Currently, there are four types of mode specifiers.
\har
\enh
\rel
\abs
\enh
When \enh
is specified, every note specifier in the output is converted to
its enharmonically equivalent note.
Currently this directive is not working correctly. This will be fixed in near future. Every application should not use this directive until it is properly fixed.
console.log( c.transposeScript( "\\enh @do raw maw faw" ) ); // " do re me"
\har The input note specifiers are not converted. This is the default mode.
console.log( c.transposeScript( "\\har @do raw maw faw" ) ); // "raw maw faw"
// This returns same " raw maw faw" since \\har is default.
console.log( c.transposeScript( "@do raw maw faw" ) );
\rel It output notes with relative octave specifier. \rel is default. TODO
console.log( c.transposeScript( "\\rel @do, do, re, mi,) ); // "do, re, mi,"
Currently this directive is under the beta state and not working correctly. This will be fixed in near future. Every application should not use this directive until it is properly fixed.
\abs It output notes with absolute octave specifier. TODO
console.log( c.transposeScript( "\\abs @do, do, re, mi,) ); // "do,, re,, mi,,"
Currently this directive is under the beta state and not working correctly. This will be fixed in near future. Every application should not use this directive until it is properly fixed.
s
is used as a rest note. In this module, it is treated as a special note.
console.log( c.transposeScript( "@do do4 re8 mi8 s4" ) ); // "do4 re8 mi8 s4"
#
\\
is ignored and
transparently sent to the output.console.log( c.transposeScript( "@do do re mi #FOO @re do re #BAR mi" ) ); // "do re mi #FOO re mi #BAR fi"
console.log( c.transposeScript( 'do do re mi "hello!" sol la' ) ); // 'do re mi "hello!" sol la'
These characters are ignored and transparently sent to the output.
! = . .. = [ ] < > s { } |
as a note
specifier is ignored and transparently sent to the output.console.log( c.transposeScript( 'do do [ re mi ] { sol la }' ) ); // 'do [ re mi ] { sol la }'
These characters are used to pass command sequences to Lilypond after the processing.
The available note name specifiers are following :
Origin | do | re | mi | fa | sol | la | ti |
---|---|---|---|---|---|---|---|
Quadruple-Flat | daes | raes | maes | faes | saes | laes | taes |
Triple-Flat | dae | rae | mae | fae | sae | lae | tae |
Double-Flat | daw | raw | maw | faw | saw | law | taw |
Flat | de | ra | me | fe | se | le | te |
Natural | do | re | mi | fa | sol | la | ti |
Sharp | di | ri | ma | fi | si | li | ta |
Double-Sharp | dai | rai | mai | fai | sai | lai | tai |
Triple-Sharp | dao | rao | mao | fao | sao | lao | tao |
Quadruple-Sharp | daos | raos | maos | faos | saos | laos | taos |
In this library, quater sharps and quater flats are also defined. The following table is a complete identifier table which includes quater notes.
Origin | do | re | mi | fa | sol | la | ti |
---|---|---|---|---|---|---|---|
Quadruple-Flat | daes | raes | maes | faes | saes | laes | taes |
7 Quarter-Flat | dawm | rawm | mawm | fawm | sawm | lawm | tawm |
Triple-Flat | dae | rae | mae | fae | sae | lae | tae |
5 Quarter-Flat | dawn | rawn | mawn | fawn | sawn | lawn | tawn |
Double-Flat | daw | raw | maw | faw | saw | law | taw |
3 Quarter-Flat | dem | ram | mem | fem | sem | lem | tem |
Flat | de | ra | me | fe | se | le | te |
1 Quarter-Flat | dew | rew | mew | few | sew | lew | tew |
Natural | do | re | mi | fa | sol | la | ti |
1 Quarter-Sharp | dia | ria | mia | fia | sia | lia | tia |
Sharp | di | ri | ma | fi | si | li | ta |
3 Quarter-Sharp | dim | rim | mam | fim | sim | lim | tam |
Double-Sharp | dai | rai | mai | fai | sai | lai | tai |
5 Quarter-Sharp | dain | rain | main | fain | sain | lain | tain |
Triple-Sharp | dao | rao | mao | fao | sao | lao | tao |
7 Quarter-Sharp | daim | raim | maim | faim | saim | laim | taim |
Quadruple-Sharp | daos | raos | maos | faos | saos | laos | taos |