Created
May 29, 2022 13:16
-
-
Save ThinaticSystem/c555cc97bc2ec9826c0a54e74b59569e to your computer and use it in GitHub Desktop.
コードネームパーサー(wip)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// TODO degreeの9, 11, 13, 7(dimMaj7のやつ)を配列に(全部配列にしちゃう?) | |
Chord | |
= r:Root q3:Quality3 q4:Quality4 o:Option s:Suspended t:Tensions { | |
const deg = new Array(1+7); | |
deg.fill(); // undefinedで埋めないとmap()で空の要素のときの処理がスキップされちゃう | |
deg[1] = 'P'; | |
let c = deg.map( (value, index) => { | |
value = (q3.constitute[index] !== undefined) ? q3.constitute[index] : value; | |
return value; | |
}); | |
if (q4 !== null) { | |
c = c.map( (value, index) => { | |
return (q4.constitute[index] !== undefined) ? q4.constitute[index] : value; | |
}); | |
} | |
if (o !== null) { | |
c = c.map( (value, index) => { | |
return (o.constitute[index] !== undefined) ? o.constitute[index] : value; | |
}); | |
} | |
if (s !== null) { | |
c = c.map( (value, index) => { | |
return (s.constitute[index] !== undefined) ? s.constitute[index] : value; | |
}); | |
} | |
if (t !== null) { | |
t.forEach( tElm => { | |
c = c.map( (value, index) => { | |
return (tElm.constitute[index] !== undefined) ? tElm.constitute[index] : value; | |
}); | |
}); | |
} | |
return { | |
tmp: { | |
root: r, | |
triad: (s !== null) ? s.type : q3.type, | |
tetrad: (q4) ? q4.type : null, | |
option: (o !== null) ? o.type : null, | |
tensions: t, | |
}, | |
degree: c, | |
}; | |
} | |
/ _ { | |
return { | |
tmp: { | |
root: null, | |
triad: null, | |
tetrad: null, | |
option: null, | |
tensions: null, | |
}, | |
degree: null, | |
}; | |
} | |
Root | |
= 'C♭' { return 11; } | |
/ 'C♯' { return 1; } | |
/ ['C''Ⅰ'] { return 0; } | |
/ '♭Ⅰ' { return 11; } | |
/ '♯Ⅰ' { return 1; } | |
/ 'D♭' { return 1; } | |
/ 'D♯' { return 3; } | |
/ ['D''Ⅱ'] { return 2; } | |
/ '♭Ⅱ' { return 1; } | |
/ '♯Ⅱ' { return 3; } | |
/ 'E♭' { return 3; } | |
/ 'E♯' { return 5; } | |
/ ['E''Ⅲ'] { return 4; } | |
/ '♭Ⅲ' { return 3; } | |
/ '♯Ⅲ' { return 5; } | |
/ 'F♭' { return 4; } | |
/ 'F♯' { return 6; } | |
/ ['F''Ⅳ'] { return 5; } | |
/ '♭Ⅳ' { return 4; } | |
/ '♯Ⅳ' { return 6; } | |
/ 'G♭' { return 6; } | |
/ 'G♯' { return 8; } | |
/ ['G''Ⅴ'] { return 7; } | |
/ '♭Ⅴ' { return 6; } | |
/ '♯Ⅴ' { return 8; } | |
/ 'A♭' { return 8; } | |
/ 'A♯' { return 10; } | |
/ ['A''Ⅵ'] { return 9; } | |
/ '♭Ⅵ' { return 8; } | |
/ '♯Ⅵ' { return 10; } | |
/ 'B♭' { return 10; } | |
/ 'B♯' { return 12; } | |
/ ['B''Ⅶ'] { return 11; } | |
/ '♭Ⅶ' { return 10; } | |
/ '♯Ⅶ' { return 12; } | |
Quality3 | |
= 'm' { | |
const degree = new Array(1 + 7); | |
degree[3] = 'm'; | |
degree[5] = 'P'; | |
return { type: 'minor', constitute: degree }; | |
} | |
/ 'dim' { | |
const degree = new Array(1 + 7); | |
degree[3] = 'm'; | |
degree[5] = 'd'; | |
return { type: 'diminished', constitute: degree }; | |
} | |
/ 'aug' { | |
const degree = new Array(1 + 7); | |
degree[3] = 'M'; | |
degree[5] = 'A'; | |
return { type: 'augumented', constitute: degree }; | |
} | |
/ '' { | |
const degree = new Array(1 + 7); | |
degree[3] = 'M'; | |
degree[5] = 'P'; | |
return { type: 'major', constitute: degree }; | |
} | |
Quality4 | |
= '6' { | |
const degree = new Array(1 + 7); | |
degree[6] = 'M'; | |
return { type: 'M6', constitute: degree }; | |
} | |
/ '7' { | |
const degree = new Array(1 + 7); | |
degree[7] = 'm'; | |
return { type: 'm7', constitute: degree }; | |
} | |
/ 'Maj7' { | |
const degree = new Array(1 + 7); | |
degree[7] = 'M'; | |
return { type: 'Maj7', constitute: degree }; | |
} | |
/ '' { return null; } | |
Option | |
= '-5' { | |
const degree = new Array(1 + 7); | |
degree[5] = 'd'; | |
return { type: 'd5', constitute: degree }; | |
} | |
/ '' { return null; } | |
Suspended | |
= 'sus4' { | |
const degree = new Array(1 + 7); | |
degree[3] = null; | |
degree[4] = 'P'; | |
return { type: 'sus4', constitute: degree }; | |
} | |
/ '' { return null; } | |
Tensions | |
= 'add' t:TensionNote { | |
const degree = new Array(1 + 7); | |
degree[t.type.degree - 7] = t.name[0]; | |
return [{ type: t.name, constitute: degree }]; | |
} | |
/ '(' t:TensionNote ')' { | |
const degree = new Array(1 + 7); | |
degree[t.type.degree - 7] = t.name[0]; | |
return [{ type: t.name, constitute: degree }]; | |
} | |
/ '(' t0:TensionNote tn:MultiTensions+ ')' { | |
tn.unshift(t0); | |
return tn.map(elm => { | |
const degree = new Array(1 + 7); | |
degree[elm.type.degree - 7] = elm.name[0]; | |
return { | |
type: elm.name, | |
constitute: degree, | |
} | |
}); | |
} | |
/ '' { return null; } | |
MultiTensions | |
= ',' _ t:TensionNote { return t; } | |
TensionNote | |
= '♭9' { return { name: 'm9', type: { degree: 9, altered: 'flatted' } }; } | |
/ '9' { return { name: 'M9', type: { degree: 9, altered: 'natural' } }; } | |
/ '♯9' { return { name: 'A9', type: { degree: 9, altered: 'sharped' } }; } | |
/ '11' { return { name: 'P11', type: { degree: 11, altered: 'natural'} }; } | |
/ '♯11' { return { name: 'A11', type: { degree: 11, altered: 'sharped' } }; } | |
/ '♭13' { return { name: 'm13', type: { degree: 13, altered: 'flatted' } }; } | |
/ '13' { return { name: 'M13', type: { degree: 13, altered: 'sharped' } }; } | |
/ 'Maj7' { return { name: 'M7', type: { degree: 14, altered: 'natural' } }; } // dimのMaj7テンション | |
_ "whitespace" | |
= [ \t\n\r]* |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment