Class Orchestra
- All Implemented Interfaces:
AutoCloseable
public class Orchestra extends Object implements AutoCloseable
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:
- Add the Talon FXs to be used as instruments using
addInstrument(com.ctre.phoenix6.hardware.ParentDevice)
. - Load the Chirp file to be played using
loadMusic(java.lang.String)
. This 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 Summary
Constructors Constructor Description Orchestra()
Constructor for a new Orchestra.Orchestra(String filepath)
Constructor for a new Orchestra using the given Chirp file.Orchestra(Collection<ParentDevice> instruments)
Constructor for a new Orchestra using the given instruments.Orchestra(Collection<ParentDevice> instruments, String filepath)
Constructor for a new Orchestra using the given instruments and Chirp file. -
Method Summary
Modifier and Type Method Description StatusCode
addInstrument(ParentDevice instrument)
Adds an instrument to the orchestra.StatusCode
addInstrument(ParentDevice instrument, int trackNumber)
Adds an instrument to the orchestra on the given track.StatusCode
clearInstruments()
Clears all instruments in the orchestra.void
close()
Closes this Orchestra instance.double
getCurrentTime()
Gets the current timestamp of the music file.boolean
isPlaying()
Gets whether the current track is actively playing.StatusCode
loadMusic(String filepath)
Loads a Chirp file at the specified file path.StatusCode
pause()
Pauses the loaded music file.StatusCode
play()
Plays the loaded music file.StatusCode
stop()
Stops the loaded music file.
-
Constructor Details
-
Orchestra
public Orchestra()Constructor for a new Orchestra. -
Orchestra
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
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
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
Closes this Orchestra instance.- Specified by:
close
in interfaceAutoCloseable
-
addInstrument
Adds an instrument to the orchestra.- Parameters:
instrument
- The device to add to the orchestra- Returns:
- Status code of adding the device
-
addInstrument
Adds an instrument to the orchestra on the given track.- Parameters:
instrument
- The device to add to the orchestratrackNumber
- 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
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
Plays the loaded music file. If the player is paused, this will resume the orchestra.- Returns:
- Status code of playing the orchestra
-
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
Stops the loaded music file. This resets the current position in the track to the start.- Returns:
- Status code of stopping the orchestra
-
isPlaying
Gets whether the current track is actively playing.- Returns:
- true if Orchestra is playing the music file
-
getCurrentTime
Gets the current timestamp of the music file. The timestamp will reset to zero wheneverloadMusic(java.lang.String)
orstop()
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
-