-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMeterNode.sc
More file actions
65 lines (51 loc) · 1.47 KB
/
Copy pathMeterNode.sc
File metadata and controls
65 lines (51 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
MeterNode {
var <>parent, <>val, <>status,<>children, <>height;
*new{ |val, children, parent, status, height|
^super.new.init(val, children, parent, status)
}
init { |val, parent = nil,children = nil, status = nil, height = nil|
this.val_(val); // a list of one or more beat lengths
this.parent_(parent); // pointer to parent node
if (this.children == nil, {this.children_([])});
this.children_(children); // pointer to array of children node
this.status_(status); // assume non-ternimal by default
this.height = height;
if (this.status == nil, {this.status_("n")});
}
modifyHeight { |modBy|
this.height = this.height + modBy;
}
recursivelyModifyHeight { |modBy|
// modify height of all descendants
this.modifyHeight(modBy);
this.children.do { |child|
child.recursivelyModifyHeight(modBy);
}
}
}
MelodyNode : MeterNode {
var <>note;
*new{ |val, children, parent, status, height, note|
^super.new(val, children, parent, status).sub_init(note)
}
sub_init { |note|
this.note = note;
}
modifyNote { |modBy|
this.note = this.note + modBy;
}
recursivelyModifyNote { |modBy|
// changes note in all descendants by a factor of modBy
this.modifyNote(modBy);
this.children.do{ |child|
child.recursivelyModifyNote(modBy);
}
}
recursivelyAdjustSubtree { |modHeight = 0, modNote = 0|
this.modifyHeight(modHeight);
this.modifyNote(modNote);
this.children.do { |child|
child.recursivelyAdjustSubtree(modHeight, modNote);
}
}
}