summaryrefslogtreecommitdiff
path: root/src/model
diff options
context:
space:
mode:
authorCalvin Morrison <calvin@pobox.com>2026-05-17 08:59:31 -0400
committerCalvin Morrison <calvin@pobox.com>2026-05-17 08:59:31 -0400
commit6ce31ba1e76f8f2980b26c00e6df1c6a884e911c (patch)
tree4272443c117155ab5880a0e2ec039e654a64e488 /src/model
parentc156bed15810e782b13ee4997124dc47a979b573 (diff)
pa op wrapper
Diffstat (limited to 'src/model')
-rw-r--r--src/model/pulsemodel.cpp42
-rw-r--r--src/model/pulsemodel.h1
2 files changed, 15 insertions, 28 deletions
diff --git a/src/model/pulsemodel.cpp b/src/model/pulsemodel.cpp
index 5b1d240..2ce329b 100644
--- a/src/model/pulsemodel.cpp
+++ b/src/model/pulsemodel.cpp
@@ -699,6 +699,14 @@ AudioDevice *PulseModel::defaultInput() const
return 0;
}
+void PulseModel::paOp( std::function<pa_operation*()> fn )
+{
+ pa_threaded_mainloop_lock( m_mainloop );
+ pa_operation *op = fn();
+ if ( op ) pa_operation_unref( op );
+ pa_threaded_mainloop_unlock( m_mainloop );
+}
+
void PulseModel::forEachDevice( std::function<void(PulseDevice*)> fn )
{
TQPtrList<PulseDevice> *lists[] = { &m_sinks, &m_sources, &m_sinkInputs, &m_sourceOutputs };
@@ -721,20 +729,14 @@ void PulseModel::setDefaultOutput( AudioDevice *dev )
{
PulseDevice *pd = dynamic_cast<PulseDevice*>(dev);
if ( !pd || pd->paName().isEmpty() || !m_context || !m_mainloop ) return;
- pa_threaded_mainloop_lock( m_mainloop );
- pa_operation *op = pa_context_set_default_sink( m_context, pd->paName().utf8().data(), 0, 0 );
- if ( op ) pa_operation_unref( op );
- pa_threaded_mainloop_unlock( m_mainloop );
+ paOp( [&]{ return pa_context_set_default_sink( m_context, pd->paName().utf8().data(), 0, 0 ); } );
}
void PulseModel::setDefaultInput( AudioDevice *dev )
{
PulseDevice *pd = dynamic_cast<PulseDevice*>(dev);
if ( !pd || pd->paName().isEmpty() || !m_context || !m_mainloop ) return;
- pa_threaded_mainloop_lock( m_mainloop );
- pa_operation *op = pa_context_set_default_source( m_context, pd->paName().utf8().data(), 0, 0 );
- if ( op ) pa_operation_unref( op );
- pa_threaded_mainloop_unlock( m_mainloop );
+ paOp( [&]{ return pa_context_set_default_source( m_context, pd->paName().utf8().data(), 0, 0 ); } );
}
void PulseModel::moveSinkInputToSink( AudioDevice *playbackDev, AudioDevice *outputDev )
@@ -742,11 +744,7 @@ void PulseModel::moveSinkInputToSink( AudioDevice *playbackDev, AudioDevice *out
PulseDevice *si = dynamic_cast<PulseDevice*>(playbackDev);
PulseDevice *sink = dynamic_cast<PulseDevice*>(outputDev);
if ( !si || !sink || !m_context || !m_mainloop ) return;
- pa_threaded_mainloop_lock( m_mainloop );
- pa_operation *op = pa_context_move_sink_input_by_index(
- m_context, si->paIndex(), sink->paIndex(), 0, 0 );
- if ( op ) pa_operation_unref( op );
- pa_threaded_mainloop_unlock( m_mainloop );
+ paOp( [&]{ return pa_context_move_sink_input_by_index( m_context, si->paIndex(), sink->paIndex(), 0, 0 ); } );
}
const PulseCardInfo *PulseModel::card( uint32_t index ) const
@@ -770,11 +768,7 @@ PulseCardInfo *PulseModel::findCard( uint32_t index )
void PulseModel::setCardProfile( uint32_t cardIndex, const TQString &profileName )
{
if ( !m_context || !m_mainloop || profileName.isEmpty() ) return;
- pa_threaded_mainloop_lock( m_mainloop );
- pa_operation *op = pa_context_set_card_profile_by_index(
- m_context, cardIndex, profileName.utf8().data(), 0, 0 );
- if ( op ) pa_operation_unref( op );
- pa_threaded_mainloop_unlock( m_mainloop );
+ paOp( [&]{ return pa_context_set_card_profile_by_index( m_context, cardIndex, profileName.utf8().data(), 0, 0 ); } );
}
TQValueList<PulseModel::DevicePortInfo> PulseModel::sinksForCard( uint32_t cardIndex ) const
@@ -816,21 +810,13 @@ TQValueList<PulseModel::DevicePortInfo> PulseModel::sourcesForCard( uint32_t car
void PulseModel::setSinkPort( uint32_t sinkPaIndex, const TQString &portName )
{
if ( !m_context || !m_mainloop || portName.isEmpty() ) return;
- pa_threaded_mainloop_lock( m_mainloop );
- pa_operation *op = pa_context_set_sink_port_by_index(
- m_context, sinkPaIndex, portName.utf8().data(), 0, 0 );
- if ( op ) pa_operation_unref( op );
- pa_threaded_mainloop_unlock( m_mainloop );
+ paOp( [&]{ return pa_context_set_sink_port_by_index( m_context, sinkPaIndex, portName.utf8().data(), 0, 0 ); } );
}
void PulseModel::setSourcePort( uint32_t sourcePaIndex, const TQString &portName )
{
if ( !m_context || !m_mainloop || portName.isEmpty() ) return;
- pa_threaded_mainloop_lock( m_mainloop );
- pa_operation *op = pa_context_set_source_port_by_index(
- m_context, sourcePaIndex, portName.utf8().data(), 0, 0 );
- if ( op ) pa_operation_unref( op );
- pa_threaded_mainloop_unlock( m_mainloop );
+ paOp( [&]{ return pa_context_set_source_port_by_index( m_context, sourcePaIndex, portName.utf8().data(), 0, 0 ); } );
}
#include "pulsemodel.moc"
diff --git a/src/model/pulsemodel.h b/src/model/pulsemodel.h
index d799a83..fc67e4d 100644
--- a/src/model/pulsemodel.h
+++ b/src/model/pulsemodel.h
@@ -146,6 +146,7 @@ private:
TQMap<uint32_t, TQValueList<PulseDevicePort>> m_sourcePorts;
void forEachDevice( std::function<void(PulseDevice*)> fn );
+ void paOp( std::function<pa_operation*()> fn );
PulseDevice *findDevice( TQPtrList<PulseDevice> &list, uint32_t paIndex );
PulseCardInfo *findCard( uint32_t index );
};