wiRedPanda
Logic Circuit Simulator
Loading...
Searching...
No Matches
AudioOutputElement.h
Go to the documentation of this file.
1// Copyright 2015 - 2026, GIBIS-UNIFESP and the wiRedPanda contributors
2// SPDX-License-Identifier: GPL-3.0-or-later
3
7
8#pragma once
9
11
25{
26 Q_OBJECT
27
28public:
32 static constexpr float kDefaultVolume = 0.5f;
33
37 explicit AudioOutputElement(ElementType type, QGraphicsItem *parent = nullptr,
38 float initialVolume = kDefaultVolume);
39
40 // --- State Queries ---
41
43 bool isPlaying() const;
45 bool isMuted() const;
47 float volume() const override;
48
49 // --- Playback Control ---
50
52 void mute(const bool mute = true);
54 void setVolume(float vol) override;
55
57 void refresh() override;
58
59protected:
60 // --- Template Method hooks (backend-specific) ---
61
63 virtual void startAudio() = 0;
65 virtual void stopAudio() = 0;
67 virtual void applyVolume() = 0;
69 virtual void applyMute() = 0;
70
71 // --- Shared state (accessible to derived classes) ---
72
73 float m_volume; // set from the ctor's initialVolume (one source, one write)
74 bool m_hasOutputDevice = false;
75 bool m_isPlaying = false;
76 bool m_muted = false;
77
78 // --- Non-virtual play/stop (delegate to hooks above) ---
79
80 void play();
81 void stop();
82};
Enums::ElementType ElementType
Definition Enums.h:107
Abstract base class for all graphical circuit elements.
bool isMuted() const
Returns true if audio output is muted.
virtual void startAudio()=0
Starts hardware playback (called from play() when m_hasOutputDevice is true).
static constexpr float kDefaultVolume
float volume() const override
Returns the audio playback volume (0.0–1.0).
void mute(const bool mute=true)
Mutes or unmutes audio according to mute.
void refresh() override
Refreshes the visual appearance based on the current input state.
bool isPlaying() const
Returns true if audio is currently playing.
void setVolume(float vol) override
Sets the audio playback volume to vol (0.0–1.0).
virtual void applyVolume()=0
Applies the current m_volume to the hardware backend.
AudioOutputElement(ElementType type, QGraphicsItem *parent=nullptr, float initialVolume=kDefaultVolume)
virtual void stopAudio()=0
Stops hardware playback (called from stop() when m_hasOutputDevice is true).
virtual void applyMute()=0
Applies the current m_muted state to the hardware backend.
GraphicElement(ElementType type, QGraphicsItem *parent=nullptr)
Constructs a graphic element of the given type, fetching all properties from the metadata registry.
int type() const override
Returns the custom type identifier for this item.