annotate include/Midi.h @ 191:b3a306da03e0

Implemented Midi output
author Giulio Moro <giuliomoro@yahoo.it>
date Wed, 03 Feb 2016 01:18:30 +0000
parents 391ad036557d
children 265a527f8be8
rev   line source
giuliomoro@181 1 /*
giuliomoro@181 2 * Midi.h
giuliomoro@181 3 *
giuliomoro@181 4 * Created on: 15 Jan 2016
giuliomoro@181 5 * Author: giulio
giuliomoro@181 6 */
giuliomoro@181 7
giuliomoro@181 8 #ifndef MIDI_H_
giuliomoro@181 9 #define MIDI_H_
giuliomoro@181 10
giuliomoro@181 11 #include <BeagleRT.h>
giuliomoro@181 12 #include <vector>
giuliomoro@181 13
giuliomoro@181 14 typedef unsigned char midi_byte_t;
giuliomoro@181 15
giuliomoro@181 16 class Midi {
giuliomoro@181 17 public:
giuliomoro@181 18 Midi();
giuliomoro@181 19 /**
giuliomoro@181 20 * Open the specified input Midi port and start reading from it.
giuliomoro@181 21 * @param port Midi port to open
giuliomoro@181 22 * @return 1 on success, -1 on failure
giuliomoro@181 23 */
giuliomoro@181 24 int readFrom(int port);
giuliomoro@181 25 /**
giuliomoro@181 26 * Open the specified output Midi port and prepares to write to it.
giuliomoro@181 27 * @param port Midi port to open
giuliomoro@181 28 * @return 1 on success, -1 on failure
giuliomoro@181 29 */
giuliomoro@181 30 int writeTo(int port);
giuliomoro@181 31
giuliomoro@181 32 /**
giuliomoro@191 33 * Get received midi bytes, one at a time.
giuliomoro@181 34 * @return -1 if no new byte is available, -2 on error,
giuliomoro@181 35 * the oldest not yet retrieved midi byte otherwise
giuliomoro@181 36 */
giuliomoro@181 37 int getInput();
giuliomoro@181 38
giuliomoro@181 39 /**
giuliomoro@181 40 * Writes a Midi byte to the output port
giuliomoro@181 41 * @param byte the Midi byte to write
giuliomoro@181 42 * @return 1 on success, -1 on error
giuliomoro@181 43 */
giuliomoro@181 44 int writeOutput(midi_byte_t byte);
giuliomoro@181 45
giuliomoro@181 46 /**
giuliomoro@181 47 * Writes Midi bytes to the output port
giuliomoro@181 48 * @param bytes an array of bytes to be written
giuliomoro@181 49 * @param length number of bytes to write
giuliomoro@181 50 * @return 1 on success, -1 on error
giuliomoro@181 51 */
giuliomoro@191 52 int writeOutput(midi_byte_t* bytes, unsigned int length);
giuliomoro@181 53
giuliomoro@181 54 virtual ~Midi();
giuliomoro@181 55 static void midiInputLoop();
giuliomoro@191 56 static void midiOutputLoop();
giuliomoro@181 57 static bool staticConstructed;
giuliomoro@181 58 static void staticConstructor();
giuliomoro@181 59 private:
giuliomoro@181 60 void readInputLoop();
giuliomoro@191 61 void writeOutputLoop();
giuliomoro@181 62 int outputPort;
giuliomoro@181 63 int inputPort;
giuliomoro@181 64 std::vector<midi_byte_t> inputBytes;
giuliomoro@181 65 unsigned int inputBytesWritePointer;
giuliomoro@181 66 unsigned int inputBytesReadPointer;
giuliomoro@181 67 std::vector<midi_byte_t> outputBytes;
giuliomoro@191 68 unsigned int outputBytesWritePointer;
giuliomoro@191 69 unsigned int outputBytesReadPointer;
giuliomoro@191 70 static std::vector<Midi*> objAddrs[2];
giuliomoro@181 71 static AuxiliaryTask midiInputTask;
giuliomoro@181 72 static AuxiliaryTask midiOutputTask;
giuliomoro@181 73 };
giuliomoro@181 74
giuliomoro@181 75
giuliomoro@181 76 #endif /* MIDI_H_ */