Rerun C++ SDK
Loading...
Searching...
No Matches
asset_audio.hpp
1// DO NOT EDIT! This file was auto-generated by crates/build/re_types_builder/src/codegen/cpp/mod.rs
2// Based on "crates/build/re_type_definitions/rerun/archetypes/asset_audio.def.rs".
3
4#pragma once
5
6#include "../collection.hpp"
7#include "../component_batch.hpp"
8#include "../component_column.hpp"
9#include "../components/blob.hpp"
10#include "../components/media_type.hpp"
11#include "../result.hpp"
12
13#include <cstdint>
14#include <filesystem>
15#include <optional>
16#include <utility>
17#include <vector>
18
19namespace rerun::archetypes {
20 /// **Archetype**: An audio file, stored as-is (`.aac`, `.flac`, `.m4a`, `.mp3`, `.ogg`, `.wav`).
21 ///
22 /// The audio starts playing at the time it was logged,
23 /// so log it on a temporal timeline (duration or timestamp) at the point where playback should begin.
24 /// The viewer plays it while time is playing, in an `views::AudioView`.
25 ///
26 /// ## Example
27 ///
28 /// ### Simple audio asset
29 /// ```cpp
30 /// #include <rerun.hpp>
31 ///
32 /// #include <iostream>
33 ///
34 /// int main(int argc, char* argv[]) {
35 /// if (argc <2) {
36 /// std::cerr <<"Usage: " <<argv[0]
37 /// <<" <path_to_audio.[aac|flac|m4a|mp3|ogg|wav]>" <<std::endl;
38 /// return 1;
39 /// }
40 ///
41 /// const auto path = argv[1];
42 ///
43 /// const auto rec = rerun::RecordingStream("rerun_example_asset_audio");
44 /// rec.spawn().exit_on_failure();
45 ///
46 /// rec.set_time_duration_secs("time", 0.0);
47 /// rec.log("audio", rerun::AssetAudio::from_file_path(path).value_or_throw());
48 /// }
49 /// ```
50 ///
51 /// ⚠ **This type is _unstable_ and may change significantly in a way that the data won't be backwards compatible.**
52 ///
53 struct AssetAudio {
54 /// The asset's bytes.
55 std::optional<ComponentBatch> blob;
56
57 /// The Media Type of the asset.
58 ///
59 /// For instance:
60 /// * `audio/aac` (raw ADTS stream)
61 /// * `audio/flac`
62 /// * `audio/mp4` (M4A)
63 /// * `audio/mpeg` (MP3)
64 /// * `audio/ogg`
65 /// * `audio/wav`
66 ///
67 /// Any audio media type can be stored.
68 /// Which ones the viewer can decode depends on the viewer version.
69 ///
70 /// If omitted, the viewer will try to guess from the data blob.
71 /// If it cannot guess, it won't be able to play the asset.
72 std::optional<ComponentBatch> media_type;
73
74 public:
75 /// The name of the archetype as used in `ComponentDescriptor`s.
76 static constexpr const char ArchetypeName[] = "rerun.archetypes.AssetAudio";
77
78 /// `ComponentDescriptor` for the `blob` field.
79 static constexpr auto Descriptor_blob = ComponentDescriptor(
81 );
82 /// `ComponentDescriptor` for the `media_type` field.
84 ArchetypeName, "AssetAudio:media_type",
86 );
87
88 public: // START of extensions from asset_audio_ext.cpp:
89 /// Creates a new `AssetAudio` from the file contents at `path`.
90 ///
91 /// The `MediaType` will be guessed from the file extension.
92 ///
93 /// If no `MediaType` can be guessed at the moment, the Rerun Viewer will try to guess one
94 /// from the data at playback-time. If it can't, playback will fail with an error.
95 static Result<AssetAudio> from_file_path(const std::filesystem::path& path);
96
97 /// Creates a new `AssetAudio` from the given `bytes`.
98 ///
99 /// If no `MediaType` is specified, the Rerun Viewer will try to guess one from the data
100 /// at playback-time. If it can't, playback will fail with an error.
103 std::optional<rerun::components::MediaType> media_type = {}
104 ) {
105 AssetAudio asset = AssetAudio(std::move(bytes));
106 if (media_type.has_value()) {
107 return std::move(asset).with_media_type(media_type.value());
108 }
109 return asset;
110 }
111
112 // END of extensions from asset_audio_ext.cpp, start of generated code:
113
114 public:
115 AssetAudio() = default;
116 AssetAudio(AssetAudio&& other) = default;
117 AssetAudio(const AssetAudio& other) = default;
118 AssetAudio& operator=(const AssetAudio& other) = default;
119 AssetAudio& operator=(AssetAudio&& other) = default;
120
121 explicit AssetAudio(rerun::components::Blob _blob)
122 : blob(ComponentBatch::from_loggable(std::move(_blob), Descriptor_blob).value_or_throw()
123 ) {}
124
125 /// Update only some specific fields of a `AssetAudio`.
127 return AssetAudio();
128 }
129
130 /// Clear all the fields of a `AssetAudio`.
132
133 /// The asset's bytes.
135 blob = ComponentBatch::from_loggable(_blob, Descriptor_blob).value_or_throw();
136 return std::move(*this);
137 }
138
139 /// This method makes it possible to pack multiple `blob` in a single component batch.
140 ///
141 /// This only makes sense when used in conjunction with `columns`. `with_blob` should
142 /// be used when logging a single row's worth of data.
144 blob = ComponentBatch::from_loggable(_blob, Descriptor_blob).value_or_throw();
145 return std::move(*this);
146 }
147
148 /// The Media Type of the asset.
149 ///
150 /// For instance:
151 /// * `audio/aac` (raw ADTS stream)
152 /// * `audio/flac`
153 /// * `audio/mp4` (M4A)
154 /// * `audio/mpeg` (MP3)
155 /// * `audio/ogg`
156 /// * `audio/wav`
157 ///
158 /// Any audio media type can be stored.
159 /// Which ones the viewer can decode depends on the viewer version.
160 ///
161 /// If omitted, the viewer will try to guess from the data blob.
162 /// If it cannot guess, it won't be able to play the asset.
164 media_type =
165 ComponentBatch::from_loggable(_media_type, Descriptor_media_type).value_or_throw();
166 return std::move(*this);
167 }
168
169 /// This method makes it possible to pack multiple `media_type` in a single component batch.
170 ///
171 /// This only makes sense when used in conjunction with `columns`. `with_media_type` should
172 /// be used when logging a single row's worth of data.
174 ) && {
175 media_type =
176 ComponentBatch::from_loggable(_media_type, Descriptor_media_type).value_or_throw();
177 return std::move(*this);
178 }
179
180 /// Partitions the component data into multiple sub-batches.
181 ///
182 /// Specifically, this transforms the existing `ComponentBatch` data into `ComponentColumn`s
183 /// instead, via `ComponentBatch::partitioned`.
184 ///
185 /// This makes it possible to use `RecordingStream::send_columns` to send columnar data directly into Rerun.
186 ///
187 /// The specified `lengths` must sum to the total length of the component batch.
189
190 /// Partitions the component data into unit-length sub-batches.
191 ///
192 /// This is semantically similar to calling `columns` with `std::vector<uint32_t>(n, 1)`,
193 /// where `n` is automatically guessed.
195 };
196
197} // namespace rerun::archetypes
198
199namespace rerun {
200 /// \private
201 template <typename T>
202 struct AsComponents;
203
204 /// \private
205 template <>
206 struct AsComponents<archetypes::AssetAudio> {
207 /// Serialize all set component batches.
208 static Result<Collection<ComponentBatch>> as_batches(const archetypes::AssetAudio& archetype
209 );
210 };
211} // namespace rerun
Generic collection of elements that are roughly contiguous in memory.
Definition collection.hpp:49
A class for representing either a usable value, or an error.
Definition result.hpp:14
All built-in archetypes. See Types in the Rerun manual.
Definition rerun.hpp:90
All Rerun C++ types and functions are in the rerun namespace or one of its nested namespaces.
Definition rerun.hpp:26
static Result< ComponentBatch > from_loggable(const rerun::Collection< T > &components, const ComponentDescriptor &descriptor)
Creates a new component batch from a collection of component instances.
Definition component_batch.hpp:46
A ComponentDescriptor fully describes the semantics of a column of data.
Definition component_descriptor.hpp:16
The Loggable trait is used by all built-in implementation of rerun::AsComponents to serialize a colle...
Definition loggable.hpp:11
Archetype: An audio file, stored as-is (.aac, .flac, .m4a, .mp3, .ogg, .wav).
Definition asset_audio.hpp:53
static Result< AssetAudio > from_file_path(const std::filesystem::path &path)
Creates a new AssetAudio from the file contents at path.
Collection< ComponentColumn > columns()
Partitions the component data into unit-length sub-batches.
AssetAudio with_media_type(const rerun::components::MediaType &_media_type) &&
The Media Type of the asset.
Definition asset_audio.hpp:163
std::optional< ComponentBatch > blob
The asset's bytes.
Definition asset_audio.hpp:55
static AssetAudio update_fields()
Update only some specific fields of a AssetAudio.
Definition asset_audio.hpp:126
AssetAudio with_blob(const rerun::components::Blob &_blob) &&
The asset's bytes.
Definition asset_audio.hpp:134
static constexpr const char ArchetypeName[]
The name of the archetype as used in ComponentDescriptors.
Definition asset_audio.hpp:76
AssetAudio with_many_blob(const Collection< rerun::components::Blob > &_blob) &&
This method makes it possible to pack multiple blob in a single component batch.
Definition asset_audio.hpp:143
static constexpr auto Descriptor_blob
ComponentDescriptor for the blob field.
Definition asset_audio.hpp:79
static constexpr auto Descriptor_media_type
ComponentDescriptor for the media_type field.
Definition asset_audio.hpp:83
std::optional< ComponentBatch > media_type
The Media Type of the asset.
Definition asset_audio.hpp:72
static AssetAudio from_file_contents(rerun::Collection< uint8_t > bytes, std::optional< rerun::components::MediaType > media_type={})
Creates a new AssetAudio from the given bytes.
Definition asset_audio.hpp:101
AssetAudio with_many_media_type(const Collection< rerun::components::MediaType > &_media_type) &&
This method makes it possible to pack multiple media_type in a single component batch.
Definition asset_audio.hpp:173
static AssetAudio clear_fields()
Clear all the fields of a AssetAudio.
Collection< ComponentColumn > columns(const Collection< uint32_t > &lengths_)
Partitions the component data into multiple sub-batches.
Component: A binary blob of data.
Definition blob.hpp:16
Component: A standardized media type (RFC2046, formerly known as MIME types), encoded as a string.
Definition media_type.hpp:20