Closed pearcemerritt closed 5 years ago
It works correctly. functions like ch() and tick() return a "view" of the original track to which all the writes go. You can change your test to the following:
describe('MTrk.note', function() {
it.only('should update the length property of the calling MTrk', function() {
var trk = new JZZ.MIDI.SMF.MTrk();
var ch = trk.ch(0);
assert.equal(trk.length, 1);
ch.note('C4', 127);
assert.equal(trk.length, 2);
});
});
ah, that makes sense! Thanks for clarifying :)
The above test fails. It can be found in my branch.
I discovered this while trying to write unit tests for some code in an app I've created that uses
MTrk
. I don't fully understand howMTrk
works and my app is working fine as far as I can see and hear, so perhaps this is expected behavior? But, even if it is, it would be nice to have the length properly reflected on theMTrk
object so that my unit tests can validate that program behavior is still correct (e.g. midi "noteOn" events have been added to SMF's, etc.) without having to play audio and use human ears to judge :)From the digging that I've done, part of the issue may be with this line:
As far as I can tell: because my code builds SMF's using
MTrk.ch
and then subsequentMtrk.note
andMtrk.tick
calls, it gets in a situation where theMTrk
object is converted into aChan
object butthis._orig
points at the originalMTrk
object theChan
was converted from. Then any calls toChan.note
result in calls toChan.send
, which updatesthis._orig
and the two objects' states get out of sync. Had theMTrk
not been wrapped by theChan
,this
would have been pointing at itself and it wouldn't have mattered if calls were made onthis
orthis._orig
.