Enable different colors for oscilloscope channels (#7155)
Enable to set different colors for the oscilloscope channels: * Left channel color * Right channel color * Color of all other channels The clipping color is now used per channel, i.e. if the left channel clips but the right does not then only the signal of the left channel is painted in the clipping color. Enable setting the colors in the style sheets and adjust the style sheets of the default and classic theme accordingly.
This commit is contained in:
committed by
GitHub
parent
45fd326787
commit
a41da81554
@@ -203,7 +203,9 @@ lmms--gui--GroupBox {
|
||||
lmms--gui--Oscilloscope {
|
||||
background: none;
|
||||
border: none;
|
||||
qproperty-normalColor: rgb(71, 253, 133);
|
||||
qproperty-leftChannelColor: rgb(71, 253, 133);
|
||||
qproperty-rightChannelColor: rgb(238, 253, 71);
|
||||
qproperty-otherChannelsColor: rgb(71, 235, 253);
|
||||
qproperty-clippingColor: rgb(255, 64, 64);
|
||||
}
|
||||
|
||||
|
||||
@@ -234,7 +234,9 @@ lmms--gui--GroupBox {
|
||||
lmms--gui--Oscilloscope {
|
||||
background: none;
|
||||
border: none;
|
||||
qproperty-normalColor: rgb(71, 253, 133);
|
||||
qproperty-leftChannelColor: rgb(71, 253, 133);
|
||||
qproperty-rightChannelColor: rgb(238, 253, 71);
|
||||
qproperty-otherChannelsColor: rgb(71, 235, 253);
|
||||
qproperty-clippingColor: rgb(255, 64, 64);
|
||||
}
|
||||
|
||||
|
||||
@@ -38,7 +38,9 @@ class Oscilloscope : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
Q_PROPERTY( QColor normalColor READ normalColor WRITE setNormalColor )
|
||||
Q_PROPERTY( QColor leftChannelColor READ leftChannelColor WRITE setLeftChannelColor )
|
||||
Q_PROPERTY( QColor rightChannelColor READ rightChannelColor WRITE setRightChannelColor )
|
||||
Q_PROPERTY( QColor otherChannelsColor READ otherChannelsColor WRITE setOtherChannelsColor )
|
||||
Q_PROPERTY( QColor clippingColor READ clippingColor WRITE setClippingColor )
|
||||
|
||||
Oscilloscope( QWidget * _parent );
|
||||
@@ -46,8 +48,14 @@ public:
|
||||
|
||||
void setActive( bool _active );
|
||||
|
||||
QColor const & normalColor() const;
|
||||
void setNormalColor(QColor const & normalColor);
|
||||
QColor const & leftChannelColor() const;
|
||||
void setLeftChannelColor(QColor const & leftChannelColor);
|
||||
|
||||
QColor const & rightChannelColor() const;
|
||||
void setRightChannelColor(QColor const & rightChannelColor);
|
||||
|
||||
QColor const & otherChannelsColor() const;
|
||||
void setOtherChannelsColor(QColor const & otherChannelsColor);
|
||||
|
||||
QColor const & clippingColor() const;
|
||||
void setClippingColor(QColor const & clippingColor);
|
||||
@@ -62,7 +70,7 @@ protected slots:
|
||||
void updateAudioBuffer( const lmms::surroundSampleFrame * buffer );
|
||||
|
||||
private:
|
||||
QColor const & determineLineColor(float level) const;
|
||||
bool clips(float level) const;
|
||||
|
||||
private:
|
||||
QPixmap m_background;
|
||||
@@ -71,7 +79,9 @@ private:
|
||||
sampleFrame * m_buffer;
|
||||
bool m_active;
|
||||
|
||||
QColor m_normalColor;
|
||||
QColor m_leftChannelColor;
|
||||
QColor m_rightChannelColor;
|
||||
QColor m_otherChannelsColor;
|
||||
QColor m_clippingColor;
|
||||
} ;
|
||||
|
||||
|
||||
@@ -45,7 +45,9 @@ Oscilloscope::Oscilloscope( QWidget * _p ) :
|
||||
m_background( embed::getIconPixmap( "output_graph" ) ),
|
||||
m_points( new QPointF[Engine::audioEngine()->framesPerPeriod()] ),
|
||||
m_active( false ),
|
||||
m_normalColor(71, 253, 133),
|
||||
m_leftChannelColor(71, 253, 133),
|
||||
m_rightChannelColor(71, 253, 133),
|
||||
m_otherChannelsColor(71, 253, 133),
|
||||
m_clippingColor(255, 64, 64)
|
||||
{
|
||||
setFixedSize( m_background.width(), m_background.height() );
|
||||
@@ -112,14 +114,34 @@ void Oscilloscope::setActive( bool _active )
|
||||
}
|
||||
|
||||
|
||||
QColor const & Oscilloscope::normalColor() const
|
||||
QColor const & Oscilloscope::leftChannelColor() const
|
||||
{
|
||||
return m_normalColor;
|
||||
return m_leftChannelColor;
|
||||
}
|
||||
|
||||
void Oscilloscope::setNormalColor(QColor const & normalColor)
|
||||
void Oscilloscope::setLeftChannelColor(QColor const & leftChannelColor)
|
||||
{
|
||||
m_normalColor = normalColor;
|
||||
m_leftChannelColor = leftChannelColor;
|
||||
}
|
||||
|
||||
QColor const & Oscilloscope::rightChannelColor() const
|
||||
{
|
||||
return m_rightChannelColor;
|
||||
}
|
||||
|
||||
void Oscilloscope::setRightChannelColor(QColor const & rightChannelColor)
|
||||
{
|
||||
m_rightChannelColor = rightChannelColor;
|
||||
}
|
||||
|
||||
QColor const & Oscilloscope::otherChannelsColor() const
|
||||
{
|
||||
return m_otherChannelsColor;
|
||||
}
|
||||
|
||||
void Oscilloscope::setOtherChannelsColor(QColor const & otherChannelsColor)
|
||||
{
|
||||
m_otherChannelsColor = otherChannelsColor;
|
||||
}
|
||||
|
||||
QColor const & Oscilloscope::clippingColor() const
|
||||
@@ -147,11 +169,9 @@ void Oscilloscope::paintEvent( QPaintEvent * )
|
||||
|
||||
const fpp_t frames = audioEngine->framesPerPeriod();
|
||||
AudioEngine::StereoSample peakValues = audioEngine->getPeakValues(m_buffer, frames);
|
||||
const float max_level = qMax<float>( peakValues.left, peakValues.right );
|
||||
|
||||
// Set the color of the line according to the maximum level
|
||||
float const maxLevelWithAppliedMasterGain = max_level * masterOutput;
|
||||
p.setPen(QPen(determineLineColor(maxLevelWithAppliedMasterGain), 0.7));
|
||||
auto const leftChannelClips = clips(peakValues.left * masterOutput);
|
||||
auto const rightChannelClips = clips(peakValues.right * masterOutput);
|
||||
|
||||
p.setRenderHint( QPainter::Antialiasing );
|
||||
|
||||
@@ -162,8 +182,14 @@ void Oscilloscope::paintEvent( QPaintEvent * )
|
||||
int x_base = 2;
|
||||
const qreal y_base = height() / 2 - 0.5;
|
||||
|
||||
qreal const width = 0.7;
|
||||
for( ch_cnt_t ch = 0; ch < DEFAULT_CHANNELS; ++ch )
|
||||
{
|
||||
QColor color = ch == 0 ? (leftChannelClips ? clippingColor() : leftChannelColor()) : // Check left channel
|
||||
ch == 1 ? (rightChannelClips ? clippingColor() : rightChannelColor()) : // Check right channel
|
||||
otherChannelsColor(); // Any other channel
|
||||
p.setPen(QPen(color, width));
|
||||
|
||||
for( int frame = 0; frame < frames; ++frame )
|
||||
{
|
||||
sample_t const clippedSample = AudioEngine::clip(m_buffer[frame][ch]);
|
||||
@@ -193,17 +219,9 @@ void Oscilloscope::mousePressEvent( QMouseEvent * _me )
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
QColor const & Oscilloscope::determineLineColor(float level) const
|
||||
bool Oscilloscope::clips(float level) const
|
||||
{
|
||||
if( level <= 1.0f )
|
||||
{
|
||||
return normalColor();
|
||||
}
|
||||
else
|
||||
{
|
||||
return clippingColor();
|
||||
}
|
||||
return level > 1.0f;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user