Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 39 additions & 10 deletions Source/CS_midiIN.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

#include <iostream>
#include <functional>

#include "parameters.h"
using namespace std;

MidiIn::MidiIn(const std::function<void(int,int)> onVelocityChanged,
Expand Down Expand Up @@ -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){
Expand All @@ -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])
Expand Down Expand Up @@ -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 ;
Expand Down Expand Up @@ -186,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;
}
Expand Down Expand Up @@ -399,7 +428,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;
Expand Down
3 changes: 3 additions & 0 deletions Source/CS_midiIN.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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] ;
Expand Down
5 changes: 5 additions & 0 deletions Source/parameters.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#pragma once

enum MidiControlChangeParameters {
ResetAllControllers = 121
};