Deep-Symmetry / afterglow

A live-coding lighting controller, building on the Open Lighting Architecture with Clojure and bits of Overtone.
Eclipse Public License 2.0
423 stars 23 forks source link

Unclear fixture usage #74

Open BlackYps opened 2 years ago

BlackYps commented 2 years ago

From how I understand the documentation I am supposed to load the a fixture file as well as the show file like this: java -jar afterglow.jar src/musiclight/my_show.clj src/afterglow/fixtures/cameo.clj However, when I do this it can't actually find the file as indicated in the log:

2022-Feb-13 21:51:05 manjaro ERROR [afterglow.core:284] - Problem loading init-file src/musiclight/my_show.clj
                       afterglow.core.main                   
                                       ...                   
                      afterglow.core/-main     core.clj:  260
                      afterglow.core/-main     core.clj:  279
                   afterglow.core/-main/fn     core.clj:  282
                                       ...                   
                musiclight.my-show/eval152  my_show.clj:    1
musiclight.my-show/eval152/loading--auto--  my_show.clj:    1
                                       ...                   
                      clojure.core/require     core.clj: 5996 (repeats 2 times)
                        clojure.core/apply     core.clj:  669
                                       ...                   
                    clojure.core/load-libs     core.clj: 5958
                    clojure.core/load-libs     core.clj: 5974
                        clojure.core/apply     core.clj:  669
                                       ...                   
                     clojure.core/load-lib     core.clj: 5917
                     clojure.core/load-lib     core.clj: 5936
                  clojure.core/load-lib/fn     core.clj: 5937
                     clojure.core/load-one     core.clj: 5897
                                       ...                   
                         clojure.core/load     core.clj: 6098
                         clojure.core/load     core.clj: 6114
                      clojure.core/load/fn     core.clj: 6115
                                       ...                   
          java.io.FileNotFoundException: Could not locate afterglow/fixtures/cameo__init.class, afterglow/fixtures/cameo.clj or afterglow/fixtures/cameo.cljc on classpath.
clojure.lang.Compiler$CompilerException: Syntax error compiling at (/media/Daten/Dateien/Repositories/musiclight/src/musiclight/my_show.clj:1:1).
    data: {:clojure.error/phase :compile-syntax-check,
           :clojure.error/line 1,
           :clojure.error/column 1,
           :clojure.error/source
           "/media/Daten/Dateien/Repositories/musiclight/src/musiclight/my_show.clj"}

Here is the start of my show file where I try to load the fixture definition:

(ns musiclight.my-show
  "Set up the fixtures, effects, and cues I actually want to use."
  (:require [afterglow.core :as core]
            [afterglow.transform :as tf]
            [afterglow.effects.color :refer [color-effect]]
            [afterglow.effects.cues :as cues]
            [afterglow.effects.dimmer :refer [dimmer-effect]]
            [afterglow.effects.fun :as fun]
            [afterglow.effects.movement :as move]
            [afterglow.effects.oscillators :as oscillators]
            [afterglow.effects.params :as params]
            [afterglow.fixtures.cameo :as cameo]
            [afterglow.rhythm :as rhythm]
            [afterglow.show :as show]
            [afterglow.show-context :refer :all]
            [com.evocomputing.colors :refer [create-color hue adjust-hue]]
            [taoensso.timbre :as timbre]))

By the way, would you rather have me message you directly per email instead of spamming your repo with issues? In this case I had a lot of logs to attach anyway, but for a quick question it seems unnecessarily complicated lol.

brunchboy commented 2 years ago

For help with learning and figuring things out, I’d suggest asking on the Afterglow Gitter chat rather than emailing me directly, because that way there is a chance that someone other than me might be able to help faster, and there is a searchable public historical record, like there is here on GitHub, that can help others in the future. If the traffic on that channel picks up I will move it to Zulip like I have my other open source projects. But I have not done that yet with Afterglow.

brunchboy commented 2 years ago

But I still plan to take a look at and answer your question here, I just need to remind myself of what the code I wrote to support initialization files does. I would also suggest that if you are going to be doing serious amounts of development like this (creating new fixture definitions and your own show setup) you would be much happier in a REPL-oriented workflow, using Leiningen to start Clojure and manage your class paths, and an editor with good Clojure integration like Emacs + CIDER or IntelliJ IDEA + Cursive, rather than launching Afterglow from the command line using java -jar. I’d suggest setting up your own Clojure project that pulls in Afterglow as a library, then you can create and use whatever namespaces you want.

brunchboy commented 2 years ago

So I think I may understand the problem here. Assuming you defined the cameo fiixture in the afterglow.fixtures.cameo namespace (so that it begins with (ns afterglow.fixtures.cameo …) then it might be enough to simply reverse the order of your initialization files. Right now it is trying to load my-show first, and loading it involves compiling it, which involves finding the afterglow.fixtures.cameo namespace. Since you have not put that file on the class path, it can’t be found, and compilation fails. Swapping the files’ order in your command line will load the fixture definition first, so it will be available when my-show loads, which should work.

But that will get quickly tedious, if you start having a lot of fixture definitions to load. It would be better to just put all the fixture definitions (and any other auxiliary helper namespaces you want to create) on the class path, so the compiler can find them when it needs them, rather than forcing you to list them all as init-files. It looks like you might have organized your src/ folder correctly for it to be used as a class path element, so you might find that java -cp afterglow.jar:src afterglow.core src/musiclight/my_show.clj works. (Sadly you can’t combine the -jar shortcut with -cp to add other things to your classpath… trying to manually wrangle classpaths for Clojure projects gets tedious quickly, so setting up your own project in Leiningen and/or a Clojure aware IDE as I suggested above will probably be a lot more pleasant.)

BlackYps commented 2 years ago

Swapping the file order indeed solved the problem. I set up Clojure with IntelliJ IDEA and used Leiningen, but I didn't really figure out how to use the Clojure REPL to start my project from there. It's not too bad though, because I run my finished project on a Raspberry Pi and I use the afterglow.jar there anyway, so I might as well use that exact approach when developing.

I think the easiest thing for now is just to point out in the readme that the order of the file arguments matters.