Skip to content

Commit 03b91fb

Browse files
committed
Rename apply-at to apply-by and implement apply-at to apply the fn at the specified time, not before it.
1 parent 75f2a94 commit 03b91fb

File tree

18 files changed

+45
-30
lines changed

18 files changed

+45
-30
lines changed

src/overtone/examples/compositions/bells.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@
106106
(at (bell-metro beat)
107107
(dorun
108108
(map #(pretty-bell % :vol 0.5) notes-to-play)))
109-
(apply-at (bell-metro next-beat) #'play-bells [next-beat (map rest notes)])))
109+
(apply-by (bell-metro next-beat) #'play-bells [next-beat (map rest notes)])))
110110

111111
;; Start the bells ringing...
112112
(defn runner

src/overtone/examples/compositions/blues.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
(play-blues instr pitch))
4040
(at (+ time (* 0.5 dur))
4141
(closed-hat 0.1))
42-
(apply-at n-time #'play-seq
42+
(apply-by n-time #'play-seq
4343
[(mod (inc count) 4) instr (next notes) (next durs) n-time odds]))))
4444

4545
; TODO: Strum the chord

src/overtone/examples/compositions/clapping_music.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
(defn player [beat]
3333
(when (= (mod beat 4) 0) (my-cycle))
3434
(play-beat beat)
35-
(apply-at (m (inc beat)) #'player (inc beat) []))
35+
(apply-by (m (inc beat)) #'player (inc beat) []))
3636

3737
(player (m))
3838
;;(stop)

src/overtone/examples/compositions/extemp_piano.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
(at (metro (+ beat offset)) (sampled-piano note 0.3)))
5151
notes-to-play
5252
beat-offsets))
53-
(apply-at (metro (inc beat)) #'beat-loop [metro (inc beat) nxt-chord-idx])))
53+
(apply-by (metro (inc beat)) #'beat-loop [metro (inc beat) nxt-chord-idx])))
5454

5555
;;start the music:
5656
(beat-loop metro (metro) 0)

src/overtone/examples/compositions/funk.clj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
(at (nome beat) (kick))
5454
(at (nome (+ 5 beat)) (kick))
5555
(at (nome (+ 7 beat)) (kick))
56-
(apply-at (nome (+ 8 beat)) drums nome [])))
56+
(apply-by (nome (+ 8 beat)) drums nome [])))
5757

5858
(defn bass [nome]
5959
(let [beat (nome)]
@@ -71,7 +71,7 @@
7171
(at (nome (+ 8 beat)) (string 51))
7272
(at (nome (+ 12 beat)) (string 51))
7373
(at (subdivide (nome (+ 12 beat)) (nome (+ 14 beat)) 1) (string 51))
74-
(apply-at (nome (+ 16 beat)) bass nome [])))
74+
(apply-by (nome (+ 16 beat)) bass nome [])))
7575

7676
(defn section [nome]
7777
(drums nome)

src/overtone/examples/compositions/jazz.clj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
(defn loop-play [bar len]
5151
(let [beat (metro)]
5252
(play-bar beat bar)
53-
(apply-at (metro (+ len beat)) #'loop-play [bar len])))
53+
(apply-by (metro (+ len beat)) #'loop-play [bar len])))
5454

5555
(def length 4)
5656

@@ -93,7 +93,7 @@
9393
next-even (if (zero? (mod beat 2))
9494
beat
9595
(inc beat))]
96-
(apply-at (metro next-even) #'jazzbass [start-note])))
96+
(apply-by (metro next-even) #'jazzbass [start-note])))
9797
([n]
9898
(let [beat (metro)
9999
tick (metro beat)
@@ -111,7 +111,7 @@
111111
(at (metro (+ beat (swing 0.5)) )
112112
(beep note)
113113
(bass (midi->hz note))))
114-
(apply-at (metro (+ beat 1)) #'jazzbass [note]))))
114+
(apply-by (metro (+ beat 1)) #'jazzbass [note]))))
115115

116116

117117
;; Set up rotater
@@ -134,7 +134,7 @@
134134
(do
135135
(at (metro start)
136136
(rotater-on note vel))
137-
(apply-at
137+
(apply-by
138138
(metro (+ len start))
139139
#'rotater-off [note]))))
140140

src/overtone/examples/compositions/piano_phase.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
(when n
1515
(at t
1616
(sampled-piano (note n)))
17-
(apply-at t-next #'player [t-next speed notes]))))
17+
(apply-by t-next #'player [t-next speed notes]))))
1818

1919
(def num-notes 1000)
2020

src/overtone/examples/getting_started/basic.clj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
(if (zero? (mod beat 6))
7575
(overpad (+ 12 (choose notes)) 0.5 0.15 0.1)
7676
(overpad (choose notes) 0.5 0.15 0.1)))
77-
(apply-at (metro (inc beat)) #'player (inc beat) (next notes) [])))
77+
(apply-by (metro (inc beat)) #'player (inc beat) (next notes) [])))
7878

7979
;;(player (metro) [])
8080
;;(stop)
@@ -87,7 +87,7 @@
8787
release 0.1
8888
next-beat (+ t beat-dur)]
8989
(at t (overpad note amp attack release))
90-
(apply-at next-beat #'play-notes next-beat beat-dur (next notes) (next attacks) []))))
90+
(apply-by next-beat #'play-notes next-beat beat-dur (next notes) (next attacks) []))))
9191

9292
;;(play-notes (now) 425 (cycle [40 42 44 45 47 49 51 52]) (repeat 0.4))
9393
;;(play-notes (now) 300 (scale :c4 :major) (repeat 0.05))
@@ -109,7 +109,7 @@
109109
(at (metro b)
110110
(doseq [note (map #(- % 12) (chord-notes))]
111111
(overpad note 0.3 (/ tick 1020))))
112-
(apply-at (metro next-beat) #'play-chords [next-beat])))
112+
(apply-by (metro next-beat) #'play-chords [next-beat])))
113113

114114
;;(play-chords (metro))
115115
;;(metro-bpm metro 70)
@@ -123,7 +123,7 @@
123123
(at t (kick-d))
124124
(at (+ t 350) (doseq [note (chord-notes)] (overpad (first notes) 0.3 0.1)))
125125
(at t (overpad (- (first notes) 36) 0.3 (/ dur 1000)))
126-
(apply-at (+ t dur) #'looper (+ t dur) dur (next notes) []))
126+
(apply-by (+ t dur) #'looper (+ t dur) dur (next notes) []))
127127

128128
;;(looper (now) 500 (cycle [60 67 65 72 75 70]))
129129
;;(stop)

src/overtone/examples/getting_started/rhythm.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
(at (m (+ 1.25 beat))
2323
(soft-hat :decay 0.03)))
2424

25-
(apply-at (m next-beat) #'player [next-beat])))
25+
(apply-by (m next-beat) #'player [next-beat])))
2626

2727
;;(player (m))
2828
;;(stop)

src/overtone/examples/getting_started/video.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
(when note
8686
(at time (plucked-string note)))
8787
(let [next-time (+ time sep)]
88-
(apply-at next-time play [next-time (rest notes) sep]))))
88+
(apply-by next-time play [next-time (rest notes) sep]))))
8989

9090
;; play some pitches
9191
(play (now) pitches 200)

src/overtone/examples/gui/basic.clj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242

4343
(defn foo-player [b]
4444
(at (m b) (foo))
45-
(apply-at (m (inc b)) #'foo-player [(inc b)]))
45+
(apply-by (m (inc b)) #'foo-player [(inc b)]))
4646

4747
; Start the synth looping, and play with the GUI to hear it change live
4848
(foo-player (m))
@@ -59,7 +59,7 @@
5959

6060
(defn bar-player [b]
6161
(at (m b) (bar))
62-
(apply-at (m (inc b)) #'bar-player [(inc b)]))
62+
(apply-by (m (inc b)) #'bar-player [(inc b)]))
6363

6464
(bar-player (m))
6565

@@ -133,7 +133,7 @@
133133
(defn step-player [b]
134134
(at (m b)
135135
(step-pad (+ 60 (nth (:steps @(:state pstep)) (mod b 16)))))
136-
(apply-at (m (inc b)) #'step-player [(inc b)]))
136+
(apply-by (m (inc b)) #'step-player [(inc b)]))
137137

138138
(:steps @(:state pstep))
139139

src/overtone/examples/notation/mad.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
(at t
1919
(synth pitch vol dur))
2020
(when elements
21-
(apply-at next-t #'p elements [next-t])))))
21+
(apply-by next-t #'p elements [next-t])))))
2222

2323
(declare calc-duration)
2424

src/overtone/examples/notation/mad2.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
beat (m)
6969
bar-start (m beat)]
7070
(play-over inst bar bar-start ms-per-bar)
71-
(apply-at (m (+ beat beats-per-bar)) #'play [inst (next bars) m t-sig]))))
71+
(apply-by (m (+ beat beats-per-bar)) #'play [inst (next bars) m t-sig]))))
7272

7373
(def metro (metronome 120))
7474

src/overtone/examples/timing/one_bar_sequencer.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
[m]
3939
(let [beat (m)]
4040
(player beat)
41-
(apply-at (m (inc beat)) #'run-sequencer [m])))
41+
(apply-by (m (inc beat)) #'run-sequencer [m])))
4242

4343
;; make beats! Edit bar whilst the beat is playing to make live changes.
4444
(run-sequencer metro)

src/overtone/gui/pianoroll.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@
147147
(when (= x index)
148148
(at (metro beat) (inst (+ offset y)))))
149149

150-
(apply-at (metro next-beat) #'piano-player
150+
(apply-by (metro next-beat) #'piano-player
151151
[state-atom next-beat])))))
152152

153153
(defn piano-roll

src/overtone/gui/sequencer.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
(when (value index)
7474
(at (metro beat) (inst))))
7575

76-
(apply-at (metro next-beat) #'step-player
76+
(apply-by (metro next-beat) #'step-player
7777
[state-atom next-beat])))))
7878

7979
(def ^{:private true} grid-line-style

src/overtone/music/time.clj

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,28 +65,43 @@
6565
[sched-fn] (at-at/kill sched-fn player-pool))
6666

6767
(def ^{:dynamic true :private true} *apply-ahead*
68-
"Amount of time apply-at is scheduled to execute *before* it was
68+
"Amount of time apply-by is scheduled to execute *before* it was
6969
scheduled by the user. This is to give room for any computation/gc
7070
cycles and to allow the executing fn to schedule actions on scsynth
7171
ahead of time using the at macro."
7272
300)
7373

74-
(defn apply-at
74+
(defn apply-by
7575
"Recursion in Time. Calls (apply f args argseq) *apply-ahead* ms
7676
before ms-time.
7777
7878
By passing a function using #'foo syntax instead of just foo, when
7979
later called by the scheduler it will lookup based on the symbol
8080
rather than using the instance of the function defined earlier.
8181
82-
(apply-at (+ dur (now)) #'my-melody arg1 arg2 [])"
82+
(apply-by (+ dur (now)) #'my-melody arg1 arg2 [])"
8383
{:arglists '([ms-time f args* argseq])}
8484
[#^clojure.lang.IFn ms-time f & args]
8585
(let [delay-time (- ms-time *apply-ahead* (now))]
8686
(if (<= delay-time 0)
8787
(after-delay 0 #(apply f (#'clojure.core/spread args)))
8888
(after-delay delay-time #(apply f (#'clojure.core/spread args))))))
8989

90+
(defn apply-at
91+
"Recursion in Time. Calls (apply f args argseq) exactly at time
92+
93+
By passing a function using #'foo syntax instead of just foo, when
94+
later called by the scheduler it will lookup based on the symbol
95+
rather than using the instance of the function defined earlier.
96+
97+
(apply-at (+ dur (now)) #'my-melody arg1 arg2 [])"
98+
{:arglists '([ms-time f args* argseq])}
99+
[#^clojure.lang.IFn ms-time f & args]
100+
(let [delay-time (- ms-time (now))]
101+
(if (<= delay-time 0)
102+
(after-delay 0 #(apply f (#'clojure.core/spread args)))
103+
(after-delay delay-time #(apply f (#'clojure.core/spread args))))))
104+
90105
(defn show-schedule
91106
"Print the schedule of currently running audio players."
92107
[]

src/overtone/studio/sequencer.clj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
(at (m (+ beat %1))
2525
(ins %2)))
2626
next-bar))
27-
(apply-at next-tick hit-fn [m next-beat ins]))))
27+
(apply-by next-tick hit-fn [m next-beat ins]))))
2828

2929
(defn mono-play-fn
3030
""
@@ -44,4 +44,4 @@
4444
(at (m (inc b))
4545
(ctl id :gate 0)))))
4646
next-bar))
47-
(apply-at next-tick play-fn [m next-beat ins]))))
47+
(apply-by next-tick play-fn [m next-beat ins]))))

0 commit comments

Comments
 (0)