From 56ee27ed9b3bd2b29ac9aade253ba81d824564e7 Mon Sep 17 00:00:00 2001 From: Tobias Doerffel Date: Sat, 8 Mar 2014 13:22:51 +0100 Subject: [PATCH] Midi: added MidiDefaultVelocity to be used for test notes etc. --- include/Midi.h | 1 + include/Piano.h | 2 +- plugins/sfxr/sfxr.cpp | 2 +- src/gui/PianoView.cpp | 8 ++++---- src/gui/piano_roll.cpp | 4 ++-- src/tracks/InstrumentTrack.cpp | 2 +- 6 files changed, 10 insertions(+), 9 deletions(-) diff --git a/include/Midi.h b/include/Midi.h index 1b6b69383..96c66ea41 100644 --- a/include/Midi.h +++ b/include/Midi.h @@ -127,6 +127,7 @@ const int MidiChannelCount = 16; const int MidiControllerCount = 128; const int MidiProgramCount = 128; const int MidiMaxVelocity = 127; +const int MidiDefaultVelocity = MidiMaxVelocity / 2; const int MidiMaxControllerValue = 127; const int MidiMaxNote = 127; diff --git a/include/Piano.h b/include/Piano.h index 1673d9479..b1487095f 100644 --- a/include/Piano.h +++ b/include/Piano.h @@ -50,7 +50,7 @@ public: return m_pressedKeys[key]; } - void handleKeyPress( int key, int midiVelocity = MidiMaxVelocity ); + void handleKeyPress( int key, int midiVelocity = MidiDefaultVelocity ); void handleKeyRelease( int key ); InstrumentTrack* instrumentTrack() const diff --git a/plugins/sfxr/sfxr.cpp b/plugins/sfxr/sfxr.cpp index 27cd287da..bdad56cb9 100644 --- a/plugins/sfxr/sfxr.cpp +++ b/plugins/sfxr/sfxr.cpp @@ -1103,7 +1103,7 @@ void sfxrInstrumentView::previewSound() sfxrInstrument* s = castModel(); InstrumentTrack* it = s->instrumentTrack(); it->silenceAllNotes(); - it->processInEvent( MidiEvent( MidiNoteOn, 0, it->baseNoteModel()->value(), MidiMaxVelocity ) ); + it->processInEvent( MidiEvent( MidiNoteOn, 0, it->baseNoteModel()->value(), MidiDefaultVelocity ) ); } diff --git a/src/gui/PianoView.cpp b/src/gui/PianoView.cpp index 021964b50..11f2cd90e 100644 --- a/src/gui/PianoView.cpp +++ b/src/gui/PianoView.cpp @@ -452,7 +452,7 @@ void PianoView::mousePressEvent( QMouseEvent * _me ) ( ( KEY_ORDER[key_num % KeysPerOctave] == Piano::WhiteKey ) ? PW_WHITE_KEY_HEIGHT : PW_BLACK_KEY_HEIGHT ) * - (float) MidiMaxVelocity ); + (float) MidiDefaultVelocity ); if( y_diff < 0 ) { velocity = 0; @@ -462,7 +462,7 @@ void PianoView::mousePressEvent( QMouseEvent * _me ) Piano::WhiteKey ) ? PW_WHITE_KEY_HEIGHT : PW_BLACK_KEY_HEIGHT ) ) { - velocity = MidiMaxVelocity; + velocity = MidiDefaultVelocity; } // set note on m_piano->midiEventProcessor()->processInEvent( MidiEvent( MidiNoteOn, 0, key_num, velocity ) ); @@ -550,7 +550,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) MidiMaxVelocity ); + (float) MidiDefaultVelocity ); // 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 @@ -562,7 +562,7 @@ void PianoView::mouseMoveEvent( QMouseEvent * _me ) ( ( KEY_ORDER[key_num % KeysPerOctave] == Piano::WhiteKey ) ? PW_WHITE_KEY_HEIGHT : PW_BLACK_KEY_HEIGHT ) ) { - velocity = MidiMaxVelocity; + velocity = MidiDefaultVelocity; } // is the calculated key different from current key? (could be the diff --git a/src/gui/piano_roll.cpp b/src/gui/piano_roll.cpp index 66dd2ab24..3d5c6e61c 100644 --- a/src/gui/piano_roll.cpp +++ b/src/gui/piano_roll.cpp @@ -1808,7 +1808,7 @@ void pianoRoll::mousePressEvent( QMouseEvent * _me ) m_lastKey = key_num; //if( ! m_recording && ! engine::getSong()->isPlaying() ) { - int v = ( (float) x ) / ( (float) WHITE_KEY_WIDTH ) * MidiMaxVelocity; + int v = ( (float) x ) / ( (float) WHITE_KEY_WIDTH ) * MidiDefaultVelocity; m_pattern->instrumentTrack()->pianoModel()->handleKeyPress( key_num, v ); } } @@ -2129,7 +2129,7 @@ void pianoRoll::mouseMoveEvent( QMouseEvent * _me ) && _me->buttons() & Qt::LeftButton ) { // clicked on a key, play the note - testPlayKey( key_num, ( (float) x ) / ( (float) WHITE_KEY_WIDTH ) * MidiMaxVelocity, 0 ); + testPlayKey( key_num, ( (float) x ) / ( (float) WHITE_KEY_WIDTH ) * MidiDefaultVelocity, 0 ); update(); return; } diff --git a/src/tracks/InstrumentTrack.cpp b/src/tracks/InstrumentTrack.cpp index d5ea42d78..e1af5d761 100644 --- a/src/tracks/InstrumentTrack.cpp +++ b/src/tracks/InstrumentTrack.cpp @@ -1062,7 +1062,7 @@ void InstrumentTrackView::toggleInstrumentWindow( bool _on ) void InstrumentTrackView::activityIndicatorPressed() { - model()->processInEvent( MidiEvent( MidiNoteOn, 0, DefaultKey, MidiMaxVelocity ) ); + model()->processInEvent( MidiEvent( MidiNoteOn, 0, DefaultKey, MidiDefaultVelocity ) ); }