From 33b9524346066baa40578b3e4df1f9fc7a74d76a Mon Sep 17 00:00:00 2001 From: Vesa Date: Sat, 22 Mar 2014 19:09:42 +0200 Subject: [PATCH] Envelope: fix drawing of envelope graph, scale to fit view if graph gets too long (also fix typo in last pianoview commit) --- include/EnvelopeAndLfoView.h | 4 +- src/gui/PianoView.cpp | 2 +- src/gui/widgets/EnvelopeAndLfoView.cpp | 61 ++++++++++++++------------ 3 files changed, 37 insertions(+), 30 deletions(-) diff --git a/include/EnvelopeAndLfoView.h b/include/EnvelopeAndLfoView.h index dec4a5bb8..8df71b0ed 100644 --- a/include/EnvelopeAndLfoView.h +++ b/include/EnvelopeAndLfoView.h @@ -23,8 +23,8 @@ * */ -#ifndef _ENVELOPE_AND_LFO_VIEW_H -#define _ENVELOPE_AND_LFO_VIEW_H +#ifndef ENVELOPE_AND_LFO_VIEW_H +#define ENVELOPE_AND_LFO_VIEW_H #include diff --git a/src/gui/PianoView.cpp b/src/gui/PianoView.cpp index 3bd43f8e6..af4b07339 100644 --- a/src/gui/PianoView.cpp +++ b/src/gui/PianoView.cpp @@ -469,7 +469,7 @@ void PianoView::mousePressEvent( QMouseEvent * _me ) Piano::WhiteKey ) ? PW_WHITE_KEY_HEIGHT : PW_BLACK_KEY_HEIGHT ) ) { - velocity = m_piano->instrumentTrack()->midiPort()->baseVelocity() ); + velocity = m_piano->instrumentTrack()->midiPort()->baseVelocity(); } // set note on m_piano->midiEventProcessor()->processInEvent( MidiEvent( MidiNoteOn, 0, key_num, velocity ) ); diff --git a/src/gui/widgets/EnvelopeAndLfoView.cpp b/src/gui/widgets/EnvelopeAndLfoView.cpp index 712f48ac5..034e00d76 100644 --- a/src/gui/widgets/EnvelopeAndLfoView.cpp +++ b/src/gui/widgets/EnvelopeAndLfoView.cpp @@ -62,8 +62,7 @@ const int SUSTAIN_KNOB_X = DECAY_KNOB_X+KNOB_X_SPACING; const int RELEASE_KNOB_X = SUSTAIN_KNOB_X+KNOB_X_SPACING; const int AMOUNT_KNOB_X = RELEASE_KNOB_X+KNOB_X_SPACING; -const float TIME_UNIT_WIDTH = 24.0; - +const int TIME_UNIT_WIDTH = 40; const int LFO_GRAPH_X = 6; const int LFO_GRAPH_Y = ENV_KNOBS_LBL_Y+14; @@ -425,48 +424,56 @@ void EnvelopeAndLfoView::paintEvent( QPaintEvent * ) const int y_base = ENV_GRAPH_Y + s_envGraph->height() - 3; const int avail_height = s_envGraph->height() - 6; - int x1 = ENV_GRAPH_X + 2 + static_cast( m_predelayKnob->value() * - TIME_UNIT_WIDTH ); - int x2 = x1 + static_cast( m_attackKnob->value() * - TIME_UNIT_WIDTH ); + int x1 = static_cast( m_predelayKnob->value() * TIME_UNIT_WIDTH ); + int x2 = x1 + static_cast( m_attackKnob->value() * TIME_UNIT_WIDTH ); + int x3 = x2 + static_cast( m_holdKnob->value() * TIME_UNIT_WIDTH ); + int x4 = x3 + static_cast( ( m_decayKnob->value() * + ( 1 - m_sustainKnob->value() ) ) * TIME_UNIT_WIDTH ); + int x5 = x4 + static_cast( m_releaseKnob->value() * TIME_UNIT_WIDTH ); + + if( x5 > 174 ) + { + x1 = ( x1 * 174 ) / x5; + x2 = ( x2 * 174 ) / x5; + x3 = ( x3 * 174 ) / x5; + x4 = ( x4 * 174 ) / x5; + x5 = ( x5 * 174 ) / x5; + } + x1 += ENV_GRAPH_X + 2; + x2 += ENV_GRAPH_X + 2; + x3 += ENV_GRAPH_X + 2; + x4 += ENV_GRAPH_X + 2; + x5 += ENV_GRAPH_X + 2; p.drawLine( x1, y_base, x2, y_base - avail_height ); p.fillRect( x1 - 1, y_base - 2, 4, 4, end_points_bg_color ); p.fillRect( x1, y_base - 1, 2, 2, end_points_color ); - x1 = x2; - x2 = x1 + static_cast( m_holdKnob->value() * TIME_UNIT_WIDTH ); - p.drawLine( x1, y_base - avail_height, x2, y_base - avail_height ); - p.fillRect( x1 - 1, y_base - 2 - avail_height, 4, 4, + p.drawLine( x2, y_base - avail_height, x3, y_base - avail_height ); + p.fillRect( x2 - 1, y_base - 2 - avail_height, 4, 4, end_points_bg_color ); - p.fillRect( x1, y_base - 1 - avail_height, 2, 2, end_points_color ); - x1 = x2; - x2 = x1 + static_cast( ( m_decayKnob->value() * - ( 1 - m_sustainKnob->value() ) ) * - TIME_UNIT_WIDTH ); + p.fillRect( x2, y_base - 1 - avail_height, 2, 2, end_points_color ); - p.drawLine( x1, y_base-avail_height, x2, static_cast( y_base - + p.drawLine( x3, y_base-avail_height, x4, static_cast( y_base - avail_height + ( 1 - m_sustainKnob->value() ) * avail_height ) ); - p.fillRect( x1 - 1, y_base - 2 - avail_height, 4, 4, + p.fillRect( x3 - 1, y_base - 2 - avail_height, 4, 4, end_points_bg_color ); - p.fillRect( x1, y_base - 1 - avail_height, 2, 2, end_points_color ); - x1 = x2; - x2 = x1 + static_cast( m_releaseKnob->value() * TIME_UNIT_WIDTH ); - - p.drawLine( x1, static_cast( y_base - avail_height + + p.fillRect( x3, y_base - 1 - avail_height, 2, 2, end_points_color ); + + p.drawLine( x4, static_cast( y_base - avail_height + ( 1 - m_sustainKnob->value() ) * - avail_height ), x2, y_base ); - p.fillRect( x1 - 1, static_cast( y_base - avail_height + + avail_height ), x5, y_base ); + p.fillRect( x4 - 1, static_cast( y_base - avail_height + ( 1 - m_sustainKnob->value() ) * avail_height ) - 2, 4, 4, end_points_bg_color ); - p.fillRect( x1, static_cast( y_base - avail_height + + p.fillRect( x4, static_cast( y_base - avail_height + ( 1 - m_sustainKnob->value() ) * avail_height ) - 1, 2, 2, end_points_color ); - p.fillRect( x2 - 1, y_base - 2, 4, 4, end_points_bg_color ); - p.fillRect( x2, y_base - 1, 2, 2, end_points_color ); + p.fillRect( x5 - 1, y_base - 2, 4, 4, end_points_bg_color ); + p.fillRect( x5, y_base - 1, 2, 2, end_points_color ); int LFO_GRAPH_W = s_lfoGraph->width() - 6; // substract border