Performance considerations in this context refers to reducing system load to ensure clean playback of sounds.
Some issues you may notice if performance is an issue:
- Sound crackling
- Skipped notes
More testing is required to fully understand the causes of these issues.
A common issue you may notice is a large amount of crackling each time you save a file while working on a composition. This can be caused by the extra system resources being consumed by a full re-compilation of the ClojureScript files.
One way to avoid this is to disable auto-rebuilding, and instead re-evaluate sections of your ClojureScript files as you change them. This technique can also provide you with finer control over execution of code while live-coding.
Use the -r
option to disable the auto-rebuilding of boot dev
:
boot dev -r
# Or, if you're using Docker:
do/docker boot dev -r
You'll need a text editor that supports connecting a ClojureScript REPL. Refer to the current list of editors with support.
Using Emacs with Cider as
an example, you will connect your editor to the REPL started by boot dev
:
- Open your
composition.cljs
file in Emacs.- You may need to run
M-x clojure-mode
to switch fromclojurescript-mode
, see: clojure-emacs/cider#3061
- You may need to run
- Run the Emacs command:
M-x cider-connect
- (M-x stands for the combination of the 'Alt' and 'x' keys)
- Select the localhost Rhapsody REPL port
- A new buffer should open with a REPL prompt
If you see warnings in the Cider REPL about nrepl
or cider-repl
versions, you may need to add the following in a
~/.boot/profile.boot
file:
(require 'boot.repl)
(swap! boot.repl/*default-dependencies*
concat '[[cider/cider-nrepl "REPLACE_WITH_YOUR_CIDER_VERSION"]])
(swap! boot.repl/*default-middleware*
conj 'cider.nrepl/cider-middleware)
At the REPL you've opened in your editor, run the following Clojure command:
(start-repl)
This will wait for a browser window running your composition to
connect to. Open up your composition in a web browser, and
(start-repl)
should connect successfully. If you already had your
composition open, you may need to hard-refresh it (Ctrl-F5).
You should then have a new ClojureScript browser REPL in your editor. ClojureScript entered into this REPL will be evaluated in the browser. For example, try executing the following to see an alert box in the browser:
(js/alert "Hello World!")
Now you should be able to send individual "forms" (self-contained sections of ClojureScript code that have an equal number of opening and closing parentheses) to the REPL to be exeucted in the browser.
For example, in Emacs, if you place your cursor after a function
definition and execute C-x C-e
(Ctrl+x Ctrl+e
), the function will
be redefined in the browser, and all code calling that function will
use the new definition.
In this way, you can edit functions and variable defintions, and immediately send them to the browser for re-evaluation without the overhead of a full re-compilation.