summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCalvin Morrison <calvin@pobox.com>2026-05-17 10:14:22 -0400
committerCalvin Morrison <calvin@pobox.com>2026-05-17 10:14:22 -0400
commit311b69c14203860ab6d98bd11633eea287c8f04e (patch)
treebad243b12d3e5935af1cf4c214bd39e90a984b94 /src
parent83ff745b43ebda7b33c52ac1a80a1408c59bfa70 (diff)
cleanups
Diffstat (limited to 'src')
-rw-r--r--src/model/pulsedevice.cpp30
-rw-r--r--src/model/pulsedevice.h1
-rw-r--r--src/model/pulsemodel.cpp6
-rw-r--r--src/ui/devicespage.cpp6
4 files changed, 16 insertions, 27 deletions
diff --git a/src/model/pulsedevice.cpp b/src/model/pulsedevice.cpp
index 2f0adb1..f91ace6 100644
--- a/src/model/pulsedevice.cpp
+++ b/src/model/pulsedevice.cpp
@@ -213,14 +213,8 @@ static pa_cvolume buildCVolume( uint8_t channels, pa_volume_t vol, int pan )
// ---- write back to PA -------------------------------------------------------
-void PulseDevice::setVolume( int v )
+void PulseDevice::pushCVolume( const pa_cvolume &cv )
{
- if ( !m_context ) return;
- v = v < 0 ? 0 : v > 100 ? 100 : v;
- m_volume = v;
- emit volumeChanged( v );
-
- pa_cvolume cv = buildCVolume( m_channels, percentToPA(v), m_pan );
pa_threaded_mainloop_lock( m_mainloop );
pa_operation *op = 0;
switch ( m_category ) {
@@ -233,24 +227,22 @@ void PulseDevice::setVolume( int v )
pa_threaded_mainloop_unlock( m_mainloop );
}
+void PulseDevice::setVolume( int v )
+{
+ if ( !m_context ) return;
+ v = v < 0 ? 0 : v > 100 ? 100 : v;
+ m_volume = v;
+ emit volumeChanged( v );
+ pushCVolume( buildCVolume( m_channels, percentToPA(v), m_pan ) );
+}
+
void PulseDevice::setPan( int p )
{
if ( !m_context ) return;
p = p < -50 ? -50 : p > 50 ? 50 : p;
m_pan = p;
emit panChanged( p );
-
- pa_cvolume cv = buildCVolume( m_channels, percentToPA(m_volume), p );
- pa_threaded_mainloop_lock( m_mainloop );
- pa_operation *op = 0;
- switch ( m_category ) {
- case Output: op = pa_context_set_sink_volume_by_index( m_context, m_paIndex, &cv, 0, 0 ); break;
- case Input: op = pa_context_set_source_volume_by_index( m_context, m_paIndex, &cv, 0, 0 ); break;
- case Playback: op = pa_context_set_sink_input_volume( m_context, m_paIndex, &cv, 0, 0 ); break;
- case Recording: op = pa_context_set_source_output_volume( m_context, m_paIndex, &cv, 0, 0 ); break;
- }
- if ( op ) pa_operation_unref( op );
- pa_threaded_mainloop_unlock( m_mainloop );
+ pushCVolume( buildCVolume( m_channels, percentToPA(m_volume), p ) );
}
void PulseDevice::setMuted( bool m )
diff --git a/src/model/pulsedevice.h b/src/model/pulsedevice.h
index 303bece..289f2ed 100644
--- a/src/model/pulsedevice.h
+++ b/src/model/pulsedevice.h
@@ -48,6 +48,7 @@ protected:
void customEvent( TQCustomEvent *e );
private:
+ void pushCVolume( const pa_cvolume &cv );
void startMonitoring();
static void monitorReadCb( pa_stream *s, size_t nbytes, void *userdata );
diff --git a/src/model/pulsemodel.cpp b/src/model/pulsemodel.cpp
index bf9f9ee..de91831 100644
--- a/src/model/pulsemodel.cpp
+++ b/src/model/pulsemodel.cpp
@@ -3,6 +3,8 @@
#include <tqapplication.h>
#include <tqtimer.h>
+#include <algorithm>
+#include <cmath>
// Custom events posted from the PA thread to the main thread.
static const int PA_EVENT = TQEvent::User + 1;
@@ -132,7 +134,7 @@ static TQString paAppIcon( pa_proplist *pl )
static int paVolumeToPercent( const pa_cvolume &cv )
{
pa_volume_t mx = pa_cvolume_max( &cv );
- return (int)( (double)mx / PA_VOLUME_NORM * 100.0 + 0.5 );
+ return (int)std::lround( (double)mx / PA_VOLUME_NORM * 100.0 );
}
// Derive pan -50..+50 from the first two channels of a cvolume.
@@ -141,7 +143,7 @@ static int cvolumeToPan( const pa_cvolume &cv )
if ( cv.channels < 2 ) return 0;
double l = cv.values[0];
double r = cv.values[1];
- double mx = ( l > r ) ? l : r;
+ double mx = std::max( l, r );
if ( mx < 1.0 ) return 0;
return (int)( ( r - l ) / mx * 50.0 );
}
diff --git a/src/ui/devicespage.cpp b/src/ui/devicespage.cpp
index 2433412..6ae12e6 100644
--- a/src/ui/devicespage.cpp
+++ b/src/ui/devicespage.cpp
@@ -44,12 +44,6 @@ static TQPixmap availDot( bool plugged, int size )
}
pm.setMask( mask );
pm.fill( plugged ? TQColor(80, 200, 80) : TQColor(160, 160, 160) );
- {
- TQPainter p( &pm );
- p.setBrush( plugged ? TQColor(80, 200, 80) : TQColor(160, 160, 160) );
- p.setPen( Qt::NoPen );
- p.drawEllipse( 1, 1, size-2, size-2 );
- }
return pm;
}