Mercurial > hg > beaglert
view include/Midi.h @ 181:391ad036557d
Basic Midi input implementation
author | Giulio Moro <giuliomoro@yahoo.it> |
---|---|
date | Fri, 15 Jan 2016 21:50:46 +0000 |
parents | |
children | b3a306da03e0 |
line wrap: on
line source
/* * Midi.h * * Created on: 15 Jan 2016 * Author: giulio */ #ifndef MIDI_H_ #define MIDI_H_ #include <BeagleRT.h> #include <vector> typedef unsigned char midi_byte_t; class Midi { public: Midi(); /** * Open the specified input Midi port and start reading from it. * @param port Midi port to open * @return 1 on success, -1 on failure */ int readFrom(int port); /** * Open the specified output Midi port and prepares to write to it. * @param port Midi port to open * @return 1 on success, -1 on failure */ int writeTo(int port); /** * Get received midi byte, one at a time. * @return -1 if no new byte is available, -2 on error, * the oldest not yet retrieved midi byte otherwise */ int getInput(); /** * Writes a Midi byte to the output port * @param byte the Midi byte to write * @return 1 on success, -1 on error */ int writeOutput(midi_byte_t byte); /** * Writes Midi bytes to the output port * @param bytes an array of bytes to be written * @param length number of bytes to write * @return 1 on success, -1 on error */ int writeMidiOut(short unsigned int* bytes, unsigned int length); virtual ~Midi(); static void midiInputLoop(); static bool staticConstructed; static void staticConstructor(); private: void readInputLoop(); int outputPort; int inputPort; std::vector<midi_byte_t> inputBytes; unsigned int inputBytesWritePointer; unsigned int inputBytesReadPointer; std::vector<midi_byte_t> outputBytes; static std::vector<Midi*> objAddrs; static AuxiliaryTask midiInputTask; static AuxiliaryTask midiOutputTask; }; #endif /* MIDI_H_ */