【发布时间】:2018-02-01 06:26:59
【问题描述】:
我需要将很多和弦名称拆分为键和和弦类型:
name = C
name = C#
name = Db
name = C#maj7b5
name = Cmaj7b5
name = Dbmaj7b5
所以根始终是它自己的字母或带有#或b的字母,它自己的字母或仅带有#或b的字母,默认情况下,根需要= maj。
root = C
chord = maj
root = C#
chord = maj
root = Db
chord = maj
root = C#
chord = maj7b5
root = C
chord = maj7b5
root = Db
chord = maj7b5
我可以得到根名称:
name1 = string.match(name, "%a#")
name2 = string.match(name, "%ab")
name3 = string.match(name, "%a")
如果我在 name1 和 name2 中得到 nil 值,那么 root = name3。也只需要和弦名称。
编辑:使用:
chord, pos = nil, 0
chord, p = string.match(region_name, "=%s+([^\n]+)()", pos)
if not p then end
pos = p
root, chord = string.match(region_name, "(%w[#b]?)(.*)$")
if not chord or #chord == 0 then chord = "maj" end
【问题讨论】: