-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscaleFunctions.lua
More file actions
148 lines (107 loc) · 3.48 KB
/
Copy pathscaleFunctions.lua
File metadata and controls
148 lines (107 loc) · 3.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
require 'scales'
require 'chords'
notes = { 'C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#', 'A', 'A#', 'B' };
flatNotes = { 'C', 'Db', 'D', 'Eb', 'E', 'F', 'Gb', 'G', 'Ab', 'A', 'Bb', 'B' };
function getScalePattern(scaleTonicNote, scale)
local scalePatternString = scale['pattern']
local scalePattern = {false,false,false,false,false,false,false,false,false,false,false}
for i = 0, #scalePatternString do
local note = getNotesIndex(scaleTonicNote+i)
if scalePatternString:sub(i+1, i+1) == '1' then
scalePattern[note] = true
end
end
return scalePattern
end
function getNotesIndex(note)
return ((note - 1) % 12) + 1
end
function getNoteName(note)
local noteName = getSharpNoteName(note)
if not string.match(preferences.scaleNotesText.value, noteName) then
return getFlatNoteName(note)
else
return noteName
end
end
function getSharpNoteName(note)
local notesIndex = getNotesIndex(note)
return notes[notesIndex]
end
function getFlatNoteName(note)
local notesIndex = getNotesIndex(note)
return flatNotes[notesIndex]
end
function getOctave(noteValue)
return math.floor(noteValue / 12)
end
function chordIsNotAlreadyIncluded(scaleChordsForRootNote, chordCode)
for chordIndex, chord in ipairs(scaleChordsForRootNote) do
if chord.code == chordCode then
return false
end
end
return true
end
function getScaleChordsForRootNote(rootNote)
local chordCount = 0
local scaleChordsForRootNote = {}
for chordIndex, chord in ipairs(chords) do
if chordIsInScale(rootNote, chordIndex) then
chordCount = chordCount + 1
scaleChordsForRootNote[chordCount] = chord
end
end
if preferences.enableModalMixtureCheckbox.value then
for chordIndex, chord in ipairs(chords) do
if chordIsNotAlreadyIncluded(scaleChordsForRootNote, chord.code) and chordIsInModalMixtureScale(rootNote, chordIndex) then
chordCount = chordCount + 1
scaleChordsForRootNote[chordCount] = chord
end
end
end
if preferences.enableAllChordsCheckbox.value then
for chordIndex, chord in ipairs(chords) do
if chordIsNotAlreadyIncluded(scaleChordsForRootNote, chord.code) then
chordCount = chordCount + 1
scaleChordsForRootNote[chordCount] = chord
end
end
end
return scaleChordsForRootNote
end
function noteIsInScale(note)
return scalePattern[getNotesIndex(note)]
end
function noteIsNotInScale(note)
return not noteIsInScale(note)
end
function chordIsInScale(rootNote, chordIndex)
local chord = chords[chordIndex]
local chordPattern = chord['pattern']
for i = 0, #chordPattern do
local note = getNotesIndex(rootNote+i)
if chordPattern:sub(i+1, i+1) == '1' and noteIsNotInScale(note) then
return false
end
end
return true
end
function noteIsInModalMixtureScale(note)
local modalMixtureScalePattern = getScalePattern(preferences.scaleTonicNote.value, scales[preferences.modalMixtureScaleType.value])
return modalMixtureScalePattern[getNotesIndex(note)]
end
function noteIsNotInModalMixtureScale(note)
return not noteIsInModalMixtureScale(note)
end
function chordIsInModalMixtureScale(rootNote, chordIndex)
local chord = chords[chordIndex]
local chordPattern = chord['pattern']
for i = 0, #chordPattern do
local note = getNotesIndex(rootNote+i)
if chordPattern:sub(i+1, i+1) == '1' and noteIsNotInModalMixtureScale(note) then
return false
end
end
return true
end