From 47b492ea1dd8058ab30b1cd819527127e7138a26 Mon Sep 17 00:00:00 2001 From: Noah Brecht Date: Wed, 8 May 2019 21:06:29 -0400 Subject: [PATCH 01/19] Add a note counter to FadeButton --- include/FadeButton.h | 3 ++- src/gui/widgets/FadeButton.cpp | 31 ++++++++++++++++++++++--------- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/include/FadeButton.h b/include/FadeButton.h index 95753ecea90..a488b8a27cc 100644 --- a/include/FadeButton.h +++ b/include/FadeButton.h @@ -44,6 +44,7 @@ class FadeButton : public QAbstractButton public slots: void activate(); + void noteEnd(); protected: @@ -55,6 +56,7 @@ public slots: QTime m_stateTimer; QColor m_normalColor; QColor m_activatedColor; + int activeNotes; void signalUpdate(); @@ -62,4 +64,3 @@ public slots: #endif - diff --git a/src/gui/widgets/FadeButton.cpp b/src/gui/widgets/FadeButton.cpp index d4244701ab1..1700e941866 100644 --- a/src/gui/widgets/FadeButton.cpp +++ b/src/gui/widgets/FadeButton.cpp @@ -2,7 +2,7 @@ * FadeButton.cpp - implementation of fade-button * * Copyright (c) 2005-2009 Tobias Doerffel - * + * * This file is part of LMMS - https://lmms.io * * This program is free software; you can redistribute it and/or @@ -21,7 +21,7 @@ * Boston, MA 02110-1301 USA. * */ - + #include #include @@ -45,6 +45,7 @@ FadeButton::FadeButton( const QColor & _normal_color, setAttribute( Qt::WA_OpaquePaintEvent, true ); setCursor( QCursor( embed::getIconPixmap( "hand" ), 3, 3 ) ); setFocusPolicy( Qt::NoFocus ); + activeNotes = 0; } @@ -65,12 +66,31 @@ 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--; + } + + signalUpdate(); +} + + + + void FadeButton::customEvent( QEvent * ) { update(); @@ -118,10 +138,3 @@ void FadeButton::signalUpdate() { QApplication::postEvent( this, new updateEvent() ); } - - - - - - - From bddd7d2fab7352e7c7ca0dc41537259c83a1baba Mon Sep 17 00:00:00 2001 From: Noah Brecht Date: Wed, 8 May 2019 21:40:20 -0400 Subject: [PATCH 02/19] color fade logic for held notes --- include/FadeButton.h | 11 ++++++--- src/gui/widgets/FadeButton.cpp | 41 ++++++++++++++++++++++++++-------- src/tracks/InstrumentTrack.cpp | 2 ++ 3 files changed, 42 insertions(+), 12 deletions(-) diff --git a/include/FadeButton.h b/include/FadeButton.h index a488b8a27cc..020082cdd5d 100644 --- a/include/FadeButton.h +++ b/include/FadeButton.h @@ -35,8 +35,10 @@ 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 ); @@ -53,9 +55,12 @@ public slots: private: - QTime m_stateTimer; + QTime m_activateStateTimer; + QTime m_holdStateTimer; + QColor m_normalColor; QColor m_activatedColor; + QColor m_holdColor; int activeNotes; void signalUpdate(); diff --git a/src/gui/widgets/FadeButton.cpp b/src/gui/widgets/FadeButton.cpp index 1700e941866..c88e007c5a1 100644 --- a/src/gui/widgets/FadeButton.cpp +++ b/src/gui/widgets/FadeButton.cpp @@ -36,11 +36,15 @@ 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_activateStateTimer(), + m_holdStateTimer(), 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 ) ); @@ -65,8 +69,10 @@ void FadeButton::setActiveColor( const QColor & activated_color ) void FadeButton::activate() { - m_stateTimer.restart(); + m_activateStateTimer.restart(); activeNotes++; + + qWarning("active notes now %d", activeNotes); signalUpdate(); } @@ -85,6 +91,9 @@ void FadeButton::noteEnd() activeNotes--; } + if(activeNotes <= 0) + m_holdStateTimer.restart(); + signalUpdate(); } @@ -102,21 +111,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. + 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() ) ); } + 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; + } QPainter p( this ); p.fillRect( rect(), col ); diff --git a/src/tracks/InstrumentTrack.cpp b/src/tracks/InstrumentTrack.cpp index 6c95f3c9a23..335fd0a20d0 100644 --- a/src/tracks/InstrumentTrack.cpp +++ b/src/tracks/InstrumentTrack.cpp @@ -969,6 +969,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 ); From 7f4618b77e8814047cd649b193e2c28c960f6b78 Mon Sep 17 00:00:00 2001 From: Noah Brecht Date: Wed, 8 May 2019 21:42:03 -0400 Subject: [PATCH 03/19] remove unnecessary timer --- include/FadeButton.h | 1 - src/gui/widgets/FadeButton.cpp | 4 ---- 2 files changed, 5 deletions(-) diff --git a/include/FadeButton.h b/include/FadeButton.h index 020082cdd5d..456427150be 100644 --- a/include/FadeButton.h +++ b/include/FadeButton.h @@ -56,7 +56,6 @@ public slots: private: QTime m_activateStateTimer; - QTime m_holdStateTimer; QColor m_normalColor; QColor m_activatedColor; diff --git a/src/gui/widgets/FadeButton.cpp b/src/gui/widgets/FadeButton.cpp index c88e007c5a1..cd97337d1a0 100644 --- a/src/gui/widgets/FadeButton.cpp +++ b/src/gui/widgets/FadeButton.cpp @@ -41,7 +41,6 @@ FadeButton::FadeButton( const QColor & _normal_color, QWidget * _parent ) : QAbstractButton( _parent ), m_activateStateTimer(), - m_holdStateTimer(), m_normalColor( _normal_color ), m_activatedColor( _activated_color ), m_holdColor( _hold_color ) @@ -91,9 +90,6 @@ void FadeButton::noteEnd() activeNotes--; } - if(activeNotes <= 0) - m_holdStateTimer.restart(); - signalUpdate(); } From adda89df46373688e04d0133d8946fd613fc32d8 Mon Sep 17 00:00:00 2001 From: Noah Brecht Date: Wed, 8 May 2019 21:55:18 -0400 Subject: [PATCH 04/19] add noteEnd() signal and emit it --- include/InstrumentTrack.h | 1 + src/gui/widgets/FadeButton.cpp | 2 -- src/tracks/InstrumentTrack.cpp | 3 +++ 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/include/InstrumentTrack.h b/include/InstrumentTrack.h index c487438d0f8..72e0d04cc44 100644 --- a/include/InstrumentTrack.h +++ b/include/InstrumentTrack.h @@ -221,6 +221,7 @@ class LMMS_EXPORT InstrumentTrack : public Track, public MidiEventProcessor void midiNoteOff( const Note& ); void nameChanged(); void newNote(); + void endNote(); protected: diff --git a/src/gui/widgets/FadeButton.cpp b/src/gui/widgets/FadeButton.cpp index cd97337d1a0..e9af212f22e 100644 --- a/src/gui/widgets/FadeButton.cpp +++ b/src/gui/widgets/FadeButton.cpp @@ -70,8 +70,6 @@ void FadeButton::activate() { m_activateStateTimer.restart(); activeNotes++; - - qWarning("active notes now %d", activeNotes); signalUpdate(); } diff --git a/src/tracks/InstrumentTrack.cpp b/src/tracks/InstrumentTrack.cpp index 335fd0a20d0..dd4c2638b15 100644 --- a/src/tracks/InstrumentTrack.cpp +++ b/src/tracks/InstrumentTrack.cpp @@ -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: @@ -981,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 ); From b3da0ce02f12a8190e743fa6ba24b7e6890a20fb Mon Sep 17 00:00:00 2001 From: Noah Brecht Date: Wed, 8 May 2019 22:28:52 -0400 Subject: [PATCH 05/19] undo rename --- include/FadeButton.h | 2 +- src/gui/widgets/FadeButton.cpp | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/include/FadeButton.h b/include/FadeButton.h index 456427150be..430f32728da 100644 --- a/include/FadeButton.h +++ b/include/FadeButton.h @@ -55,7 +55,7 @@ public slots: private: - QTime m_activateStateTimer; + QTime m_stateTimer; QColor m_normalColor; QColor m_activatedColor; diff --git a/src/gui/widgets/FadeButton.cpp b/src/gui/widgets/FadeButton.cpp index e9af212f22e..1c040e326e4 100644 --- a/src/gui/widgets/FadeButton.cpp +++ b/src/gui/widgets/FadeButton.cpp @@ -40,7 +40,7 @@ FadeButton::FadeButton( const QColor & _normal_color, const QColor & _hold_color, QWidget * _parent ) : QAbstractButton( _parent ), - m_activateStateTimer(), + m_stateTimer(), m_normalColor( _normal_color ), m_activatedColor( _activated_color ), m_holdColor( _hold_color ) @@ -68,7 +68,7 @@ void FadeButton::setActiveColor( const QColor & activated_color ) void FadeButton::activate() { - m_activateStateTimer.restart(); + m_stateTimer.restart(); activeNotes++; signalUpdate(); } @@ -106,10 +106,10 @@ void FadeButton::paintEvent( QPaintEvent * _pe ) { QColor col = m_normalColor; - if( ! m_activateStateTimer.isNull() && m_activateStateTimer.elapsed() < FadeDuration ) + if( ! m_stateTimer.isNull() && m_stateTimer.elapsed() < FadeDuration ) { // The first part of the fade, when a note is triggered. - const float state = 1 - m_activateStateTimer.elapsed() / FadeDuration; + const float state = 1 - m_stateTimer.elapsed() / FadeDuration; const int r = (int)( m_holdColor.red() * ( 1.0f - state ) + m_activatedColor.red() * state ); @@ -122,8 +122,8 @@ void FadeButton::paintEvent( QPaintEvent * _pe ) col.setRgb( r, g, b ); QTimer::singleShot( 20, this, SLOT( update() ) ); } - else if( ! m_activateStateTimer.isNull() - && m_activateStateTimer.elapsed() >= FadeDuration + else if( ! m_stateTimer.isNull() + && m_stateTimer.elapsed() >= FadeDuration && activeNotes > 0) { // The fade is done, but at least one note is still held. From 69bbd449133a6abaf3d8840028aea1fa1f6e14bc Mon Sep 17 00:00:00 2001 From: Noah Brecht Date: Wed, 8 May 2019 22:53:30 -0400 Subject: [PATCH 06/19] convert spaces->tabs --- src/gui/widgets/FadeButton.cpp | 50 +++++++++++++++++----------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/src/gui/widgets/FadeButton.cpp b/src/gui/widgets/FadeButton.cpp index 1c040e326e4..09fa7ca9df2 100644 --- a/src/gui/widgets/FadeButton.cpp +++ b/src/gui/widgets/FadeButton.cpp @@ -69,7 +69,7 @@ void FadeButton::setActiveColor( const QColor & activated_color ) void FadeButton::activate() { m_stateTimer.restart(); - activeNotes++; + activeNotes++; signalUpdate(); } @@ -78,17 +78,17 @@ void FadeButton::activate() void FadeButton::noteEnd() { - if(activeNotes <= 0) - { - qWarning("noteEnd() triggered without a corresponding activate()!"); - activeNotes = 0; - } - else - { - activeNotes--; - } - - signalUpdate(); + if(activeNotes <= 0) + { + qWarning("noteEnd() triggered without a corresponding activate()!"); + activeNotes = 0; + } + else + { + activeNotes--; + } + + signalUpdate(); } @@ -108,7 +108,7 @@ void FadeButton::paintEvent( QPaintEvent * _pe ) if( ! m_stateTimer.isNull() && m_stateTimer.elapsed() < FadeDuration ) { - // The first part of the fade, when a note is triggered. + // The first part of the fade, when a note is triggered. const float state = 1 - m_stateTimer.elapsed() / FadeDuration; const int r = (int)( m_holdColor.red() * ( 1.0f - state ) + @@ -122,18 +122,18 @@ void FadeButton::paintEvent( QPaintEvent * _pe ) 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 - { - // No fade, no notes. Reset to default color. - col = m_normalColor; - } + 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 + { + // No fade, no notes. Reset to default color. + col = m_normalColor; + } QPainter p( this ); p.fillRect( rect(), col ); From d19be5034e13fa8638e521794ea52badf494aa07 Mon Sep 17 00:00:00 2001 From: Noah Brecht Date: Wed, 8 May 2019 23:28:04 -0400 Subject: [PATCH 07/19] more spaces->tabs --- src/gui/widgets/FadeButton.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gui/widgets/FadeButton.cpp b/src/gui/widgets/FadeButton.cpp index 09fa7ca9df2..23d6bd22c2c 100644 --- a/src/gui/widgets/FadeButton.cpp +++ b/src/gui/widgets/FadeButton.cpp @@ -43,12 +43,12 @@ FadeButton::FadeButton( const QColor & _normal_color, m_stateTimer(), m_normalColor( _normal_color ), m_activatedColor( _activated_color ), - m_holdColor( _hold_color ) + m_holdColor( _hold_color ) { setAttribute( Qt::WA_OpaquePaintEvent, true ); setCursor( QCursor( embed::getIconPixmap( "hand" ), 3, 3 ) ); setFocusPolicy( Qt::NoFocus ); - activeNotes = 0; + activeNotes = 0; } From 75965d42266d9b2091b046ee476219b0fac0c645 Mon Sep 17 00:00:00 2001 From: Noah Brecht Date: Wed, 8 May 2019 23:31:31 -0400 Subject: [PATCH 08/19] one more space->tab --- src/gui/widgets/FadeButton.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gui/widgets/FadeButton.cpp b/src/gui/widgets/FadeButton.cpp index 23d6bd22c2c..c8f113aa3d6 100644 --- a/src/gui/widgets/FadeButton.cpp +++ b/src/gui/widgets/FadeButton.cpp @@ -37,8 +37,8 @@ const float FadeDuration = 300; FadeButton::FadeButton( const QColor & _normal_color, const QColor & _activated_color, - const QColor & _hold_color, - QWidget * _parent ) : + const QColor & _hold_color, + QWidget * _parent ) : QAbstractButton( _parent ), m_stateTimer(), m_normalColor( _normal_color ), From 1ffcbd2ad40d0c2832d77795ab2d6da9a7377cfb Mon Sep 17 00:00:00 2001 From: Noah Brecht Date: Thu, 9 May 2019 15:43:44 -0400 Subject: [PATCH 09/19] one more space->tab --- src/gui/widgets/FadeButton.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/widgets/FadeButton.cpp b/src/gui/widgets/FadeButton.cpp index c8f113aa3d6..6cd9343b463 100644 --- a/src/gui/widgets/FadeButton.cpp +++ b/src/gui/widgets/FadeButton.cpp @@ -81,7 +81,7 @@ void FadeButton::noteEnd() if(activeNotes <= 0) { qWarning("noteEnd() triggered without a corresponding activate()!"); - activeNotes = 0; + activeNotes = 0; } else { From ecaa1590c75bb1ea43e4ec4fbfcb8da14a818d81 Mon Sep 17 00:00:00 2001 From: Noah Brecht Date: Thu, 9 May 2019 15:46:14 -0400 Subject: [PATCH 10/19] Final formatting fixes --- src/gui/widgets/FadeButton.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gui/widgets/FadeButton.cpp b/src/gui/widgets/FadeButton.cpp index 6cd9343b463..797c509afbf 100644 --- a/src/gui/widgets/FadeButton.cpp +++ b/src/gui/widgets/FadeButton.cpp @@ -80,12 +80,12 @@ void FadeButton::noteEnd() { if(activeNotes <= 0) { - qWarning("noteEnd() triggered without a corresponding activate()!"); + qWarning("noteEnd() triggered without a corresponding activate()!"); activeNotes = 0; } else { - activeNotes--; + activeNotes--; } signalUpdate(); From 7299809be369fd5d9743c29c30a17d78088fcb72 Mon Sep 17 00:00:00 2001 From: noahb01 Date: Mon, 13 May 2019 23:08:18 -0400 Subject: [PATCH 11/19] Add an ADSR "release" fade when all notes are released --- include/FadeButton.h | 1 + src/gui/widgets/FadeButton.cpp | 25 +++++++++++++++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/include/FadeButton.h b/include/FadeButton.h index 430f32728da..42dbb2a5fdb 100644 --- a/include/FadeButton.h +++ b/include/FadeButton.h @@ -56,6 +56,7 @@ public slots: private: QTime m_stateTimer; + QTime m_releaseTimer; QColor m_normalColor; QColor m_activatedColor; diff --git a/src/gui/widgets/FadeButton.cpp b/src/gui/widgets/FadeButton.cpp index 797c509afbf..ac283177022 100644 --- a/src/gui/widgets/FadeButton.cpp +++ b/src/gui/widgets/FadeButton.cpp @@ -41,6 +41,7 @@ FadeButton::FadeButton( const QColor & _normal_color, QWidget * _parent ) : QAbstractButton( _parent ), m_stateTimer(), + m_releaseTimer(), m_normalColor( _normal_color ), m_activatedColor( _activated_color ), m_holdColor( _hold_color ) @@ -88,6 +89,11 @@ void FadeButton::noteEnd() activeNotes--; } + if (activeNotes == 0) + { + m_releaseTimer.restart(); + } + signalUpdate(); } @@ -122,16 +128,31 @@ void FadeButton::paintEvent( QPaintEvent * _pe ) col.setRgb( r, g, b ); QTimer::singleShot( 20, this, SLOT( update() ) ); } - else if( ! m_stateTimer.isNull() + 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 + else if ( ! m_releaseTimer.isNull() && m_releaseTimer.elapsed() < FadeDuration ) { // No fade, no notes. Reset 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 + { col = m_normalColor; } From c08af151cb99a54053692a7cea78325c359c521f Mon Sep 17 00:00:00 2001 From: noahb01 Date: Mon, 13 May 2019 23:14:05 -0400 Subject: [PATCH 12/19] Fix misleading comments --- src/gui/widgets/FadeButton.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/gui/widgets/FadeButton.cpp b/src/gui/widgets/FadeButton.cpp index ac283177022..df0826b8c4e 100644 --- a/src/gui/widgets/FadeButton.cpp +++ b/src/gui/widgets/FadeButton.cpp @@ -137,7 +137,7 @@ void FadeButton::paintEvent( QPaintEvent * _pe ) } else if ( ! m_releaseTimer.isNull() && m_releaseTimer.elapsed() < FadeDuration ) { - // No fade, no notes. Reset to default color. + // 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 ) + @@ -153,6 +153,7 @@ void FadeButton::paintEvent( QPaintEvent * _pe ) } else { + // No fade, no notes. Set to default color. col = m_normalColor; } From ae59c5868c3241e41d374fd76db0b82adb806d0f Mon Sep 17 00:00:00 2001 From: noahb01 Date: Mon, 13 May 2019 23:16:26 -0400 Subject: [PATCH 13/19] Fix a formatting issue --- src/gui/widgets/FadeButton.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/widgets/FadeButton.cpp b/src/gui/widgets/FadeButton.cpp index df0826b8c4e..274220648d7 100644 --- a/src/gui/widgets/FadeButton.cpp +++ b/src/gui/widgets/FadeButton.cpp @@ -79,7 +79,7 @@ void FadeButton::activate() void FadeButton::noteEnd() { - if(activeNotes <= 0) + if (activeNotes <= 0) { qWarning("noteEnd() triggered without a corresponding activate()!"); activeNotes = 0; From 65e028015dcb5818c019bf031e05a5895f10e8e9 Mon Sep 17 00:00:00 2001 From: noahb01 Date: Fri, 7 Jun 2019 21:18:48 -0400 Subject: [PATCH 14/19] Factor out fade logic into seperate function --- include/FadeButton.h | 1 + src/gui/widgets/FadeButton.cpp | 43 ++++++++++++++++------------------ 2 files changed, 21 insertions(+), 23 deletions(-) diff --git a/include/FadeButton.h b/include/FadeButton.h index 42dbb2a5fdb..26ef76fd892 100644 --- a/include/FadeButton.h +++ b/include/FadeButton.h @@ -64,6 +64,7 @@ public slots: int activeNotes; void signalUpdate(); + QColor fadeToColor(QColor, QColor, QTime, float); } ; diff --git a/src/gui/widgets/FadeButton.cpp b/src/gui/widgets/FadeButton.cpp index 274220648d7..7df31be5edf 100644 --- a/src/gui/widgets/FadeButton.cpp +++ b/src/gui/widgets/FadeButton.cpp @@ -107,7 +107,6 @@ void FadeButton::customEvent( QEvent * ) - void FadeButton::paintEvent( QPaintEvent * _pe ) { QColor col = m_normalColor; @@ -115,17 +114,7 @@ void FadeButton::paintEvent( QPaintEvent * _pe ) 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_holdColor.red() * - ( 1.0f - state ) + - m_activatedColor.red() * state ); - const int g = (int)( m_holdColor.green() * - ( 1.0f - state ) + - m_activatedColor.green() * state ); - const int b = (int)( m_holdColor.blue() * - ( 1.0f - state ) + - m_activatedColor.blue() * state ); - col.setRgb( r, g, b ); + col = fadeToColor(m_activatedColor, m_holdColor, m_stateTimer, FadeDuration); QTimer::singleShot( 20, this, SLOT( update() ) ); } else if ( ! m_stateTimer.isNull() @@ -138,17 +127,7 @@ void FadeButton::paintEvent( QPaintEvent * _pe ) 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 ); + col = fadeToColor(m_holdColor, m_normalColor, m_releaseTimer, FadeDuration); QTimer::singleShot( 20, this, SLOT( update() ) ); } else @@ -171,6 +150,24 @@ void FadeButton::paintEvent( QPaintEvent * _pe ) } +QColor FadeButton::fadeToColor(QColor startCol, QColor endCol, QTime timer, float duration) +{ + QColor col; + + const float state = 1 - timer.elapsed() / duration; + const int r = (int)( endCol.red() * + ( 1.0f - state ) + + startCol.red() * state ); + const int g = (int)( endCol.green() * + ( 1.0f - state ) + + startCol.green() * state ); + const int b = (int)( endCol.blue() * + ( 1.0f - state ) + + startCol.blue() * state ); + col.setRgb( r, g, b ); + + return col; +} void FadeButton::signalUpdate() From 478a453a16d86772b0c78affaba9e72e8fb2e7e8 Mon Sep 17 00:00:00 2001 From: noahb01 Date: Fri, 7 Jun 2019 21:27:24 -0400 Subject: [PATCH 15/19] Add comments describing the 3 colors --- include/FadeButton.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/FadeButton.h b/include/FadeButton.h index 26ef76fd892..8f56a77b22e 100644 --- a/include/FadeButton.h +++ b/include/FadeButton.h @@ -58,8 +58,11 @@ public slots: QTime m_stateTimer; QTime m_releaseTimer; + // the default color of the widget QColor m_normalColor; + // the color on note play QColor m_activatedColor; + // the color after the "play" fade is done but a note is still playing QColor m_holdColor; int activeNotes; From 55f800723cc9b42cbc3583f84559fa887862a957 Mon Sep 17 00:00:00 2001 From: Noah Brecht Date: Mon, 10 Jun 2019 18:45:10 -0400 Subject: [PATCH 16/19] Reinsert removed space Co-Authored-By: Shmuel H. --- src/gui/widgets/FadeButton.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/widgets/FadeButton.cpp b/src/gui/widgets/FadeButton.cpp index 7df31be5edf..23f94b87ee1 100644 --- a/src/gui/widgets/FadeButton.cpp +++ b/src/gui/widgets/FadeButton.cpp @@ -2,7 +2,7 @@ * FadeButton.cpp - implementation of fade-button * * Copyright (c) 2005-2009 Tobias Doerffel - * + * * This file is part of LMMS - https://lmms.io * * This program is free software; you can redistribute it and/or From 8345e0e5eb6f5f2f90d31dfdf74bcfe506bad8e2 Mon Sep 17 00:00:00 2001 From: Noah Brecht Date: Mon, 10 Jun 2019 18:45:24 -0400 Subject: [PATCH 17/19] Reinsert removed space Co-Authored-By: Shmuel H. --- src/gui/widgets/FadeButton.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/widgets/FadeButton.cpp b/src/gui/widgets/FadeButton.cpp index 23f94b87ee1..c63da411f54 100644 --- a/src/gui/widgets/FadeButton.cpp +++ b/src/gui/widgets/FadeButton.cpp @@ -21,7 +21,7 @@ * Boston, MA 02110-1301 USA. * */ - + #include #include From 1c3065ac628cc650d18aa00e081a5d68fecbee2e Mon Sep 17 00:00:00 2001 From: noahb01 Date: Sun, 23 Jun 2019 16:20:52 -0400 Subject: [PATCH 18/19] better formatting --- src/gui/widgets/FadeButton.cpp | 55 ++++++++++++++++------------------ 1 file changed, 26 insertions(+), 29 deletions(-) diff --git a/src/gui/widgets/FadeButton.cpp b/src/gui/widgets/FadeButton.cpp index c63da411f54..b327fcafbbb 100644 --- a/src/gui/widgets/FadeButton.cpp +++ b/src/gui/widgets/FadeButton.cpp @@ -37,14 +37,14 @@ const float FadeDuration = 300; FadeButton::FadeButton( const QColor & _normal_color, const QColor & _activated_color, - const QColor & _hold_color, + const QColor & holdColor, QWidget * _parent ) : QAbstractButton( _parent ), m_stateTimer(), m_releaseTimer(), m_normalColor( _normal_color ), m_activatedColor( _activated_color ), - m_holdColor( _hold_color ) + m_holdColor( holdColor ) { setAttribute( Qt::WA_OpaquePaintEvent, true ); setCursor( QCursor( embed::getIconPixmap( "hand" ), 3, 3 ) ); @@ -59,7 +59,7 @@ FadeButton::~FadeButton() { } -void FadeButton::setActiveColor( const QColor & activated_color ) +void FadeButton::setActiveColor(const QColor & activated_color) { m_activatedColor = activated_color; } @@ -100,35 +100,35 @@ void FadeButton::noteEnd() -void FadeButton::customEvent( QEvent * ) +void FadeButton::customEvent(QEvent *) { update(); } -void FadeButton::paintEvent( QPaintEvent * _pe ) +void FadeButton::paintEvent(QPaintEvent * _pe) { QColor col = m_normalColor; - if( ! m_stateTimer.isNull() && m_stateTimer.elapsed() < FadeDuration ) + if(!m_stateTimer.isNull() && m_stateTimer.elapsed() < FadeDuration) { // The first part of the fade, when a note is triggered. col = fadeToColor(m_activatedColor, m_holdColor, m_stateTimer, FadeDuration); - QTimer::singleShot( 20, this, SLOT( update() ) ); + QTimer::singleShot(20, this, SLOT(update())); } - else if ( ! m_stateTimer.isNull() + 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 ) + else if (!m_releaseTimer.isNull() && m_releaseTimer.elapsed() < FadeDuration) { // Last note just ended. Fade to default color. col = fadeToColor(m_holdColor, m_normalColor, m_releaseTimer, FadeDuration); - QTimer::singleShot( 20, this, SLOT( update() ) ); + QTimer::singleShot(20, this, SLOT(update())); } else { @@ -136,17 +136,17 @@ void FadeButton::paintEvent( QPaintEvent * _pe ) col = m_normalColor; } - QPainter p( this ); - p.fillRect( rect(), col ); + QPainter p(this); + p.fillRect(rect(), col); int w = rect().right(); int h = rect().bottom(); - p.setPen( m_normalColor.darker(130) ); - p.drawLine( w, 1, w, h ); - p.drawLine( 1, h, w, h ); - p.setPen( m_normalColor.lighter(130) ); - p.drawLine( 0, 0, 0, h-1 ); - p.drawLine( 0, 0, w, 0 ); + p.setPen(m_normalColor.darker(130)); + p.drawLine(w, 1, w, h); + p.drawLine(1, h, w, h); + p.setPen(m_normalColor.lighter(130)); + p.drawLine(0, 0, 0, h-1); + p.drawLine(0, 0, w, 0); } @@ -155,16 +155,13 @@ QColor FadeButton::fadeToColor(QColor startCol, QColor endCol, QTime timer, floa QColor col; const float state = 1 - timer.elapsed() / duration; - const int r = (int)( endCol.red() * - ( 1.0f - state ) + - startCol.red() * state ); - const int g = (int)( endCol.green() * - ( 1.0f - state ) + - startCol.green() * state ); - const int b = (int)( endCol.blue() * - ( 1.0f - state ) + - startCol.blue() * state ); - col.setRgb( r, g, b ); + const int r = (int)(endCol.red() * (1.0f - state) + + startCol.red() * state); + const int g = (int)(endCol.green() * (1.0f - state) + + startCol.green() * state); + const int b = (int)(endCol.blue() * (1.0f - state) + + startCol.blue() * state); + col.setRgb(r, g, b); return col; } @@ -172,5 +169,5 @@ QColor FadeButton::fadeToColor(QColor startCol, QColor endCol, QTime timer, floa void FadeButton::signalUpdate() { - QApplication::postEvent( this, new updateEvent() ); + QApplication::postEvent(this, new updateEvent()); } From a920f5a750f9a8afbfe6d1159964a0ecf154b60c Mon Sep 17 00:00:00 2001 From: noahb01 Date: Sun, 23 Jun 2019 16:21:25 -0400 Subject: [PATCH 19/19] better formatting pt 2 --- src/gui/widgets/FadeButton.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/gui/widgets/FadeButton.cpp b/src/gui/widgets/FadeButton.cpp index b327fcafbbb..b633286b18b 100644 --- a/src/gui/widgets/FadeButton.cpp +++ b/src/gui/widgets/FadeButton.cpp @@ -35,10 +35,10 @@ const float FadeDuration = 300; -FadeButton::FadeButton( const QColor & _normal_color, - const QColor & _activated_color, - const QColor & holdColor, - QWidget * _parent ) : +FadeButton::FadeButton(const QColor & _normal_color, + const QColor & _activated_color, + const QColor & holdColor, + QWidget * _parent) : QAbstractButton( _parent ), m_stateTimer(), m_releaseTimer(), @@ -46,9 +46,9 @@ FadeButton::FadeButton( const QColor & _normal_color, m_activatedColor( _activated_color ), m_holdColor( holdColor ) { - setAttribute( Qt::WA_OpaquePaintEvent, true ); - setCursor( QCursor( embed::getIconPixmap( "hand" ), 3, 3 ) ); - setFocusPolicy( Qt::NoFocus ); + setAttribute(Qt::WA_OpaquePaintEvent, true); + setCursor(QCursor(embed::getIconPixmap("hand"), 3, 3)); + setFocusPolicy(Qt::NoFocus); activeNotes = 0; }