Class Orpheus

java.lang.Object
lol.trq.orpheus.Orpheus
All Implemented Interfaces:
AutoCloseable

public final class Orpheus extends Object implements AutoCloseable
The entry point: collects what the sources report, picks one session, and offers it as a snapshot, as events and through commands.

Reading (snapshot(), playback(), lyrics(), cover()) is safe from any thread, never blocks and allocates nothing. Listeners run on the executor given to the builder, or on a library thread, in order. Command futures complete on a library thread. Nothing runs before start() and no thread survives stop(), unless a source or a lyrics provider hangs for more than five seconds while it stops.

  • Method Details

    • builder

      public static Orpheus.Builder builder()
    • start

      public void start()
      Starts the sources. Does nothing when already started.
    • stop

      public void stop()
      Stops the sources and every library thread, fails commands still in flight and clears the snapshot. Safe to call from a listener and more than once. Can be started again afterwards.
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
    • snapshot

      public Snapshot snapshot()
      Playback, lyrics and cover of this instant, guaranteed to belong together.
    • playback

      public Playback playback()
    • lyrics

      public Lyrics lyrics()
    • cover

      public Cover cover()
      The decoded cover of the playing track, or null.
    • sessions

      public List<SessionInfo> sessions()
      Every session the sources report, including hidden ones (without track data).
    • sources

      public List<SourceInfo> sources()
      The configured sources in priority order, each with its status. Before start() every source is listed as starting.
    • listen

      public Subscription listen(Consumer<? super OrpheusEvent> listener)
      Registers a listener for every event. If listeners fall more than 256 events behind, the oldest waiting events are dropped; every event carries the state of its moment, so the newest one is always current.
    • controls

      public Controls controls()
      Commands for whichever session is selected at the moment each command is sent.
    • controls

      public Controls controls(Playback playback)
      Commands for the session of playback, even if the selection moves on.
    • queue

      public PlayQueue queue()
    • devices

      public Outputs devices()
    • library

      public Library library()
    • pin

      public void pin(String sourceId)
      Manual choice: shows only sessions of one source, for example only the operating system or only one service. Among its sessions the usual automatic choice applies. See sources() for the ids.
    • pin

      public void pin(String sourceId, String appId)
      Shows only sessions of one application of one source. appId is matched like an AppRules rule.
    • unpin

      public void unpin()
      Returns to the automatic choice: something playing beats something paused, and between equals the source added to the builder first wins. So with the operating system first, a service is only shown while the system has nothing playing.
    • apps

      public void apps(AppRules newRules)
      Replaces the rules deciding which applications are visible.
    • shareable

      public void shareable(String sourceId, boolean share)
      Opts a source in or out of Playback.shareable(). Off for every source until set.
    • lyricsOffset

      public void lyricsOffset(Duration offset)
      Shifts the lyrics of the playing song; positive shows lines earlier. Remembered per song until stop(); does nothing while nothing plays.