跟踪行为 - Java MIDI
我正在从 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;
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
经过几个小时的调试,我设法找到了错误,我删除事件的方式意味着其中一半永远不会被考虑,这导致轨道的大小永远不会达到零。
我添加的任何事件都会放置在已经存在的事件之后,这可以解释为什么我在某些部分听到多个音符。
该问题(以及这个问题)的答案可以在这里找到:无法删除来自 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.