CTRE Phoenix 6 C++ 24.3.0
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 * The robot must be enabled to play music. Additionally, devices playing in Orchestra
22 * will not run any other control requests while Orchestra is running. Users can #Pause
23 * or #Stop the Orchestra to re-enable device control.
24 *
25 * \details Each device can only play a single track within the music file. For multi-track
26 * files, multiple devices are needed. Devices can be added with an explicit track
27 * number. Otherwise, the first track will be played through the first Talon FX added,
28 * the second track will be played through the second Talon FX added, etc.
29 *
30 * To use Orchestra:
31 * - Add the Talon FXs to be used as instruments using #AddInstrument.
32 * - Load the Chirp file to be played using #LoadMusic.
33 * Both of these can also be done in the Orchestra constructor.
34 *
35 * Once ready, the Orchestra can be controlled using #Play/#Pause/#Stop. New music
36 * files can be loaded at any time.
37 */
38class Orchestra {
39private:
40 uint16_t _id{};
41
42public:
43 /**
44 * \brief Constructor for a new Orchestra.
45 */
47 /**
48 * \brief Constructor for a new Orchestra using the given Chirp file.
49 *
50 * \param filepath The path to the music file to immediately load into the orchestra.
51 */
52 Orchestra(char const *filepath) : Orchestra{}
53 {
54 LoadMusic(filepath);
55 }
56 /**
57 * \brief Constructor for a new Orchestra using the given Chirp file.
58 *
59 * \param instruments A vector of device addresses that will be used as instruments in the orchestra.
60 */
61 Orchestra(std::vector<hardware::ParentDevice *> const &instruments) : Orchestra{}
62 {
63 for (auto instrument : instruments) {
64 AddInstrument(*instrument);
65 }
66 }
67 /**
68 * \brief Constructor for a new Orchestra using the given Chirp file.
69 *
70 * \param instruments An array of device addresses that will be used as instruments in the orchestra.
71 */
72 template <size_t N>
73 Orchestra(std::array<hardware::ParentDevice *, N> const &instruments) : Orchestra{}
74 {
75 for (auto instrument : instruments) {
76 AddInstrument(*instrument);
77 }
78 }
79 /**
80 * \brief Constructor for a new Orchestra using the given Chirp file.
81 *
82 * \param instruments A vector of device addresses that will be used as instruments in the orchestra.
83 * \param filepath The path to the music file to immediately load into the orchestra.
84 */
85 Orchestra(std::vector<hardware::ParentDevice *> const &instruments, char const *filepath) : Orchestra{}
86 {
87 for (auto instrument : instruments) {
88 AddInstrument(*instrument);
89 }
90 LoadMusic(filepath);
91 }
92 /**
93 * \brief Constructor for a new Orchestra using the given Chirp file.
94 *
95 * \param instruments An array of device addresses that will be used as instruments in the orchestra.
96 * \param filepath The path to the music file to immediately load into the orchestra.
97 */
98 template <size_t N>
99 Orchestra(std::array<hardware::ParentDevice *, N> const &instruments, char const *filepath) : Orchestra{}
100 {
101 for (auto instrument : instruments) {
102 AddInstrument(*instrument);
103 }
104 LoadMusic(filepath);
105 }
106
108
109 /**
110 * \brief Adds an instrument to the orchestra.
111 *
112 * \param instrument The device to add to the orchestra
113 * \returns Status code of adding the device
114 */
115 ctre::phoenix::StatusCode AddInstrument(hardware::ParentDevice const &instrument);
116
117 /**
118 * \brief Adds an instrument to the orchestra on the given track.
119 *
120 * \param instrument The device to add to the orchestra
121 * \param trackNumber The track number the device should play, starting at 0
122 * \returns Status code of adding the device
123 */
124 ctre::phoenix::StatusCode AddInstrument(hardware::ParentDevice const &instrument, uint16_t trackNumber);
125
126 /**
127 * \brief Clears all instruments in the orchestra.
128 *
129 * \returns Status code of clearing all devices
130 */
131 ctre::phoenix::StatusCode ClearInstruments();
132
133 /**
134 * \brief Loads a Chirp file at the specified file path.
135 *
136 * If the Chirp file is inside your "src/main/deploy" directory, it will be
137 * automatically deployed to a default directory on the roboRIO when you
138 * deploy code. For these files, the name and file extension is sufficient.
139 *
140 * A Chirp file can be created from a MIDI file using Phoenix Tuner.
141 *
142 * \param filepath The path to the Chirp file
143 * \returns Status code of loading the Chirp file
144 */
145 ctre::phoenix::StatusCode LoadMusic(char const *filepath);
146
147 /**
148 * \brief Plays the loaded music file. If the player is paused, this will resume
149 * the orchestra.
150 *
151 * \returns Status code of playing the orchestra
152 */
153 ctre::phoenix::StatusCode Play();
154
155 /**
156 * \brief Pauses the loaded music file. This saves the current position in the
157 * track so it can be resumed later.
158 *
159 * \returns Status code of pausing the orchestra
160 */
161 ctre::phoenix::StatusCode Pause();
162
163 /**
164 * \brief Stops the loaded music file. This resets the current position in the
165 * track to the start.
166 *
167 * \returns Status code of stopping the orchestra
168 */
169 ctre::phoenix::StatusCode Stop();
170
171 /**
172 * \brief Gets whether the current track is actively playing.
173 *
174 * \returns true if Orchestra is playing the music file
175 */
176 bool IsPlaying() const;
177
178 /**
179 * \brief Gets the current timestamp of the music file. The timestamp will reset
180 * to zero whenever #LoadMusic or #Stop is called.
181 *
182 * \details If #IsPlaying returns false, this method can be used to determine
183 * if the music is stopped or paused.
184 *
185 * \returns The current timestamp of the music file, in seconds
186 */
187 double GetCurrentTime() const;
188};
189
190} // namespace phoenix6
191} // namespace ctre
Orchestra is used to play music through devices.
Definition: Orchestra.hpp:38
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:99
Orchestra(std::vector< hardware::ParentDevice * > const &instruments, char const *filepath)
Constructor for a new Orchestra using the given Chirp file.
Definition: Orchestra.hpp:85
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:73
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:61
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:52
Parent class for all devices.
Definition: ParentDevice.hpp:29
Definition: string_util.hpp:15