# Safe practices for dealing with MidiBuffer

**URL:** <https://forum.juce.com/t/safe-practices-for-dealing-with-midibuffer/17262>\
**Category:** General JUCE discussion\
**Created:** [April 14, 2016, 10:17am UTC](https://forum.juce.com/t/safe-practices-for-dealing-with-midibuffer/17262 "2016-04-14T10:17:10Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![alfonso-santimone](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/alfonso-santimone/32/6_2.png) [@alfonso-santimone](https://forum.juce.com/u/alfonso-santimone)\
**Post date:** [April 14, 2016, 10:17am UTC](https://forum.juce.com/t/safe-practices-for-dealing-with-midibuffer/17262/1 "2016-04-14T10:17:10Z")

</div>

Hi all, i’m buidling a MIDI VST plugin that should let pass Midi data in and add a lot of MIDI CC to its output.  
I need to automate via VST some plugin that does not have a full VST parameter implementation and rely on MIDI CC only to automate its parameters (all XILS stuff and Tassmann i.e. ).  
So i’ve built a test version that do this with one parameter only.  
This is my process block.

```
void StiXctrlAudioProcessor::processBlock (AudioSampleBuffer& buffer, MidiBuffer& midiMessages)
{
    buffer.clear(); // clear audio buffer
    MidiMessage m; 
    int8 cc00Val = *cc00; //get cc00 VST parameter value

    if (cc00Val != cc00TempVal) // generate a new cc00 Controller Event only if cc00 value is changed
    {
        m = MidiMessage::controllerEvent(1, 0, cc00Val);
        midiMessages.addEvent(m, midiMessages.getLastEventTime());
    }
    
    cc00TempVal = cc00Val; // store cc00 value in a temp variable for the if statement above
    
}

```

Now i wonder if this is a good way to deal with MidiBuffer (i’m not using any Iterator but i simply add MIDI CC Events to the incoming MIDI stream).  
Ideally the plugin will have a lot of parameters (780 parameters) each one generating a particular MIDI CC on a particular MIDI channel.

thanks and all the best
