# Generate sustain pedal event from button?

**URL:** <https://forum.juce.com/t/generate-sustain-pedal-event-from-button/48397>\
**Category:** Audio Plugins\
**Created:** [October 23, 2021, 12:35am UTC](https://forum.juce.com/t/generate-sustain-pedal-event-from-button/48397 "2021-10-23T00:35:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![pizzafilms](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/pizzafilms/32/562_2.png) [@pizzafilms](https://forum.juce.com/u/pizzafilms)\
**Post date:** [October 23, 2021, 12:35am UTC](https://forum.juce.com/t/generate-sustain-pedal-event-from-button/48397/1 "2021-10-23T00:35:22Z")

</div>

I’d like to generate a sustain pedal event from a button press in my plugin’s UI. Is there a simple way to do that and send to the host? Or, in this case, my standalone app/plugin?

---

<div class="post-metadata">

**Author:** ![benvining](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/benvining/32/9922_2.png) [@benvining](https://forum.juce.com/u/benvining)\
**Post date:** [October 23, 2021, 5:34pm UTC](https://forum.juce.com/t/generate-sustain-pedal-event-from-button/48397/2 "2021-10-23T17:34:15Z")

</div>

I would have in the processor a queue/list of midi events recieved from the UI, and then the processor can inject those midi events into the next I/O MidiBuffer sent to the next processBlock() call

---

<div class="post-metadata">

**Author:** ![pizzafilms](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/pizzafilms/32/562_2.png) [@pizzafilms](https://forum.juce.com/u/pizzafilms)\
**Post date:** [October 23, 2021, 9:07pm UTC](https://forum.juce.com/t/generate-sustain-pedal-event-from-button/48397/3 "2021-10-23T21:07:12Z")

</div>

Yes, thanks. Here’s a snippet for those who might want to do this:

This goes in the processor’s processBlock.

```
        int channel = 0; // 0-15, not 1-16
		int controller = 64; // sustain pedal
		int value = 64; // 64 = down, 0 = up
		
		int b0 = 0xB0 + channel;
		int b1 = controller;
		int b2 = value;
		
		auto m = MidiMessage(b0, b1, b2);
		midiMessages.addEvent(m, 0);
```
