吉他tab到uke tab程序帮助

2024-05-12 16:45:39 发布

您现在位置:Python中文网/ 问答频道 /正文

所以我做了一个程序,它有一个吉他标签,得到了fret的号码,运行它通过一个字典,它得到了音符,并在uke音符字典中搜索它。在

但我的问题是如果我在txt文件中有一个标签,例如:

|-----11----------11----------11------11--13--11----------11----------11----------11------11--13--11---------------|
|-------13----------13----------13--------------------------13----------13----------13-----------------------------|
|--13-----13---13-----13---12-----12---------------12-13------13---13-----13---12-----12--------------------------|
|------------------------------------------------------------------------------------------------------------------|
|------------------------------------------------------------------------------------------------------------------|
|------------------------------------------------------------------------------------------------------------------|

所以我想要的是打开txt文件,在每一个与行相关的数字前面放一个字母。所以第一行的每一个数字都会写一个“e”,第二行:“B”,第三行:“G”

按顺序排列,最终结果是:G13 e11 B13 G13等。。。 有什么想法吗?在


Tags: 文件程序txt字典字母数字标签号码
2条回答

对于解析,请编写一个函数,该函数使用一行制表符和一个注释,该函数生成FRET以及位置:

import re

def parse_line(line, note):
    fret_pattern = re.compile(r'\d+')
    for match in fret_pattern.finditer(line):
        yield (match.start(), ''.join((note, match.group(0))))

对于第一行| -11 ,这将产生(6, "e11")。以后可以使用元组对所有字符串上的所有注释进行排序。在

现在只要open()文件,读入前6行并给它们正确的名称:

^{pr2}$

这应该是你想要的。但已经很晚了。在

tablines  = '''|   11     11     11   11 13 11     11     11     11   11 13 11       |
|   -13     13     13             13     13     13              -|
| 13  -13 -13  -13 -12  -12       -12-13   13 -13  -13 -12  -12             -|
|        -7                                                |
|   9     7                                                |
|        -7                                                |'''

# this will rotate them sideways, so you can compare them.
tabs = zip(*[list(l) for l in tablines.split("\n")][::-1])

ot = []
tl = len(tabs)
i = 1;
strings = 'eadgbe'
while i + 1 < tl:
    chord = []
    for j in range(6):
       # Because we need to care very strictly about order, we need to look 
       # through each point on the set of lines individually.
       dt = tabs[i][j] + tabs[i+1][j]
       if dt.isdigit():
           # both are digits, that means this is a chord.
           chord.append(strings[j] + dt)
       elif tabs[i-1][j] == '-' and tabs[i][j].isdigit():
           chord.append(strings[j] + tabs[i][j])
    if chord: # a chord has been found
       # tuples used because there the distinct possibility of two chords at once
       ot.append(tuple(chord))
    i+=1

print ot

结果是:

[('g13',), ('a9', 'e11'), ('b13',), ('g13',), ('g13',), ('e7', 'a7', 'd7'), ('e11',), ('b13',), ('g13',), ('g12',), ('e11',), ('b13',), ('g12',), ('e11',), ('e13',), ('e11',), ('g12',), ('g13',), ('e11',), ('b13',), ('g13',), ('g13',), ('e11',), ('b13',), ('g13',), ('g12',), ('e11',), ('b13',), ('g12',), ('e11',), ('e13',), ('e11',)]

相关问题 更多 >