Comments (2)
Hi! Sorry about the delay, I don't have a lot of time for open-source these days :)
There is a full description of the API on cljdoc, I don't know it is is apparent enough from the README, but here it is: https://cljdoc.org/d/dvlopt/dsim/1.0.0-beta1/doc/readme
So, your example fails because of what is going on with the path
. I reckon it is not obvious and in the future I will make it throw with an explicit exception. Essentially, it fails because you try to schedule something deeper in the event tree (at [:note]
) while there is already something scheduled at a lower path (at nil
, the root of the event tree).
It ends up doing something similar to this, which also fails in a somewhat obscure way:
(assoc-in {:a 42}
[:a :b]
:whatever)
=> java.lang.Long cannot be cast to clojure.lang.Associative
In general, it is always best to be explicit about the path
, remember it is a simple but useful feature. Doing so greatly simplify things. For instance, in your example, you nest e-conj
calls which make it hard to follow while I believe the same result is achieved with this simple implementation. I even mention the note number (60 = Middle C) in the path, I guess this is what you want:
(require '[dvlopt.dsim :as dsim])
(def run
(dsim/historic (dsim/ptime-engine)))
(defn held-note
"Prepares a queue for holding a note."
[duration]
(dsim/queue (fn turn-on [ctx]
(assoc-in ctx
(dsim/path ctx)
"on"))
(dsim/wq-delay (dsim/rank+ duration))
(fn turn-off [ctx]
(assoc-in ctx
(dsim/path ctx)
"off"))))
(def a 10)
(def b 10)
(map #(dissoc %
::dsim/events)
(run (-> {}
(dsim/e-conj [0]
[:note 60]
(held-note a))
(dsim/e-conj [b]
[:note 60]
(held-note 20)))))
I did fix a tiny little issue, try this code with version 1.0.0-beta1
;)
from dsim.cljc.
Thanks for the response. It's taken a bit of hammock time, but things are all feeling a bit more intuitive now. Oh, and I appreciate the bugfix!
from dsim.cljc.
Related Issues (4)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dsim.cljc.