Dr.Godfried-Willem RAES

<GMT> & <Harmony Library> Reference Manual


<Back to introduction>   <To Index>
<Index > <Introduction> <General Functions>
<Fuzzy Functions> <Analysis Functions> <Acoustical Functions>
<Visualisation Functions> <File Management> <Psychological Functions>

BASIC HARMONY LIBRARY

CHAPTER 1: HARM_GEN

Files: source code now all included in g_mus.bas. The library is in g_mus.dll. The public declarations for Power Basic in g_mus.bi

This dll van be called from any complete programming language.


List of Functions contained in the HARM_GEN library-module:

FUNCTION AddChords% (ChordNumber1%, ChordNumber2%)
FUNCTION AddNoteInChord% (ChordNumber%, a%)
FUNCTION Cnr2Ctp& (ChordNumber%, Tc%)
FUNCTION ComChords% (ChordNumber1%, ChordNumber2%)
FUNCTION Ctp2Cnr% (Chordtype&, Tc%)
FUNCTION DelNoteInChord% (ChordNumber%, a%)
FUNCTION DifChords% (ChordNumber1%, ChordNumber2%)
FUNCTION Get3Kadens! (chord1%, chord2%, chord3%, chord4%)
FUNCTION GetConsonance! (Chordnumber%)
FUNCTION GetDissonance! (Chordnumber%)
FUNCTION GetNrNotes% (ChordNumber%)
FUNCTION GetRndNote% (modus%, Tc%)
FUNCTION GetScaleCnr% (modus%, Tc%)
FUNCTION GetTc% (ChordNumber%)
FUNCTION IsNoteInChord% (Chordnumber%, note%)
FUNCTION Make3ChordNum% (a%, b%, c%)
FUNCTION Make4ChordNum% (a%, b%, c%, d%)
FUNCTION MakeChordNum% (a%, b%, c%, d%, e%, f%, g%, h%, i%, j%, k%, l%)
FUNCTION MakeHarmChord% (ChordNumber%, modus%, harmonysystem%)
FUNCTION MirCnr% (ChordNumber%, note%)
FUNCTION Neg% (ChordNumber%)
FUNCTION NxNt% (modus%, Tc%, note%, sign%)
FUNCTION ParaChord% (n%, disvalue!, convalue!, tolerance!)
FUNCTION ParConChord% (n%, convalue!, tolerance!)
FUNCTION ParDisChord% (n%, disvalue!, tolerance!)
FUNCTION Richt% (note1%, note2%)
FUNCTION Rol% (ChordNumber%, n%)
FUNCTION Ror% (ChordNumber%, n%)
FUNCTION SameChord (BYVAL Cnr1 AS INTEGER, BYVAL Cnr2 AS INTEGER) AS WORD
FUNCTION SetTc% (ChordNumber%, Tc%)
FUNCTION SolveCnr (BYVAL Cnr AS INTEGER, BYVAL tc AS INTEGER) AS INTEGER
FUNCTION TransChordNum% (ChordNumber%, n%)
FUNCTION TransChordType& (ChordType&, n%)
FUNCTION VarChord% (ChordNumber%)

In order to guide the user into the first steps required to take profit of the possibilities of this library, we will describe the method for chord descriptor construction in a few steps first. After this, the explanation and users guide for the functions and procedures contained in the library follow.

First step:

Use one of the Make-functions to create a chordnumber in which each of the 12 lowest bit positions corresponds to the presence or non presence of a note in the chord. This chordnumber serves as a pure binary chorddescriptor . The library HARM_FUZ extends this format to include fuzzy-values as chorddesciptor. This format is explained further. The pure binary form is the easiest to understand, so this is where we start off. The number code structure of the integer chord descriptor is:

d15 d14 d13 d12 d11 d10 d9 d8 d7 d6 d5 d4 d3 d2 d1 d0
        B Bb A Ab G F# F E Eb D C# C

tonality bits----------|Note-bits------------------------------------------|

High byte----------------------------------|---------- Low byte -----------|

MSB ---------------------------------------|--------------LSB--------------|

Reading the chord descriptor as a hexadecimal number facilitates reading quite a bit. Use the basic function HEX$(Cnn%) for this conversion. To calculate these numbers from a set of notes, coded as non-zero midi note values (7-bit numbers) we provided the user with some specific functions.

(Sometimes it comes in handy not to use the provided functions and instead make use of inline statements as

Crd% = Crd% OR (2^(note% MOD 12))

to add a note to a chord-number. There is no objection against doing so. A much faster method however is offered by Power Basic:

BIT SET Crd%, note% MOD 12

FUNCTION Make3ChordNum%(i%,j%,k%)

FUNCTION Make4ChordNum%(i%,j%,k%,l%)

FUNCTION MakeChordNum%(i%,...t%)

Use:

To convert a triad of notes into this code use the function: 
Cnn% = Make3ChordNum%(a%,b%,c%)
For a 4-note chord you can use:
Cnn% = Make4ChordNum%(a%.b%,c%,d%)
Use the function MakeChordNum% to convert a series of notes into such a unique binary chordnumber:
  • Cnn% = MakeChordNum% (a%, b%, c%, d%, e%, f%, g%, h%, i%, j%, k%, l%)
  • All twelve parameters must be transferred. Not used notes must be 0. The note%=0 values will not be written to the chord, so dont use midi note 0 as a note! Use note 12 instead. Notes must be 7-bit integer-type (midi-note values) and must be > 0. Another way of constructing chordnumbers may make use of the function AddNoteInChord%(). Construction of a one note chord is this possible as follows:

    Cnn% = AddNoteInChord%(0, note%)

    Adding further notes as required also goes as follows:

    Cnn%= AddNoteInChord% (Cnn%, note2%)

    Second step:

    FUNCTION SetTc%(i%,j%)

    Use:

    If you know the tonal center for this chord, you can add it to the chordnumber. It will be written in the highest nibble of the chordnumber. If this is not done, the highest nibble will be set to F (all 1's).

    Cnn% = SetTc% (Cnn%, ToneCenter%)

    Note: The highest nibble (4-bits) corresponds to the following meaning:

    This mapping cannot be changed by the user. In a later implementation it would be possible to use remaining bits for special mode-detection, hence following values are reserved:

    Once these first steps were performed, all the following functions and procedures can be used on the chordnumbers returned. 


    FUNCTION GetNrNotes%(i%)

    Use:

    Counting the number of different notes in a chordnumber:

  • n% = GetNrNotes%(Cnn%)
  • This Function returns a value between 0 and 12. Of course the return value zero indicates an empty chord (not containing any notes). The return values 12 indicates a full chromatic cluster.


    FUNCTION GetTc%(i%)

    Use:

    Reading the tonal center from the high nibble of a chordnumber:

  • TonalCenter% = GetTc% (Cnn%)
  • If no tonal center was set, the function returns -1. Otherwise it is a value 0-11, corresponding to Midi note coding in the lowest octave position.


    FUNCTION AddNoteInChord% (Cnn%,n%)

    Use:

  • Cnn%= AddNoteInChord%(Cnn%, note%)
  • This function, mentioned already above, lets you add a single note to a chordnumber. The note should conform to the valid midi note-range. If the note is already present in the chord, the chordnumber returned will remain unchanged. It is equivalent to writing: BIT SET Cnn%, note% MOD 12

    Code example:

    The following code fragments return the same result in chord%:

    1.: chord% = Make3ChordNum%(64, 65, 66)

    2.: chord% = False

    chord% = AddNoteInChord%(chord%, 64)

    chord% = AddNoteInChord%(chord%, 65)

    chord% = AddNoteInChord%(chord%, 66)


    Determination and recognition of chords:

    FUNCTION IsNoteInChord% (i%, n%)

    Use:

    b%= IsNoteInChord% (Cnn%, note%)

      This function returns either true or false (-1 or 0) depending on the presence of absence of a given note in a given chord. The first parameter must be a valid chordnumber, the second one, any value corresponding to a midi note number (0-127). The function comes in very handy in conditional statements as in:

    Example:

    IF IsNoteInChord%(number%,64) THEN

    MakeHarmChord%(number%,0,3)

    ENDIF

    Using PowerBasic's function, it can also be coded as:

    IF BIT(Cnn%, note% MOD 12) THEN

    ...

    ENDIF


    FUNCTION Cnr2Ctp&(c%, n%)

    Use:

    Ctype&= Cnr2Ctp& (Cnn%, Tc%)

    This function returns a unique number describing the chord completely in terms of its intervals relative to the tonal center. The number of bytes returned corresponds to the number of notes in the chord. Each hexadecimal byte represents the interval (0 - B, or, 0 to 11 in decimal) of a note in the chord as seen from the tonal center. The value for Tc% given as a parameter may be different than the value as written into the input chordnumbers' high nibble. Obviously the result will be different for different values of Tc%. (Tonal Center). Tc% should be specified as a note number 0-11. If the context makes tone-center analysis irrelevant, you can set Tc% to -1. This equals to taking midi note 12 (C) as reference.
    The the function can be used to find a tonal center from where the given chord gets specific properties. This function is essential if you want to use any procedure contained in the module HARM_ANA, covered in section 2 of this users manual.
    Since the long-integer format is limited to 8 bytes, we designed the function such as to return a numeric value with a different meaning for chords consisting of more than 7 notes. In those case the function will return the chord-complement (the notes missing in the chord given to make it a complete chromatic cluster). To make this clear to the user, the function will set the highest bit in trhe number returned. So determining such cases can simply be done by checking the highest bit (AND with &H80000000) or by looking at the sign of the number in decimal. If the number is negative, the chord is given as a complement chord.
    Note that the following is always valid for non-zero numbers contained in chordtypes:

    lsb... msb

    b0 < b1 < b2 < b3 < b4 < b5 < b6 < b7 < b8

    The only byte that can ever be 0 is always b0. The smallest possible value for b1 hence must be 1 etcetera. If a higher ordered byte is set to 0, the number must be negative and representing a complement-chord.
    The list below gives some numeric examples for different parameters and their return values.

    cnr%= (2^0) + (2^4) + (2^7) ' this makes a C-E-G major chord

    tp&= Cnr2Ctp&(cnr%,0) ' ask the chordtype as seen from the tonal center C

    MSGBOX HEX$(tp&)

    now the program will display the number 740, as will be seen from the following table:

    msb lsb

    b7 b6 b5 b4 b3 b2 b1 b0

    - - - - - 7 4 0 C - E - G on C

    However, if we now change the tonal center to Tc%= 7 and ask the chordtype again, the function will return the hexadecimal number 950, since this chord can be constructed as:

    Tc% + 0 (G)

    Tc% + 5 (C)

    Tc% + 9 (E)

    Suppose now we would feed the function a diatonic cluster (C-D-E-F-G-A-B) and set Tc% to 0. We get the following result after PRINT HEX$(tp&): B975420, corresponding to:

    msb lsb

    b7 b6 b5 b4 b3 b2 b1 b0

    - B 9 7 5 4 2 0 diatonic cluster

    Suppose, to give an example for a complement-chordtype, we feed the function with

    crn%= MakeChordNumber%(1,2,3,5,6,8,9,10,11,0,0,0) the following result should be expected:

    tp& = &H80000740

    This corresponds to the missing chord in crn% for making it a complete cluster. It is the same result as in out first example, but the highest bit is now set. In principle feeding the function with a zero-chord should be an illegal condition. Instead of returning a arror message, be decided to let the function return Tc% if set, and otherwise 0. The other exception happens when we feed the function a full cluster. In this case it will return &H80000000.

    FUNCTION Ctp2Cnr% (Ct&, tc%)

    Use:

    Cnn% = Ctp2Cnr% (Ctype&, Tc%)

    This function is the functional complement of the previous one (Cnr2Ctp&()). So it makes it possible for the user to build chords in a relative way, i.e. to build them to a relative tonal center of his/her liking.


    FUNCTION GetScaleCnr% (modus%, Tc%)

    Use:

    Cnn% = GetScaleCnr%( modenumber%, Tonic%)

    This function returns in the format of a chordnumber, all notes belonging to a musical scale as specified by the value set in Tonic% as well as by the parameter transferred in modenumber. For this mode-support the library knows the following 12 scale modes:

    Mode number name intervalstructure nrnotes chordnumber
    0 major 0-2-4-5-7-9-11 7 2741
    1 minor 0-2-3-5-7-8-11 7 2477
    2 minor old 0-2-3-5-7-8-10 7 1453
    3 minor melodic 0-2-3-5-7-9-11 7 2733
    4 symmetric 1 0-1-3-5-7-9-11 7 2731
    5 symmetric 2 0-1-3-5-6-7-9-11 8 2795
    6 g1 0-1-3-6-7-8-11 7 2507
    7 g2 0-1-3-5-7-8-11 7 2475
    8 wholetone 0-2-4-6-8-10 6 1365
    9 3 semitone 0-3-6-9 4 585
    10 pentatonic 0-2-5-7-9 5 677
    11 chromatic 0 1 2 3 4 5 6 7 8 9 10 11 12 4095

    The data for these modes reside in declared constants in the library and they cannot be changed by the user unless he changes the constants and recompiles the libraries.

    The function makes it easy for the programmer to check the validity of note-values against a parameterized tone-system. As will be seen later, we also implemented different types of chordbuilding (so, not only based on juxtaposition of thirds but also on seconds or fourths as chord-building structure). To that purpose we introduced a harmonytype parameter . 


    Bit pattern shifting utilities:

    These functions come in handy when it comes to finding chord-patterns in chordnumbers by rotation of the pattern. We provided the following pair of functions:


    FUNCTION Rol%(i%,j%)

    FUNCTION Ror%(i%,j%)

    Use:

    These function return de chordnumber, with the bit pattern in the lowest 12 bit-position shifted left (Rol) or right (Ror) a number of bits represented by n%. The overflow bit is always carried to the other side of the number. The function can be used to shift bits in its own argument:

  • Cnn% = Rol%(Cnn%, n%)
  • The function is very suitable for musical transposition and modulation.The function does not change any bits in the highest nibble of chordnumber. It preserves the setting for the tone-center. When n% = 0, nothing happens to the argument and the output value will be the argument. n% should not be negative. Use Ror and Rol instead for rotations to the right and to the left.

    These functions can be used as general equivalents for exponentiations of the number 2, however, they are not faster. Following statements are functionally equivalent for values of n% between 0 and 11:

  • d% = 2 ^ n% and d% = Rol%(1,n%)

  • FUNCTION Neg%(i%)

    Use:

    Cnn% = Neg%(Cnn%)

    This function inverts all note bits in the argument. It does not change the high nibble. It can be used to know the notes that are not present in the chord given in the argument. It comes in handy for chords consisting of more than seven notes. It than returns a value for the chordnumber of the missing chord.

    Code example:

    chord%= Make4ChordNum% (60,64,67,70)

    negchord% = Neg%(chord%)

    ' negchord% will now contain the notes 1,2,3,5,6,8,9,11

    chord% = Neg%(negchord%)

    ' now chord% will again contain 0,4,7,10


    Chord Mathematics:

    FUNCTION AddChords% (Crd1%, Crd2%)

    Use:

    Cnn% = AddChords% (Cn1%, Cn2%)

    This function adds to notes from two chordnumbers to form a new combined chord. If the Tc% nibble was set in both chords, the tonality setting from the first chordnumber passed will be retained. If only the second chord has a tonality nibble set, this will be returned. In no tonality nibble was set in either chord, the result will have no setting in the tonality nibble (-1, or &HFxxx) .If the output of the function equals the arguments, the arguments where identical. If the output contains the same number of notes as one of the arguments, one of the chords in the argument was already contained in the other.


    FUNCTION DifChords% (Crd1%, Crd2%)

    Use:

    Cnn% = DifChords% (Cn1%, Cn2%)

    This function returns only the notes that make up the difference between both chords passed to it as arguments.

    Example: Do - Mi - Sol and Do - Fa - La would give an output of Mi - Sol - Fa - La.

    To get only the common notes, use the function ComChords%(). To get the sum of two chords, use the function AddChords%() 


    FUNCTION ComChords% (Crd1%, Crd2%)

    Use:

    Cnn% = ComChords% (Cn1%, Cn2%)

    This function returns a chord that consists only of the notes that the chords given as arguments have in common. The setting of the tonality in Crd1%, if set, is kept in the result. If no tonality was set in Crd1%, than the function will return the value of Crd2%. If no tonality was set in either of the arguments, no tonality nibble will be set in the result.


    FUNCTION MirCnr% (Crd%, n%)

    Use:

    Cnn% = MirCnr% (Crd%, note%)

    This function returns the mirror of a chord. The reference note for the interval mirroring operation should be passed in the parameter note%. If the value for note% is negative (or the constant True, i.e. -1) the reference will be taken to be the tonal center as set in the high nibble of the chordnumber. If this nibble is set to atonal, C will be taken as a mirroring reference. The parameter for note%, if positive, should be a midi note number. (0-127).

    Example:

    SCREEN 12: WIDTH 80, 60 ' needed for HARM_VIZ library

    Crn% = Make3ChordNum%(12, 4, 7): ' notes C-E-G

    ShowLargeStaff Crn%, 15, 15 :' to show the input chord

    Cr2% = MirCnr%(Crn%, 0) ' calls the function

    ShowLargeStaff Cr2%, 15, 45 ' shows the result

    In this example the chord returned will contain the notes C-F-Ab, the mirror chord of C-E-G versus C. Do not confuse this function with MirHar$(), operating on Harmony type variables only, but performing a similar function. 


    FUNCTION GetDissonance! (Crd%)

    Use:

    d! = GetDissonance! (Crd%)

    This function returns a value for the dissonance of a chord. The returned value is normalized and thus returns a value between 0 and 1. The 1 value can only be achieved for a full chromatic cluster. The zero value will be achieved for chords consisting of fifths, fourths, thirds. All other intervals add to the dissonance value. If the tonality nibble is set in Crd%, notes in the chords that are not part of either the major or minor scale within the given tonality, will also add to the dissonance value returned. Note that the results returned by this function do not reflect an equal distribution. Neither is the distribution curve isomorphic with the curve for GetConsonance!().


    FUNCTION GetConsonance! (Crd%)

    Use:

    c! = GetConsonance! (Crd%)

    This function returns a normalized value (0-1) for the consonance of a chord. It is not a mathematical complement to the GetDissonance function. The function will return zero for the full chromatic cluster. In tonal contexts, any note not belonging to the major or minor scale will decrease the consonance value of the chord. Thus the consonance value returned will change according to the setting of the tonality nibble. If the chord given in the argument contains no notes, the function returns zero (false). If the chord contains a single note, it will return 1 if the tonality nibble is not set and when the tonality nibble is set, it will return 1 only for notes belonging to the major or minor scale. The value returned for notes not belonging to the scale will always be larger than 0 however. Note that the results returned by this function do not reflect an equal distribution. Neither is the distribution curve isomorphic with the curve for GetDissonance!().


    FUNCTION SameChord (BYVAL Cnr1 AS INTEGER, BYVAL Cnr2 AS INTEGER) AS WORD

    This function returns %True when Cnr1 and Cnr2 are isomorph chords. That is, if the chord passed in Cnr1 is a transposition in any key of the chord passed in Cnr2.


    ChordConstruction:

    FUNCTION MakeHarmChord% (Crd%, mode%, harmonytype%)

    Use:

    Cnn% = MakeHarmChord% (Crd%, modusnr%,htype%)

    Each time the function is called, the chordnumber passed to it will grow with a single interval after the chordbuildingrules set in htype%.

    Only the following values for htype% are acceptable:

    2 sets the chord construction basis for the harmony to seconds (belonging to the mode and scale specified)
    3 sets the chord construction basis for the harmony to traditional thirds (major and minor, as dictated by classical harmony)
    4 sets the chord construction basis for the harmony to fourths.

    The mode% parameter should be either a value 0-11 corresponding to the mode-constants integrated in these libraries or else, if a user wants to define a scale of his own, a chordnumber with all notes belonging to the scale he wants to use set in their respective bitpositions.

    If the chordnumber passed to the function cannot be a basis for a valid chord within the limits of the parameters as set, the function will always return an unmodified chord. This feature can be used to check syntactic validity of chords:

    Example:

    IF Cnn%= MakeHarmChord%(Cnn%, 0, 3) THEN Valid%= False

    Example:

    If you want to build a majortriad chord, starting from a given chordnumber, you could proceed as in the following example:

    IF GetNrNotes%(Crd%) < 3 THEN

    DO

    M3Crd%= MakeHarmChord%(Crd%, 0, 3)

    LOOP UNTIL GetNrNotes%(M3Crd%) = 3

    END IF

    The function will never return chords with altered notes. It is up to the user to get this result by either changing the mode accordingly, or by using one of the dim... or aug.. functions provided in this library.

    WARNING: This is not intended to be a 'classical' harmony function, although it will try to build triad-based chords if harmtype is set to the value 3 and the mode is set to some traditional scale. The strategy is such that the function will search through all tonal grades in the given mode within the chord in order to return a valid chord. So, it may well be that chords are build on the 7th grade. Also, if called in succession on its own return value, it will continue building until a maximum of 7 notes is reached . Above that number of notes in Crd%, the function will stop building and will return the chord passed to it unmodified.

    If no chord-building was possible, the function will always return its argument unmodified. 


    FUNCTION GetRndNote% (mode%, Tc%)

    Use:

    note% = GetRndNote% (mode%, tc%)

    This function returns a single random note (0 to 11) belonging to a musical scale determined by Tc% and mode%. If you want a random note in a pure atonal context (although in such a case, the algorithm note%= RND(1) * 11 is far more practical) using this function you should proceed as follows:

    note%= GetRndNote% (11,-1)

    The parameter specified in mode% follows the numbering convention specified above (cfr. Function GetScaleCnr%). This mode% parameter should be either a value 0-11 corresponding to the mode-constants integrated in these libraries or else, if a user wants to define a scale of his own, a chordnumber with all notes belonging to the scale he wants to use set in their respective bitpositions.

    To get a random note belonging to the scale of Eb Major, you use the function as follows:

    note%= GetRndNote% (0,3)

    Documentation on the preset modes available can be found in the documentation provided with the function GetScaleCnr%(). User-mode/scale chordnumbers can be easily constructing using the function MakeChordNum%(n1,n2,n3,n4,n5.n6,n7,n8,n9,n10,n11,n12).


    FUNCTION NxNt% (mode%, Tc%, note%, sign%)

    Use:

    sucnote%= NxNt%(2, 7, 67, +1)

    prevnote%= NxNt% (1, 7, 67, -1)

    This function returns the next or previous note belonging to the mode and the scale as specified in the parameters. The next note (higher) in the scale is returned if the sign% is positive and the previous note (lower) if sign% has a negative value. If the result would fall out of the acceptable midi range, the note given in the argument will be returned. The reference note should be passed in the parameter note%.

    Example:

    Snt%= NxNt% (0, 0, 65, 1)

    PRINT Snt%

    will print 67, since G is the note following F in the scale of C-major.

    Pnt%=NxNt%(0,0,65,-1)

    PRINT Pnt%

    will print 64, since E is the note preceding F in C-major.

    The following code will return a complete scale of F#-minor:

    ni%= 0

    DO

    ni%=no%

    no%= NxNt% ( 1,6,ni%,1)

    ' no% will step through the whole scale..

    LOOP UNTIL ni%=no%

    If mode is set to 11, chromatic scale, it is advisable not to use this function at all, since code as n%=n%+1 is a whole lot faster in such a case.

    The mode% parameter should be either a value 0-11 corresponding to the mode-constants integrated in these libraries or else, if a user wants to define a scale of his own, a chordnumber with all notes belonging to the scale he wants to use, set in their respective bitpositions. Documentation on the preset modes available can be found in the documentation provided with the function GetScaleCnr%(). User-mode/scale chordnumbers can be easily constructing using the function MakeChordNum%(n1,n2,n3,n4,n5.n6,n7,n8,n9,n10,n11,n12).


    FUNCTION DelNoteInChord% (Crd%, n%)

    Use:

    Cnn% = DelNoteInChord% (Crd%, n%)

    This functions removes a note passed in n% from the chordnumber passed in Crd% and returns the result in the function.


    Transposition of chords:

    FUNCTION TransChordNum% (Crd%, n%)

    Use:

    Cnn% = TransChordNum% (Crd%, n%)

    This function returns the argument Crd% transposed up n% number of semitones. If n%= 0 then the result equals the argument. If n% is positive, the function transposes upwards. If n% is negative it transposes downwards. The function does NOT change the nibble for the tonal center. Changing that nibble can be done using the function SetTc. This function combines the Rol% and Ror% functions in order to allow free bipolar transposition.


    FUNCTION TransChordType& (Ctype&, n%)

    Use:

    Ctp& = TransChordType& (Ctype&, n%)

    This function expects a long integer chordtype number in its argument and transposes this number n% semitones. The value for n% can be bipolar. The argument Ctype& should have been calculated with the function Cnr2Ctp&(Chordnumber%,Tc%). This function sofar only works for chords consisting of max. 7 notes... This bug still has to be solved.


    In time functions for harmony analysis:

    In these functions and procedures, the order in which the parameters are given plays a rule. The order is assumed to follow temporal ordering, the first parameter always being the 'oldest', the last one the most recent.


    FUNCTION Richt% (b1%, b2%)

    Use:

    r% = Richt% (note1%, note2%)

    Function returning the direction of an interval consisting of two succesive notes b1% and b2%. Possible values are +1 (ascending), -1 (descending) or 0 (iteration). The parameters must be valid midi-note numbers (7-bit, 0-127 values).


    FUNCTION Get3Kadens!(i%,j%,k%,l%)

    Use:

    b!= Get3Kadens!(Cn1%,Cn2%,Cn3%,Cn4%)

    The chordnumbers used as arguments must follow the chronological order. Cn4% must be the last chord. If the succession of chords meet the classical requirements, the function returns full 1: it recognised the sequence as a cadens. In all other cases it will return a value less than unity. This value can be considered a fuzzy value. Evaluation of the result is left to the user. The chordnumbers used as arguments must conform to the standard as laid out here. They can be calculated using one of the MakeChord-functions MakeChordNum%(), Make3ChordNum%(), Make4ChordNum%() etc.


    Functions for chordgeneration:

    FUNCTION VarChord%(crd%, modus%)

    Use:

    newchord% = VarChord%(crd%, modus%)

    This function changes one note in the chord given as argument. The changed note added will belong to the tonal system if the tonality nibble is set in crd%. The mode can be set using the mode% parameter. (cfr. the function GetScaleCnr%() ).The mode% parameter should be either a value 0-11 corresponding to the mode-constants integrated in these libraries or else, if a user wants to define a scale of his own, a chordnumber with all notes belonging the scale he wants to use set in their respective bitpositions.

    The function makes use of a fuzzy logic engine and may return different values for the same argument, if it is called more than once in a row. The chordnumber returned will contain the same number of notes as the given chord for chords up to 5 notes. If chords containing more than 5 notes are given, the function returns a chord containing one note less, such that the returned chord is less dissonant than the argument. This function is not a classical harmony function. If it is called many times in a row, the returned chords will form a series of chords with always decreasing dissonance. If there was no dissonance in the chord in the argument, the function will try to return an alternative chord with no dissonance in the same tone system. Only if the algorithm could not construct an alternate chord with zero dissonance, it may return a chord with some dissonance. This function is NOT an academic harmony function.

    Warning: because of the nature of the algorithm, the function spends a variable amount of time executing. This time (average measured over all possible argument chords and tonality settings is less than 1 ms on a Pentium processor) is not only dependent on the complexity of the argument chord, but also on the history of the function and previous values returned.


    FUNCTION ParaChord% (t%, p1!, p2!, tl!)

    Use:

    Crd% = ParaChord% (tonality%, dissonancevalue!, consonancevalue!, tolerance!)

    This is a parameterized chordbuilding function. The first argument is the value for the tonality setting. If no tonality setting is required, set this parameter to -1. All other midi-note values are acceptable. The second parameter must be a normalized value for the maximum allowed dissonance of the chord. The third parameter must be a normalized value for the minimum amount of consonance required in the chord. Both these parameters must be in the range 0 to 1. The function will try to return a chord with a variable number of notes, being the minimum or maximum number of notes required to fullfill the boundaries set in the parameters. The last argument, tolerance, is the normalized value for the amount of deviation allowed in the result. Note that this function will start searching for a return value from the tolerance value given. If the conditions within these fault margins could not be fullfilled, it will adjust the tolerance value internally. This was done in order to guarantee that the function would always return a value. It is left to the user to accept or reject the value returned.

    REMARK:

    1.- This function performs rather slow and may not be very usefull in a real-time context.
    2.- Different calls to the same function will yield different results. However, the function is not a chance-function or a monte-carlo engine. Internally it always looks through all possible chords and returns the first one it finds that fullfills the conditions. In order to make the function less redundant, we decided to build it in such a way that it will always start its search through possible chords, with a different chordnumber from the gamut. Hence this result.

    FUNCTION ParDisChord% (t%, p1!, tl!)

    Use:

    Crd% = ParDisChord% (tonality%, dissonancevalue!, tolerance!)

    This is a parameterized chordbuilding function. The first argument is the value for the tonality setting. If no tonality setting is required, set this parameter to -1. All other midi-note values are acceptable. The second parameter must be a normalized value for the maximum allowed dissonance of the chord.

    The function will try to return a chord with a variable number of notes, being the number of notes required to fullfill the boundaries set in the parameters. The minimum number of notes returned will be 3. The last argument, tolerance, is the normalized value for the amount of deviation allowed in the result. Note that this function will start searching for a return value from the tolerance value given. If the conditions within these fault margins could not be fullfilled, it will adjust the tolerance value internally. For tolerance values not less than 0.05, internal adjustments are never needed.

    REMARK: cfr. ParaChord%(). However this function performs about three times faster.


    FUNCTION ParConChord% (t%, p1!, tl!)

    Use:

    Crd% = ParDisChord% (tonality%, consononcevalue!, tolerance!)

    This is a parameterized chordbuilding function. The first argument is the value for the tonality setting. If no tonality setting is required, set this parameter to -1. All other midi-note values are acceptable. The second parameter must be a normalized value for the minimum required consonance of the chord. The function will try to return a chord with a variable number of notes, being the number of notes required to fullfill the boundaries set in the parameters. The minimum number of notes returned will be 3, since a consonance value of 1 can be realized using triads. The last argument, tolerance, is the normalized value for the amount of deviation allowed in the result. Note that this function will start searching for a return value from the tolerance value given. If the conditions within these fault margins could not be fullfilled, it will adjust the tolerance value internally. For tolerance values not less than 0.1, internal adjustments are never needed.

    REMARK: cfr. ParaChord (). However this function performs about four times faster.


    FUNCTION SolveCnr (BYVAL Cnr AS INTEGER, BYVAL tc AS INTEGER) AS INTEGER

    Use:

    Crd% = SolveCnr (chordnumber, tonal_center)

    This function attemps to find a solution for the chord passed in Cnr. If you pass a value for tc, the function will try to return a solution oriented towards the tonic implied by this value. If you pass -1 for tc, the solve algorithm will search for any possible solution.

    Filedate: 960320/ last update:2004-11-02

    To: <Index-Harmlib> complete gmt language reference. link to homepage dr.Godfried-Willem RAES EXIT composition software website