Package com.ctre.phoenix.music
Class Orchestra
java.lang.Object
com.ctre.phoenix.music.Orchestra
An Orchestra is used to play music through Talon FX motor controllers.
It uses a "Chirp" (.chrp) music file that can be generated using Phoenix Tuner.
Chirp files are generated from standard MIDI files.
Each Talon FX can only play a single track within the music file.
For multi-track files, multiple Talon FXs are needed.
ie, 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.
Any Chirp file located in the src/main/deploy directory of your FRC project
will automatically be copied to the roboRIO on code deploy.
To use the Orchestra:
- Add the Talon FXs to be used as instruments
- Load the Chirp file to be played using the loadMusic routine.
Both of these can also be done in the Orchestra constructor.
Once ready, the Orchestra can be controlled using standard
play/pause/stop routines.
New music files can be loaded at any time.
The robot must be enabled to play music.
Calling set on any of the TalonFX instruments while the orchestra is
playing will pause the orchestra.
-
Constructor Summary
ConstructorsConstructorDescriptionConstructor for an Orchestra Object.Orchestra
(Collection<TalonFX> instruments) Constructor for an Orchestra Object.Orchestra
(Collection<TalonFX> instruments, String filePath) Constructor for an Orchestra Object -
Method Summary
Modifier and TypeMethodDescriptionaddInstrument
(TalonFX instrument) Adds another instrument to the orchestra.Clears all instruments in the orchestra.int
boolean
Returns whether the current track is actively playing or notLoads a Chirp file at the specified file path.pause()
Pauses the music file that's loaded.play()
Plays the music file that's loaded.stop()
Stops the music file that's loaded.
-
Constructor Details
-
Orchestra
public Orchestra()Constructor for an Orchestra Object. Call AddInstrument after this to add the instruments. -
Orchestra
Constructor for an Orchestra Object.- Parameters:
instruments
- A collection of TalonFX's that will be used as instruments inside the orchestra.
-
Orchestra
Constructor for an Orchestra Object- Parameters:
instruments
- A collection of TalonFX's that will be used as instruments inside the orchestra.filePath
- The path to the music file to immediately load into the orchestra.
-
-
Method Details
-
loadMusic
Loads a Chirp file at the specified file path. If the Chirp file is inside your "src/main/deploy" directory this file will be automatically deployed to a default directory in the RoboRIO when you deploy code. For these files, the name and file extension is sufficient. Use Tuner to create a Chirp file.- Parameters:
filePath
- The path to the Chirp File.- Returns:
- Error Code generated by function. 0 indicates no error.
-
play
Plays the music file that's loaded. If the player is paused, this will resume. This will also resume a song if the orchestra was interrupted.- Returns:
- Error Code generated by function. 0 indicates no error.
-
stop
Stops the music file that's loaded. This resets the current position in the track to the start.- Returns:
- Error Code generated by function. 0 indicates no error.
-
pause
Pauses the music file that's loaded. This saves the current position in the track, so it can be resumed later. Pausing while stopped is an invalid request.- Returns:
- Error Code generated by function. 0 indicates no error.
-
isPlaying
Returns whether the current track is actively playing or not- Returns:
- True if playing, false otherwise
-
getCurrentTime
- Returns:
- The current timestamp of the music file (playing or paused) in milliseconds. The timestamp will reset to zero whenever loadMusic() or stop() is called. If isPlaying() returns false, this routine can be used to determine if music is stopped or paused.
-
clearInstruments
Clears all instruments in the orchestra.- Returns:
- Error Code generated by function. 0 indicates no error.
-
addInstrument
Adds another instrument to the orchestra.- Parameters:
instrument
- TalonFX to add to orchestra- Returns:
- Error Code generated by function. 0 indicates no error.
-