theory

package
v0.0.0-...-486f928 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 14, 2022 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Primitive and high level music theory concepts to manipulate notes, chords, rhythms, etc.

Index

Constants

View Source
const (
	C1  = 24
	C2  = 36
	C3  = 48
	C4  = 60
	Db4 = 61
	D4  = 62
	E4  = 64
	F4  = 65
	G4  = 67
	A4  = 69
	B4  = 71
	C5  = 72
	C6  = 84
	C7  = 96
	A7  = 105
)

Variables

View Source
var Aeolian = NewScale(
	MustNotesFromString("A B C D E F G"),
	MustNotesFromString("G F E D C B A"),
)
View Source
var Chords = map[string][]int{
	"m":   []int{3, 4, 5},
	"M":   []int{4, 3, 5},
	"m7":  []int{3, 4, 3, 2},
	"m67": []int{3, 4, 1, 2, 2},
	"M7":  []int{4, 3, 4, 1},
	"7":   []int{4, 3, 3, 2},
}
View Source
var Diatonic = Ionian
View Source
var Dorian = NewScale(
	MustNotesFromString("D E F G A B C"),
	MustNotesFromString("C B A G F E D"),
)
View Source
var HarmonicMajor = NewScale(
	MustNotesFromString("C D E F G Ab B"),
	MustNotesFromString("B Ab G F E D C"),
)
View Source
var Ionian = NewScale(
	MustNotesFromString("C D E F G A B"),
	MustNotesFromString("B A G F E D C"),
)
View Source
var Locrian = NewScale(
	MustNotesFromString("B C D E F G A"),
	MustNotesFromString("A G F E D C B"),
)
View Source
var Lydian = NewScale(
	MustNotesFromString("F G A B C D E"),
	MustNotesFromString("C B A G F E D"),
)
View Source
var MajorScale = Ionian
View Source
var Mixolydian = NewScale(
	MustNotesFromString("G A B C D E F"),
	MustNotesFromString("B A G F E D C"),
)
View Source
var NoteNames = []NoteName{C, D, E, F, G, A, B}
View Source
var NoteToPitch = make([]float64, 128)
View Source
var Phrygian = NewScale(
	MustNotesFromString("E F G A B C D"),
	MustNotesFromString("D C B A G F E"),
)
View Source
var Scales = map[string]*Scale{
	"diatonic":       Diatonic,
	"ionian":         Ionian,
	"dorian":         Dorian,
	"phrygian":       Phrygian,
	"lydian":         Lydian,
	"mixolydian":     Mixolydian,
	"aeolian":        Aeolian,
	"locrian":        Locrian,
	"harmonic major": HarmonicMajor,
}

Functions

func ChordOnNoteInt

func ChordOnNoteInt(note int, chord string) []int

func EuclidianRhythm

func EuclidianRhythm(n, over int) []bool

func InvertChord

func InvertChord(chord []int, inversions int) []int

func NoteNameToString

func NoteNameToString(n NoteName) string

func ScaleOnNoteInt

func ScaleOnNoteInt(note int, scale string) []int

Types

type Note

type Note struct {
	Name        NoteName
	Accidentals int
	Octave      int
}

func MustNoteFromString

func MustNoteFromString(s string) *Note

func NoteFromInt

func NoteFromInt(n int) *Note

func NoteFromString

func NoteFromString(s string) (*Note, error)

func (*Note) Augment

func (n *Note) Augment()

func (*Note) Chord

func (n *Note) Chord(chord string) Notes

func (*Note) Diminish

func (n *Note) Diminish()

func (*Note) Int

func (n *Note) Int() int

func (*Note) Pitch

func (n *Note) Pitch() float64

func (*Note) String

func (n *Note) String() string

type NoteName

type NoteName = int
const (
	C NoteName = 0
	D NoteName = 2
	E NoteName = 4
	F NoteName = 5
	G NoteName = 7
	A NoteName = 9
	B NoteName = 11
)

func MustNewNoteNameFromString

func MustNewNoteNameFromString(s string) NoteName

func NewNoteNameFromString

func NewNoteNameFromString(s string) (NoteName, error)

type Notes

type Notes []*Note

func ChordOnNote

func ChordOnNote(note *Note, chord string) Notes

func MustNotesFromString

func MustNotesFromString(s string) Notes

func NotesFromString

func NotesFromString(s string) (Notes, error)

func (Notes) Augment

func (n Notes) Augment()

func (Notes) Diminish

func (n Notes) Diminish()

type Scale

type Scale struct {
	Ascending  Notes
	Descending Notes
}

func NewScale

func NewScale(ascending, descending Notes) *Scale

The ascending and descending notes should be supplied in the key of C. If descending is nil then it will default to the reverse of ascending.

func (*Scale) GetAscendingIntervals

func (s *Scale) GetAscendingIntervals() []int

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL