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@181
|
33 * Get received midi byte, 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@181
|
52 int writeMidiOut(short unsigned int* bytes, unsigned int length);
|
giuliomoro@181
|
53
|
giuliomoro@181
|
54 virtual ~Midi();
|
giuliomoro@181
|
55 static void midiInputLoop();
|
giuliomoro@181
|
56 static bool staticConstructed;
|
giuliomoro@181
|
57 static void staticConstructor();
|
giuliomoro@181
|
58 private:
|
giuliomoro@181
|
59 void readInputLoop();
|
giuliomoro@181
|
60 int outputPort;
|
giuliomoro@181
|
61 int inputPort;
|
giuliomoro@181
|
62 std::vector<midi_byte_t> inputBytes;
|
giuliomoro@181
|
63 unsigned int inputBytesWritePointer;
|
giuliomoro@181
|
64 unsigned int inputBytesReadPointer;
|
giuliomoro@181
|
65 std::vector<midi_byte_t> outputBytes;
|
giuliomoro@181
|
66 static std::vector<Midi*> objAddrs;
|
giuliomoro@181
|
67 static AuxiliaryTask midiInputTask;
|
giuliomoro@181
|
68 static AuxiliaryTask midiOutputTask;
|
giuliomoro@181
|
69 };
|
giuliomoro@181
|
70
|
giuliomoro@181
|
71
|
giuliomoro@181
|
72 #endif /* MIDI_H_ */
|