MIDI library and MIDI.sendRealTime function

I'm using the MIDI.h library (version 4.0) and can't figure out how to use the MIDI.sendRealTime function properly. I want to send the clock signal, like...

MIDI.sendRealTime(Clock);

but it says Clock was not declared in this scope. The MIDI library defines Clock with;

/*! Enumeration of MIDI types */
enum kMIDIType {
	NoteOff	              = 0x80,	///< Note Off
	NoteOn                = 0x90,	///< Note On
	AfterTouchPoly        = 0xA0,	///< Polyphonic AfterTouch
	ControlChange         = 0xB0,	///< Control Change / Channel Mode
	ProgramChange         = 0xC0,	///< Program Change
	AfterTouchChannel     = 0xD0,	///< Channel (monophonic) AfterTouch
	PitchBend             = 0xE0,	///< Pitch Bend
	SystemExclusive       = 0xF0,	///< System Exclusive
	TimeCodeQuarterFrame  = 0xF1,	///< System Common - MIDI Time Code Quarter Frame
	SongPosition          = 0xF2,	///< System Common - Song Position Pointer
	SongSelect            = 0xF3,	///< System Common - Song Select
	TuneRequest           = 0xF6,	///< System Common - Tune Request
	Clock                 = 0xF8,	///< System Real Time - Timing Clock
	Start                 = 0xFA,	///< System Real Time - Start
	Continue              = 0xFB,	///< System Real Time - Continue
	Stop                  = 0xFC,	///< System Real Time - Stop
	ActiveSensing         = 0xFE,	///< System Real Time - Active Sensing
	SystemReset           = 0xFF,	///< System Real Time - System Reset
	InvalidType           = 0x00    ///< For notifying errors
};

Since I'm including MIDI.h, shouldn't I have access to the Clock variable? Am I not understanding enum correctly? I tried to define this at the top of my code, but it still says Clock is not declared, and doesn't know kMIDIType.

kMIDIType mClock = Clock;

thanks for the help!

Line 37 is the culprit. That's what my ouiji board says.

??? That's a joke, right.

There are two stickies at the top of the forum that you are supposed to read before posting here. I know that you didn't bother to read them. Go do so now, and you'll get the joke.

I assume this comment is because I didn't include the entire sketch. Here 'tis, thx.

/*  SEQ8 - An analog-style 8 step MIDI note sequencer
    NG Elec, 2014
    
    Analog inputs:
    A0 = Velocity
    A1 = Gate
    A2 = Octave
    A3 = Note
    A4 = Tempo
    
    Digital I/O:
    1 (tx) = MIDI output, pin 5
    2 = channel select 0 (S0)
    4 = channel select 1 (S1)
    7 = channel select 2 (S2)
    8 = Tempo LED output
    9 = Start/Stop button input
    12 = Button input
    13 = LED channel output
    
    MIDI out connections:
    pin 2 = ground
    pin 5 = serial out
    pin 4 = 220 Ohm to +5V
    
    Delay between 8th notes:
    bpm = ((bpm_max-bpm_min)*x/1023) + bpm_min
    delay_msec = 30000/bpm;
    
    Gate Time:
    x = Gate value: 0 to 1023
    max gate time = delay_msec
    gateTime = ((delay_msec-1)x/1023) + 1;
    
    MIDI clock out uses 24 pulses per quarter note:
    clockTick = 2*delay_msec/24;
*/

#include <MIDI.h>

// pin assignments
int S0 = 2;
int S1 = 4;
int S2 = 7;
int TempoLED = 8;
int StartButton = 9;
int button = 12;
int LEDpin = 13;

// variables
int bpm_max = 500;
int bpm_min = 5;
int Velocity = 0;
int Gate = 0;
int Octave = 0;
int Note = 0;
int Tempo = 0;
long delay_msec = 0;  // From the tempo knob, the time between 8th notes
long previousMillis = 0;
long previousTempoMillis = 0;
long previousTriggerMillis = 0;
long previousNoteOnMillis = 0;
long previousClockMillis = 0;
int LEDdelay = 200;  // blink time in msec
int clockTick = 0;   // time between 1/24th of a quarter note
int gateTime = 0;    // time between note ON and OFF
int channel = 0;

void setup ()
{
  pinMode(S0, OUTPUT);
  pinMode(S1, OUTPUT);
  pinMode(S2, OUTPUT);
  pinMode(TempoLED, OUTPUT);
  pinMode(StartButton, INPUT);
  pinMode(button, INPUT);
  pinMode(LEDpin, OUTPUT);
  Serial.begin(9600);
  MIDI.begin();
}

void loop() {
  unsigned long currentMillis = millis();  // get the timestamp in msec
  
  // Read the Tempo pot and adjust the time between 8th notes, and clock ticks
  Tempo = ((bpm_max-bpm_min)*float(analogRead(A4)/float(1023))) + bpm_min;
  delay_msec = 30000/Tempo;
  clockTick = 2*delay_msec/24;
  
  // Is it time to turn on the tempo LED (top of the measure)?
  if(currentMillis - previousTempoMillis > 8*delay_msec) {  
    previousTempoMillis = currentMillis;
    digitalWrite(TempoLED, LOW);  
  }
  // Is it time to turn the tempo LED off?
  if (currentMillis - previousTempoMillis > LEDdelay) {
    digitalWrite(TempoLED, HIGH);
  }
  
  // Is it time to send a MIDI clock signal?
  if (currentMillis - previousClockMillis > clockTick) {
    // send MIDI clock
    MIDI.sendRealTime(Clock);
  }
  
  // Is it time to turn the button light off?
  if (currentMillis - previousTriggerMillis > LEDdelay) {
    digitalWrite(LEDpin, LOW);
  }
  // Is it time to turn the MIDI note OFF?
  if (currentMillis - previousNoteOnMillis > gateTime) {
    MIDI.sendNoteOff(42, 0, 1);
  }
  
  // Continue if start/stop is on
  if (digitalRead(StartButton) == HIGH){
    
    // Is it time to turn on a note?
    if(currentMillis - previousTriggerMillis > delay_msec){
      previousTriggerMillis = currentMillis;    // reset the last time a trigger happened
      
      // Write the channel selection to the muxs
      setMUX(channel);
      
      // Read the voltages from the knobs and switches  
      Velocity = analogRead(A0);
      Gate = analogRead(A1);
      gateTime = ((delay_msec-1)*Gate/1023) + 1;
      Octave = analogRead(A2);
      Note = analogRead(A3);
    
      // Turn on the LED
      digitalWrite(LEDpin, HIGH);
      
      // Play the note, if the button is pressed
      if (digitalRead(button)) {
        MIDI.sendNoteOn(42, 127, 1);
        previousNoteOnMillis = currentMillis;    // reset the last time a note ON happened  
      }
      
      // Increment the Channel, or roll over to zero
      if (channel < 8){
        channel = channel + 1;
      }
      else {
        channel = 0;
      }          
    }  
  }
  else {
    channel = 0;  // reset the channel to zero, so the sequence starts at channel zero when start/stop is pressed
  }
}

void setMUX(int ch){
  digitalWrite(S0, (ch >> 0) & 1);
  digitalWrite(S1, (ch >> 1) & 1);
  digitalWrite(S2, (ch >> 2) & 1);
}

I assume this comment is because I didn't include the entire sketch.

Exactly.

I'm using the MIDI.h library (version 4.0)

That you got from where?

How to access the Clock value depends on where in the header file that enum is defined.

Whether sending that constant, or not, as "real time" data makes sense, or not, remains to be seen. I have my doubts, but I need to look at the library first.

thanks for the reply, Paul.

I downloaded the MIDI library from Github, details can be found here...

http://playground.arduino.cc/Main/MIDILibrary#.UzrJrfldWC0

I'm not convinced sendRealTime is the right method to send the clock either, it's just what I found in the library for sending the clock.

I've seen ways to do it at a lower level (without the library), but I don't want to mix methods for sending MIDI, and the library seems useful for anything more advanced than sending note on/off, etc.

Where did this:

/*! Enumeration of MIDI types */
enum kMIDIType {

come from?

The version of the library I just downloaded contains:

/*! Enumeration of MIDI types */
enum MidiType
{

So, you should be able to say:

MidiType type = Clock;

and then:

MIDI.sendRealTime(type);

looks like the "kMIDIType" was in a previous version of the library. I just checked my installed library, and I do have the "MidiType" enum def.

However, I try...

MidiType type = Clock;

but the compiler still doesn't like it...
'MidiType' does not name a type

Is there a way to see what file is getting used when I do a #include? I wonder if it's using a different version of MIDI.h

I don't like the way that the MIDI library uses namespaces. You may need to look at the header files, and determine what the namespace is, and then use that namespace name to qualify the declaration of type.

Or just count, in the enum, starting at 0, to get the value assigned to Clock, and hard-code that value in the call to sendRealTime().

namespace was the trick. thanks!

This works...

using namespace midi;

then,

MIDI.sendRealTime(Clock);

namespace was the trick.

Good to know.