FM synth with midi in arduino code help?

Hey so recently I started making this arduino-based FM synth that I found on Youtube that looks pretty easy and have gotten some decent results after making it. But the problem is that it uses tactile buttons to play the notes and I wanted to implement midi into it, because, why not? So I still don’t have a lot of experience coding on arduino and tried combining the two code together and I tried my best putting the Nuts and Volt’s midi input code into the void setup and loop of the arduino FM synth, and kind of bumped into some trouble merging the two together, and was wondering what exactly I have to do to make them work together? Here are both the videos and codes of each project.
Arduino FM synth video-https://youtu.be/MX-l05_u3gA
Arduino Fm synth code- https://content.instructables.com/ORIG/FCE/BNVA/JSAOSXHI/FCEBNVAJSAOSXHI.ino
Midi input circuit video- https://youtu.be/Twx0kzxXvp4
Midi input circuit code- https://www.notesandvolts.com/2015/02/midi-for-arduino-input-test.html

2 Likes

What seems to be the problem? Some odd compilation error?

Has anybody used the Mozzi library? Does it have limitations on what you need?

1 Like

Well after a few hours here’s what a few suggestions from reddit suggested, and they are some interesting ideas. In the arduino fm synth code, there is the “keypressed” and “keyreleased” variable that instead of mapping it to the button states, you would map it to Midi bytes. I’ve tried that and found very minor success using some midi byte example in C3, with it only producing one sound and that’s about it. So maybe it is possible to simple change the pressed and released variable to just midi bytes and from there figuring out what goes to what, but even then on reddit the comment section is suggesting that it might be too complicated or this approach might not be ideal. I will link the thread to the post, any ideas?

That is exactly the idea. Instead of the buttons you need to listen to incoming MIDI note-on/note-off messages and set these both variables accordingly. A simple (dry-coded) example for this would be:

  int offset, note;
  offset = 10;
  if (MIDI.read()) {
    byte type = MIDI.getType();
    switch (type) {
      case midi::NoteOn:
        note = MIDI.getData1();
        if (note >= offset && note < offset+18) {
          keypressed = note-offset;
        }
        break;
      case midi::NoteOff:
        note = MIDI.getData1();
        if (note >= offset && note < offset+18) {
          keyreleased = note-offset;
        }
        break;
    }
  }

The offset variable is representing the offset of your incoming notes and maps it to the buttons. This example uses note 10 to 27 to trigger/release the associated button. This is not a real working example, it just represents the idea how to get it working! I did not super deep dived into the FM synth code, it’s rather advanced and not that easy to understand. You also need the Arduino MIDI library and initialize it properly to get it working. I think a good starting point is to get incoming MIDI messages working in general and then integrate it into the FM synth code.

3 Likes

Would I have to implement this code for every keypress/release or somewhere in the code?