Class Orchestra

java.lang.Object
com.ctre.phoenix6.Orchestra
All Implemented Interfaces:
AutoCloseable

public class Orchestra
extends Object
implements AutoCloseable
Orchestra is used to play music through devices. It uses a "Chirp" (.chrp) music file that can be generated using Phoenix Tuner. Chirp files are generated from standard MIDI files.

Any Chirp file located in the src/main/deploy directory of your FRC project will automatically be copied to the roboRIO on code deploy.

The robot must be enabled to play music. Additionally, devices playing in Orchestra will not run any other control requests while Orchestra is running. Users can pause() or stop() the Orchestra to re-enable device control.

Each device can only play a single track within the music file. For multi-track files, multiple devices are needed. Devices can be added with an explicit track number. Otherwise, the first track will be played through the first Talon FX added, the second track will be played through the second Talon FX added, etc.

To use Orchestra:

Both of these can also be done in the Orchestra constructor.

Once ready, the Orchestra can be controlled using play()/pause()/stop(). New music files can be loaded at any time.

  • Constructor Details

    • Orchestra

      public Orchestra()
      Constructor for a new Orchestra.
    • Orchestra

      public Orchestra​(String filepath)
      Constructor for a new Orchestra using the given Chirp file.
      Parameters:
      filepath - The path to the music file to immediately load into the orchestra.
    • Orchestra

      public Orchestra​(Collection<ParentDevice> instruments)
      Constructor for a new Orchestra using the given instruments.
      Parameters:
      instruments - A collection of devices that will be used as instruments in the orchestra.
    • Orchestra

      public Orchestra​(Collection<ParentDevice> instruments, String filepath)
      Constructor for a new Orchestra using the given instruments and Chirp file.
      Parameters:
      instruments - A collection of devices that will be used as instruments in the orchestra.
      filepath - The path to the music file to immediately load into the orchestra.
  • Method Details

    • close

      public void close()
      Closes this Orchestra instance.
      Specified by:
      close in interface AutoCloseable
    • addInstrument

      public StatusCode addInstrument​(ParentDevice instrument)
      Adds an instrument to the orchestra.
      Parameters:
      instrument - The device to add to the orchestra
      Returns:
      Status code of adding the device
    • addInstrument

      public StatusCode addInstrument​(ParentDevice instrument, int trackNumber)
      Adds an instrument to the orchestra on the given track.
      Parameters:
      instrument - The device to add to the orchestra
      trackNumber - The track number the device should play, starting at 0
      Returns:
      Status code of adding the device
    • clearInstruments

      Clears all instruments in the orchestra.
      Returns:
      Status code of clearing all devices
    • loadMusic

      public StatusCode loadMusic​(String filepath)
      Loads a Chirp file at the specified file path.

      If the Chirp file is inside your "src/main/deploy" directory, it will be automatically deployed to a default directory on the roboRIO when you deploy code. For these files, the name and file extension is sufficient.

      A Chirp file can be created from a MIDI file using Phoenix Tuner.

      Parameters:
      filepath - The path to the Chirp file
      Returns:
      Status code of loading the Chirp file
    • play

      public StatusCode play()
      Plays the loaded music file. If the player is paused, this will resume the orchestra.
      Returns:
      Status code of playing the orchestra
    • pause

      public StatusCode pause()
      Pauses the loaded music file. This saves the current position in the track so it can be resumed later.
      Returns:
      Status code of pausing the orchestra
    • stop

      public StatusCode stop()
      Stops the loaded music file. This resets the current position in the track to the start.
      Returns:
      Status code of stopping the orchestra
    • isPlaying

      public boolean isPlaying()
      Gets whether the current track is actively playing.
      Returns:
      true if Orchestra is playing the music file
    • getCurrentTime

      public double getCurrentTime()
      Gets the current timestamp of the music file. The timestamp will reset to zero whenever loadMusic(java.lang.String) or stop() is called.

      If isPlaying() returns false, this method can be used to determine if the music is stopped or paused.

      Returns:
      The current timestamp of the music file, in seconds