From 166d48f444082a9f9c6e6ff139fb9d01de801105 Mon Sep 17 00:00:00 2001 From: Gauthier Segay Date: Sun, 14 May 2023 18:03:42 +0200 Subject: [PATCH 1/3] handle channel pressure to scale the volume, refactor code which handles volume computation. --- Source/CS_midiIN.cpp | 45 +++++++++++++++++++++++++++++++++++--------- Source/CS_midiIN.h | 3 +++ 2 files changed, 39 insertions(+), 9 deletions(-) diff --git a/Source/CS_midiIN.cpp b/Source/CS_midiIN.cpp index 3387cf2..c302b2c 100644 --- a/Source/CS_midiIN.cpp +++ b/Source/CS_midiIN.cpp @@ -96,6 +96,17 @@ void MidiIn::handleMIDIMessage2(int Ch, int value1, int value2){ }else if (Ch >=224 && Ch <240){ HandlePitchWheel(Ch-223, value1, value2); } + + auto statusByte = Ch & 0xF0; // extract status byte + auto midiChannel = Ch & 0x0F;// extract MIDI channel + switch(statusByte) { + // channel pressure + case 0xd0: + auto oneBasedMidiChannel = midiChannel + 1; + channelPressure[oneBasedMidiChannel] = value1; + updateFinalVelocity(oneBasedMidiChannel); + break; + } } void MidiIn::RealTimeStartNote(int Ch, int value1, int value2){ @@ -109,17 +120,36 @@ void MidiIn::RealTimeStartNote(int Ch, int value1, int value2){ noteonCh[Ch] = value1; velociteCh[Ch] = value2; noteonfinalCh[Ch] = ((noteonCh[Ch]) + pitchbendCh[Ch]) ; - volumefinalCh[Ch] =(velociteCh[Ch] *(ControlCh[7][Ch]/127.0))*(500./127.) ; - if(volumefinalCh[Ch] < 0.0)volumefinalCh[Ch]=0.0; - if(volumefinalCh[Ch] > 500.0)volumefinalCh[Ch]=500.0; + updateFinalVelocity(Ch); // (velociteCh[Ch] *(ControlCh[7][Ch]/127.0))*(500./127.) ; tourmoteurCh[Ch] = tabledecorresponcanceMidinote(noteonfinalCh[Ch], Ch); sendVariaCh(Ch); - sendVolCh((int) (volumefinalCh[Ch]*ChangevolumegeneralCh[Ch]), Ch); + channelPressure[Ch] = 127; }else if(Ch==10){ if(value1 > 1 && value2 > 1) JouerClic(value1); } } +static float computeFinalVelocity(float channelVelocity, float volumeControllerValue, float channelPressure) { + auto result = (channelVelocity *(volumeControllerValue/127.0)*(channelPressure/127.0))*(500./127.); + return result; +} + +void MidiIn::updateFinalVelocity(int Ch){ + auto finalVelocity = computeFinalVelocity(velociteCh[Ch], ControlCh[7][Ch], channelPressure[Ch]); + volumefinalCh[Ch] = finalVelocity; + if(volumefinalCh[Ch] < 0.0) + { + volumefinalCh[Ch]=0.0; + assert(false); + } + if(volumefinalCh[Ch] > 500.0) + { + volumefinalCh[Ch]=500.0; + assert(false); + } + sendVolCh((int)(volumefinalCh[Ch]*ChangevolumegeneralCh[Ch]), Ch); +} + void MidiIn::RealTimeStopNote(int Ch, int note){ if (Ch < 8) { if(note == noteonCh[Ch]) @@ -153,10 +183,7 @@ void MidiIn::HandleControlChange(int Ch, int value1, int value2){ break; case 7 : ControlCh[7][Ch] = value2 ; - volumefinalCh[Ch] =(velociteCh[Ch] *(ControlCh[7][Ch]/127.0))*(500./127.) ; - if(volumefinalCh[Ch] < 0.0)volumefinalCh[Ch]=0.0; - if(volumefinalCh[Ch] > 500.0)volumefinalCh[Ch]=500.0; - sendVolCh((int)(volumefinalCh[Ch]*ChangevolumegeneralCh[Ch]), Ch); + updateFinalVelocity(Ch); break; case 9 : ControlCh[9][Ch] = value2 ; @@ -399,7 +426,7 @@ void MidiIn::resetSireneCh(int Ch){ noteonfinalCh[Ch]=0.0; ///////////////////////////////////////////////////****** Ferme les volets - + channelPressure[Ch] = 0; AncienVolFinalCh[Ch]=-1; ControlCh[1][Ch]=0; ControlCh[5][Ch]=0; diff --git a/Source/CS_midiIN.h b/Source/CS_midiIN.h index 35ed7ed..7b68754 100644 --- a/Source/CS_midiIN.h +++ b/Source/CS_midiIN.h @@ -25,6 +25,8 @@ class MidiIn void HandleControlChange(int Ch, int value1, int value2); void HandlePitchWheel(int Ch, int value1, int value2); + void updateFinalVelocity(int Ch); + float tabledecorresponcanceMidinote(float note, int Ch); void sendVolCh(int message, int Ch); @@ -55,6 +57,7 @@ class MidiIn float velociteCh[17] = {0}; float pitchbendCh[17] = {0}; float ControlCh[127][17] = {0}; + float channelPressure[17] = {0}; float Control1FinalCh[17] = {0}; float noteonfinalCh[17] = {0}; float volumefinalCh[17] ; From e8e896cf11de28d90860772a70b20997dd0c8a63 Mon Sep 17 00:00:00 2001 From: Gauthier Segay Date: Sun, 14 May 2023 18:05:47 +0200 Subject: [PATCH 2/3] formatting --- Source/CS_midiIN.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/CS_midiIN.cpp b/Source/CS_midiIN.cpp index c302b2c..7f0e559 100644 --- a/Source/CS_midiIN.cpp +++ b/Source/CS_midiIN.cpp @@ -123,15 +123,15 @@ void MidiIn::RealTimeStartNote(int Ch, int value1, int value2){ updateFinalVelocity(Ch); // (velociteCh[Ch] *(ControlCh[7][Ch]/127.0))*(500./127.) ; tourmoteurCh[Ch] = tabledecorresponcanceMidinote(noteonfinalCh[Ch], Ch); sendVariaCh(Ch); - channelPressure[Ch] = 127; + channelPressure[Ch] = 127; }else if(Ch==10){ if(value1 > 1 && value2 > 1) JouerClic(value1); } } static float computeFinalVelocity(float channelVelocity, float volumeControllerValue, float channelPressure) { - auto result = (channelVelocity *(volumeControllerValue/127.0)*(channelPressure/127.0))*(500./127.); - return result; + auto result = (channelVelocity *(volumeControllerValue/127.0)*(channelPressure/127.0))*(500./127.); + return result; } void MidiIn::updateFinalVelocity(int Ch){ From 42dbd06b19c7aed3c58e16ff707fa7509b515d26 Mon Sep 17 00:00:00 2001 From: Gauthier Segay Date: Sun, 14 May 2023 18:29:14 +0200 Subject: [PATCH 3/3] controlleur 121 pour reset la sirene. --- Source/CS_midiIN.cpp | 4 +++- Source/parameters.h | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 Source/parameters.h diff --git a/Source/CS_midiIN.cpp b/Source/CS_midiIN.cpp index 7f0e559..63de58c 100644 --- a/Source/CS_midiIN.cpp +++ b/Source/CS_midiIN.cpp @@ -12,7 +12,7 @@ #include #include - +#include "parameters.h" using namespace std; MidiIn::MidiIn(const std::function onVelocityChanged, @@ -213,6 +213,8 @@ void MidiIn::HandleControlChange(int Ch, int value1, int value2){ case 92 : ControlCh[92][Ch]= value2 ; break; + case MidiControlChangeParameters::ResetAllControllers: + resetSireneCh(Ch); default: break; } diff --git a/Source/parameters.h b/Source/parameters.h new file mode 100644 index 0000000..57d1a24 --- /dev/null +++ b/Source/parameters.h @@ -0,0 +1,5 @@ +#pragma once + +enum MidiControlChangeParameters { + ResetAllControllers = 121 +};