Skip to content

Latest commit

 

History

History
1565 lines (972 loc) · 52.7 KB

API.md

File metadata and controls

1565 lines (972 loc) · 52.7 KB

Cadd9

Contents

Accidental type

Namespace

Cadd9.Model

Summary

Represents an accidental that shifts some note or pitch by a certain number of semitones away from natural.

#ctor(semitones) constructor

Summary

Returns a new Accidental

Parameters
Name Type Description
semitones System.Int32 The number of semitones this accidental shifts a pitch or note

Description property

Summary

A formatted representation of this Accidental as a UTF-8 string.

Semitones property

Summary

The number of semitones this accidental shifts a pitch or note. Positive values indicate sharps, negative values indicate flats.

Enharmonic(other) method

Summary

Returns true if other is enharmonic with this Accidental.

Parameters
Name Type Description
other Cadd9.Model.Accidental The Accidental to compare with
Remarks

Two accidentals are enharmonic if they are equal or if their Semitones differ by an even multiple of 12. For example 5 sharps is enharmonic with 7 flats: C♯♯♯♯♯ and C♭♭♭♭♭♭♭ are both enharmonic with each other and with F natural.

Equals(other) method

Summary

Determines whether two Accidentals are value-equivalent

Parameters
Name Type Description
other Cadd9.Model.Accidental The Accidental to compare

GetHashCode() method

Summary

Produces a high-entropy hash code such that two value-equivalent Accidentals are guaranteed to produce the same result.

Parameters

This method has no parameters.

Parse(input) method

Summary

Returns a new Accidental based on the given input string.

Parameters
Name Type Description
input System.String The plain ASCII input string to parse
Exceptions
Name Description
System.FormatException The given input cannot be parsed
Remarks

Assumes the input will be in plain ASCII: "b" for flats and "#" for sharps. An empty string or the string "nat" may be used for natural.

ToString() method

Summary

Returns a string representation of this Accidental, primarily for debugging purposes.

Parameters

This method has no parameters.

Alteration type

Namespace

Cadd9.Model.Quality

Summary

Encapsulates an alteration of a chord quality, by dropping, adding, or replacing some intervals.

#ctor() constructor

Summary

Returns a new Alteration

Parameters

This constructor has no parameters.

Add property

Summary

The interval that is added as part of this modification, or null if nothing is added.

Drop property

Summary

The generic interval to be removed by this modification, or null if nothing is removed.

Constants type

Namespace

Cadd9.Model

Summary

Defines several frequently-used music theory constants.

MIDDLE_C_MIDI_NUMBER constants

Summary

The MIDI note number corresponding to middle C

Remarks

This is not a universal definition. In fact as far as the MIDI standard is concerned, the note numbers are not strictly related to any musical pitches. They are simply a set of 127 sequential numbers that can be turned on and off with control messages. But 60 is used by most device manufacturers.

MIDDLE_C_OCTAVE constants

Summary

The octave number of middle C

Remarks

There is no universal definition: middle C is also sometimes labeled as C3.

NAMES_PER_OCTAVE constants

Summary

The number of note names per octave

Remarks

Western tonal music is built around the diatonic scale, which is a heptatonic scale (containing seven tones) arranged so there are 2 half-steps (single semitone) and 5 whole-steps (two semitones) separating each. The arrangement of steps and half-steps determines the Mode of the scale.

SEMITONES_PER_OCTAVE constants

Summary

The number of semitones per octave

Remarks

In Western tonal music using equal temperament, an octave is a doubling of frequency, and it is further subdivided into 12 semitones where each is in a 2^(1/12):1 ratio with the one before it.

EnumerableExtensions type

Namespace

Cadd9.Util

Summary

Adds useful extension methods to IEnumerable`1

EveryN``1() method

Summary

Returns the first element in the input and every Nth afterward.

Parameters

This method has no parameters.

Example

This example demonstrates how to use EveryN``1 to take every Nth element of a range.

  var result = Enumerable.Range(1, 10).EveryN(3);
  foreach (var num in result)
  {
      Console.WriteLine(num);
  }
  // This produces: 1, 4, 7, 10

Generic type

Namespace

Cadd9.Model.Interval

Summary

Represents a generic interval between two notes or pitches independent of semitone width

Remarks

For instance, the generic interval between any F and any A is always a third. From F to A♯ is an augmented third (5 semitones), and from F to A♭ is a minor third (3 semitones) but the generic interval is always a third. In other words, this is the number of note names shifted from the bottom to top of the interval.

IntExtensions type

Namespace

Cadd9.Util

Summary

Adds extension methods for some useful integer math

Demodulus() method

Summary

Returns the integer congruent to operand (mod modulus) with smallest absolute value.

Parameters

This method has no parameters.

Remarks

The range of this method is [-modulus/2, modulus/2) -- basically the goal is to return an integer that is modulo-congruent with operand but is as close as possible to zero. Primarily this is used to simplify accidentals as much as possible: if we have 11 sharps, a more ideal (and enharmonic) accidental would be one flat, represented as -1 and congruent to 11 (mod 12).

Modulus() method

Summary

Returns the value of operand mod modulus

Parameters

This method has no parameters.

Remarks

Formally this method returns the least non-negative integer N such that operand ≡ N (mod modulus). It differs from C#'s % operator in its treatment of negative values: -1 % 7 == -1 while -1.Modulus(7) == 6.

Ordinal() method

Summary

Returns a string representation of an integer in ordinal form

Parameters

This method has no parameters.

Interval type

Namespace

Cadd9.Model

Summary

Represents a musical width between notes or pitches.

#ctor(genericWidth,specificWidth) constructor

Summary

Creates an Interval with the given generic and specific widths.

Parameters
Name Type Description
genericWidth Cadd9.Model.Interval.Generic The number of note names spanned by the interval
specificWidth System.Int32 The number of semitones spanned by the interval

Abbreviation property

Summary

A short formatted description of the interval, like "P4"

Description property

Summary

A long-form formatted description of the interval, like "Perfect Fourth"

GenericWidth property

Summary

The generic width of this Interval, in other words, the difference in note names from bottom to top.

SpecificWidth property

Summary

The specific width of this Interval, in other words, the semitones shifted between the bottom and top.

Between(bottom,top) method

Summary

Returns a new Interval representing the width between two Names.

Parameters
Name Type Description
bottom Cadd9.Model.Name The lower Name to compare
top Cadd9.Model.Name The higher Name to compare
Remarks

It is always assumed that the interval is going up from first to second: C to B would give an interval of a major seventh (despite being much closer to go down a minor second). Also for this reason, this method will always produce an interval between unison (inclusive) and an octave (exclusive).

Between(bottom,top) method

Summary

Returns a new Interval representing the width between two Notes.

Parameters
Name Type Description
bottom Cadd9.Model.Note The lower Note to compare
top Cadd9.Model.Note The higher Note to compare
Remarks

It is always assumed that the interval is going up from first to second: C♯ to B would give an interval of a minor seventh (despite being much closer to go down a major second). Also for this reason, this method will always produce an interval between unison (inclusive) and an octave (exclusive).

Between(bottom,top) method

Summary

Returns a new Interval representing the width between two Pitches.

Parameters
Name Type Description
bottom Cadd9.Model.Pitch The lower Pitch to compare
top Cadd9.Model.Pitch The higher Pitch to compare
Remarks

It is always assumed that the interval is going up from first to second: C♯3 to B4 would give an interval of a minor fifteenth.

Enharmonic(other) method

Summary

Returns true if other is enharmonically equivalent to this interval.

Parameters
Name Type Description
other Cadd9.Model.Interval The other Interval to compare
Remarks

Two intervals are enharmonic if they have the same specific width. Perfect unison and diminished second, for example, are enharmonic despite having different generic widths.

Equals(other) method

Summary

Determines whether two Intervals are value-equivalent

Parameters
Name Type Description
other Cadd9.Model.Interval The Intervals to compare

GenericName() method

Summary

Returns the name of the given generic width

Parameters

This method has no parameters.

GetHashCode() method

Summary

Produces a high-entropy hash code such that two value-equivalent Intervals are guaranteed to produce the same result.

Parameters

This method has no parameters.

Parse(input) method

Summary

Returns a new Interval by parsing the given string input.

Parameters
Name Type Description
input System.String The input to parse
Exceptions
Name Description
System.FormatException The given input cannot be parsed
System.ArgumentException If an illegal modifier is supplied for the interval
Remarks

Two formats are accepted: Formal, like P4 and d3, or simple, like b5 and #9. If the simple form is used, then the major/perfect matching interval is sharped the given number of times. The formal form understands (P)erfect, (d)iminished, (m)inor, (M)ajor, and (A)ugmented descriptors for each interval as appropriate.

ParseFormal() method

Summary

Parses the given input using "formal" notation, or null if it cannot be parsed accordingly

Parameters

This method has no parameters.

Exceptions
Name Description
System.ArgumentException If an illegal modifier is supplied for the interval
Remarks

"Formal" notation indicates "P4" for a perfect fourth, "m3" for a minor third, etc.

ParseSimple() method

Summary

Parses the given input using "simple" notation, or returns null if it cannot be parsed accordingly

Parameters

This method has no parameters.

Remarks

This notation uses "3" for a major third, "b5" for a flat fifth, etc. Commonly used to describe the component intervals of chords.

ReducedGenericWidth() method

Summary

Returns the generic width from unison to seventh that is enharmonic with the given generic width

Parameters

This method has no parameters.

ToString() method

Summary

A string representation of this Interval, useful for debugging.

Parameters

This method has no parameters.

op_Addition() method

Summary

Creates a new compound Interval by combining two others.

Parameters

This method has no parameters.

Remarks

For example, adding together a perfect octave and a perfect fifth produces a perfect thirteenth.

op_Subtraction() method

Summary

Creates a new compound Interval by subtracting one from the other.

Parameters

This method has no parameters.

Remarks

For example, subtracting a minor second from a perfect octave produces a major seventh.

Mode type

Namespace

Cadd9.Model

Summary

Represents a musical mode based on its component intervals.

#ctor(title,intervals) constructor

Summary

Returns a new Mode

Parameters
Name Type Description
title System.String The title of this Mode
intervals Cadd9.Model.Interval[] The intervals that make up this Mode
Exceptions
Name Description
System.ArgumentException Thrown if a generic interval appears multiple times

#ctor(title,intervals) constructor

Summary

Returns a new Mode

Parameters
Name Type Description
title System.String The title of this Mode
intervals System.String[] String representations of the intervals that make up this Mode
Exceptions
Name Description
System.ArgumentException Thrown if the given intervals do not feature every generic interval 0-6 exactly once
Remarks

The intervals given in this constructor will be parsed according to the behavior in Parse which allows short-hand construction.

Intervals property

Summary

A set of all the Intervals that make up this Mode

Remarks

Title property

Summary

A descriptive title of this Mode

AccidentalFor() method

Summary

Yields the Accidental associated with a given name for a given key.

Parameters

This method has no parameters.

Remarks

This may be used, for example, to place sharps and flats on a staff given a particular key. In the D major (Ionian) key, F and C have a sharp accidental while all other names are natural. This may also be used to determine how to render a note: if its accidental is the same as the accidental for its name in the key, no symbol need be added.

Ascend() method

Summary

Yields every Interval in this mode starting from unison.

Parameters

This method has no parameters.

Remarks

Will progress infinitely, so take only what is needed.

DiatonicChord(degree,count) method

Summary

Returns a chord based on stacked thirds from the given scale degree of this mode.

Parameters
Name Type Description
degree Cadd9.Model.Degree The scale degree to use as the root
count System.Int32 The number of notes to return (3 = triad, 4 = 7th, 5 = 9th, etc) (min 3)
Exceptions
Name Description
System.ArgumentException If degree or width are out of bounds
Remarks

Each mode has 7 scale degrees that produce 7 signature chord qualities. For example, the major (Ionian) mode's fourth scale degree (iv) is a minor triad, while the Phrygian mode's fifth scale degree (v°) is a diminished triad.

Important note: the value of degree is treated starting at zero.

Equals(other) method

Summary

Determines whether two Modes are value-equivalent.

Parameters
Name Type Description
other Cadd9.Model.Mode The other Mode to compare

GetHashCode() method

Summary

Produces a high-entropy hash code such that two value-equivalent Modes are guaranteed to produce the same result.

Parameters

This method has no parameters.

Scale() method

Summary

Yields every Note in this mode starting from the given tonic.

Parameters

This method has no parameters.

Remarks

Will progress infinitely, so take only what is needed.

Scale() method

Summary

Yields every Pitch in this mode starting from the given tonic.

Parameters

This method has no parameters.

Remarks

Will progress infinitely, so take only what is needed.

ToString() method

Summary

A string representation of this Mode, useful for debugging.

Parameters

This method has no parameters.

Name type

Namespace

Cadd9.Model

Summary

An enumeration of the seven note Names used in Western tonal music.

Note type

Namespace

Cadd9.Model

Summary

Represents a note Name with an associated modifying Accidental.

#ctor(name,accidental) constructor

Summary

Returns a new Note

Parameters
Name Type Description
name Cadd9.Model.Name The Name associated with this Note
accidental Cadd9.Model.Accidental The Accidental modifying this Note

Accidental property

Summary

The Accidental modifying this Note

Description property

Summary

A formatted representation of this Note as a UTF-8 string.

Name property

Summary

The Name associated with this Note

PitchClass property

Summary

The pitch class (0 to 11) of this Note.

Remarks

The concept of pitch class is often used in post-tonal music to describe pitches without being based in any given heptatonic scale. C is equivalent to a pitch class of 0, and each pitch class going up is separated by a semitone. All Notes that are enharmonic by definition have the same pitch class.

Apply(interval) method

Summary

Produces a new Note by applying the given Interval.

Parameters
Name Type Description
interval Cadd9.Model.Interval The width between the current Note and the new Note to be generated.

Enharmonic(other) method

Summary

Determines whether two Notes are enharmonically equivalent

Parameters
Name Type Description
other Cadd9.Model.Note The other Note to compare
Remarks

Two Notes are enharmonic if they map to the same key on a keyboard: for example, while D♯ and E♭ are distinct notes that play different musical roles, they are enharmonic.

Equals(other) method

Summary

Determines whether two Notes are value-equivalent

Parameters
Name Type Description
other Cadd9.Model.Note The other Note to compare

GetHashCode() method

Summary

Produces a high-entropy hash code such that two value-equivalent Notes are guaranteed to produce the same result.

Parameters

This method has no parameters.

Parse(input) method

Summary

Parses the given input as a Note

Parameters
Name Type Description
input System.String The input to parse
Exceptions
Name Description
System.FormatException The given input cannot be parsed
Remarks

The input is treated as case-insensitive. The first character is parsed as a Name while the rest is parsed according to Parse. Examples of valid Notes would include "B", "Ebb", "c#"

ToString() method

Summary

Returns a string representation of this Note, primarily for debugging purposes.

Parameters

This method has no parameters.

ParseHelpers type

Namespace

Cadd9.Util

Summary

Contains helper methods to parse notes, pitches, and intervals

N() method

Summary

Parses the given input as a Note

Parameters

This method has no parameters.

P() method

Summary

Parses the given input as a Pitch

Parameters

This method has no parameters.

W() method

Summary

Parses the given input as an Interval

Parameters

This method has no parameters.

Remarks

The letter W (for Width) is used instead of I to prevent collision with I when both are statically included in the same file.

Pitch type

Namespace

Cadd9.Model

Summary

A particular musical pitch achieved by playing a Note in a particular octave

#ctor(note,octave) constructor

Summary

Returns a new Pitch

Parameters
Name Type Description
note Cadd9.Model.Note The Note to represent this Pitch
octave System.Int32 The octave corresponding to this Pitch

#ctor(name,accidental,octave) constructor

Summary

Returns a new Pitch

Parameters
Name Type Description
name Cadd9.Model.Name The Name of this Pitch's Note
accidental Cadd9.Model.Accidental The Accidental of this Pitch's Note
octave System.Int32 The octave corresponding to this Pitch

Description property

Summary

A formatted representation of this Pitch as a UTF-8 string.

Midi property

Summary

The MIDI note number associated with this Pitch

Remarks

Though there is no universal standard for what octave represents middle-C, we treat C-4 as middle C, with the MIDI note number 60.

Note property

Summary

The Note represented by this Pitch

Octave property

Summary

The octave corresponding to this Pitch, where middle C = C4

Apply(interval) method

Summary

Produces a new (higher) Pitch by applying the given Interval.

Parameters
Name Type Description
interval Cadd9.Model.Interval The Interval between this and the new Pitch
Remarks

The Note Name will be incremented by interval.Generic, while the pitch will be incremented by interval.Specific (in semitones). The new Accidental will be set as appropriate to achieve this pitch.

DescribeInKey(key,signature) method

Summary

A formatted representation of this Pitch as a UTF-8 string in the given key.

Parameters
Name Type Description
key Cadd9.Model.Note The tonic of the key
signature Cadd9.Model.Mode The mode of the key
Remarks

This method will include a symbol for the accidental only if it is different than the associated Name in the given key. For example, C♮4 would be rendered "C4" in the key of C Ionian, but would be "C♮4" in the key of D Ionian, because in that key a C would normally be sharp. Likewise, in D Ionian the pitch F♯3 would be rendered as "F3" because F is normally sharp in that key.

Enharmonic(other) method

Summary

Determines whether two Pitches are enharmonically equivalent

Parameters
Name Type Description
other Cadd9.Model.Pitch The other Pitch to compare
Remarks

Two Pitches are enharmonic if they map to the same key on a keyboard: for example, while D♯4 and E♭4 are distinct notes that play different musical roles, they are enharmonic.

Equals(other) method

Summary

Determines whether two Pitches are value-equivalent

Parameters
Name Type Description
other Cadd9.Model.Pitch The other Pitch to compare

GetHashCode() method

Summary

Produces a high-entropy hash code such that two value-equivalent Pitches are guaranteed to produce the same result.

Parameters

This method has no parameters.

InOctave(octave) method

Summary

Returns a new Note transposed into the given octave.

Parameters
Name Type Description
octave System.Int32 The octave of the desired note.

Parse(input) method

Summary

Parses the given input as a Pitch

Parameters
Name Type Description
input System.String The input to parse
Exceptions
Name Description
System.FormatException The given input cannot be parsed
Remarks

The input is treated as case-insensitive. The first character is parsed as a Name and the rest is broken into an accidental part and an octave. The accidental is parsed according to Parse. Examples of valid Pitches would include "B2", "Ebb17", "c#-1"

ToString() method

Summary

Returns a string representation of this Pitch, primarily for debugging purposes.

Parameters

This method has no parameters.

Transpose(octaves) method

Summary

Returns a new Note transposed by the given number of octaves.

Parameters
Name Type Description
octaves System.Int32 The number of octaves to transpose.
Remarks

If octaves is positive, the pitch will increase. If negative, it will decrease.

Program type

Namespace
Summary

Empty program class

Remarks

Exists only to allow the library to compile successfully. For some reason, netcoreapp2.2 class libraries still require a class with a Main method.

Main() method

Summary

Empty main method

Parameters

This method has no parameters.

Quality type

Namespace

Cadd9.Model

Summary

Represents a particular chord quality that may be applied with any given root

#ctor(intervals) constructor

Summary

Returns a new Quality

Parameters
Name Type Description
intervals Cadd9.Model.Interval[] The set of Intervals that define this chord quality
Exceptions
Name Description
System.ArgumentException Thrown if a generic interval appears multiple times

#ctor(intervals) constructor

Summary

Returns a new Quality

Parameters
Name Type Description
intervals System.String[] String representations of the Intervals for this chord quality
Exceptions
Name Description
System.ArgumentException Thrown if a generic interval appears multiple times
Remarks

The intervals given in this constructor will be parsed according to the behavior in Parse which allows short-hand construction.

Intervals property

Summary

The set of Intervals that define this chord quality

Add(add) method

Summary

Returns a new Quality by adding the given Interval

Parameters
Name Type Description
add Cadd9.Model.Interval The Interval to add
Remarks

This can be used to create a chord with arbitrary extensions, like 9th, 13th, etc.

Alter(alt) method

Summary

Returns a new Quality by applying the given Alteration.

Parameters
Name Type Description
alt Cadd9.Model.Quality.Alteration The Alteration to apply
Remarks

This is generally used to modify the 3rd or 5th of the quality, like creating a sus2 or a flat-5 chord.

Apply() method

Summary

Returns a sequence of Notes by applying all of this Quality's Intervals to the given root.

Parameters

This method has no parameters.

Apply() method

Summary

Returns a sequence of Pitches by applying all of this Quality's Intervals to the given root.

Parameters

This method has no parameters.

Equals(other) method

Summary

Determines whether two Qualities are value-equivalent

Parameters
Name Type Description
other Cadd9.Model.Quality The other Quality to compare

GetHashCode() method

Summary

Produces a high-entropy hash code such that two value-equivalent Qualities are guaranteed to produce the same result.

Parameters

This method has no parameters.

ToString() method

Summary

A string representation of this Mode, useful for debugging.

Parameters

This method has no parameters.

Voicing type

Namespace

Cadd9.Model

Equals(other) method

Summary

Determines whether two Voicings are value-equivalent

Parameters
Name Type Description
other Cadd9.Model.Voicing The other Voicings to compare

GetHashCode() method

Summary

Produces a high-entropy hash code such that two value-equivalent Qualities are guaranteed to produce the same result.

Parameters

This method has no parameters.