giuliomoro@181: /* giuliomoro@181: * Midi.h giuliomoro@181: * giuliomoro@181: * Created on: 15 Jan 2016 giuliomoro@181: * Author: giulio giuliomoro@181: */ giuliomoro@181: giuliomoro@181: #ifndef MIDI_H_ giuliomoro@181: #define MIDI_H_ giuliomoro@181: giuliomoro@181: #include giuliomoro@181: #include giuliomoro@181: giuliomoro@181: typedef unsigned char midi_byte_t; giuliomoro@181: giuliomoro@181: class Midi { giuliomoro@181: public: giuliomoro@181: Midi(); giuliomoro@181: /** giuliomoro@181: * Open the specified input Midi port and start reading from it. giuliomoro@181: * @param port Midi port to open giuliomoro@181: * @return 1 on success, -1 on failure giuliomoro@181: */ giuliomoro@181: int readFrom(int port); giuliomoro@181: /** giuliomoro@181: * Open the specified output Midi port and prepares to write to it. giuliomoro@181: * @param port Midi port to open giuliomoro@181: * @return 1 on success, -1 on failure giuliomoro@181: */ giuliomoro@181: int writeTo(int port); giuliomoro@181: giuliomoro@181: /** giuliomoro@181: * Get received midi byte, one at a time. giuliomoro@181: * @return -1 if no new byte is available, -2 on error, giuliomoro@181: * the oldest not yet retrieved midi byte otherwise giuliomoro@181: */ giuliomoro@181: int getInput(); giuliomoro@181: giuliomoro@181: /** giuliomoro@181: * Writes a Midi byte to the output port giuliomoro@181: * @param byte the Midi byte to write giuliomoro@181: * @return 1 on success, -1 on error giuliomoro@181: */ giuliomoro@181: int writeOutput(midi_byte_t byte); giuliomoro@181: giuliomoro@181: /** giuliomoro@181: * Writes Midi bytes to the output port giuliomoro@181: * @param bytes an array of bytes to be written giuliomoro@181: * @param length number of bytes to write giuliomoro@181: * @return 1 on success, -1 on error giuliomoro@181: */ giuliomoro@181: int writeMidiOut(short unsigned int* bytes, unsigned int length); giuliomoro@181: giuliomoro@181: virtual ~Midi(); giuliomoro@181: static void midiInputLoop(); giuliomoro@181: static bool staticConstructed; giuliomoro@181: static void staticConstructor(); giuliomoro@181: private: giuliomoro@181: void readInputLoop(); giuliomoro@181: int outputPort; giuliomoro@181: int inputPort; giuliomoro@181: std::vector inputBytes; giuliomoro@181: unsigned int inputBytesWritePointer; giuliomoro@181: unsigned int inputBytesReadPointer; giuliomoro@181: std::vector outputBytes; giuliomoro@181: static std::vector objAddrs; giuliomoro@181: static AuxiliaryTask midiInputTask; giuliomoro@181: static AuxiliaryTask midiOutputTask; giuliomoro@181: }; giuliomoro@181: giuliomoro@181: giuliomoro@181: #endif /* MIDI_H_ */