Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 4 of 4

Thread: MIDI sequencer : need directions

  1. #1
    Senior Member
    Join Date
    Dec 2018
    Posts
    145

    MIDI sequencer : need directions

    Hello,

    I would like to build a MIDI sequencer. I don't know how to implement a solid timebase to trigger midi events.

    For instance, let's consider the way I could generate the MIDI clock "clics" using usbMIDI.sendRealTime(usbMIDI.Clock) function. This message is sent 24 times per quarter note. My idea would be to use an "elapsedMillis" variable. Here is the relation between midi tempo and clics period :
    clic periode (ms) = 60 / tempo / 24 * 1000
    if the tempo is set to 80, I have to send a clic every 31ms. The code would be something like :

    Code:
    elapsedMillis ticks
    byte tempo = 80;
    
    void sendTicks() {
      if (ticks > 60 / tempo / 24 * 1000) {
        usbMIDI.sendRealTime(usbMIDI.Clock);
        ticks = 0;
      }
    }
    Is it the right way ?
    Can I use other elapsedMillis variable to trigger other midi events ?

    Thank you
    Emmanuel

  2. #2
    Senior Member mortonkopf's Avatar
    Join Date
    Apr 2013
    Location
    London, uk
    Posts
    941
    You have stumbled upon the question that invariably comes with Midi sequencer building. See here for examples:

    https://forum.pjrc.com/threads/66500...ght=midi+clock

    and
    https://forum.pjrc.com/threads/53467...ght=midi+clock


    NB, using elapsed micros rather than millis is preferable, and avoiding interval timers is also wise if you are not happy with handling their potential side effects.

  3. #3
    Senior Member
    Join Date
    Dec 2018
    Posts
    145
    Thank you.
    These examples are clear. I think I know how to start.

    I have another question. What could be the way to implement shuffle function ? Shuffle adds some "swing" in the tempo. I wonder how I can achieve that.

  4. #4
    Senior Member mortonkopf's Avatar
    Join Date
    Apr 2013
    Location
    London, uk
    Posts
    941
    a number of ways, and swing means different things, some are every even beat, and some sequencers might just add to 3rd and 7th note.

    For an example (just one way of many) see here for swing on every even beat:
    https://github.com/mortonkopf/Teensy...Drum_30dac.ino

    in it, the rotary is mapped to a value that is converted to an amount of millis that is added to the gap between beats. beats are counter so that you know if you have an even beat (but using modulo). the beat trigger elapsed function adds the swing amount before triggering the beat / sound / etc

    eg:
    Code:
    if ((currentClTime > (oldClTime + (clockGap))) &&
          ((!(clockStep % 2) == 0)))
      { ...}

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •