CTRE Phoenix 6 C++ 25.0.0-beta-4
Loading...
Searching...
No Matches
Orchestra.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) Cross The Road Electronics.  All rights reserved.
3 * License information can be found in CTRE_LICENSE.txt
4 * For support and suggestions contact support@ctr-electronics.com or file
5 * an issue tracker at https://github.com/CrossTheRoadElec/Phoenix-Releases
6 */
7
9
10namespace ctre {
11namespace phoenix6 {
12
13/**
14 * \brief Orchestra is used to play music through devices. It uses a "Chirp" (.chrp)
15 * music file that can be generated using Phoenix Tuner. Chirp files are generated
16 * from standard MIDI files.
17 *
18 * Any Chirp file located in the src/main/deploy directory of your FRC project will
19 * automatically be copied to the roboRIO on code deploy.
20 *
21 * Unless configs#AudioConfigs#AllowMusicDurDisable is enabled, the robot must be enabled
22 * to play music. Additionally, devices playing in Orchestra will not run any other
23 * control requests while Orchestra is running. Users can #Pause or #Stop the Orchestra
24 * to re-enable device control.
25 *
26 * \details Each device can only play a single track within the music file. For multi-track
27 * files, multiple devices are needed. Devices can be added with an explicit track
28 * number. Otherwise, the first track will be played through the first Talon FX added,
29 * the second track will be played through the second Talon FX added, etc.
30 *
31 * To use Orchestra:
32 * - Add the Talon FXs to be used as instruments using #AddInstrument.
33 * - Load the Chirp file to be played using #LoadMusic.
34 * Both of these can also be done in the Orchestra constructor.
35 *
36 * Once ready, the Orchestra can be controlled using #Play/#Pause/#Stop. New music
37 * files can be loaded at any time.
38 */
39class Orchestra {
40private:
41 uint16_t _id{};
42
43public:
44 /**
45 * \brief Constructor for a new Orchestra.
46 */
48 /**
49 * \brief Constructor for a new Orchestra using the given Chirp file.
50 *
51 * This API is blocking on the file read.
52 *
53 * \param filepath The path to the music file to immediately load into the orchestra.
54 */
55 Orchestra(char const *filepath) : Orchestra{}
56 {
57 LoadMusic(filepath);
58 }
59 /**
60 * \brief Constructor for a new Orchestra using the given Chirp file.
61 *
62 * \param instruments A vector of device addresses that will be used as instruments in the orchestra.
63 */
64 Orchestra(std::vector<hardware::ParentDevice *> const &instruments) : Orchestra{}
65 {
66 for (auto instrument : instruments) {
67 AddInstrument(*instrument);
68 }
69 }
70 /**
71 * \brief Constructor for a new Orchestra using the given Chirp file.
72 *
73 * \param instruments An array of device addresses that will be used as instruments in the orchestra.
74 */
75 template <size_t N>
76 Orchestra(std::array<hardware::ParentDevice *, N> const &instruments) : Orchestra{}
77 {
78 for (auto instrument : instruments) {
79 AddInstrument(*instrument);
80 }
81 }
82 /**
83 * \brief Constructor for a new Orchestra using the given Chirp file.
84 *
85 * This API is blocking on the file read.
86 *
87 * \param instruments A vector of device addresses that will be used as instruments in the orchestra.
88 * \param filepath The path to the music file to immediately load into the orchestra.
89 */
90 Orchestra(std::vector<hardware::ParentDevice *> const &instruments, char const *filepath) : Orchestra{}
91 {
92 for (auto instrument : instruments) {
93 AddInstrument(*instrument);
94 }
95 LoadMusic(filepath);
96 }
97 /**
98 * \brief Constructor for a new Orchestra using the given Chirp file.
99 *
100 * This API is blocking on the file read.
101 *
102 * \param instruments An array of device addresses that will be used as instruments in the orchestra.
103 * \param filepath The path to the music file to immediately load into the orchestra.
104 */
105 template <size_t N>
106 Orchestra(std::array<hardware::ParentDevice *, N> const &instruments, char const *filepath) : Orchestra{}
107 {
108 for (auto instrument : instruments) {
109 AddInstrument(*instrument);
110 }
111 LoadMusic(filepath);
112 }
113
115
116 /**
117 * \brief Adds an instrument to the orchestra.
118 *
119 * This adds the instrument to the next track; it does not wrap
120 * back to track 0 if all tracks have been filled. To assign
121 * multiple instruments to a track, use #AddInstrument(hardware#ParentDevice const &, uint16_t).
122 *
123 * \param instrument The device to add to the orchestra
124 * \returns Status code of adding the device
125 */
127
128 /**
129 * \brief Adds an instrument to the orchestra on the given track.
130 *
131 * This can be used to assign multiple instruments to a track.
132 *
133 * \param instrument The device to add to the orchestra
134 * \param trackNumber The track number the device should play, starting at 0
135 * \returns Status code of adding the device
136 */
137 ctre::phoenix::StatusCode AddInstrument(hardware::ParentDevice const &instrument, uint16_t trackNumber);
138
139 /**
140 * \brief Clears all instruments in the orchestra.
141 *
142 * \returns Status code of clearing all devices
143 */
145
146 /**
147 * \brief Loads a Chirp file at the specified file path.
148 *
149 * If the Chirp file is inside your "src/main/deploy" directory, it will be
150 * automatically deployed to a default directory on the roboRIO when you
151 * deploy code. For these files, the name and file extension is sufficient.
152 *
153 * A Chirp file can be created from a MIDI file using Phoenix Tuner.
154 *
155 * This API is blocking on the file read.
156 *
157 * \param filepath The path to the Chirp file
158 * \returns Status code of loading the Chirp file
159 */
161
162 /**
163 * \brief Plays the loaded music file. If the player is paused, this will resume
164 * the orchestra.
165 *
166 * \returns Status code of playing the orchestra
167 */
169
170 /**
171 * \brief Pauses the loaded music file. This saves the current position in the
172 * track so it can be resumed later.
173 *
174 * \returns Status code of pausing the orchestra
175 */
177
178 /**
179 * \brief Stops the loaded music file. This resets the current position in the
180 * track to the start.
181 *
182 * \returns Status code of stopping the orchestra
183 */
185
186 /**
187 * \brief Gets whether the current track is actively playing.
188 *
189 * \returns true if Orchestra is playing the music file
190 */
191 bool IsPlaying() const;
192
193 /**
194 * \brief Gets the current timestamp of the music file. The timestamp will reset
195 * to zero whenever #LoadMusic or #Stop is called.
196 *
197 * \details If #IsPlaying returns false, this method can be used to determine
198 * if the music is stopped or paused.
199 *
200 * \returns The current timestamp of the music file, in seconds
201 */
202 double GetCurrentTime() const;
203};
204
205} // namespace phoenix6
206} // namespace ctre
Orchestra is used to play music through devices.
Definition Orchestra.hpp:39
double GetCurrentTime() const
Gets the current timestamp of the music file.
ctre::phoenix::StatusCode AddInstrument(hardware::ParentDevice const &instrument)
Adds an instrument to the orchestra.
Orchestra(std::array< hardware::ParentDevice *, N > const &instruments, char const *filepath)
Constructor for a new Orchestra using the given Chirp file.
Definition Orchestra.hpp:106
Orchestra(std::vector< hardware::ParentDevice * > const &instruments, char const *filepath)
Constructor for a new Orchestra using the given Chirp file.
Definition Orchestra.hpp:90
bool IsPlaying() const
Gets whether the current track is actively playing.
ctre::phoenix::StatusCode LoadMusic(char const *filepath)
Loads a Chirp file at the specified file path.
Orchestra(std::array< hardware::ParentDevice *, N > const &instruments)
Constructor for a new Orchestra using the given Chirp file.
Definition Orchestra.hpp:76
ctre::phoenix::StatusCode Stop()
Stops the loaded music file.
ctre::phoenix::StatusCode Pause()
Pauses the loaded music file.
Orchestra(std::vector< hardware::ParentDevice * > const &instruments)
Constructor for a new Orchestra using the given Chirp file.
Definition Orchestra.hpp:64
Orchestra()
Constructor for a new Orchestra.
ctre::phoenix::StatusCode AddInstrument(hardware::ParentDevice const &instrument, uint16_t trackNumber)
Adds an instrument to the orchestra on the given track.
ctre::phoenix::StatusCode Play()
Plays the loaded music file.
ctre::phoenix::StatusCode ClearInstruments()
Clears all instruments in the orchestra.
Orchestra(char const *filepath)
Constructor for a new Orchestra using the given Chirp file.
Definition Orchestra.hpp:55
Parent class for all devices.
Definition ParentDevice.hpp:29
Status codes reported by APIs, including OK, warnings, and errors.
Definition StatusCodes.h:27
Definition StatusCodes.h:18