Skip to main content

Module monitor

Module monitor 

Source
Expand description

What is playing, at what tempo, where in the bar — and who is master.

Two ports answer that question and neither answers all of it.

UDP 50001 is broadcast. Beat packets arrive on the beat, so a passive listener that has announced nothing still sees every playing deck’s tempo, its pitch fader and its position in the bar. Monitor::start is that, and it transmits nothing.

UDP 50002 is unicast to peers that have announced themselves and to nobody else (F21). It carries the loaded track, the play state and — at byte 0x9e — who holds tempo master, which is published there and nowhere else. A device that never announces can therefore never know who the master is, however long it listens. Monitor::with_status takes a VirtualCdj by reference for exactly that reason: the requirement is in the signature rather than in a comment somebody has to read.

§Interpolating phase

A beat packet is an event, not a report: its arrival is the deck saying “I am starting a beat now”. So phase is elapsed_since_the_packet / beat_interval, clamped rather than wrapped, and re-anchored by the next arrival. The interval comes from the effective tempo — the track’s BPM with the pitch fader applied — because the packet’s own millisecond fields are quoted as if the fader were centred (see prolink_proto::beat).

Clamped, not wrapped, because a deck that has stopped should sit at the end of its beat rather than spin: a wrapped estimate looks alive, and looking alive is the one thing a stopped deck must not do.

After BEAT_STALE_AFTER — three beats at 60 BPM, and seven at 145 — the phase is not merely old, it is meaningless, and BeatObservation::beat_phase returns None. The last tempo is still readable, because “it was playing at 128 and stopped” is more useful than an empty row.

Silence is evidence, but only about a CDJ. A nexus deck sends beat packets only while playing and only for a rekordbox-analysed track: in this project’s corpus not one status packet reporting “nothing loaded” had a beat from the same deck in the preceding second. A mixer sends them continuously as a backup metronome, so no such inference holds for one.

§One socket per port, and who else wants them

Monitor::with_status binds UDP 50002, and a VirtualCdj built with emit_status set binds it too, to answer media queries. Both sockets set SO_REUSEPORT, so both binds succeed — but a unicast datagram is delivered to only one of them: macOS gives it to the socket bound first, Linux hashes. So a monitor and a serving virtual CDJ cannot both read status.

That is not the constraint it looks like. What makes peers unicast their status to us is the keep-alive, not our own status stream, so a virtual CDJ configured with emit_status: false announces, receives everything, and leaves 50002 free for the monitor. Emitting status is needed only to be browsed. prolink status --announce does exactly that.

Structs§

BeatObservation
A beat packet and how long ago it landed.
LoadedTrack
What a player has loaded, and where it came from.
Monitor
A live view of the players on the network.
PlayState
Byte 0x7b of a status packet: what the platter is doing.
PlayerState
Everything both ports say about one device, as of one instant.
PlayerStatus
The fields of a status packet this crate models.
StatusObservation
A status packet’s modelled fields and how long ago it landed.
TrackKind
Byte 0x2a of a status packet: what kind of thing is loaded.

Enums§

MonitorEvent
Something changed.

Constants§

BEAT_STALE_AFTER
A device that has sent no beat packet for this long has stopped, and its phase is stale rather than merely old.
FORGET_AFTER
A device that has said nothing on either port for this long is dropped.