Skip to content

Commit

Permalink
Fix access to trigger globals from trigger expressions!
Browse files Browse the repository at this point in the history
  • Loading branch information
brunchboy committed May 3, 2024
1 parent cdc75e1 commit a9ed748
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 19 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ This change log follows the conventions of

### Fixed

- The ability to access trigger globals from trigger expressions had
been broken for some time, probably since the show interface was
added.
- The phrase trigger Started expression now has basic information
about the player causing the trigger to start much more of the time,
but no longer assumes this is due to a `CdjStatus` packet, because
Expand Down
5 changes: 2 additions & 3 deletions src/beat_link_trigger/editors.clj
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,7 @@
[update-binding simulate-status trigger compiled]
(binding [util/*simulating* (util/data-for-simulation)]
(binding [util/*simulating* (update-binding)]
(compiled (simulate-status) @(seesaw/user-data trigger)
(requiring-resolve 'beat-link-trigger.triggers/expression-globals)))))
(compiled (simulate-status) @(seesaw/user-data trigger) expressions/globals))))

(def trigger-editors
"Specifies the kinds of editor which can be opened for a trigger,
Expand Down Expand Up @@ -308,7 +307,7 @@
(help/user-guide-link "ShowInternals.html#show")
"\">User Guide</a> for details.")}

'trigger-globals {:code '@(resolve 'beat-link-trigger.triggers/expression-globals)
'trigger-globals {:code 'expressions/globals
:doc "The expression globals in the Triggers
window, in case you want to share values with
them."}})
Expand Down
5 changes: 5 additions & 0 deletions src/beat_link_trigger/expressions.clj
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@

;;; These first definitions are intended for use by user expressions and shared functions:

(defonce ^{:doc "Provides a space for trigger expressions to store
values they want to share across triggers. Visible to other
namespaces so that, for example, Show expressions can access them."}
globals (atom {}))

(def default-repositories
"Have our add-dependencies function default to searching Clojars as
well as Maven Central."
Expand Down
5 changes: 3 additions & 2 deletions src/beat_link_trigger/players.clj
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
(ns beat-link-trigger.players
"Provides the user interface for seeing the status of active
players, as well as telling players to load tracks."
(:require [beat-link-trigger.track-loader :as track-loader]
(:require [beat-link-trigger.expressions :as expressions]
[beat-link-trigger.track-loader :as track-loader]
[beat-link-trigger.simulator :as simulator]
[beat-link-trigger.util :as util]
[clojure.core.async :as async :refer [<! >!!]]
Expand Down Expand Up @@ -729,7 +730,7 @@
[visible-players]
(let [num-players (count visible-players)
default-columns (default-column-calculator num-players)]
(if-let [cols (:player-status-columns @@(resolve 'beat-link-trigger.triggers/expression-globals))]
(if-let [cols (:player-status-columns @expressions/globals)]
(cond
(integer? cols)
cols
Expand Down
17 changes: 3 additions & 14 deletions src/beat_link_trigger/triggers.clj
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,9 @@
[org.deepsymmetry.electro Metronome]
[uk.co.xfactorylibrarians.coremidi4j CoreMidiDeviceProvider]))

(defonce ^{:doc "Provides a space for trigger expressions to store
values they want to share across triggers. Visible to other
namespaces so that, for example, Show expressions can access them."}
expression-globals (atom {}))

;; Make the expression globals conveniently available when compiling
;; shared functions too.
(in-ns 'beat-link-trigger.expressions)

#_{:clj-kondo/ignore [:unresolved-namespace]}
(def globals
"The Beat Link Trigger expression globals"
beat-link-trigger.triggers/expression-globals)
(in-ns 'beat-link-trigger.triggers)
;; This used to be where this was defined, but for compilation order reasons, it has been swapped
;; into the expressions namespace.
(refer 'beat-link-trigger.expressions :only '[globals] :rename '{globals expression-globals})

(defonce ^{:private true
:doc "Holds the trigger window, through which we can access and
Expand Down

0 comments on commit a9ed748

Please sign in to comment.