Skip to content
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions include/FadeButton.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,18 @@ class FadeButton : public QAbstractButton
{
Q_OBJECT
public:
FadeButton( const QColor & _normal_color, const QColor &
_activated_color, QWidget * _parent );
FadeButton( const QColor & _normal_color,
const QColor & _activated_color,
const QColor & _hold_color,
QWidget * _parent );

virtual ~FadeButton();
void setActiveColor( const QColor & activated_color );


public slots:
void activate();
void noteEnd();


protected:
Expand All @@ -53,13 +56,16 @@ public slots:

private:
QTime m_stateTimer;
QTime m_releaseTimer;

QColor m_normalColor;
QColor m_activatedColor;
QColor m_holdColor;
int activeNotes;

void signalUpdate();

} ;


#endif

1 change: 1 addition & 0 deletions include/InstrumentTrack.h
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ class LMMS_EXPORT InstrumentTrack : public Track, public MidiEventProcessor
void midiNoteOff( const Note& );
void nameChanged();
void newNote();
void endNote();


protected:
Expand Down
80 changes: 66 additions & 14 deletions src/gui/widgets/FadeButton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* FadeButton.cpp - implementation of fade-button
*
* Copyright (c) 2005-2009 Tobias Doerffel <tobydox/at/users.sourceforge.net>
*
*
* This file is part of LMMS - https://lmms.io
*
* This program is free software; you can redistribute it and/or
Expand All @@ -21,7 +21,7 @@
* Boston, MA 02110-1301 USA.
*
*/


#include <QTimer>
#include <QApplication>
Expand All @@ -36,15 +36,20 @@ const float FadeDuration = 300;


FadeButton::FadeButton( const QColor & _normal_color,
const QColor & _activated_color, QWidget * _parent ) :
const QColor & _activated_color,
const QColor & _hold_color,
QWidget * _parent ) :
QAbstractButton( _parent ),
m_stateTimer(),
m_releaseTimer(),
m_normalColor( _normal_color ),
m_activatedColor( _activated_color )
m_activatedColor( _activated_color ),
m_holdColor( _hold_color )
{
setAttribute( Qt::WA_OpaquePaintEvent, true );
setCursor( QCursor( embed::getIconPixmap( "hand" ), 3, 3 ) );
setFocusPolicy( Qt::NoFocus );
activeNotes = 0;
}


Expand All @@ -65,6 +70,30 @@ void FadeButton::setActiveColor( const QColor & activated_color )
void FadeButton::activate()
{
m_stateTimer.restart();
activeNotes++;
signalUpdate();
}




void FadeButton::noteEnd()
{
if (activeNotes <= 0)
{
qWarning("noteEnd() triggered without a corresponding activate()!");
activeNotes = 0;
}
else
{
activeNotes--;
}

if (activeNotes == 0)
{
m_releaseTimer.restart();
}

signalUpdate();
}

Expand All @@ -82,21 +111,51 @@ void FadeButton::customEvent( QEvent * )
void FadeButton::paintEvent( QPaintEvent * _pe )
{
QColor col = m_normalColor;

if( ! m_stateTimer.isNull() && m_stateTimer.elapsed() < FadeDuration )
{
// The first part of the fade, when a note is triggered.
const float state = 1 - m_stateTimer.elapsed() / FadeDuration;
const int r = (int)( m_normalColor.red() *
const int r = (int)( m_holdColor.red() *
( 1.0f - state ) +
m_activatedColor.red() * state );
const int g = (int)( m_normalColor.green() *
const int g = (int)( m_holdColor.green() *
( 1.0f - state ) +
m_activatedColor.green() * state );
const int b = (int)( m_normalColor.blue() *
const int b = (int)( m_holdColor.blue() *
( 1.0f - state ) +
m_activatedColor.blue() * state );
col.setRgb( r, g, b );
QTimer::singleShot( 20, this, SLOT( update() ) );
}
else if ( ! m_stateTimer.isNull()
&& m_stateTimer.elapsed() >= FadeDuration
&& activeNotes > 0)
{
// The fade is done, but at least one note is still held.
col = m_holdColor;
}
else if ( ! m_releaseTimer.isNull() && m_releaseTimer.elapsed() < FadeDuration )
{
// Last note just ended. Fade to default color.
const float state = 1 - m_releaseTimer.elapsed() / FadeDuration;
const int r = (int)( m_normalColor.red() *
( 1.0f - state ) +
m_holdColor.red() * state );
const int g = (int)( m_normalColor.green() *
( 1.0f - state ) +
m_holdColor.green() * state );
const int b = (int)( m_normalColor.blue() *
( 1.0f - state ) +
m_holdColor.blue() * state );
col.setRgb( r, g, b );
QTimer::singleShot( 20, this, SLOT( update() ) );
}
else
{
// No fade, no notes. Set to default color.
col = m_normalColor;
}

QPainter p( this );
p.fillRect( rect(), col );
Expand All @@ -118,10 +177,3 @@ void FadeButton::signalUpdate()
{
QApplication::postEvent( this, new updateEvent() );
}







5 changes: 5 additions & 0 deletions src/tracks/InstrumentTrack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,7 @@ void InstrumentTrack::processOutEvent( const MidiEvent& event, const MidiTime& t
m_instrument->handleMidiEvent( MidiEvent( MidiNoteOff, midiPort()->realOutputChannel(), key, 0 ), time, offset );
}
m_midiNotesMutex.unlock();
emit endNote();
break;

default:
Expand Down Expand Up @@ -969,6 +970,8 @@ InstrumentTrackView::InstrumentTrackView( InstrumentTrack * _it, TrackContainerV
QPalette::Background),
QApplication::palette().color( QPalette::Active,
QPalette::BrightText ),
QApplication::palette().color( QPalette::Active,
QPalette::BrightText).darker(),
getTrackSettingsWidget() );
m_activityIndicator->setGeometry(
widgetWidth-2*24-11, 2, 8, 28 );
Expand All @@ -979,6 +982,8 @@ InstrumentTrackView::InstrumentTrackView( InstrumentTrack * _it, TrackContainerV
this, SLOT( activityIndicatorReleased() ) );
connect( _it, SIGNAL( newNote() ),
m_activityIndicator, SLOT( activate() ) );
connect( _it, SIGNAL( endNote() ),
m_activityIndicator, SLOT( noteEnd() ) );
connect( &_it->m_mutedModel, SIGNAL( dataChanged() ), this, SLOT( muteChanged() ) );

setModel( _it );
Expand Down