FastLED 3.9.15
Loading...
Searching...
No Matches
audio.h
Go to the documentation of this file.
1#pragma once
2
3#include "fl/asset/asset.h"
4#include "fl/audio/audio.h"
5#include "fl/audio/audio_input.h" // For audio::Config // IWYU pragma: keep
6#include "fl/stl/optional.h"
7#include "fl/stl/shared_ptr.h"
8#include "fl/stl/string.h"
9#include "fl/stl/url.h"
10#include "fl/stl/compiler_control.h" // IWYU pragma: keep
11#include "fl/stl/noexcept.h"
12#include "fl/log/log.h"
13#include "fl/ui/element.h"
14#include "platforms/ui_defs.h"
15
16#ifndef FASTLED_HAS_UI_AUDIO
17#define FASTLED_HAS_UI_AUDIO 0
18#endif
19
20namespace fl {
21
22#if !FASTLED_HAS_UI_AUDIO
24 public:
25 UIAudioImpl(const fl::string& name) { FASTLED_UNUSED(name); }
26 UIAudioImpl(const fl::string& name, const fl::url& url) {
27 FASTLED_UNUSED(name);
29 }
30 UIAudioImpl(const fl::string& name, const fl::audio::Config& config) {
31 FASTLED_UNUSED(name);
32 FASTLED_UNUSED(config);
33 }
35
37 FL_WARN("Audio sample not implemented");
38 return audio::Sample();
39 }
40
41 bool hasNext() {
42 FL_WARN("Audio sample not implemented");
43 return false;
44 }
45
46 // Stub method for group setting (does nothing on non-WASM platforms)
47 void setGroup(const fl::string& groupName) { FASTLED_UNUSED(groupName); }
48
49 // Stub: no underlying audio input on non-WASM platforms
51};
52#endif
53
54class UIAudio : public UIElement {
55 public:
57 UIAudio(const fl::string& name) FL_NOEXCEPT;
58 UIAudio(const fl::string& name, const fl::url& url) FL_NOEXCEPT;
67 audio::Sample next() FL_NOEXCEPT { return mImpl.next(); }
68 bool hasNext() FL_NOEXCEPT { return mImpl.hasNext(); }
69
70 // Expose underlying audio input for FastLED.add() auto-pump
72
73 // Returns the hardware microphone config, if one was provided.
75
76 // Lazily registers with CFastLED::add() on first call and returns the
77 // auto-pumped audio::Processor. Subsequent calls return the cached processor.
79
80 // Override setGroup to also update the implementation
81 void setGroup(const fl::string& groupName) FL_NOEXCEPT override {
82 UIElement::setGroup(groupName);
83 // Update the implementation's group if it has the method (WASM platforms)
84 mImpl.setGroup(groupName);
85 }
86
87 protected:
91};
92
93} // namespace fl
First-class asset handles for sketches that live under <sketch>/data/.
fl::shared_ptr< audio::Processor > processor() FL_NOEXCEPT
Definition audio.cpp.hpp:22
UIAudioImpl mImpl
Definition audio.h:88
fl::shared_ptr< audio::IInput > audioInput() FL_NOEXCEPT
Definition audio.h:71
bool hasNext() FL_NOEXCEPT
Definition audio.h:68
fl::shared_ptr< audio::Processor > mProcessor
Definition audio.h:90
~UIAudio() FL_NOEXCEPT
Definition audio.cpp.hpp:20
audio::Sample next() FL_NOEXCEPT
Definition audio.h:67
FL_NO_COPY(UIAudio) UIAudio(const fl UIAudio(const fl::string &name, const fl::url &url) FL_NOEXCEPT
Definition audio.cpp.hpp:8
const fl::optional< audio::Config > & config() const FL_NOEXCEPT
Definition audio.h:74
void setGroup(const fl::string &groupName) FL_NOEXCEPT override
Definition audio.h:81
fl::optional< audio::Config > mConfig
Definition audio.h:89
void setGroup(const fl::string &groupName)
Definition audio.h:47
UIAudioImpl(const fl::string &name)
Definition audio.h:25
bool hasNext()
Definition audio.h:41
UIAudioImpl(const fl::string &name, const fl::audio::Config &config)
Definition audio.h:30
audio::Sample next()
Definition audio.h:36
UIAudioImpl(const fl::string &name, const fl::url &url)
Definition audio.h:26
~UIAudioImpl() FL_NOEXCEPT
Definition audio.h:34
fl::shared_ptr< audio::IInput > audioInput()
Definition audio.h:50
virtual void setGroup(const fl::string &groupName) FL_NOEXCEPT
Definition element.h:31
UIElement() FL_NOEXCEPT
Opaque handle to a sketch-local asset.
Definition asset.h:84
Definition url.h:15
#define FL_NO_COPY(CLASS)
Definition element.h:8
#define FL_WARN(X)
Definition log.h:276
Centralized logging categories for FastLED hardware interfaces and subsystems.
constexpr asset_ref asset(const char *path) FL_NOEXCEPT
Construct an asset handle from a relative sketch path at runtime.
Definition asset.h:128
Optional< T > optional
Definition optional.h:16
Base definition for an LED controller.
Definition crgb.hpp:179
#define FASTLED_UNUSED(x)
#define FL_NOEXCEPT
Lightweight URL parser for embedded environments.