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

Thread: midiClock / BPM

  1. #1
    Senior Member
    Join Date
    Nov 2016
    Posts
    179

    midiClock / BPM

    Hi,

    so now the point has come at which I have to deal with coding a sequencer for my project.

    this has nothing to do with the thread-question but as I want the sequencer to be very feature rich, I ask myself if it will not be too much for the teensy.
    I mean I use a T_3.6. but beside a ton of digital/analog-readings, the teensy needs to send the state permanenty to the Raspi (which acts as a display).
    When I now add a sequencer for 16 tracks, each track with extensive functions, also this updates needs to be send to the Raspi.

    Can one T_3.6. handle that all, or should I suggest to split it? .. maybe another teensy just for the sequencer?


    so first things first, I thought I start with the midi-clock.
    I searched and tried around, but I can't figure out how the midi-clock is working on teensy. Is there a good explanation, maybe with a working example out there?
    I need to have:
    - midi-clock-generator so my sequencer can run at some BPM-rate
    - send the midiClock through MIDI-OUT, so other hardware or DAWs can sync
    - teensy recieving midi-clock through MIDI-IN (teensy as clock-slave) and move through the pattern on each tick

  2. #2
    Senior Member mortonkopf's Avatar
    Join Date
    Apr 2013
    Location
    London, uk
    Posts
    898
    There a discussion on generating a BPM clock signal for midi here: https://forum.pjrc.com/threads/50559...ith-Teensy-2-0
    Might be a useful start

  3. #3
    Senior Member
    Join Date
    Nov 2016
    Posts
    179
    Quote Originally Posted by mortonkopf View Post
    There a discussion on generating a BPM clock signal for midi here: https://forum.pjrc.com/threads/50559...ith-Teensy-2-0
    Might be a useful start
    Thanks I tried around a little bit, and now it works. Adapred the last example from the thread:

    Code:
    #include <Arduino.h>
    /*
    Repeating Timer
    Code Alternative to ElapsedMillis
    
    (c)2015 Forward Computing and Control Pty. Ltd.
    This code may be freely used for both private and commerical use.
    Provide this copyright is maintained. 
    */
    unsigned long timer; 
    int tim;
    
    void setup() {
    
    timer = millis(); 
    }
    
    void loop() {
     // int tim = 100; // 25 bpm
     //int tim = 10; // 250 bpm
      
      int tim = 19;
      unsigned long INTERVAL = tim; 
      if ((millis()-timer) > INTERVAL) {
    
        timer += INTERVAL;
        usbMIDI.sendRealTime(usbMIDI.Clock);
      }
    }
    now.. tim=19 is 132 BPM
    and.. tim= 20 is 125 BPM

    but how would i get more precisely? .. I would like to be able to send as precisely as possible.. lets say like 128,34 BPM

    how would I do that?

  4. #4
    Senior Member+ Theremingenieur's Avatar
    Join Date
    Feb 2014
    Location
    Colmar, France
    Posts
    2,442
    Use micros instead of millis which allows a 1000 times finer resolution

    Converting bpm in a period duration and vice versa is a simple 6th grade exercise, man!

  5. #5
    Senior Member
    Join Date
    Nov 2016
    Posts
    179
    Quote Originally Posted by Theremingenieur View Post
    Use micros instead of millis which allows a 1000 times finer resolution

    Converting bpm in a period duration and vice versa is a simple 6th grade exercise, man!
    thanks

    .. it is not the converting, it was the timer-resolution with micros() everything works like a charm

  6. #6
    Senior Member mortonkopf's Avatar
    Join Date
    Apr 2013
    Location
    London, uk
    Posts
    898
    great you got working. With one more variable calculation you could have it so that your input variable was the exact bpm that you want, int tim would then be calculated and give you your INTERVAL.

  7. #7
    Senior Member
    Join Date
    Nov 2016
    Posts
    179
    Quote Originally Posted by mortonkopf View Post
    great you got working. With one more variable calculation you could have it so that your input variable was the exact bpm that you want, int tim would then be calculated and give you your INTERVAL.
    that is a great idea!! .. I am now working on a other problem of the project, but I will make this for sure. thanks bro

Posting Permissions

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