【问题标题】:Why are there multiple set_tempo meta midi messages? (and how to deal)为什么有多个 set_tempo meta midi 消息? (以及如何处理)
【发布时间】:2019-12-27 14:33:20
【问题描述】:

我目前正在为 midi 文件编写一个解析器,这样我就可以使用马尔可夫链生成自己的音乐。

我有点困惑,为什么每个文件都有这么多 set_tempo midi 元消息(在音轨 0 元消息部分)。我会理解它们是否设置为不同的增量时间,但有些不是。还有一些似乎为相同的增量时间设置了相同的速度,这似乎是多余的。

这是一个例子......

<meta message set_tempo tempo=857139 time=0>
<meta message set_tempo tempo=857139 time=0>
<meta message set_tempo tempo=857632 time=0>
<meta message set_tempo tempo=857632 time=180224>
<meta message set_tempo tempo=895896 time=438>
<meta message set_tempo tempo=930917 time=438>
<meta message set_tempo tempo=967865 time=438>
<meta message set_tempo tempo=1008868 time=438>
<meta message set_tempo tempo=1053514 time=438>
<meta message set_tempo tempo=1101084 time=438>
<meta message set_tempo tempo=2403785 time=438>
<meta message set_tempo tempo=857632 time=1030>
<meta message set_tempo tempo=895896 time=292>
<meta message set_tempo tempo=930917 time=292>
<meta message set_tempo tempo=967865 time=292>
<meta message set_tempo tempo=1008868 time=292>
<meta message set_tempo tempo=1053514 time=292>
<meta message set_tempo tempo=1101084 time=292>
<meta message set_tempo tempo=2403785 time=292>
<meta message set_tempo tempo=2403785 time=1028>
<meta message end_of_track time=5119>

所以,

(1) 为什么会有重复?
(2) 不同增量时间的节奏变化重要吗? (即,这是因为音乐在各个部分加速/减速
(3) 是否值得为我的生成器实现一个处理节奏变化的隐藏马尔可夫链

任何帮助都将不胜感激。注:我对音乐理论知之甚少

干杯

这是我的解决方案,我做错了什么吗(在下面的答案中回复评论)。


import mido

all_mid = [' (Yiruma).mid']

# add time from start to message data (for sorting and adjusted delta time purposes)
def add_cumulative_time(msg, current_time):
    add_on = msg.time
    current_time += add_on
    return current_time, add_on

def clean(mid, all_messages):  # for each track (then message) do the following
    msgwithtempos = []
    for i, track in enumerate(mid.tracks):
        current_time = 0
        for msg in track:
            current_time = add_cumulative_time(msg, current_time)[0]
            allowed_types = ["note_on", "note_off", "program_change", "set_tempo"] 
            if msg.type in allowed_types:
                all_messages.append([msg, current_time])
            else:
                pass
    return all_messages, msgwithtempos


def main():  # for each midi file do the following
    all_lists = []
    for i in range(0, len(all_mid)):
        all_messages = []
        mid = mido.MidiFile(all_mid[i])
        ticksperbeat = mid.ticks_per_beat
        all_messages, msgwithtempos = clean(mid, all_messages)
        final_messages = all_messages + msgwithtempos
        final_messages = sorted(final_messages, key=lambda x: x[1])
        all_lists += final_messages
    for i, item in enumerate(all_lists):
        if all_lists[i][0].type == "set_tempo":
            while all_lists[i+1][0].type == "set_tempo": # talk about this as an error with i-1 being logical but not working
                all_lists.pop(i+1)
    return all_lists, ticksperbeat


if __name__ == '__main__':
    main()

【问题讨论】:

    标签: python midi markov-chains


    【解决方案1】:
    1. 我想这些复制品只是用真实乐器或类似的东西录制的人工制品。这不重要。
    2. 是的,速度变化会导致音乐播放速度变慢或变快。
    3. 您绝对必须尊重所有节奏变化。这是上一句的结果。

    【讨论】:

    • 你知道为什么他们为相同的增量时间设置不同的节奏吗?我该如何处理。谢谢
    • 我不知道为什么会发生这种情况,但我多次看到这种情况。在这种情况下,我只取最后一个速度值。
    • 我的项目从那时起就取得了进展,虽然我采用了最后一个速度值(并以此为基础),但听起来仍然很奇怪。将其更改为第一个,现在效果很好。看起来很不合逻辑的巴士唉
    • @staplegun,你能提供你测试过你的程序的文件吗?我会在我这边检查一下。但无论如何,你应该采取最后的节奏。我想您的程序在代码中的某处以错误的方式构建。 MIDI 数据始终根据事件位置进行处理,每个新事件都会立即应用。
    • 嗯 - 我认为最好在我上面的问题中发布我所有的 MIDI 格式化代码。我将累积时间(而不是增量时间)添加到每个音轨的每条消息中,然后按累积时间对所有音轨进行排序。然后我通过遍历整个列表来删除速度消息。我已经在来自不同网站的许多 MIDI 文件上对其进行了测试。
    【解决方案2】:

    如果您使用的是 0 格式文件,则 MIDI 1.0 规范说明如下:

    对于格式 0 的文件,速度会分散在音轨中, 节奏图阅读器应忽略中间事件

    我认为这意味着第一个节奏是要使用的节奏。我已经将具有多个速度事件的 MIDI 文件拖到多个程序中,并且它们倾向于选择第一个速度,尽管 Ableton 似乎有时会随机选择哪个速度。

    【讨论】:

      【解决方案3】:

      我的 midi 文件还有一长串“set tempo”消息。它们似乎是虚拟消息,仅用于它们的“时间”字段值。

      时间字段用于在第一轨道的特定时间放置“marker”和“key_signature”消息。这第一首曲目中没有音符。见下文。在这个 midi 文件中,第二和第三个音轨都有音符(这两个音轨在下面没有显示)。

          MIDI-MESSAGE KEY:VALUE pairs ...
       
          track_name name:Clair de Lune, time:0
          ...
          time_signature numerator:9, denominator:8, clocks_per_click:12, notated_32nd_notes_per_beat:8, time:0
          key_signature key:Db, time:0
          set_tempo tempo:600000, time:0
          marker text:Andante tres expressif, time:0
          set_tempo tempo:1875000, time:240
          set_tempo tempo:888889, time:240
          set_tempo tempo:821918, time:1680
          ...
          set_tempo tempo:789474, time:240
          set_tempo tempo:863309, time:240
          set_tempo tempo:909091, time:460
          ...
          set_tempo tempo:1846154, time:740
          set_tempo tempo:863309, time:240
          marker text:Tempo rubato, time:0
          set_tempo tempo:857756, time:40
          ...
          set_tempo tempo:571429, time:40
          set_tempo tempo:585366, time:600
          set_tempo tempo:535714, time:120
          set_tempo tempo:515818, time:480
          key_signature key:E, time:240
          set_tempo tempo:524017, time:0
          marker text:En animant, time:0
          set_tempo tempo:481618, time:480
          set_tempo tempo:498132, time:240
          ...
          end_of_track
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-07-26
        • 2016-10-30
        • 2018-02-20
        • 1970-01-01
        • 2021-05-29
        • 1970-01-01
        • 2013-08-25
        相关资源
        最近更新 更多