From f986f099da12ce71bf7ee79ceef5aded043ddf84 Mon Sep 17 00:00:00 2001 From: Vesa Date: Sat, 22 Mar 2014 12:32:43 +0200 Subject: [PATCH] Piano widget: make keypresses (gui and keyboard) based on the MIDI base velocity spinner --- include/Piano.h | 6 +++--- src/core/Piano.cpp | 8 ++++++-- src/gui/PianoView.cpp | 16 ++++++++-------- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/include/Piano.h b/include/Piano.h index b1487095f..8e86622fc 100644 --- a/include/Piano.h +++ b/include/Piano.h @@ -22,8 +22,8 @@ * */ -#ifndef _PIANO_H -#define _PIANO_H +#ifndef PIANO_H +#define PIANO_H #include "note.h" #include "Model.h" @@ -50,7 +50,7 @@ public: return m_pressedKeys[key]; } - void handleKeyPress( int key, int midiVelocity = MidiDefaultVelocity ); + void handleKeyPress( int key, int midiVelocity = -1 ); void handleKeyRelease( int key ); InstrumentTrack* instrumentTrack() const diff --git a/src/core/Piano.cpp b/src/core/Piano.cpp index 584362f46..93fa34869 100644 --- a/src/core/Piano.cpp +++ b/src/core/Piano.cpp @@ -3,7 +3,7 @@ * for testing + according model class * * Copyright (c) 2004-2014 Tobias Doerffel - * + * * This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net * * This program is free software; you can redistribute it and/or @@ -31,7 +31,7 @@ * \mainpage Instrument plugin keyboard display classes * * \section introduction Introduction - * + * * \todo fill this out * \todo write isWhite inline function and replace throughout */ @@ -95,6 +95,10 @@ void Piano::setKeyState( int key, bool state ) */ void Piano::handleKeyPress( int key, int midiVelocity ) { + if( midiVelocity == -1 ) + { + midiVelocity = m_instrumentTrack->midiPort()->baseVelocity(); + } if( isValidKey( key ) ) { m_midiEvProc->processInEvent( MidiEvent( MidiNoteOn, 0, key, midiVelocity ) ); diff --git a/src/gui/PianoView.cpp b/src/gui/PianoView.cpp index ce945ec5f..3bd43f8e6 100644 --- a/src/gui/PianoView.cpp +++ b/src/gui/PianoView.cpp @@ -3,7 +3,7 @@ * for testing + according model class * * Copyright (c) 2004-2014 Tobias Doerffel - * + * * This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net * * This program is free software; you can redistribute it and/or @@ -31,7 +31,7 @@ * \mainpage Instrument plugin keyboard display classes * * \section introduction Introduction - * + * * \todo fill this out * \todo write isWhite inline function and replace throughout */ @@ -160,7 +160,7 @@ PianoView::~PianoView() -/*! \brief Map a keyboard key being pressed to a note in our keyboard view +/*! \brief Map a keyboard key being pressed to a note in our keyboard view * * \param _k The keyboard scan code of the key being pressed. * \todo check the scan codes for ',' = c, 'L' = c#, '.' = d, ':' = d#, @@ -255,7 +255,7 @@ int PianoView::getKeyFromKeyEvent( QKeyEvent * _ke ) case 19: return 27; // 0 = d'# case 33: return 28; // P = e' case 34: return 29; // [ - case 21: return 30; // = + case 21: return 30; // = case 35: return 31; // ] } #endif @@ -459,7 +459,7 @@ void PianoView::mousePressEvent( QMouseEvent * _me ) ( ( KEY_ORDER[key_num % KeysPerOctave] == Piano::WhiteKey ) ? PW_WHITE_KEY_HEIGHT : PW_BLACK_KEY_HEIGHT ) * - (float) MidiDefaultVelocity ); + (float) m_piano->instrumentTrack()->midiPort()->baseVelocity() ); if( y_diff < 0 ) { velocity = 0; @@ -469,7 +469,7 @@ void PianoView::mousePressEvent( QMouseEvent * _me ) Piano::WhiteKey ) ? PW_WHITE_KEY_HEIGHT : PW_BLACK_KEY_HEIGHT ) ) { - velocity = MidiDefaultVelocity; + velocity = m_piano->instrumentTrack()->midiPort()->baseVelocity() ); } // set note on m_piano->midiEventProcessor()->processInEvent( MidiEvent( MidiNoteOn, 0, key_num, velocity ) ); @@ -557,7 +557,7 @@ void PianoView::mouseMoveEvent( QMouseEvent * _me ) int velocity = (int)( (float) y_diff / ( ( KEY_ORDER[key_num % KeysPerOctave] == Piano::WhiteKey ) ? PW_WHITE_KEY_HEIGHT : PW_BLACK_KEY_HEIGHT ) * - (float) MidiDefaultVelocity ); + (float) m_piano->instrumentTrack()->midiPort()->baseVelocity() ); // maybe the user moved the mouse-cursor above or under the // piano-widget while holding left button so check that and // correct volume if necessary @@ -569,7 +569,7 @@ void PianoView::mouseMoveEvent( QMouseEvent * _me ) ( ( KEY_ORDER[key_num % KeysPerOctave] == Piano::WhiteKey ) ? PW_WHITE_KEY_HEIGHT : PW_BLACK_KEY_HEIGHT ) ) { - velocity = MidiDefaultVelocity; + velocity = m_piano->instrumentTrack()->midiPort()->baseVelocity(); } // is the calculated key different from current key? (could be the