Index
HarmonisedScore
DB
HSScore
Rules
DBs
Distro
HS
Schoenberg
Default
Jazz
Partch
Johnston
Harrison
Chalmers
Catler
ArithmeticalSeriesChords
Functor defines data abstraction for a user-defined database of settings like chord and scale structures which are used by the contribution HarmonisedScore. See SetDB of further details.

Functor

Import

Export

Define

proc{SetDB NewDB}
Sets the database which is used by the HarmonisedScore contribution (e.g., its music representation and rules).
The syntax of the database is
<DB> ==:: unit([chordDB:<PCGroupDB>]
[scaleDB:<PCGroupDB>]
[intervalDB:<IntervalDB>]
[pitchesPerOctave:<PitchesPerOctave>]
[accidentalOffset:<AccidentalOffset>]
[octaveDomain:<OctaveDomain>])
<PCGroupDB> ==:: unit(<PCGroupEntry>+)
<PCGroupEntry> ==:: unit(pitchClasses:<IntList>
roots:<IntList>
[<FeatureValuePair>*]
[comment:<Value>])
<IntervalDB> ==:: unit([<FeatureValuePair>+]
[comment:<Value>])
<PitchesPerOctave> ==:: <Int>
<AccidentalOffset> ==:: <Int>
<OctaveDomain> ==:: <Int>#<Int>

All features of the DB and also of some sub-DBs (e.g. of the chordDB and scaleDB) are optional (as marked by square brackets). Missing features are set to the features of the default database (HS.dbs.default). However, in case PitchesPerOctave \= 12, then the following features are mandatory: chordDB, scaleDB and intervalDB.
Note the above doc is unfinished: for further details read the doc of the aux accessors (available in the source file contributions/anders/HarmonisedScore/source/Database.oz).

'comment' feature of database entries: is either a single value (usually an atom) or a record.
Naming database entries: either by an atom given to the 'comment' feature of a database, or an atom given to the 'name' feature of the record at the 'comment' feature, or -- for multiple alternative names -- a list of atoms given to the 'name' feature of the record at the 'comment' feature.

TODO: write a better doc..


fun{GetEditChordDB }
fun{GetInternalChordDB }
fun{GetEditScaleDB }
fun{GetInternalScaleDB }
fun{GetEditIntervalDB }
fun{GetInternalIntervalDB }
fun{GetPitchesPerOctave }
fun{GetPitchUnit }
fun{GetAccidentalOffset }
fun{GetOctaveDomain }
fun{MakePitchClassFDInt }
Return a FD integer representing a pitch class (range defined by PitchesPerOctave).


fun{MakeOctaveFDInt }
Return a FD integer representing an octave (range OctaveDomain).


fun{MakeAccidentalFDInt }
Return a FD integer representing an accidental (range 0#AccidentalOffset*2).


fun{MakeScaleDegreeFDInt }
Returns a FD integer representing a scale degree (range 1#MaxScaleLength).


fun{MakeChordDegreeFDInt }
Returns a FD integer representing a chord degree (range 1#MaxChordLength).


proc{RatiosInDBEntryToPCs MyDBEntry KeysPerOctave Out}
Processes an entry for a HS database (e.g. for a chord database). HS depends on pitches as keynumbers and pitch classes (all represented by integers or FD ints), both depending on KeysPerOctave. RatiosInDBEntryToPCs, on the other hand, permits also ratios (floats or fractions specs) which are transformed and rounded to the nearest pitch class (a ratio representing an interval exceeding an octave is transformed into an interval within an octave).
MyDBEntry is a record with arbitrary features. Each feature value is either an interger, a list of integers, a ratio spec (either a float or a fraction spec in the form <Int>#<Int>), or a list of ratio specs. The output contains each integer/lists of integers unchanged but substitutes each ratio/list of ratios by the nearest pitch class interval (an integer), depending on KeysPerOctave (an integer).
Additionally, a comment feature in MyDBEntry with arbitrary value is permitted. The returned record has always a comment feature with a record as value. The explanation of the comment in the return value is a bit complicated and depends on MyDBEntry. For features in MyDBEntry with a ratio, collect in comment the ratio, its pitch class plus the error, for other features in Test keep the orig value. In case MyDBEntry contains a feature comment as well, this value is preserved: in case MyDBEntry.comment is a record as well, its features are added to the comment record of the result. However, in case MyDBEntry.comment contains a feature 'comment' with the same feature as a feature in MyDBEntry itself, then the feature of MyDBEntry.comment is preferred. See the test file for examples.
Because the comment feature of the returned DB entry is changed, the function WasRatiosDBEntry recognises a DB entry processed by RatiosInDBEntryToPCs.

NB: in HS.db, an OctaveDomain is also specified as <Int>#<Int>, but must not be mixed up with a fraction spec.


BUG: reported error signs not correct -- check JI signs (you know what to expect..)


fun{WasRatiosDBEntry MyDBEntry}
Returns true if MyDBEntry was processed by RatiosInDBEntryToPCs.


fun{Pc2Ratios PC IntervalDB}
Returns a list of all ratios which match PC (an int) in IntervalDB (given in its edit form) which was defined using ratios (e.g. {HS.dbs.partch.getIntervals {HS.db.getPitchesPerOctave}}).
A ratio consists in two integers and has the form Nom#Denom. If no entry in the database matches PC, nil is returned.

Two examples:
{PC2Ratios 9 {HS.dbs.partch.getIntervals 12}}
{PC2Ratios 53 {HS.dbs.partch.getIntervals 72}}

NB: Pc2Ratios is a deterministic function and no constraint.


fun{GetChordIndex MyName}
Convenience functions. ChordIndex expects a name (atom) for a chord and returns the corresponding index. This name is either the value stored under the edit database feature 'comment', or the value of a feature 'name' of a record stored under the edit database feature 'comment'. If no database entry with this name is defined, then nil is returned.
ScaleIndex and IntervalIndex do the same for scales and intervals.


fun{GetScaleIndex MyName}
fun{GetIntervalIndex MyName}
fun{GetComment X}
Expects a chord, scale or interval object and returns the comment value in its internal database format.
Blocks until the index parameter is determined.


fun{GetName X}
Returns the name of a chord, scale or interval specified in its database entry (a VS, usually an atom). The name is a list of atoms (its a list because there are sometimes multiple name alternatives). Returns nil if no name was found.
Blocks until the index parameter is determined.

The name is often specified as an atom at the 'comment' feature of a database entry. Alternatively, the entry defines a record at the 'comment' feature, and then the name is and atom at the feature 'name' in this subrecord, or a list of atoms at the feature 'name' (for specifying multiple alternative names).


fun{GetUntransposedRatios X}
Returns the ratios specs by which X (chord or scale object) is declared in the database. If X was declared by pitch classes instead and thus no ratios are available then nil is returned.


fun{GetUntransposedRootRatio X}
Returns the ratio specs by which the roots of X (chord or scale object) are declared in the database. If the root was declared by a pitch class instead and thus no ratio is available then nil is returned.


fun{GetUntransposedRootRatio_Float X}
Returns the frequency ratio of the [first] root of X (chord or scale object) as a float. For example, if the ratio 1#1 or the pitch class 0 is declared as root, then 1.0 is returned; it it is 3#2 then 1.5 is returned.

NB: blocks until root and transposition of X are determined.


End