Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FadeButtons now remain partially lit as a note plays out #4969

Merged
merged 19 commits into from Jun 25, 2019
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 9 additions & 4 deletions include/FadeButton.h
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,
enp2s0 marked this conversation as resolved.
Show resolved Hide resolved
QWidget * _parent );

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


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


protected:
Expand All @@ -52,14 +55,16 @@ public slots:


private:
QTime m_stateTimer;
QTime m_activateStateTimer;

PhysSong marked this conversation as resolved.
Show resolved Hide resolved
QColor m_normalColor;
QColor m_activatedColor;
QColor m_holdColor;
enp2s0 marked this conversation as resolved.
Show resolved Hide resolved
int activeNotes;

void signalUpdate();

} ;


#endif

1 change: 1 addition & 0 deletions include/InstrumentTrack.h
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
66 changes: 48 additions & 18 deletions src/gui/widgets/FadeButton.cpp
Expand Up @@ -2,7 +2,7 @@
* FadeButton.cpp - implementation of fade-button
*
* Copyright (c) 2005-2009 Tobias Doerffel <tobydox/at/users.sourceforge.net>
*
*
enp2s0 marked this conversation as resolved.
Show resolved Hide resolved
* 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.
*
*/

enp2s0 marked this conversation as resolved.
Show resolved Hide resolved

#include <QTimer>
#include <QApplication>
Expand All @@ -36,15 +36,19 @@ 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 ) :
PhysSong marked this conversation as resolved.
Show resolved Hide resolved
QAbstractButton( _parent ),
m_stateTimer(),
m_activateStateTimer(),
m_normalColor( _normal_color ),
m_activatedColor( _activated_color )
m_activatedColor( _activated_color ),
m_holdColor( _hold_color )
PhysSong marked this conversation as resolved.
Show resolved Hide resolved
{
setAttribute( Qt::WA_OpaquePaintEvent, true );
setCursor( QCursor( embed::getIconPixmap( "hand" ), 3, 3 ) );
setFocusPolicy( Qt::NoFocus );
activeNotes = 0;
enp2s0 marked this conversation as resolved.
Show resolved Hide resolved
}


Expand All @@ -64,13 +68,32 @@ void FadeButton::setActiveColor( const QColor & activated_color )

void FadeButton::activate()
{
m_stateTimer.restart();
m_activateStateTimer.restart();
activeNotes++;
PhysSong marked this conversation as resolved.
Show resolved Hide resolved
signalUpdate();
}




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

signalUpdate();
}
PhysSong marked this conversation as resolved.
Show resolved Hide resolved




void FadeButton::customEvent( QEvent * )
{
update();
Expand All @@ -82,21 +105,35 @@ void FadeButton::customEvent( QEvent * )
void FadeButton::paintEvent( QPaintEvent * _pe )
{
QColor col = m_normalColor;
if( ! m_stateTimer.isNull() && m_stateTimer.elapsed() < FadeDuration )

if( ! m_activateStateTimer.isNull() && m_activateStateTimer.elapsed() < FadeDuration )
{
const float state = 1 - m_stateTimer.elapsed() / FadeDuration;
const int r = (int)( m_normalColor.red() *
// The first part of the fade, when a note is triggered.
PhysSong marked this conversation as resolved.
Show resolved Hide resolved
const float state = 1 - m_activateStateTimer.elapsed() / FadeDuration;
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() ) );
PhysSong marked this conversation as resolved.
Show resolved Hide resolved
}
else if( ! m_activateStateTimer.isNull()
&& m_activateStateTimer.elapsed() >= FadeDuration
&& activeNotes > 0)
{
// The fade is done, but at least one note is still held.
col = m_holdColor;
}
else
{
// No fade, no notes. Reset to default color.
col = m_normalColor;
}
PhysSong marked this conversation as resolved.
Show resolved Hide resolved

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







5 changes: 5 additions & 0 deletions src/tracks/InstrumentTrack.cpp
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