Newbie having trouble with midi implementation on microtonal arpeggiator

Hello,
I am having some trouble getting midi to work with my microtonal arpeggiator. I want to assign the variable “pitch” to correlated to the note I strike on my keyboard. Ideally I’d have polyphony such that if I hit a specific chord, the midi would follow accordingly.

Thanks,
Nakul

   for (int channel = 0; channel < totalNumInputChannels; ++channel)
{
    auto* channelData = buffer.getWritePointer (channel);

    for (int sample = 0; sample < buffer.getNumSamples(); ++sample)
    {
//            channelData[sample] = buffer.getSample(channel, sample) * rawVolume;
       
        auto currentSample = (float) std::sin (currentAnglec + std::sin(currentAnglem));
        //            currentAngle += angleDelta;
        
//            auto currentSample = (float) std::sin (currentAnglec);
////            currentAngle += angleDelta;
        
        currentAnglec += freqc*pow(2,(pitch + arppitch-offset)/12)*2*3.1415/44100;
        if (currentAnglec > 2.0 * MathConstants<double>::pi)
            currentAnglec -= 2.0 * MathConstants<double>::pi;
        
        currentAnglem += freqm*pow(2,(pitch + arppitch-offset)/12)*2*3.1415/44100;
        if (currentAnglem > 2.0 * MathConstants<double>::pi)
            currentAnglem -= 2.0 * MathConstants<double>::pi;
        
        channelData[sample]  = currentSample*(gain + gainOffset);
        samplesElapsed = samplesElapsed + 1;
        if (samplesElapsed >= speed)
            {
//
                gainCount++;
                if(gainCount > accentFrequency )
                {
                    gainCount = 0;
                }
                
                switch( gainCount )
                {
//                    case 0 : gainOffset = pow(10.0, 10*0.000001);;
                    case 0 : gainOffset = accentVolume;
                        break;
                default : gainOffset = 0;
                        break;
                }
                
//                    angleDelta = angleDelta + 0.01;
                arppitch = arppitch + interval;
                while (arppitch > upperRange)
                    arppitch -= lowerRange;
                samplesElapsed = 0.0;
//                    if (angleDelta > 0.1)
//                        angleDelta = 0.01;
                
            };
    
        
    }
}
}