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