Hi, I know this has come up before, but I've found nothing that has resulted in a fix for me.
I have a teensy 3.2 which works fine with the 'bundled' MIDI library on Arduino 1.6.7 and teensyduino.
I need to have multiple midi instances (more than one uart connected din socket), so I've (temporarily) put MIDI 4.2 in my librarys folder.
I can get a clean compile of my sketch which runs just fine, except that it generates no activity on the serial port and responds to no input either.
Below are some fragments from the Midi 4.2 code. I've made one minor modification in order to try to see what's happening, some serial.print()s in the sending section.
Otherwise, it's all as is.
I have read posts that say the library on github doesn't work, but that a 'tagged' version does. I have downloaded and compared both, they are identical, so that didn't help.
This is driving me nuts.
This is a fragment from the top of Midi_defs.h
#pragma once
#include "midi_NamespacePW.h"
#include "HardwareSerial.h"
#if ARDUINO
#include <Arduino.h>
#else
#include <inttypes.h>
typedef uint8_t byte;
#endif
And later in midi_defs.h
/*! \brief Create an instance of the library attached to a serial port.
You can use HardwareSerial or SoftwareSerial for the serial port.
Example: MIDI_CREATE_INSTANCE(HardwareSerial, Serial2, midi2);
Then call midi2.begin(), midi2.read() etc..
*/
#define MIDI_CREATE_INSTANCE(Type, SerialPort, Name) \
midi::MidiInterface<Type> Name((Type&)SerialPort);
#if defined(ARDUINO_SAM_DUE) || defined(USBCON)
// Leonardo, Due and other USB boards use Serial1 by default.
#define MIDI_CREATE_DEFAULT_INSTANCE() \
MIDI_CREATE_INSTANCE(HardwareSerial, Serial1, MIDI);
#else
/*! \brief Create an instance of the library with default name, serial port
and settings, for compatibility with sketches written with pre-v4.2 MIDI Lib,
or if you don't bother using custom names, serial port or settings.
*/
#define MIDI_CREATE_DEFAULT_INSTANCE() \
MIDI_CREATE_INSTANCE(HardwareSerial, Serial, MIDI);
#endif
within midi.hpp the actual 'sending code' - I've added some serial.print()s to see if this is getting exected.
template<class SerialPort, class Settings>
void MidiInterface<SerialPort, Settings>::send(MidiType inType,
DataByte inData1,
DataByte inData2,
Channel inChannel)
{
// Then test if channel is valid
if (inChannel >= MIDI_CHANNEL_OFF ||
inChannel == MIDI_CHANNEL_OMNI ||
inType < 0x80)
{
if (Settings::UseRunningStatus)
{
mRunningStatus_TX = InvalidType;
}
Serial.println("Don't send");
return; // Don't send anything
}
if (inType <= PitchBend) // Channel messages
{
// Protection: remove MSBs on data
inData1 &= 0x7f;
inData2 &= 0x7f;
const StatusByte status = getStatus(inType, inChannel);
if (Settings::UseRunningStatus)
{
if (mRunningStatus_TX != status)
{
// New message, memorise and send header
mRunningStatus_TX = status;
mSerial.write(mRunningStatus_TX);
}
}
else
{
// Don't care about running status, send the status byte.
mSerial.write(status);
}
// Then send data
mSerial.write(inData1);
Serial.println("sending data1");
if (inType != ProgramChange && inType != AfterTouchChannel)
{
mSerial.write(inData2);
Serial.println("sending data2");
}
}
else if (inType >= TuneRequest && inType <= SystemReset)
{
sendRealTime(inType); // System Real-time and 1 byte.
}
}
I have a teensy 3.2 which works fine with the 'bundled' MIDI library on Arduino 1.6.7 and teensyduino.
I need to have multiple midi instances (more than one uart connected din socket), so I've (temporarily) put MIDI 4.2 in my librarys folder.
I can get a clean compile of my sketch which runs just fine, except that it generates no activity on the serial port and responds to no input either.
Below are some fragments from the Midi 4.2 code. I've made one minor modification in order to try to see what's happening, some serial.print()s in the sending section.
Otherwise, it's all as is.
I have read posts that say the library on github doesn't work, but that a 'tagged' version does. I have downloaded and compared both, they are identical, so that didn't help.
This is driving me nuts.
This is a fragment from the top of Midi_defs.h
#pragma once
#include "midi_NamespacePW.h"
#include "HardwareSerial.h"
#if ARDUINO
#include <Arduino.h>
#else
#include <inttypes.h>
typedef uint8_t byte;
#endif
And later in midi_defs.h
/*! \brief Create an instance of the library attached to a serial port.
You can use HardwareSerial or SoftwareSerial for the serial port.
Example: MIDI_CREATE_INSTANCE(HardwareSerial, Serial2, midi2);
Then call midi2.begin(), midi2.read() etc..
*/
#define MIDI_CREATE_INSTANCE(Type, SerialPort, Name) \
midi::MidiInterface<Type> Name((Type&)SerialPort);
#if defined(ARDUINO_SAM_DUE) || defined(USBCON)
// Leonardo, Due and other USB boards use Serial1 by default.
#define MIDI_CREATE_DEFAULT_INSTANCE() \
MIDI_CREATE_INSTANCE(HardwareSerial, Serial1, MIDI);
#else
/*! \brief Create an instance of the library with default name, serial port
and settings, for compatibility with sketches written with pre-v4.2 MIDI Lib,
or if you don't bother using custom names, serial port or settings.
*/
#define MIDI_CREATE_DEFAULT_INSTANCE() \
MIDI_CREATE_INSTANCE(HardwareSerial, Serial, MIDI);
#endif
within midi.hpp the actual 'sending code' - I've added some serial.print()s to see if this is getting exected.
template<class SerialPort, class Settings>
void MidiInterface<SerialPort, Settings>::send(MidiType inType,
DataByte inData1,
DataByte inData2,
Channel inChannel)
{
// Then test if channel is valid
if (inChannel >= MIDI_CHANNEL_OFF ||
inChannel == MIDI_CHANNEL_OMNI ||
inType < 0x80)
{
if (Settings::UseRunningStatus)
{
mRunningStatus_TX = InvalidType;
}
Serial.println("Don't send");
return; // Don't send anything
}
if (inType <= PitchBend) // Channel messages
{
// Protection: remove MSBs on data
inData1 &= 0x7f;
inData2 &= 0x7f;
const StatusByte status = getStatus(inType, inChannel);
if (Settings::UseRunningStatus)
{
if (mRunningStatus_TX != status)
{
// New message, memorise and send header
mRunningStatus_TX = status;
mSerial.write(mRunningStatus_TX);
}
}
else
{
// Don't care about running status, send the status byte.
mSerial.write(status);
}
// Then send data
mSerial.write(inData1);
Serial.println("sending data1");
if (inType != ProgramChange && inType != AfterTouchChannel)
{
mSerial.write(inData2);
Serial.println("sending data2");
}
}
else if (inType >= TuneRequest && inType <= SystemReset)
{
sendRealTime(inType); // System Real-time and 1 byte.
}
}