Refactoring to build on the new AVR core.

This commit is contained in:
Francois Best 2012-06-16 17:36:34 +02:00
parent 22218892c0
commit 3edb9c15ea
2 changed files with 21 additions and 22 deletions

View File

@ -9,7 +9,8 @@
*/ */
#include "MIDI.h" #include "MIDI.h"
#include "Serial.h" #include "core.h"
#include "hardware_Serial.h"
#include <stdlib.h> #include <stdlib.h>
@ -21,7 +22,7 @@ MIDI_Class MIDI;
MIDI_Class::MIDI_Class() MIDI_Class::MIDI_Class()
{ {
#if USE_CALLBACKS #if COMPILE_MIDI_IN && USE_CALLBACKS
// Initialise callbacks to NULL pointer // Initialise callbacks to NULL pointer
mNoteOffCallback = NULL; mNoteOffCallback = NULL;
@ -310,8 +311,7 @@ void MIDI_Class::sendPitchBend(double PitchValue,
byte Channel) byte Channel)
{ {
unsigned int pitchval = (PitchValue+1.f)*8192; int pitchval = PitchValue * MIDI_PITCHBEND_MAX;
if (pitchval > 16383) pitchval = 16383; // overflow protection
sendPitchBend(pitchval,Channel); sendPitchBend(pitchval,Channel);
} }
@ -528,16 +528,16 @@ bool MIDI_Class::read(const byte inChannel)
// Private method: MIDI parser // Private method: MIDI parser
bool MIDI_Class::parse(byte inChannel) bool MIDI_Class::parse(byte inChannel)
{ {
const byte bytes_available = MIDI_SERIAL_PORT.available();
const int bytes_available = MIDI_SERIAL_PORT.available(); if (bytes_available == 0)
if (bytes_available <= 0) {
// No data available. // No data available.
return false; return false;
}
// If the buffer is full -> Don't Panic! Call the Vogons to destroy it. // If the buffer is full -> Don't Panic! Call the Vogons to destroy it.
if (bytes_available == UART_BUFFER_SIZE) { Serial << "Overflow, call the Vogons!!" << endl; if (bytes_available == UART::bufferSize)
{
PRINT_DEBUG("MIDI Overflow");
MIDI_SERIAL_PORT.flush(); MIDI_SERIAL_PORT.flush();
} }
else { else {
@ -1184,5 +1184,3 @@ void MIDI_Class::thru_filter(byte inChannel)
#endif // Thru #endif // Thru

View File

@ -8,11 +8,10 @@
* license GPL Forty Seven Effects - 2011 * license GPL Forty Seven Effects - 2011
*/ */
#ifndef LIB_MIDI_H_ #ifndef _FSE_LIB_MIDI_H_
#define LIB_MIDI_H_ #define _FSE_LIB_MIDI_H_
#include "Types.h" // Include all the types we need.
#include "core_Types.h" // Include all the types we need.
/* /*
############################################################### ###############################################################
@ -58,7 +57,7 @@
#define MIDI_CHANNEL_OMNI 0 #define MIDI_CHANNEL_OMNI 0
#define MIDI_CHANNEL_OFF 17 // and over #define MIDI_CHANNEL_OFF 17 // and over
#define MIDI_SYSEX_ARRAY_SIZE 255 // Maximum size is 65535 bytes. #define MIDI_SYSEX_ARRAY_SIZE 128 // Maximum size is 65535 bytes.
#define MIDI_PITCHBEND_MIN -8192 #define MIDI_PITCHBEND_MIN -8192
#define MIDI_PITCHBEND_MAX 8191 #define MIDI_PITCHBEND_MAX 8191
@ -66,7 +65,8 @@
/*! Enumeration of MIDI types */ /*! Enumeration of MIDI types */
enum kMIDIType { enum kMIDIType
{
NoteOff = 0x80, ///< Note Off NoteOff = 0x80, ///< Note Off
NoteOn = 0x90, ///< Note On NoteOn = 0x90, ///< Note On
AfterTouchPoly = 0xA0, ///< Polyphonic AfterTouch AfterTouchPoly = 0xA0, ///< Polyphonic AfterTouch
@ -146,7 +146,7 @@ struct midimsg
See member descriptions to know how to use it, See member descriptions to know how to use it,
or check out the examples supplied with the library. or check out the examples supplied with the library.
*/ */
class MIDI_Class class MIDI_Class
{ {
public: public:
@ -252,9 +252,9 @@ private:
byte mRunningStatus_RX; byte mRunningStatus_RX;
byte mInputChannel; byte mInputChannel;
byte mPendingMessage[MIDI_SYSEX_ARRAY_SIZE]; byte mPendingMessage[3]; // SysEx are dumped into mMessage directly.
unsigned int mPendingMessageExpectedLenght; unsigned int mPendingMessageExpectedLenght;
unsigned int mPendingMessageIndex; // Extended to unsigned int for larger sysex payloads. unsigned int mPendingMessageIndex; // Extended to unsigned int for larger SysEx payloads.
midimsg mMessage; midimsg mMessage;
@ -339,7 +339,7 @@ private:
void thru_filter(byte inChannel); void thru_filter(byte inChannel);
bool mThruActivated; bool mThruActivated;
kThruFilterMode mThruFilterMode; kThruFilterMode mThruFilterMode;
#endif // Thru #endif // Thru
@ -347,4 +347,5 @@ private:
extern MIDI_Class MIDI; extern MIDI_Class MIDI;
#endif // LIB_MIDI_H_
#endif // _FSE_LIB_MIDI_H_