Class Scale
- Namespace
- Sigil.Sound
- Assembly
- Sigil.Sound.Notes.dll
A scale: a root note and the steps above it. Degrees count up the scale from 0 and run past the octave, so degree 7 of a seven-note scale is the root again an octave up, and negative degrees go below the root.
public sealed class ScaleInheritance
Inherited Members
Examples
// A melody by scale degree. 48 is C3; degree 0 is 48, degree 2 is 51 and degree 7 is the octave, 60.
var scale = Scale.Minor(48);
scale.Notes(Mini.Integers("0 2 <4 7> ~"))
.Play(v => Saw(v.Frequency).LowPass(2000).Adsr(0.005, 0.1, 0.5, 0.2), bpm: 110) * 0.3
Constructors
Scale(int, IEnumerable<int>, string)
A scale from a root pitch and the semitone steps above it, which must rise from 0 and stay within one octave.
public Scale(int root, IEnumerable<int> steps, string name = "custom")Parameters
rootint-
The MIDI pitch of degree 0.
stepsIEnumerable<int>-
Semitones above the root for each degree: 0 first, strictly rising, all below 12.
namestring-
A label.
Properties
Count
How many degrees one octave holds.
public int Count { get; }Property Value
Name
The scale's name, such as "minor".
public string Name { get; }Property Value
Root
The MIDI pitch of degree 0.
public int Root { get; }Property Value
this[int]
The MIDI pitch of a degree. Degrees past the end climb an octave per Sigil.Sound.Scale.Count; negative ones go down.
public int this[int degree] { get; }Property Value
Methods
Blues(int)
The blues scale: minor pentatonic with a flat fifth.
public static Scale Blues(int root)Parameters
rootint
Returns
Chromatic(int)
Every semitone.
public static Scale Chromatic(int root)Parameters
rootint
Returns
Contains(int)
True when pitch is a tone of the scale in some octave. It reads a precomputed set and allocates nothing, so it
is fit to ask of every note as it plays.
public bool Contains(int pitch)Parameters
pitchint-
A MIDI pitch.
Returns
Examples
// Only the notes of C major: C# and D# are not tones of it and are left out.
Mini.Notes("c3 c#3 d3 d#3 e3 f3 g3 a3")
.Where(n => Scale.Major(48).Contains(n.Pitch))
.Play(v => Triangle(v.Frequency).Adsr(0.005, 0.1, 0.4, 0.15), bpm: 140) * 0.3
Degrees(params int[])
The notes on the given degrees, in order: Scale.Minor(C3).Degrees(0, 2, 4, 7).
public IReadOnlyList<Note> Degrees(params int[] degrees)Parameters
degreesint[]
Returns
Degrees(string)
The notes on the degrees written as whole numbers in Sigil.Sound.Mini notation: Scale.Parse("c3 minor").Degrees("0 2 4 7").
public IReadOnlyList<Note> Degrees(string degrees)Parameters
degreesstring
Returns
Exceptions
- MiniNotationException
-
The text is not valid.
Dorian(int)
Dorian: minor with a raised sixth.
public static Scale Dorian(int root)Parameters
rootint
Returns
HarmonicMinor(int)
Harmonic minor: natural minor with a raised seventh.
public static Scale HarmonicMinor(int root)Parameters
rootint
Returns
Locrian(int)
Locrian: minor with lowered second and fifth.
public static Scale Locrian(int root)Parameters
rootint
Returns
Lydian(int)
Lydian: major with a raised fourth.
public static Scale Lydian(int root)Parameters
rootint
Returns
Major(int)
Major (Ionian): 0 2 4 5 7 9 11.
public static Scale Major(int root)Parameters
rootint
Returns
MajorPentatonic(int)
Major pentatonic: 0 2 4 7 9.
public static Scale MajorPentatonic(int root)Parameters
rootint
Returns
MelodicMinor(int)
Melodic minor (ascending): minor with raised sixth and seventh.
public static Scale MelodicMinor(int root)Parameters
rootint
Returns
Minor(int)
Natural minor (Aeolian): 0 2 3 5 7 8 10.
public static Scale Minor(int root)Parameters
rootint
Returns
MinorPentatonic(int)
Minor pentatonic: 0 3 5 7 10.
public static Scale MinorPentatonic(int root)Parameters
rootint
Returns
Mixolydian(int)
Mixolydian: major with a lowered seventh.
public static Scale Mixolydian(int root)Parameters
rootint
Returns
Note(int, float)
The note on a degree.
public Note Note(int degree, float velocity = 0.8)Parameters
Returns
Notes(string)
Turns degrees written in Sigil.Sound.Mini notation into a pattern of notes, so the scale and the melody are both text:
Scale.Parse("c3 minor").Notes("0 2 <4 7> ~").
public Pattern<Note> Notes(string degrees)Parameters
degreesstring
Returns
Exceptions
- MiniNotationException
-
The text is not valid.
Notes(Pattern<int>)
Turns a pattern of degrees into a pattern of notes.
public Pattern<Note> Notes(Pattern<int> degrees)Parameters
Returns
Parse(string)
A scale by name: "c3 minor", "F#2 dorian" or "c3:minor". A root without an octave is in octave 3.
Names are case-insensitive; spaces, dashes and underscores inside a name are ignored ("minor pentatonic" works).
public static Scale Parse(string text)Parameters
textstring
Returns
Exceptions
- FormatException
-
The text is not a root and a known scale.
Phrygian(int)
Phrygian: minor with a lowered second.
public static Scale Phrygian(int root)Parameters
rootint
Returns
ToString()
The scale as text, such as C major.
public override string ToString()Returns
WholeTone(int)
Whole tone: six notes a whole step apart.
public static Scale WholeTone(int root)Parameters
rootint
Returns
WithRoot(int)
This scale started on another root.
public Scale WithRoot(int root)Parameters
rootint