我有一個包含小節(jié)線刻度線和可以與小節(jié)線重疊的 MIDI 音符的列表。所以我列出了“barlineticks”列表:barlinepos = [0, 768.0, 1536.0, 2304.0, 3072.0, 3840.0, 4608.0, 5376.0, 6144.0, 6912.0, 0, 576.0, 1152.0, 1728.0, 2304.0, 2880.0, 3456.0, 4032.0, 4608.0, 5184.0, 5760.0, 6336.0, 6912.0, 7488.0]和一個 MidiFile:{'type': 'time_signature', 'numerator': 4, 'denominator': 4, 'time': 0, 'duration': 768, 'ID': 0}{'type': 'set_tempo', 'tempo': 500000, 'time': 0, 'ID': 1}{'type': 'track_name', 'name': 'Tempo Track', 'time': 0, 'ID': 2}{'type': 'track_name', 'name': 'New Instrument', 'time': 0, 'ID': 3}{'type': 'note_on', 'time': 0, 'channel': 0, 'note': 48, 'velocity': 100, 'ID': 4, 'duration': 956}{'type': 'time_signature', 'numerator': 3, 'denominator': 4, 'time': 768, 'duration': 6911, 'ID': 5}{'type': 'note_on', 'time': 768, 'channel': 0, 'note': 46, 'velocity': 100, 'ID': 6, 'duration': 575}{'type': 'note_off', 'time': 956, 'channel': 0, 'note': 48, 'velocity': 0, 'ID': 7}{'type': 'note_off', 'time': 1343, 'channel': 0, 'note': 46, 'velocity': 0, 'ID': 8}{'type': 'end_of_track', 'time': 7679, 'ID': 9}我想檢查 MIDI 音符是否與小節(jié)線重疊。每條 note_on 消息都有一個“時間”和“持續(xù)時間”值。我必須檢查其中一個小節(jié)線(列表中)是否在注釋(“時間”和“持續(xù)時間”)的范圍內(nèi)。我試過:if barlinepos in range(0, 956): print(True)當然這不起作用,因為 barlinepos 是一個列表。如何檢查列表中的某個值是否結果為 True?
1 回答

守著一只汪
TA貢獻1872條經(jīng)驗 獲得超4個贊
簡單迭代即可解決需求:
for i in midifile:
start, end = i["time"], i["time"]+i["duration"]
for j in barlinepos:
if j >= start and j<= end:
print(True)
break
print(False)
添加回答
舉報
0/150
提交
取消