-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTimeSpan.sc
110 lines (67 loc) · 1.57 KB
/
TimeSpan.sc
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*
TimeSpan.sc
Use:
t = TimeSpan(25); // 25 seconds
u = TimeSpan(20);
t = t + 2;
t = t + u;
t.duration
t.asTimeString
t.numNotes(120); // How many 8th 25 sec with tempo=120 ?
t.duration_(60);
t.tempo_(60);
t.numNotes
*/
TimeSpan {
var <>duration, <tempo, <quavers, minutes, seconds;
*new { arg duration=30, tempo=60;
^super.new.init(duration, tempo);
}
init { |thisDuration, thisTempo|
duration = thisDuration;
tempo = thisTempo;
}
tempo_ { |newTempo|
tempo = newTempo;
}
numNotes {
^((this.tempo * this.duration) / 60).round(0.5)
}
asTimeString {
^this.duration.asTimeString
}
asTimeSigArray {
^this.numNotes.asTimeSigArray
}
asTimeSig {
^this.numNotes.asTimeSig
}
+ { |aThing|
case
{ (aThing.class == Integer).or(aThing.class == Float) } {
this.duration = this.duration + aThing }
{ aThing.class == TimeSpan } {
this.duration = this.duration + aThing.duration }
}
- { |aThing|
case
{ (aThing.class == Integer).or(aThing.class == Float) } {
this.duration = this.duration - aThing }
{ aThing.class == TimeSpan } {
this.duration = this.duration - aThing.duration }
}
* { |aThing|
case
{ (aThing.class == Integer).or(aThing.class == Float) } {
this.duration = this.duration * aThing }
{ aThing.class == TimeSpan } {
this.duration = this.duration * aThing.duration }
}
/ { |aThing|
case
{ (aThing.class == Integer).or(aThing.class == Float) } {
this.duration = this.duration / aThing }
{ aThing.class == TimeSpan } {
this.duration = this.duration / aThing.duration }
}
}