IPlug2 Faust IMidiMsg Note On / Note Off

hello everyone, i am trying to figure out how to receive midi from my DAW inside of my Faustcode for a couple of days now.
i have this event handler running:

void mySynth::ProcessMidiMsg(const IMidiMsg& msg)
{
  int status = msg.StatusMsg();
  switch (status)
  {
  case IMidiMsg::kNoteOn:
  {
    
    SendMidiMsg(msg);
    break;
  }
  case IMidiMsg::kNoteOff:
  {
    
    SendMidiMsg(msg);
    break;
  }


on faust’s side i have this code:

declare options “[midi:on]”;

frequency = hslider("frequency",500,30,12000,0.01);

gate = checkbox("h:gate");

osc = os.osc(frequency);  

process = osc*gate;

but i miss the link inbetween. how can i send the midi on and off messages to the “gate” ?

thanks for your help in advance

Since the gate is a parameter of the Faust dsp in your above example, you can use mFaustProcessor.SetParameterValue("gate", 1.) to set it high when there is a note on message.

related news…

Stéphane Letz, one of the Faust developers has added support for faust’s own poly dsp midi handling, so you can now make a polysynth in faust like this (see IPlugFaustDSP example)

declare options "[midi:on][nvoices:12]";
declare name "FaustExample";

import("stdfaust.lib");

freq = hslider("freq ",200,50,1000,0.01);
gain = hslider("gain",0.5,0,1,0.01);
master = hslider("master [midi: ctrl 7]",0.5,0,1,0.01);
gate = button("gate");
envelope = en.adsr(0.01,0.01,0.8,0.1,gate)*gain;
process = os.sawtooth(freq)*envelope*master <: (_,_);
1 Like

thanks a lot… i am going to try that out very soon