跟踪行为 - Java MIDI

发布于 2024-11-01 18:41:47 字数 1162 浏览 3 评论 0原文

我正在从 MIDI 轨道中删除事件,并且我假设这样做,轨道的总持续时间会相应减少,如果轨道中没有事件,那么我认为轨道的大小将为 0。

不幸的是,似乎事实并非如此,即使事件被删除,Ticks 的大小也不会改变,只会随着添加更多事件而增加。

这是正常的 MIDI/Java 行为吗?

编辑:

这是从轨道中删除所有事件的方法:

public static boolean Remove() {
    //TODO: Test the bejeezus out of it.

    if(_sequencer.isRunning()){
        _sequencer.stop();
    }

    for (int i = 0; i < _track.size(); i++) {
        if (!_track.remove(_track.get(i))) {
            Logger.Add("MIDI Event not removed");
            return false;
        }
    }

    //Used for debugging purposes
    long z = _track.ticks();
}

然而,当我使用一些粗略的调试技术并在删除事件后直接检查刻度数时,我发现了这一点;

在此处输入图像描述

这似乎没有什么区别,我真的不明白为什么要这样做。我假设刻度的大小取决于轨道中事件的数量,因此,如果轨道中有 10 个事件,则刻度大小将为 10(当我将它们添加到轨道时将刻度长度设置为 1),同样,如果没有大小为 0 的事件。

添加事件:

public static void AddMessage(int channel, int pitch, long tick, int velocity) {
        _track.add(CreateNoteOnEvent(channel, pitch, tick, velocity));
        _track.add(CreateNoteOffEvent(channel, pitch tick, velocity));
    }

I am removing events from a MIDI Track and I assumed that by doing so the total duration of the Track would reduce accordingly, If there are no events in the Track then I thought that the size of the Track would be 0.

Unfortunately it seems it is not the case, even though the events are removed the size in Ticks does not change and only increases as more are added.

Is this normal MIDI/Java behaviour?

Edit:

This is the method that removes all of the events from the Track:

public static boolean Remove() {
    //TODO: Test the bejeezus out of it.

    if(_sequencer.isRunning()){
        _sequencer.stop();
    }

    for (int i = 0; i < _track.size(); i++) {
        if (!_track.remove(_track.get(i))) {
            Logger.Add("MIDI Event not removed");
            return false;
        }
    }

    //Used for debugging purposes
    long z = _track.ticks();
}

Yet when I use some crude debugging techniques and check the amount of ticks directly after removing the events, I find this;

enter image description here

It seemingly makes no difference, I don't really understand why it's doing it. I assumed that the size of Ticks depends on the amount of events in the Track, therefore if there were 10 events in a track the tick size would be 10 (As I set the tick length to 1 when adding them to the track) likewise if there were no events the size would be 0.

Adding events:

public static void AddMessage(int channel, int pitch, long tick, int velocity) {
        _track.add(CreateNoteOnEvent(channel, pitch, tick, velocity));
        _track.add(CreateNoteOffEvent(channel, pitch tick, velocity));
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

悍妇囚夫 2024-11-08 18:41:47

经过几个小时的调试,我设法找到了错误,我删除事件的方式意味着其中一半永远不会被考虑,这导致轨道的大小永远不会达到零。

我添加的任何事件都会放置在已经存在的事件之后,这可以解释为什么我在某些部分听到多个音符。

该问题(以及这个问题)的答案可以在这里找到:无法删除来自 Track 的活动

感谢您抽出时间,我非常感激。

After many hours debugging I managed to track the bug down, the way I was removing events meant that half of them would never be considered which led to the size of the track never reaching zero.

Any event I added would then be placed after the already existing events which would explain why I was hearing multiple notes in certain parts.

The answer to that question (and this one) can be found here: Unable to Remove Events from Track

Thanks for your time, I greatly appreciate it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文