summaryrefslogtreecommitdiff
path: root/src/model
diff options
context:
space:
mode:
authorCalvin Morrison <calvin@pobox.com>2026-05-17 09:05:18 -0400
committerCalvin Morrison <calvin@pobox.com>2026-05-17 09:05:18 -0400
commit62ac7a360129aa741d898ea2e70c3ab958877305 (patch)
tree1e06ee90dcb14d8e9fa43fbf8ef377bd29e936a5 /src/model
parent6ce31ba1e76f8f2980b26c00e6df1c6a884e911c (diff)
cleanups
Diffstat (limited to 'src/model')
-rw-r--r--src/model/pulsemodel.cpp108
-rw-r--r--src/model/pulsemodel.h5
2 files changed, 50 insertions, 63 deletions
diff --git a/src/model/pulsemodel.cpp b/src/model/pulsemodel.cpp
index 2ce329b..ad17439 100644
--- a/src/model/pulsemodel.cpp
+++ b/src/model/pulsemodel.cpp
@@ -146,6 +146,33 @@ static int cvolumeToPan( const pa_cvolume &cv )
return (int)( ( r - l ) / mx * 50.0 );
}
+static void applyCardEvent( const PACardEvent *ev, PulseCardInfo &info )
+{
+ info.name = ev->name;
+ info.description = ev->description;
+ info.activeProfile = ev->activeProfile;
+ info.vendor = ev->vendor;
+ info.product = ev->product;
+ info.formFactor = ev->formFactor;
+ info.busType = ev->busType;
+ info.profiles.clear();
+ info.ports.clear();
+ for ( TQValueList<PACardEvent::Profile>::ConstIterator it = ev->profiles.begin();
+ it != ev->profiles.end(); ++it ) {
+ PulseCardProfile p;
+ p.name = (*it).name; p.description = (*it).description; p.available = (*it).available;
+ info.profiles.append( p );
+ }
+ for ( TQValueList<PACardEvent::Port>::ConstIterator it = ev->ports.begin();
+ it != ev->ports.end(); ++it ) {
+ PulseCardPort port;
+ port.name = (*it).name; port.description = (*it).description;
+ port.available = (*it).available; port.direction = (*it).direction;
+ port.type = (*it).type; port.availabilityGroup = (*it).availGroup;
+ info.ports.append( port );
+ }
+}
+
// ---- ctor / dtor ------------------------------------------------------------
PulseModel::PulseModel( TQObject *parent )
@@ -506,52 +533,12 @@ void PulseModel::customEvent( TQCustomEvent *e )
}
PulseCardInfo *existing = findCard( ev->index );
if ( existing ) {
- existing->name = ev->name;
- existing->description = ev->description;
- existing->activeProfile = ev->activeProfile;
- existing->vendor = ev->vendor;
- existing->product = ev->product;
- existing->formFactor = ev->formFactor;
- existing->busType = ev->busType;
- existing->profiles.clear();
- existing->ports.clear();
- for ( TQValueList<PACardEvent::Profile>::Iterator it = ev->profiles.begin();
- it != ev->profiles.end(); ++it ) {
- PulseCardProfile p; p.name = it->name; p.description = it->description; p.available = it->available;
- existing->profiles.append( p );
- }
- for ( TQValueList<PACardEvent::Port>::Iterator it = ev->ports.begin();
- it != ev->ports.end(); ++it ) {
- PulseCardPort port;
- port.name = it->name; port.description = it->description;
- port.available = it->available; port.direction = it->direction;
- port.type = it->type; port.availabilityGroup = it->availGroup;
- existing->ports.append( port );
- }
+ applyCardEvent( ev, *existing );
emit cardUpdated( ev->index );
} else {
PulseCardInfo info;
- info.index = ev->index;
- info.name = ev->name;
- info.description = ev->description;
- info.activeProfile = ev->activeProfile;
- info.vendor = ev->vendor;
- info.product = ev->product;
- info.formFactor = ev->formFactor;
- info.busType = ev->busType;
- for ( TQValueList<PACardEvent::Profile>::Iterator it = ev->profiles.begin();
- it != ev->profiles.end(); ++it ) {
- PulseCardProfile p; p.name = it->name; p.description = it->description; p.available = it->available;
- info.profiles.append( p );
- }
- for ( TQValueList<PACardEvent::Port>::Iterator it = ev->ports.begin();
- it != ev->ports.end(); ++it ) {
- PulseCardPort port;
- port.name = it->name; port.description = it->description;
- port.available = it->available; port.direction = it->direction;
- port.type = it->type; port.availabilityGroup = it->availGroup;
- info.ports.append( port );
- }
+ info.index = ev->index;
+ applyCardEvent( ev, info );
m_cards.append( info );
emit cardAdded( ev->index );
}
@@ -771,40 +758,35 @@ void PulseModel::setCardProfile( uint32_t cardIndex, const TQString &profileName
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
+TQValueList<PulseModel::DevicePortInfo> PulseModel::devicesForCard( uint32_t cardIndex,
+ const TQPtrList<PulseDevice> &list,
+ const TQMap<uint32_t,uint32_t> &cardMap,
+ const TQMap<uint32_t,TQString> &activePortMap,
+ const TQMap<uint32_t,TQValueList<PulseDevicePort>> &portsMap ) const
{
TQValueList<DevicePortInfo> result;
- for ( TQPtrListIterator<PulseDevice> it(m_sinks); *it; ++it ) {
+ for ( TQPtrListIterator<PulseDevice> it(list); *it; ++it ) {
uint32_t idx = (*it)->paIndex();
- if ( !m_sinkCard.contains(idx) || m_sinkCard[idx] != cardIndex )
+ if ( !cardMap.contains(idx) || cardMap[idx] != cardIndex )
continue;
DevicePortInfo info;
info.paIndex = idx;
info.description = (*it)->name();
- info.activePort = m_sinkActivePort.contains(idx) ? m_sinkActivePort[idx] : TQString();
- info.ports = m_sinkPorts.contains(idx) ? m_sinkPorts[idx]
- : TQValueList<PulseDevicePort>();
+ info.activePort = activePortMap.contains(idx) ? activePortMap[idx] : TQString();
+ info.ports = portsMap.contains(idx) ? portsMap[idx] : TQValueList<PulseDevicePort>();
result.append( info );
}
return result;
}
+TQValueList<PulseModel::DevicePortInfo> PulseModel::sinksForCard( uint32_t cardIndex ) const
+{
+ return devicesForCard( cardIndex, m_sinks, m_sinkCard, m_sinkActivePort, m_sinkPorts );
+}
+
TQValueList<PulseModel::DevicePortInfo> PulseModel::sourcesForCard( uint32_t cardIndex ) const
{
- TQValueList<DevicePortInfo> result;
- for ( TQPtrListIterator<PulseDevice> it(m_sources); *it; ++it ) {
- uint32_t idx = (*it)->paIndex();
- if ( !m_sourceCard.contains(idx) || m_sourceCard[idx] != cardIndex )
- continue;
- DevicePortInfo info;
- info.paIndex = idx;
- info.description = (*it)->name();
- info.activePort = m_sourceActivePort.contains(idx) ? m_sourceActivePort[idx] : TQString();
- info.ports = m_sourcePorts.contains(idx) ? m_sourcePorts[idx]
- : TQValueList<PulseDevicePort>();
- result.append( info );
- }
- return result;
+ return devicesForCard( cardIndex, m_sources, m_sourceCard, m_sourceActivePort, m_sourcePorts );
}
void PulseModel::setSinkPort( uint32_t sinkPaIndex, const TQString &portName )
diff --git a/src/model/pulsemodel.h b/src/model/pulsemodel.h
index fc67e4d..b7200e3 100644
--- a/src/model/pulsemodel.h
+++ b/src/model/pulsemodel.h
@@ -147,6 +147,11 @@ private:
void forEachDevice( std::function<void(PulseDevice*)> fn );
void paOp( std::function<pa_operation*()> fn );
+ TQValueList<DevicePortInfo> devicesForCard( uint32_t cardIndex,
+ const TQPtrList<PulseDevice> &list,
+ const TQMap<uint32_t,uint32_t> &cardMap,
+ const TQMap<uint32_t,TQString> &activePortMap,
+ const TQMap<uint32_t,TQValueList<PulseDevicePort>> &portsMap ) const;
PulseDevice *findDevice( TQPtrList<PulseDevice> &list, uint32_t paIndex );
PulseCardInfo *findCard( uint32_t index );
};