Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- E E E E E E E E E E E S S E E E E E E
- --E||--------------------|----------------------|--------------------|
- --B||--0-----0--0-----0--|--0-----0--0-----2h-3-|--0-----0--0-----0--|
- --G||-----4--------4-----|-----4--------4-------|-----4--------4-----|
- --D||--------------------|----------------------|--------------------|
- --A||--2-----------------|----------------------|--2-----------------|
- --E||-----------2--------|--3--------0----------|-----------2--------|
- --fingers G# 1234 1235 43451
- local tArgs = {...}
- if #tArgs == 0 then
- term.setTextColor(colors.yellow)
- print("Usage: [programName] [key] [notes] <capo>")
- term.setTextColor(colors.red)
- print("ie fingers G# 55345653454323 1")
- print(" lowercase [key] if minor scale")
- error()
- end
- local circleOfFifths = {'C','G','D','A','E','B','F#','C#','G#','D#','A#','F'}
- NoteConverter = {
- noteOrder = {'A','A#','B','C','C#','D','D#','E','F','F#','G','G#'},
- scale = {},
- major = true,
- startingNote = string.upper(tostring(tArgs[1])),
- inputKey = tArgs[1],
- inputNotes = tostring(tArgs[2]),
- decipheredNotes = {},
- iterator = 0,
- noteTable = {},
- capo = tArgs[3] or 0,
- findNoteIndex = function(self,note)
- for i,v in pairs(self.noteOrder) do
- if v == note then
- return i
- end
- end
- end,
- findScale = function(self)
- --assuming major
- local noteIndex = self:findNoteIndex(string.upper(self.inputKey))
- local ifCapital = string.sub(self.inputKey,1,1)
- if ifCapital:byte() >= 65 and ifCapital:byte() <= 90 then
- self.major = true
- elseif ifCapital:byte() >= 97 and ifCapital:byte() <= 122 then
- self.major = false
- else
- error("[key] is either false or nil, try \"A#\" or \"a\"")
- end
- --1,step2,step3,half4,step5,step6,step7,half8
- local majorPattern = {0,2,4,5,7,9,11,12}
- local minorPattern = {0,2,3,5,7,8,10,12}
- local selectedPattern = majorPattern
- if not self.major then
- selectedPattern = minorPattern
- end
- for i,v in pairs(selectedPattern) do
- local num = tonumber(noteIndex) + v
- num = num - 1
- num = num%#self.noteOrder
- num = num + 1
- table.insert(self.scale,self.noteOrder[ num ])
- end
- end,
- decipherAllNumbers = function(self)
- while true do
- self.iterator = self.iterator + 1
- local number = tonumber(self.inputNotes:sub(self.iterator,self.iterator))
- if not number then
- break
- end
- table.insert(self.decipheredNotes,self.scale[number])
- end
- end,
- printOutput = function(self)
- for i,v in pairs(self.scale) do
- write(v)
- write(" ")
- end
- print()
- for i,v in pairs(self.decipheredNotes) do
- write(v)
- write(" ")
- end
- print()
- end,
- printNoteTable = function(self)
- for i,v in pairs(self.noteTable) do
- write(i)
- write(": ")
- for _,val in pairs(v) do
- write(val)
- write(" ")
- end
- print()
- end
- end,
- printNumTable = function(self)
- print()
- print(" 01234")
- print("--------")
- for i,v in pairs(self.noteTable) do
- write(i)
- write(": ")
- for _,val in pairs(v) do
- --if found in scale then present corresponding num else x
- local found = false
- for a,b in pairs(self.scale) do
- if val == b then
- found = a
- break
- end
- end
- if found then
- write(found)
- else
- write("x")
- end
- end
- print()
- end
- print("--------")
- end,
- transposeNote = function(self,charNote,nHalfSteps)
- --transposeNote('G#',-2) --> A#
- local indexNote = self:findNoteIndex(charNote)
- if not indexNote then
- error(tostring(charNote).." is not a note")
- end
- indexNote = indexNote + nHalfSteps
- local result = self.noteOrder[((indexNote-1)%#self.noteOrder)+1]
- return result
- end,
- determineCapo = function(self)
- local majorKeys = {'C','G','D','A','E'}
- local minorKeys = {'A','D','E'}
- local desiredKeys = majorKeys
- if not self.major then
- desiredKeys = minorKeys
- end
- for i = 1,11 do
- i = i * -1
- local note = self:transposeNote(self.startingNote,i)
- for a,b in pairs(desiredKeys) do
- if b == note:upper() then
- write("capo ")
- write(i*-1)
- write(" ")
- print(note)
- end
- end
- end
- end,
- fillNoteTable = function(self)
- --determines the note of the open 6th string when the capo is applied
- --determines each note at the capo for each open string
- --fills out a the notetable for the first 4 frets of the highest 4 strings
- --local Eindex = self:findNoteIndex('E')
- --Eindex = Eindex + capo
- --local S6th = self.noteOrder[((Eindex-1)%#self.noteOrder)+1]
- self.noteTable[6] = {self:transposeNote('E',self.capo)}
- self.noteTable[5] = {self:transposeNote(self.noteTable[6][1],5)}
- self.noteTable[4] = {self:transposeNote(self.noteTable[5][1],5)}
- self.noteTable[3] = {self:transposeNote(self.noteTable[4][1],5)}
- self.noteTable[2] = {self:transposeNote(self.noteTable[3][1],4)}
- self.noteTable[1] = {self:transposeNote(self.noteTable[2][1],5)}
- for i=1,6 do
- for j = 1,4 do
- table.insert(self.noteTable[i],self:transposeNote(self.noteTable[i][1],j))
- end
- end
- end,
- }
- NoteConverter:findScale()
- NoteConverter:decipherAllNumbers()
- NoteConverter:printOutput()
- NoteConverter:fillNoteTable()
- NoteConverter:printNumTable()
- NoteConverter:determineCapo()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement