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