Skip to content

Commit

Permalink
Start integrating VirtualRekordbox.
Browse files Browse the repository at this point in the history
  • Loading branch information
brunchboy committed May 1, 2024
1 parent 248cf4b commit d6d1cc2
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 42 deletions.
4 changes: 1 addition & 3 deletions src/beat_link_trigger/BeatLinkTrigger.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
executed. Its task is to parse command-line arguments and provide
help about them if requested, before passing the parsed results to
`beat-link-trigger.core/start`."
(:require [clojure.java.browse :as browse]
[clojure.string]
(:require [clojure.string]
[clojure.tools.cli :as cli]
[beat-link-trigger.util :as util])
(:import [javax.swing JOptionPane])
(:gen-class))

(def cli-options
Expand Down
6 changes: 4 additions & 2 deletions src/beat_link_trigger/about.clj
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,12 @@
"Create and show a frame that explains we are looking for devices.
`continue-offline` and `quit` are atoms that we should set to `true`
if the user clicks the corresponding button."
[continue-offline quit]
[opus-mode? continue-offline quit]
(seesaw/invoke-now
(let [searching (create-frame (partial create-searching-panel continue-offline quit)
:title "Looking for DJ Link devices…")]
:title (if opus-mode?
"Looking for Opus Quad…"
"Looking for DJ Link devices…"))]
(seesaw/config! searching :resizable? false :on-close :nothing)
(seesaw/show! searching)
searching)))
91 changes: 55 additions & 36 deletions src/beat_link_trigger/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
[taoensso.timbre :as timbre])
(:import [java.awt GraphicsEnvironment]
[javax.swing JFrame UIManager]
[org.deepsymmetry.beatlink DeviceAnnouncement DeviceFinder VirtualCdj]))
[org.deepsymmetry.beatlink DeviceAnnouncement DeviceFinder VirtualCdj VirtualRekordbox]))

(def ^DeviceFinder device-finder
"A convenient reference to the [Beat Link
Expand All @@ -30,6 +30,12 @@
singleton."
(VirtualCdj/getInstance))

(def ^VirtualRekordbox virtual-rekordbox
"A convenient reference to the [Beat Link
`VirtualRekordbox`](https://deepsymmetry.org/beatlink/apidocs/org/deepsymmetry/beatlink/VirtualRekordbox.html)
singleton."
(VirtualRekordbox/getInstance))

(def dynamic-class-loader
"The class loader that supports dynamic additions, for users to be
able to pull in new dependencies. This gets initialized in `start`."
Expand Down Expand Up @@ -91,8 +97,9 @@
([options]
(let [continue-offline (atom false)
quit (atom false)
searching (atom (about/create-searching-frame continue-offline quit))
real-player (triggers/real-player?)
opus-quad? (triggers/opus-quad?)
searching (atom (about/create-searching-frame opus-quad? continue-offline quit))
real-player? (triggers/real-player?)
network-label (seesaw/invoke-now (seesaw/label))]
(try
(.start device-finder) ; We are going to look for devices ourselves, so the user can interrupt us.
Expand All @@ -111,10 +118,11 @@
:title "Problem Trying to Go Online" :type :error)
(seesaw/dispose! @searching)
(reset! quit true))))
(timbre/info "Trying to go online, Use Real Player Number?" real-player)
(timbre/info "Trying to go online, Opus Quad mode? " opus-quad? ", Use Real Player Number?" real-player?)
(loop [tries-before-troubleshooting 200] ; Try for twenty seconds before switching to the troubleshooting window.
(cond
(not (or @continue-offline @quit (zero? tries-before-troubleshooting) (seq (.getCurrentDevices device-finder))))
(not (or @continue-offline @quit (zero? tries-before-troubleshooting)
(seq (.getCurrentDevices device-finder))))
(do ; Keep looping and looking until something of interest happens.
(Thread/sleep 100)
(recur (dec tries-before-troubleshooting)))
Expand Down Expand Up @@ -146,39 +154,50 @@
:else ; We saw a DJ-Link device, and so can go online.
(do
(seesaw/invoke-soon (seesaw/dispose! @searching))
(.setUseStandardPlayerNumber virtual-cdj real-player)
(if (try (.start virtual-cdj) ; Make sure we can start the VirtualCdj
(catch Exception e
(timbre/warn e "Unable to create Virtual CDJ")
(seesaw/invoke-now
(seesaw/alert (str "<html>Unable to create Virtual CDJ, check log for details.<br><br>" e)
:title "DJ Link Connection Failed" :type :error))))
(do ; We succeeded in finding a DJ Link network
(timbre/info "Went online, using player number" (.getDeviceNumber virtual-cdj))
(let [opus-ok (or (not opus-quad?) ; If we are in Opus Quad mode we need to start VirtualRekordbox
(try (.start virtual-rekordbox)
(catch Exception e
(timbre/warn e "Unable to create virtual rekordbox")
(seesaw/invoke-now
(seesaw/alert (str "<html>Unable to create Virtual rekordbox, "
"check log for details.<br><br>" e)
:title "Opus Quad Connection Failed" :type :error)))))]
(.setUseStandardPlayerNumber virtual-cdj real-player?)
(if (and opus-ok
(try (.start virtual-cdj) ; Make sure we can start the VirtualCdj
(catch Exception e
(timbre/warn e "Unable to create Virtual CDJ")
(seesaw/invoke-now
(seesaw/alert (str "<html>Unable to create Virtual CDJ, "
"check log for details.<br><br>" e)
:title "DJ Link Connection Failed" :type :error)))))
(do ; We succeeded in finding a DJ Link or Opus Quad network
(timbre/info "Went online, using player number" (.getDeviceNumber virtual-cdj)
"and Opus Quad mode is " opus-quad?)

;; Provide warnings about network topology problems
(when-let [interfaces (seq (help/list-conflicting-network-interfaces))]
(seesaw/invoke-now
(seesaw/alert (str "<html>Found multiple network interfaces on the DJ Link network.<br>"
"This can lead to duplicate packets and unreliable results:<br><br>"
(str/join "<br>" interfaces))
:title "Network Configuration Problem" :type :warning)))

(when-let [unreachables (seq (.findUnreachablePlayers virtual-cdj))]
(let [descriptions (map (fn [^DeviceAnnouncement device]
(str (.getDeviceName device) " (" (.getHostAddress (.getAddress device)) ")"))
unreachables)]
;; Provide warnings about network topology problems
(when-let [interfaces (seq (help/list-conflicting-network-interfaces))]
(seesaw/invoke-now
(seesaw/alert (str "<html>Found devices on multiple networks, and DJ Link can only use one.<br>"
"We will not be able to communicate with the following device"
(when (> (count unreachables) 1) "s") ":<br><br>"
(str/join "<br>" (sort descriptions)))
:title "Network Configuration Problem" :type :error)))))
(do ; We could not go online even though we see devices.
(timbre/warn "Unable to create Virtual CDJ")
(seesaw/invoke-now
(seesaw/alert "Unable to create Virtual CDJ, check the log for details."
:title "DJ Link Connection Failed" :type :error))))))))
(seesaw/alert (str "<html>Found multiple network interfaces on the DJ Link network.<br>"
"This can lead to duplicate packets and unreliable results:<br><br>"
(str/join "<br>" interfaces))
:title "Network Configuration Problem" :type :warning)))

(when-let [unreachables (seq (.findUnreachablePlayers virtual-cdj))]
(let [descriptions (map (fn [^DeviceAnnouncement device]
(str (.getDeviceName device) " (" (.getHostAddress (.getAddress device)) ")"))
unreachables)]
(seesaw/invoke-now
(seesaw/alert (str "<html>Found devices on multiple networks, and DJ Link can only use one.<br>"
"We will not be able to communicate with the following device"
(when (> (count unreachables) 1) "s") ":<br><br>"
(str/join "<br>" (sort descriptions)))
:title "Network Configuration Problem" :type :error)))))
(do ; We could not go online even though we see devices.
(timbre/warn "Unable to create Virtual CDJ")
(seesaw/invoke-now
(seesaw/alert "Unable to create Virtual CDJ, check the log for details."
:title "DJ Link Connection Failed" :type :error)))))))))

(finish-startup options)))

Expand Down
10 changes: 9 additions & 1 deletion src/beat_link_trigger/triggers.clj
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
[java.awt.event WindowEvent]
[javax.swing JFrame JMenu JMenuItem JCheckBoxMenuItem JRadioButtonMenuItem]
[org.deepsymmetry.beatlink BeatFinder BeatListener CdjStatus CdjStatus$TrackSourceSlot
DeviceAnnouncementListener DeviceFinder DeviceUpdateListener LifecycleListener Util VirtualCdj]
DeviceAnnouncementListener DeviceFinder DeviceUpdateListener LifecycleListener Util VirtualCdj
VirtualRekordbox]
[org.deepsymmetry.beatlink.data AnalysisTagFinder ArtFinder BeatGridFinder CrateDigger MetadataFinder
SearchableItem SignatureFinder TimeFinder TrackMetadata WaveformFinder]
[beat_link_trigger.util MidiChoice]
Expand Down Expand Up @@ -85,6 +86,12 @@
singleton."
(VirtualCdj/getInstance))

(def ^VirtualRekordbox virtual-rekordbox
"A convenient reference to the [Beat Link
`VirtualRekordbox`](https://deepsymmetry.org/beatlink/apidocs/org/deepsymmetry/beatlink/VirtualRekordbox.html)
singleton."
(VirtualRekordbox/getInstance))

(def ^MetadataFinder metadata-finder
"A convenient reference to the [Beat Link
`MetadataFinder`](https://deepsymmetry.org/beatlink/apidocs/org/deepsymmetry/beatlink/data/MetadataFinder.html)
Expand Down Expand Up @@ -1842,6 +1849,7 @@
(.stop (BeatFinder/getInstance))
(.stop (org.deepsymmetry.beatlink.dbserver.ConnectionManager/getInstance))
(.stop virtual-cdj)
(.stop virtual-rekordbox)
(Thread/sleep 200)) ; Wait for straggling update packets
(reflect-online-state)
(rebuild-all-device-status)))
Expand Down

0 comments on commit d6d1cc2

Please sign in to comment.