开发者

Track behaviour - Java MIDI

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(_tra开发者_StackOverflowck.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;

Track behaviour - Java MIDI

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));
    }


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜