GithubHelp home page GithubHelp logo

Comments (2)

helins avatar helins commented on July 19, 2024

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.

telekid avatar telekid commented on July 19, 2024

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 photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.