Skip to content

Commit

Permalink
Allow artist label to be replaced, closes #190
Browse files Browse the repository at this point in the history
  • Loading branch information
brunchboy committed Dec 8, 2024
1 parent 94fcd01 commit 1a4728b
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 8 deletions.
31 changes: 25 additions & 6 deletions doc/modules/ROOT/pages/Expressions_TriggerGlobal.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,37 @@ share across expressions.
This is run when Beat Link Trigger starts up, or when you open a new
Trigger file, so it runs before any of your individual trigger
expressions. As a simple example of what you might want to do, here is
an expression opens the <<Players.adoc#,Player Status window>>:
an expression that reconfigures the <<Players.adoc#,Player Status
window>> so that the line that normally shows the artist who created a
track instead shows the track comment (in case that's more useful for
communicating with your front-of-house staff):

[source,clojure]
----
(replace-artist-line (fn [metadata _player] (.getComment metadata)))
----

NOTE: This won't affect any tracks whose metadata is already displayed
in the Player Status window, if that was already open when you added
this to Global Setup. If that happens to you, load a new track to see
the results.

The `replace-artist-line` function gets passed a function that takes
the track metadata object and the player number, and returns the
string you want displayed on the second player status line. In this
example we are ignoring the player number, but you could use it to
look up other things if you need to.

We could combine this with another expression that opens the
<<Players.adoc#,Player Status window>>:

[source,clojure,subs=attributes+]
----
(beat-link-trigger.triggers/show-player-status)
----

Setting this as your Global Setup Expression will automatically open
the Player Status window whenever Beat Link Trigger launches. (This
also makes sure subsystems like the `TimeFinder` are running, which
can be helpful if you are writing other expressions that depend on
knowing the playback position of tracks.)
Having this in your Global Setup Expression will automatically open
the Player Status window whenever Beat Link Trigger launches.

If you ever start up BLT in offline mode with this Global Setup
Expression in place, however, you will be presented with an error
Expand Down
8 changes: 8 additions & 0 deletions src/beat_link_trigger/expressions.clj
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,14 @@
(when-not (str/blank? builder-name)
(su/swap-show! show update :cue-builders dissoc (str/trim builder-name))))

(defn replace-artist-line
"Allows customization of what is displayed in the artist line of the
player status window. Must be supplied a function that takes two
arguments, the track metadata and the player number, and returns the
string to be displayed."
[f]
(reset! @(requiring-resolve 'beat-link-trigger.players/artist-label-fn) f))

;;; The remainder of the functions in this namespace are used by the
;;; expression compiler, and are not intended for users to interact
;;; with directly.
Expand Down
12 changes: 10 additions & 2 deletions src/beat_link_trigger/players.clj
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@
[]
(empty? (filter #(<= 1 (.getDeviceNumber %) 4) (.getCurrentDevices device-finder))))

(defn- extract-label
(defn extract-label
"Given a `SearchableItem` from track metadata, extracts the string
label. If passed `nil` simply returns `nil`."
[^SearchableItem item]
Expand Down Expand Up @@ -445,6 +445,14 @@
(seesaw/show! root)
(.toFront root))))

(def artist-label-fn
"Holds the function that returns the text to display on the artist
line, so this can be customized when people want something else
there. Takes two arguments, the track metadata and the player
number."
(atom (fn [metadata _player]
(extract-label (.getArtist metadata)))))

(defn- update-metadata-labels
"Updates the track title and artist name when the metadata has
changed. Let the user know if they are not going to be able to get
Expand All @@ -454,7 +462,7 @@
(seesaw/invoke-soon
(if metadata
(do (seesaw/config! title-label :text (or (util/remove-blanks (.getTitle metadata)) "[no title]"))
(seesaw/config! artist-label :text (or (util/remove-blanks (extract-label (.getArtist metadata)))
(seesaw/config! artist-label :text (or (util/remove-blanks (@artist-label-fn metadata player))
"[no artist]")))
(let [^CdjStatus status (when (.isRunning virtual-cdj) (.getLatestStatusFor virtual-cdj (int player)))
title (if (= CdjStatus$TrackType/NO_TRACK (when status (.getTrackType status)))
Expand Down

0 comments on commit 1a4728b

Please sign in to comment.