Skip to content

Commit

Permalink
changing part removing behavior
Browse files Browse the repository at this point in the history
if a part is at the given time, it will remove the entire part instead of recursively checking and removing an event from the subpart.

fixes #269
  • Loading branch information
tambien committed Jan 9, 2019
1 parent fd26f6a commit b971ef9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
8 changes: 3 additions & 5 deletions Tone/event/Part.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,8 @@ define(["../core/Tone", "../event/Event", "../type/Type", "../core/Transport"],
};

/**
* Remove an event from the part. Will recursively iterate
* into nested parts to find the event.
* Remove an event from the part. If the event at that time is a Tone.Part,
* it will remove the entire part.
* @param {Time} time The time of the event
* @param {*} value Optionally select only a specific event value
* @return {Tone.Part} this
Expand All @@ -271,9 +271,7 @@ define(["../core/Tone", "../event/Event", "../type/Type", "../core/Transport"],
time = this.toTicks(time);
for (var i = this._events.length - 1; i >= 0; i--){
var event = this._events[i];
if (event instanceof Tone.Part){
event.remove(time, value);
} else if (event.startOffset === time){
if (event.startOffset === time){
if (Tone.isUndef(value) || (Tone.isDefined(value) && event.value === value)){
this._events.splice(i, 1);
event.dispose();
Expand Down
18 changes: 18 additions & 0 deletions test/event/Sequence.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,24 @@ function(Basic, Sequence, Tone, Transport, Event, Offline, Test, Time){
});
});

it("can add a subsequence and remove the entire subsequence", function(){
return Offline(function(){
var seq = new Sequence(function(){}, [0, 1, 2]);
expect(seq.length).to.equal(3);
seq.remove(0);
seq.add(0, [1, 2]);
expect(seq.length).to.equal(3);
console.log(seq.at(0));
expect(seq.at(0).at(0).value).to.equal(1);
expect(seq.at(0).at(1).value).to.equal(2);
seq.remove(0);
expect(seq.at(0)).to.equal(null);
seq.add(0, 4);
expect(seq.at(0).value).to.equal(4);
seq.dispose();
});
});

it("can add and retrieve a subSequence with 'at'", function(){
return Offline(function(){
var seq = new Sequence(function(){}, [0, 1, 2]);
Expand Down

0 comments on commit b971ef9

Please sign in to comment.