diff options
| author | Calvin Morrison <calvin@pobox.com> | 2026-05-17 23:38:18 -0400 |
|---|---|---|
| committer | Calvin Morrison <calvin@pobox.com> | 2026-05-17 23:38:18 -0400 |
| commit | 3909a06fe6786027c83e3adaef89c343cde4fbe3 (patch) | |
| tree | f5ea87c98b50764c8ad87e598f274319df0e74db /src/ui/backendcontroller.cpp | |
| parent | 311b69c14203860ab6d98bd11633eea287c8f04e (diff) | |
ALSA backend, backend switcher, UX fixesalsa-wip
- ALSA backend: AlsaModel, AlsaDevice, AlsaMixerWindow, AlsaTray, AlsaPopup
- BackendController: live pulse↔alsa switching, preserves window position/visibility
- PA shutdown fix: stop mainloop thread before disconnect/free to prevent crash
- Exit crash fix: BackendController deleted explicitly before TQApplication exits
- Waiting-for-PulseAudio placeholder when PA not connected
- Preferences: live backend stack (Pulse/ALSA), Startup/Exit card with autostart,
Recording card, no-tabs greying, remove stale "requires restart" label
- Recording tray: track source outputs directly; fix LED init in popup;
level meter forwarding for monitor-source recordings via m_monitorSourceToSink
- TmixTray: fix config group General→Tray for scroll/mute/popup settings;
RecordingTray suppresses right-click menu
- audiodevice.h: add recordingActive() virtual accessor
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'src/ui/backendcontroller.cpp')
| -rw-r--r-- | src/ui/backendcontroller.cpp | 162 |
1 files changed, 162 insertions, 0 deletions
diff --git a/src/ui/backendcontroller.cpp b/src/ui/backendcontroller.cpp new file mode 100644 index 0000000..3a41b8d --- /dev/null +++ b/src/ui/backendcontroller.cpp @@ -0,0 +1,162 @@ +#include "backendcontroller.h" +#include "tmixapp.h" + +#include <tdeconfig.h> +#include <tdeglobal.h> +#include <tdeapplication.h> +#include <tqtimer.h> + +#ifdef WITH_PULSE +#include "../model/pulsemodel.h" +#include "mixerwindow.h" +#endif + +#ifdef WITH_ALSA +#include "../model/alsamodel.h" +#include "alsa/alsamixerwindow.h" +#include "alsa/alsatray.h" +#endif + +BackendController::BackendController( TQObject *parent ) + : TQObject(parent) +#ifdef WITH_PULSE + , m_pulseModel(0), m_pulseWin(0) +#endif +#ifdef WITH_ALSA + , m_alsaModel(0), m_alsaWin(0), m_alsaTray(0) +#endif +{} + +BackendController::~BackendController() +{ + stop(); +} + +void BackendController::start() +{ + TDEConfig *cfg = TDEGlobal::config(); + cfg->setGroup("General"); + m_currentBackend = cfg->readEntry("Backend", "pulse"); + +#ifdef WITH_ALSA + if ( m_currentBackend == "alsa" ) { startAlsa(); return; } +#endif +#ifdef WITH_PULSE + startPulse(); +#endif +} + +void BackendController::stop() +{ +#ifdef WITH_ALSA + if ( m_alsaTray ) { delete m_alsaTray; m_alsaTray = 0; } + if ( m_alsaWin ) { delete m_alsaWin; m_alsaWin = 0; } + if ( m_alsaModel ) { delete m_alsaModel; m_alsaModel = 0; } +#endif +#ifdef WITH_PULSE + // Model first: stops the PA mainloop thread before any widget is destroyed. + if ( m_pulseModel ) { delete m_pulseModel; m_pulseModel = 0; } + if ( m_pulseWin ) { delete m_pulseWin; m_pulseWin = 0; } +#endif +} + +#ifdef WITH_PULSE +void BackendController::startPulse( bool showWindow ) +{ + m_pulseModel = new PulseModel( this ); + if ( !m_pulseModel->open() ) { + delete m_pulseModel; + m_pulseModel = 0; + return; + } + m_pulseWin = new MixerWindow( m_pulseModel ); + connect( m_pulseWin, TQ_SIGNAL(settingsChanged()), + this, TQ_SLOT(onSettingsChanged()) ); + static_cast<TmixApp*>(kapp)->setMainWindow( m_pulseWin ); + + TDEConfig *cfg = TDEGlobal::config(); + cfg->setGroup("Tray"); + bool dockInTray = cfg->readBoolEntry("DockInTray", true); + if ( !dockInTray || showWindow ) + m_pulseWin->show(); +} +#endif + +#ifdef WITH_ALSA +void BackendController::startAlsa( bool showWindow ) +{ + m_alsaModel = new AlsaModel( this ); + if ( !m_alsaModel->open() ) { + delete m_alsaModel; + m_alsaModel = 0; + return; + } + m_alsaWin = new AlsaMixerWindow( m_alsaModel ); + connect( m_alsaWin, TQ_SIGNAL(settingsChanged()), + this, TQ_SLOT(onSettingsChanged()) ); + static_cast<TmixApp*>(kapp)->setMainWindow( m_alsaWin ); + + TDEConfig *cfg = TDEGlobal::config(); + cfg->setGroup("Tray"); + bool dockInTray = cfg->readBoolEntry("DockInTray", true); + if ( dockInTray ) { + m_alsaTray = new AlsaTray( m_alsaModel, m_alsaWin, m_alsaWin ); + m_alsaWin->setTray( m_alsaTray ); + m_alsaTray->show(); + } + if ( !dockInTray || showWindow ) + m_alsaWin->show(); +} +#endif + +void BackendController::onSettingsChanged() +{ + TDEConfig *cfg = TDEGlobal::config(); + cfg->setGroup("General"); + TQString newBackend = cfg->readEntry("Backend", "pulse"); + if ( newBackend != m_currentBackend ) + TQTimer::singleShot( 0, this, TQ_SLOT(doSwitch()) ); +} + +void BackendController::doSwitch() +{ + TDEConfig *cfg = TDEGlobal::config(); + cfg->setGroup("General"); + m_currentBackend = cfg->readEntry("Backend", "pulse"); + + // Remember whether the mixer window was open so we can reopen it after the switch. + bool wasVisible = false; +#ifdef WITH_PULSE + if ( m_pulseWin ) { + wasVisible = m_pulseWin->isVisible(); + if ( wasVisible ) { + cfg->setGroup("MainWindow"); + cfg->writeEntry("XPos", m_pulseWin->x()); + cfg->writeEntry("YPos", m_pulseWin->y()); + cfg->sync(); + } + } +#endif +#ifdef WITH_ALSA + if ( m_alsaWin ) { + wasVisible = wasVisible || m_alsaWin->isVisible(); + if ( m_alsaWin->isVisible() ) { + cfg->setGroup("MainWindow"); + cfg->writeEntry("XPos", m_alsaWin->x()); + cfg->writeEntry("YPos", m_alsaWin->y()); + cfg->sync(); + } + } +#endif + + stop(); + +#ifdef WITH_ALSA + if ( m_currentBackend == "alsa" ) { startAlsa( wasVisible ); return; } +#endif +#ifdef WITH_PULSE + startPulse( wasVisible ); +#endif +} + +#include "backendcontroller.moc" |
