ofxPDSP
MidiIn.h
1 
2 // Input.h
3 // ofxPDSP
4 // Nicola Pisanti, MIT License, 2016
5 
6 #ifndef OFXPDSPMIDI_PDSPMIDIIN_H_INCLUDED
7 #define OFXPDSPMIDI_PDSPMIDIIN_H_INCLUDED
8 
9 #ifndef __ANDROID__
10 
11 #include "ofxMidi.h"
12 #include <chrono>
13 #include "helper/PositionedMidiMessage.h"
14 #include "../DSP/pdspCore.h"
15 
20 namespace pdsp { namespace midi {
21 
22 class Input : public ofxMidiListener, public pdsp::Preparable {
23 
24 public:
25  Input();
26  ~Input();
27 
28 
33  void openPort(int index);
34 
39  void openPort( std::string name );
40 
45  void openVirtualPort( std::string name );
46 
50  void closePort();
51 
55  void listPorts();
56 
60  int getPortCount();
61 
65  std::vector<std::string> getPortList();
66 
71  void linkToMidiIn(ofxMidiIn &midiInput);
72 
73 
77  void processMidi( const int &bufferSize ) noexcept;
78 
79  void newMidiMessage(ofxMidiMessage& eventArgs) noexcept override;
80 
81  const std::vector<_PositionedMidiMessage> & getMessageVector() const;
86 protected:
87  void prepareToPlay( int expectedBufferSize, double sampleRate ) override;
88  void releaseResources() override;
89 
90 private:
91 
92  ofxMidiIn midiIn;
93  ofxMidiIn* midiIn_p;
94 
95  std::atomic<int> index;
96  int lastread;
97  std::vector<_PositionedMidiMessage> circularBuffer;
98  std::vector<_PositionedMidiMessage> readVector;
99 
100  double oneSlashMicrosecForSample;
101  std::chrono::time_point<std::chrono::high_resolution_clock> bufferChrono;
102 
103  void pushToReadVector( _PositionedMidiMessage & message );
104 
105  bool connected;
106 
107  void initPort();
108 
109 };
110 
111 }}
112 
113 #endif
114 
115 #endif // OFXPDSPMIDI_PDSPMIDIIN_H_INCLUDED
Definition: MidiIn.h:22
int getPortCount()
return number of available midi in ports
Definition: MidiIn.cpp:76
void openVirtualPort(std::string name)
create a virtual input port with the given name
Definition: MidiIn.cpp:55
void linkToMidiIn(ofxMidiIn &midiInput)
uses an already open ofxMidiIn instead of opening a port
Definition: MidiIn.cpp:24
void openPort(int index)
open the port with the given index
Definition: MidiIn.cpp:43
void closePort()
close the opened port
Definition: MidiIn.cpp:61
std::vector< std::string > getPortList()
return list of available ports name
Definition: MidiIn.cpp:81
Thread-safe value control with smoothing.
Definition: SequencerBridge.h:11
void listPorts()
list the available ports
Definition: MidiIn.cpp:72
Definition: Preparable.h:36