CsoundUnity 4.0.0-alpha.3
Loading...
Searching...
No Matches
Csound.Unity.Utilities.MusicUtils Class Reference

Static utilities for music theory calculations: scale intervals, frequency conversion, tempo math. These are shared across CsoundUnity features (Timelines, standalone components, etc.). More...

Static Public Member Functions

static int[] GetIntervals (Scale scale)
 Returns the semitone interval array for the given scale.
static float[] BuildPitchArray (float rootHz, Scale scale, int octaves, bool includeClosingRoot=false)
 Builds a flat array of frequencies in Hz spanning octaves octaves of the given scale, starting from rootHz .
static int[] GetChordIntervals (Chord chord)
 Returns the semitone interval array for the given chord. Returns null for Chord.Custom — the caller must supply the intervals.
static float[] BuildPitchArrayFromChord (float rootHz, Chord chord, int octaves, int[] customIntervals=null, bool includeClosingRoot=false)
 Builds a flat array of frequencies in Hz from a chord, spanning octaves octaves. Chord intervals may already span more than one octave (e.g. 9ths, 11ths, 13ths); additional octaves stack the same intervals shifted up by 12 semitones per octave.
static float DivisionToSeconds (float bpm, RhythmicDivision division)
 Returns the interval in seconds between notes for a given BPM and rhythmic division.
static float MidiToHz (int midiNote)
 Converts a MIDI note number to frequency in Hz (A4 = MIDI 69 = 440 Hz).
static int HzToMidi (float hz)
 Converts a frequency in Hz to the nearest MIDI note number.
static string MidiToNoteName (int midi)
 Returns the note name for a MIDI note number (e.g. 60 → "C4").
static string HzToNoteName (float hz)
 Returns the note name for a frequency in Hz (e.g. 261.63 → "C4").
static int NoteNameToMidi (string name)
 Parses a note name (e.g. "C4", "C#3", "Db4") into a MIDI note number (0–127). Returns -1 if the name cannot be parsed.
static float GetPitchAtStep (float[] pitches, int stepIndex, ArpDirection direction)
 Picks a pitch from pitches based on the current step index and the desired direction .
static bool[] BuildEuclideanPattern (int hits, int steps, int rotation=0)
 Builds a Euclidean (Bjorklund) rhythm pattern as a boolean array. Distributes hits active steps as evenly as possible across steps total steps, then rotates the result by rotation positions.

Static Public Attributes

static readonly int[] IntervalsChromatic = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 }
 Semitone intervals for the Scale.Chromatic scale (all 12 semitones).
static readonly int[] IntervalsMajor = { 0, 2, 4, 5, 7, 9, 11 }
 Semitone intervals for the Scale.Major (Ionian) scale.
static readonly int[] IntervalsMinor = { 0, 2, 3, 5, 7, 8, 10 }
 Semitone intervals for the Scale.Minor (Aeolian) scale.
static readonly int[] IntervalsPentatonic = { 0, 2, 4, 7, 9 }
 Semitone intervals for the Scale.Pentatonic (major pentatonic) scale.
static readonly int[] IntervalsDorian = { 0, 2, 3, 5, 7, 9, 10 }
 Semitone intervals for the Scale.Dorian mode.
static readonly int[] IntervalsPhrygian = { 0, 1, 3, 5, 7, 8, 10 }
 Semitone intervals for the Scale.Phrygian mode.
static readonly int[] IntervalsLydian = { 0, 2, 4, 6, 7, 9, 11 }
 Semitone intervals for the Scale.Lydian mode.
static readonly int[] IntervalsMixolydian = { 0, 2, 4, 5, 7, 9, 10 }
 Semitone intervals for the Scale.Mixolydian mode.
static readonly int[] IntervalsHarmonicMinor = { 0, 2, 3, 5, 7, 8, 11 }
 Semitone intervals for the Scale.HarmonicMinor scale.
static readonly int[] ChordUnison = { 0 }
 Semitone intervals for the Chord.Unison (root only).
static readonly int[] ChordMinorThird = { 0, 3 }
 Semitone intervals for the Chord.MinorThird dyad.
static readonly int[] ChordMajorThird = { 0, 4 }
 Semitone intervals for the Chord.MajorThird dyad.
static readonly int[] ChordFourth = { 0, 5 }
 Semitone intervals for the Chord.Fourth dyad.
static readonly int[] ChordFifth = { 0, 7 }
 Semitone intervals for the Chord.Fifth dyad.
static readonly int[] ChordMajor = { 0, 4, 7 }
 Semitone intervals for the Chord.Major triad.
static readonly int[] ChordMinor = { 0, 3, 7 }
 Semitone intervals for the Chord.Minor triad.
static readonly int[] ChordDiminished = { 0, 3, 6 }
 Semitone intervals for the Chord.Diminished triad.
static readonly int[] ChordAugmented = { 0, 4, 8 }
 Semitone intervals for the Chord.Augmented triad.
static readonly int[] ChordSus2 = { 0, 2, 7 }
 Semitone intervals for the Chord.Sus2 triad.
static readonly int[] ChordSus4 = { 0, 5, 7 }
 Semitone intervals for the Chord.Sus4 triad.
static readonly int[] ChordMajor7 = { 0, 4, 7, 11 }
 Semitone intervals for the Chord.Major7 chord.
static readonly int[] ChordMinor7 = { 0, 3, 7, 10 }
 Semitone intervals for the Chord.Minor7 chord.
static readonly int[] ChordDominant7 = { 0, 4, 7, 10 }
 Semitone intervals for the Chord.Dominant7 chord.
static readonly int[] ChordDiminished7 = { 0, 3, 6, 9 }
 Semitone intervals for the Chord.Diminished7 chord.
static readonly int[] ChordHalfDiminished7 = { 0, 3, 6, 10 }
 Semitone intervals for the Chord.HalfDiminished7 chord.
static readonly int[] ChordMinorMajor7 = { 0, 3, 7, 11 }
 Semitone intervals for the Chord.MinorMajor7 chord.
static readonly int[] ChordAugmented7 = { 0, 4, 8, 10 }
 Semitone intervals for the Chord.Augmented7 chord.
static readonly int[] ChordAugmentedMajor7 = { 0, 4, 8, 11 }
 Semitone intervals for the Chord.AugmentedMajor7 chord.
static readonly int[] ChordMajor9 = { 0, 4, 7, 11, 14 }
 Semitone intervals for the Chord.Major9 chord.
static readonly int[] ChordMinor9 = { 0, 3, 7, 10, 14 }
 Semitone intervals for the Chord.Minor9 chord.
static readonly int[] ChordDominant9 = { 0, 4, 7, 10, 14 }
 Semitone intervals for the Chord.Dominant9 chord.
static readonly int[] ChordAdd9 = { 0, 4, 7, 14 }
 Semitone intervals for the Chord.Add9 chord (major triad + 9th, no 7th).
static readonly int[] ChordMajor11 = { 0, 4, 7, 11, 14, 17 }
 Semitone intervals for the Chord.Major11 chord.
static readonly int[] ChordMinor11 = { 0, 3, 7, 10, 14, 17 }
 Semitone intervals for the Chord.Minor11 chord.
static readonly int[] ChordDominant11 = { 0, 4, 7, 10, 14, 17 }
 Semitone intervals for the Chord.Dominant11 chord.
static readonly int[] ChordMajor13 = { 0, 4, 7, 11, 14, 17, 21 }
 Semitone intervals for the Chord.Major13 chord.
static readonly int[] ChordMinor13 = { 0, 3, 7, 10, 14, 17, 21 }
 Semitone intervals for the Chord.Minor13 chord.
static readonly int[] ChordDominant13 = { 0, 4, 7, 10, 14, 17, 21 }
 Semitone intervals for the Chord.Dominant13 chord.

Detailed Description

Static utilities for music theory calculations: scale intervals, frequency conversion, tempo math. These are shared across CsoundUnity features (Timelines, standalone components, etc.).

Member Function Documentation

◆ BuildEuclideanPattern()

bool[] Csound.Unity.Utilities.MusicUtils.BuildEuclideanPattern ( int hits,
int steps,
int rotation = 0 )
inlinestatic

Builds a Euclidean (Bjorklund) rhythm pattern as a boolean array. Distributes hits active steps as evenly as possible across steps total steps, then rotates the result by rotation positions.

Parameters
hitsNumber of active hits (1 – steps).
stepsTotal number of steps (1 – 32).
rotationNumber of positions to rotate the pattern clockwise (0 = no rotation).
Returns
Boolean array of length steps where true = hit, false = rest.

◆ BuildPitchArray()

float[] Csound.Unity.Utilities.MusicUtils.BuildPitchArray ( float rootHz,
Scale scale,
int octaves,
bool includeClosingRoot = false )
inlinestatic

Builds a flat array of frequencies in Hz spanning octaves octaves of the given scale, starting from rootHz .

When includeClosingRoot is true, each octave ends with the root of the next octave as a turnaround note — use this for ArpDirection.UpDown so the top note is included (e.g. A B C D E F G A G F E D C B A). When false (default), no closing root is added — use this for ArpDirection.Up / ArpDirection.Down / ArpDirection.Random so the cycle repeats without duplicating the root (e.g. A B C D E F G | A B C D E F G | ...).

Parameters
rootHzThe frequency the scale starts from.
scaleThe scale to walk.
octavesHow many octaves to stack.
includeClosingRootWhen true each octave ends with its own root.
Returns
The frequencies in Hz, low to high.

◆ BuildPitchArrayFromChord()

float[] Csound.Unity.Utilities.MusicUtils.BuildPitchArrayFromChord ( float rootHz,
Chord chord,
int octaves,
int[] customIntervals = null,
bool includeClosingRoot = false )
inlinestatic

Builds a flat array of frequencies in Hz from a chord, spanning octaves octaves. Chord intervals may already span more than one octave (e.g. 9ths, 11ths, 13ths); additional octaves stack the same intervals shifted up by 12 semitones per octave.

For Chord.Custom, pass the custom semitone intervals via customIntervals . If null or empty, falls back to Chord.Major.

includeClosingRoot adds the root of the next octave after each octave block — use this for ArpDirection.UpDown turnaround (same semantics as BuildPitchArray).

Parameters
rootHzThe frequency the chord is built on.
chordThe chord to stack.
octavesHow many octaves to stack.
customIntervalsThe semitone intervals used when chord is Chord.Custom.
includeClosingRootWhen true each octave ends with its own root.
Returns
The frequencies in Hz, low to high.

◆ DivisionToSeconds()

float Csound.Unity.Utilities.MusicUtils.DivisionToSeconds ( float bpm,
RhythmicDivision division )
inlinestatic

Returns the interval in seconds between notes for a given BPM and rhythmic division.

Parameters
bpmTempo in beats per minute.
divisionThe rhythmic value to measure.
Returns
The length of one division in seconds at that tempo.

◆ GetChordIntervals()

int[] Csound.Unity.Utilities.MusicUtils.GetChordIntervals ( Chord chord)
inlinestatic

Returns the semitone interval array for the given chord. Returns null for Chord.Custom — the caller must supply the intervals.

Parameters
chordThe chord to look up. Chord.Custom returns the major chord.
Returns
The chord's semitone offsets from its root, which may span more than one octave.

◆ GetIntervals()

int[] Csound.Unity.Utilities.MusicUtils.GetIntervals ( Scale scale)
inlinestatic

Returns the semitone interval array for the given scale.

Parameters
scaleThe scale to look up.
Returns
The scale's semitone offsets from its root.

◆ GetPitchAtStep()

float Csound.Unity.Utilities.MusicUtils.GetPitchAtStep ( float[] pitches,
int stepIndex,
ArpDirection direction )
inlinestatic

Picks a pitch from pitches based on the current step index and the desired direction .

Parameters
pitchesThe frequencies to arpeggiate.
stepIndexThe step to read, counting from 0 and wrapping.
directionThe order the pitches are visited in.
Returns
The frequency in Hz for that step, following the arpeggio direction.

◆ HzToMidi()

int Csound.Unity.Utilities.MusicUtils.HzToMidi ( float hz)
inlinestatic

Converts a frequency in Hz to the nearest MIDI note number.

Parameters
hzThe frequency in Hz.
Returns
The nearest MIDI note number.

◆ HzToNoteName()

string Csound.Unity.Utilities.MusicUtils.HzToNoteName ( float hz)
inlinestatic

Returns the note name for a frequency in Hz (e.g. 261.63 → "C4").

Parameters
hzThe frequency in Hz. Zero or less gives a dash.
Returns
The name of the nearest note, with its octave.

◆ MidiToHz()

float Csound.Unity.Utilities.MusicUtils.MidiToHz ( int midiNote)
inlinestatic

Converts a MIDI note number to frequency in Hz (A4 = MIDI 69 = 440 Hz).

Parameters
midiNoteMIDI note number, 0 to 127.
Returns
The frequency in Hz, in equal temperament with A4 at 440 Hz.

◆ MidiToNoteName()

string Csound.Unity.Utilities.MusicUtils.MidiToNoteName ( int midi)
inlinestatic

Returns the note name for a MIDI note number (e.g. 60 → "C4").

Parameters
midiMIDI note number, 0 to 127.
Returns
The note name with its octave, such as C4 or F#3.

◆ NoteNameToMidi()

int Csound.Unity.Utilities.MusicUtils.NoteNameToMidi ( string name)
inlinestatic

Parses a note name (e.g. "C4", "C#3", "Db4") into a MIDI note number (0–127). Returns -1 if the name cannot be parsed.

Parameters
nameA note name with its octave, such as C4, f#3 or Bb2.
Returns
The MIDI note number, or -1 when the name cannot be read.

Member Data Documentation

◆ ChordAdd9

readonly int [] Csound.Unity.Utilities.MusicUtils.ChordAdd9 = { 0, 4, 7, 14 }
static

Semitone intervals for the Chord.Add9 chord (major triad + 9th, no 7th).

◆ ChordAugmented

readonly int [] Csound.Unity.Utilities.MusicUtils.ChordAugmented = { 0, 4, 8 }
static

Semitone intervals for the Chord.Augmented triad.

◆ ChordAugmented7

readonly int [] Csound.Unity.Utilities.MusicUtils.ChordAugmented7 = { 0, 4, 8, 10 }
static

Semitone intervals for the Chord.Augmented7 chord.

◆ ChordAugmentedMajor7

readonly int [] Csound.Unity.Utilities.MusicUtils.ChordAugmentedMajor7 = { 0, 4, 8, 11 }
static

Semitone intervals for the Chord.AugmentedMajor7 chord.

◆ ChordDiminished

readonly int [] Csound.Unity.Utilities.MusicUtils.ChordDiminished = { 0, 3, 6 }
static

Semitone intervals for the Chord.Diminished triad.

◆ ChordDiminished7

readonly int [] Csound.Unity.Utilities.MusicUtils.ChordDiminished7 = { 0, 3, 6, 9 }
static

Semitone intervals for the Chord.Diminished7 chord.

◆ ChordDominant11

readonly int [] Csound.Unity.Utilities.MusicUtils.ChordDominant11 = { 0, 4, 7, 10, 14, 17 }
static

Semitone intervals for the Chord.Dominant11 chord.

◆ ChordDominant13

readonly int [] Csound.Unity.Utilities.MusicUtils.ChordDominant13 = { 0, 4, 7, 10, 14, 17, 21 }
static

Semitone intervals for the Chord.Dominant13 chord.

◆ ChordDominant7

readonly int [] Csound.Unity.Utilities.MusicUtils.ChordDominant7 = { 0, 4, 7, 10 }
static

Semitone intervals for the Chord.Dominant7 chord.

◆ ChordDominant9

readonly int [] Csound.Unity.Utilities.MusicUtils.ChordDominant9 = { 0, 4, 7, 10, 14 }
static

Semitone intervals for the Chord.Dominant9 chord.

◆ ChordFifth

readonly int [] Csound.Unity.Utilities.MusicUtils.ChordFifth = { 0, 7 }
static

Semitone intervals for the Chord.Fifth dyad.

◆ ChordFourth

readonly int [] Csound.Unity.Utilities.MusicUtils.ChordFourth = { 0, 5 }
static

Semitone intervals for the Chord.Fourth dyad.

◆ ChordHalfDiminished7

readonly int [] Csound.Unity.Utilities.MusicUtils.ChordHalfDiminished7 = { 0, 3, 6, 10 }
static

Semitone intervals for the Chord.HalfDiminished7 chord.

◆ ChordMajor

readonly int [] Csound.Unity.Utilities.MusicUtils.ChordMajor = { 0, 4, 7 }
static

Semitone intervals for the Chord.Major triad.

◆ ChordMajor11

readonly int [] Csound.Unity.Utilities.MusicUtils.ChordMajor11 = { 0, 4, 7, 11, 14, 17 }
static

Semitone intervals for the Chord.Major11 chord.

◆ ChordMajor13

readonly int [] Csound.Unity.Utilities.MusicUtils.ChordMajor13 = { 0, 4, 7, 11, 14, 17, 21 }
static

Semitone intervals for the Chord.Major13 chord.

◆ ChordMajor7

readonly int [] Csound.Unity.Utilities.MusicUtils.ChordMajor7 = { 0, 4, 7, 11 }
static

Semitone intervals for the Chord.Major7 chord.

◆ ChordMajor9

readonly int [] Csound.Unity.Utilities.MusicUtils.ChordMajor9 = { 0, 4, 7, 11, 14 }
static

Semitone intervals for the Chord.Major9 chord.

◆ ChordMajorThird

readonly int [] Csound.Unity.Utilities.MusicUtils.ChordMajorThird = { 0, 4 }
static

Semitone intervals for the Chord.MajorThird dyad.

◆ ChordMinor

readonly int [] Csound.Unity.Utilities.MusicUtils.ChordMinor = { 0, 3, 7 }
static

Semitone intervals for the Chord.Minor triad.

◆ ChordMinor11

readonly int [] Csound.Unity.Utilities.MusicUtils.ChordMinor11 = { 0, 3, 7, 10, 14, 17 }
static

Semitone intervals for the Chord.Minor11 chord.

◆ ChordMinor13

readonly int [] Csound.Unity.Utilities.MusicUtils.ChordMinor13 = { 0, 3, 7, 10, 14, 17, 21 }
static

Semitone intervals for the Chord.Minor13 chord.

◆ ChordMinor7

readonly int [] Csound.Unity.Utilities.MusicUtils.ChordMinor7 = { 0, 3, 7, 10 }
static

Semitone intervals for the Chord.Minor7 chord.

◆ ChordMinor9

readonly int [] Csound.Unity.Utilities.MusicUtils.ChordMinor9 = { 0, 3, 7, 10, 14 }
static

Semitone intervals for the Chord.Minor9 chord.

◆ ChordMinorMajor7

readonly int [] Csound.Unity.Utilities.MusicUtils.ChordMinorMajor7 = { 0, 3, 7, 11 }
static

Semitone intervals for the Chord.MinorMajor7 chord.

◆ ChordMinorThird

readonly int [] Csound.Unity.Utilities.MusicUtils.ChordMinorThird = { 0, 3 }
static

Semitone intervals for the Chord.MinorThird dyad.

◆ ChordSus2

readonly int [] Csound.Unity.Utilities.MusicUtils.ChordSus2 = { 0, 2, 7 }
static

Semitone intervals for the Chord.Sus2 triad.

◆ ChordSus4

readonly int [] Csound.Unity.Utilities.MusicUtils.ChordSus4 = { 0, 5, 7 }
static

Semitone intervals for the Chord.Sus4 triad.

◆ ChordUnison

readonly int [] Csound.Unity.Utilities.MusicUtils.ChordUnison = { 0 }
static

Semitone intervals for the Chord.Unison (root only).

◆ IntervalsChromatic

readonly int [] Csound.Unity.Utilities.MusicUtils.IntervalsChromatic = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 }
static

Semitone intervals for the Scale.Chromatic scale (all 12 semitones).

◆ IntervalsDorian

readonly int [] Csound.Unity.Utilities.MusicUtils.IntervalsDorian = { 0, 2, 3, 5, 7, 9, 10 }
static

Semitone intervals for the Scale.Dorian mode.

◆ IntervalsHarmonicMinor

readonly int [] Csound.Unity.Utilities.MusicUtils.IntervalsHarmonicMinor = { 0, 2, 3, 5, 7, 8, 11 }
static

Semitone intervals for the Scale.HarmonicMinor scale.

◆ IntervalsLydian

readonly int [] Csound.Unity.Utilities.MusicUtils.IntervalsLydian = { 0, 2, 4, 6, 7, 9, 11 }
static

Semitone intervals for the Scale.Lydian mode.

◆ IntervalsMajor

readonly int [] Csound.Unity.Utilities.MusicUtils.IntervalsMajor = { 0, 2, 4, 5, 7, 9, 11 }
static

Semitone intervals for the Scale.Major (Ionian) scale.

◆ IntervalsMinor

readonly int [] Csound.Unity.Utilities.MusicUtils.IntervalsMinor = { 0, 2, 3, 5, 7, 8, 10 }
static

Semitone intervals for the Scale.Minor (Aeolian) scale.

◆ IntervalsMixolydian

readonly int [] Csound.Unity.Utilities.MusicUtils.IntervalsMixolydian = { 0, 2, 4, 5, 7, 9, 10 }
static

Semitone intervals for the Scale.Mixolydian mode.

◆ IntervalsPentatonic

readonly int [] Csound.Unity.Utilities.MusicUtils.IntervalsPentatonic = { 0, 2, 4, 7, 9 }
static

Semitone intervals for the Scale.Pentatonic (major pentatonic) scale.

◆ IntervalsPhrygian

readonly int [] Csound.Unity.Utilities.MusicUtils.IntervalsPhrygian = { 0, 1, 3, 5, 7, 8, 10 }
static

Semitone intervals for the Scale.Phrygian mode.


The documentation for this class was generated from the following file: